Buffer Interface
BiDef.h
Go to the documentation of this file.
1 /**************************************************************************
2 *
3 * BiDef.h
4 *
5 * BufIn API
6 *
7 * Types and defines for Bi library
8 *
9 * Copyright (C) 1999 by BitFlow, Inc. All Rights Reserved.
10 *
11 * 06/25/99 sms created
12 *
13 **************************************************************************/
14 
15 #include "BFDef.h"
16 #include "CiApi.h"
17 #include <time.h>
18 #include "BFIODef.h"
19 
20 #if !defined(__BIDEF__)
21  #define __BIDEF__
22 
23 
24 #define MINWRKSIZE 0x1000000
25 #define PAGE_SIZE 0x1000
26 
27 
29 // Board Types
30 #define BiTypeR2 CISYS_TYPE_R2 // RoadRunner
31 #define BiTypeR64 CISYS_TYPE_R64 // R64
32 #define BiTypeGn2 CISYS_TYPE_GN2 // GN2
33 #define BiTypeAny 0xFFFFFFFF // First board seen in the system
34 
35 // return for BiErrorShow
36 #define BI_CANCEL 1
37 
38 
40 // Parameters for BiBrdInquire()
41 
42 // RoadRunner and Raven Parameters
43 #define BiBrdInqModel CiBrdInqModel // Return Board Model
44 #define BiBrdInqIDReg CiBrdInqIDReg // ID switch on the board
45 // RoadRunner Parameters
46 #define BiBrdInqSpeed CiBrdInqSpeed // Board receivers speed
47 #define BiBrdInqLUT CiBrdInqLUT // type of LUT mounted to the board
48 // Raven Parameters
49 #define BiBrdInqScanType CiBrdInqScanType // Scan type
50 #define BiBrdInqColorDecoder CiBrdInqColorDecoder // NTSC/PAL decoder
51 #define BiBrdInqAnalogType CiBrdInqAnalogType // analog video input board
52 #define BiBrdInqNumCams CiBrdInqNumCams // Number of cameras the board is setup for
53 
54 // RoadRunner and Raven Parameters
55 #define BiCamInqXSize CiCamInqXSize // Width of image in pixels
56 #define BiCamInqYSize0 CiCamInqYSize0 // Height of image in lines
57 #define BiCamInqFormat CiCamInqFormat // Image format
58 #define BiCamInqBitsPerPix CiCamInqPixBitDepth // Depth of pixel in bits, as acquired to host
59 #define BiCamInqBytesPerPix CiCamInqBytesPerPix // Depth of pixel in bytes, as acquired to host
60 #define BiCamInqAqTimeout CiCamInqAqTimeout // Number of mS to wait before Acq. command
61 #define BiCamInqFrameSize0 CiCamInqFrameSize0 // Total size of image in bytes, as acq. to host
62 #define BiCamInqFrameWidth CiCamInqFrameWidth // Width of image in bytes, as acq. to host
63 #define BiCamInqBytesPerPixDisplay CiCamInqBytesPerPixDisplay // Depth of pixel in bytes, as acq. to display
64 #define BiCamInqBitsPerPixDisplay CiCamInqPixBitDepthDisplay // Depth of pixel in bits, as acq. to display
65 #define BiCamInqDisplayFrameSize0 CiCamInqDisplayFrameSize0 // Total size of image in bytes, as acq. to display
66 #define BiCamInqDisplayFrameWidth CiCamInqDisplayFrameWidth // Width of image in bytes, as acq. to display
67 // RoadRunner Parameters will give an error for Raven
68 #define BiCamInqBitsPerSequence CiCamInqBitsPerSequence // Depth of multi-channel pixel in bits, as acq. to host
69 #define BiCamInqBitsPerSequenceDisplay CiCamInqBitsPerSequenceDisplay // Depth of multi-channel pixel in bits, as acq. to display
70 #define BiCamInqCamType CiCamInqCamType // Which camera type
71 #define BiCamInqControlType CiCamInqControlType // Type of camera control accessible through API
72 // Raven Parameters will give an error for RoadRunner
73 #define BiCamInqYSize1 CiCamInqYSize1 // Camera 1 height of image in lines
74 #define BiCamInqYSize2 CiCamInqYSize2 // Camera 2 height of image in lines
75 #define BiCamInqYSize3 CiCamInqYSize3 // Camera 3 height of image in lines
76 #define BiCamInqFrameSize1 CiCamInqFrameSize1 // Camera 1 total size of image in bytes, as acq. to host
77 #define BiCamInqFrameSize2 CiCamInqFrameSize2 // Camera 2 total size of image in bytes, as acq. to host
78 #define BiCamInqFrameSize3 CiCamInqFrameSize3 // Camera 3 total size of image in bytes, as acq. to host
79 #define BiCamInqPackedPixels CiCamInqPackedPixels // Packed Pixels
80 
81 
82 
84 // Parameters for Triggering Functions
85 
86 #define BiTrigFreeRun CiTrigFreeRun
87 #define BiTrigContinuousData CiTrigContinuousData
88 #define BiTrigOneShot CiTrigOneShot
89 #define BiTrigOneShotJbyAandKbyB 20
90 #define BiTrigOneShotStartStop 21
91 #define BiTrigOneShotSSJbyAandKbyB 22
92 #define BiTrigOneShotStartAStopB 23
93 #define BiTrigAqCmd CiTrigAqCmd
94 #define BiTrigAqCmdJbyAandKbyB 25
95 #define BiTrigAqCmdFreezeCmd CiTrigAqCmdStartStop
96 #define BiTrigAqCmdFrzCmdJbyAandKFree 26
97 #define BiTrigOneShotSelfTrig CiTrigOneShotSelfTriggered
98 #define BiTrigModeUnknown CiTrigModeUnknown
99 #define BiTrigOneShotStartAStopALevel CiTrigOneShotStartAStopALevel
100 #define BiTrigSnapQualified BFTrigSnapQualified
101 #define BiTrigNTGOneShot CiTrigNTGOneShot
102 
103 // For Polarity
104 #define BiTrigAssertedHigh 30
105 #define BiTrigAssertedLow 31
106 #define BiTrigAHighBLow 32
107 #define BiTrigALowBHigh 33
108 
109 // For BiTrigForce
110 #define BiTrigAssertTrigA 40
111 #define BiTrigAssertTrigB 41
112 #define BiTrigDeassertTrigA 42
113 #define BiTrigDeassertTrigB 43
114 
115 
117 // Compatibility for old defines
118 
119 #define BIRC BFRC
120 
122 // BiAqSetupSequence parameters
123 
124 // Options
125 #define BiAqEngJ 4
126 #define BiAqEngK 8
127 #define NoResetOnError 16
128 #define AbortMissedFrame 32
129 #define DisableAqErrorSig 64
130 #define UseHighResTimer 128
131 #define InvertEvenFrames 256
132 #define InvertOddFrames 512
133 #define OnlyOddLines 1024
134 #define OnlyEvenLines 2048
135 #define DestAddrIsPhys 4096
136 #define NonDefaultPitch 8192
137 
138 // BiSeqControl and BiCirControl options
139 #define BiWait 256
140 #define BiAsync 512
141 
142 
144 // Thread states
145 #define NormalAbort 2 // thread has been killed by normal means. ex. all buffers are in
146 #define ErrorAbort 3 // thread killed itself due to error
147 #define SignalCancel 4
148 
149 
150 
152 // BiSeqControl & BiCirControl parameters
153 #define BISTART 0
154 #define BISTOP 1
155 #define BIPAUSE 2
156 #define BIRESUME 3
157 #define BIABORT 4
158 
159 
160 
162 // BiDiskI/O paramenters
163 #define BIBMP 0
164 #define BITIF 1
165 #define BIAVI 2
166 #define BIRAW 3
167 
168 
170 // Options
171 #define SwapRGB SWAPRGB
172 #define Pack32to24Bit PACK32TO24BIT
173 
174 
175 
177 // Circular buffer error modes
178 #define CirErStop 0
179 #define CirErLast 1
180 #define CirErNew 2
181 #define CirErIgnore 3
182 
184 // How memory is allocated
185 #define BufferAlloc 0xf001
186 #define BufferAllocAligned 0xf002
187 #define BufferAssign 0xf003
188 
189 
191 // Curcular buffer status
192 #define BIAVAILABLE 0
193 #define BIFRESH 1
194 #define BINEW 2
195 #define BIHOLD 3
196 #define BIQUEUED 4
197 
198 #define AVAIL_Q_EMPTY 0xFFFFFFFF // the available queue is empty
199 
201 // Structures
202 
203 // This structure is used by BiSeqBufferStatus to get infomation
204 // about the image in the sequence of buffers.
205 typedef struct _BiSeqInfo
206 {
207  BFU32 FrameCount;
208  BFTimeStruct TimeStamp;
209  BFTime HiResTimeStamp;
210  BFU32 NumLinesAcquired;
211  BFU32 CXPSrcTag;
212  BFU32 CXPXOffset;
213  BFU32 CXPYOffset;
214 
216 
217 
218 // This structure is used for the internal queue. BFQNodes
219 // are placed and removed from the queue.
220 typedef struct _QueueNode
221 {
222  BFU32 Status;
223  PBFU32 pBuffer;
224  BFU32 FrameCount;
225  BFTimeStruct TimeStamp;
226  BFTime HiResTimeStamp;
227  BFU32 BufferNumber;
228  BFU32 NumLinesAcquired;
229  BFU32 NumItemsOnQueue;
230  struct _QueueNode *Next;
231 
232 }BFQNode, *PBFQNode;
233 
234 
236 // This sturcture is used as a parameter in BiCirWaitNext, BiCirMark,
237 // BiCirStatus and BiCirSetNext, to pass info about the linked list.
238 
239 typedef struct _BiCirHandle
240 {
241  PBFU32 pBufData; // A pointer to the image data buffer.
242  BFU32 FrameCount; // The frame count for a node in the link list.
243  BFTimeStruct TimeStamp;
244  BFTime HiResTimeStamp; // The time stamp of the acquired image.
245  BFU32 BufferNumber; // The buffer number the image is in.
246  BFU32 NumLinesAcquired;
247  BFU32 NumItemsOnQueue; // The number of frames that have not
248  // been remvoed from the buffer queue.
249  BFU32 CXPSrcTag;
250  BFU32 CXPXOffset;
251  BFU32 CXPYOffset;
252  PBFQNode pNode; // A pointer to the node in the linked list .
253 
255 
256 
257 typedef struct _BFBUFARY
258 {
259  // Set by BiAlloc()
260  BFU32 NumBuffers; // The number of buffers that have been allocated by BiAlloc()
261  BFU32 BufferSize; // The size of the each buffer that has be allocated
262  PBFU32 *BufferArry; // An array of pointers pointing to each of the buffers
263  PBFU32 BufferMem; // FrameSize * Number of buffers + Page size
264 
265  // Set by SeqParameters()
266  BFU32 StartFrame; // The first buffer to acquire into
267  BFU32 NumOfFrames; // The number of frame to acquire
268  BFU32 SkipFrames; // The number of frames to skip between captures
269 
270  // Used by Circular
271  BFU32 CirErrorMode; // CirErStop, CirErLast or CirErNew
272  PBFQNode BufinQHead; // Pointer to the first node in the bufin queue
273  PBFQNode BufinQTail; // Pointer to the last item in the bufin queue
274  PBFQNode BufinQRetrieve; // Points to the bufin node to be retrieved by BiCirWaitNext
275  PBFQNode BufinQStore; // Points to the next bufin node to stored data into
276  BFU32 BufinQCount; // Counts the number of items in the bufin queue
277  BFBOOL SIPEnabled; // TRUE <=> SIP is enabled
278  HANDLE StatusSetMutex; // Mutex to prevent multiple threads from entering the status set function.
279  HANDLE AvailQueueMutex; // Mutex to prevent muiltiple access to the available queue
280  HANDLE BufferQueueMutex; // Mutex around the get and set for the buffer queue
281  HANDLE BufferStatusMutex; // Mutex to prevent muiltiple access to buffer status
282  HANDLE ResetAcqMutex; // Mutex to provide sycronization between commands and resetting acquistion on errors.
283  PBFU32 HoldQueue; // A queue of the buffers being held
284  BFU32 HoldQStoreIndex; // Index to store hold buffers
285  BFU32 HoldQGetIndex; // Index to retrieve hold buffers
286  PBFU32 AvailableQueue; // The queue of available buffers
287  BFU32 AvailSIndex; // Index to store available buffers
288  BFU32 AvailRIndex; // Index to retrieve available buffers
289  BFU32 OverwriteFlag; // Flag to indicate that buffers were overwritten in CirErIgnore mode.
290  BFU32 BuffersFullSemCount; // Number of buffers queued by the BuffersFull Semaphore
291  BFU32 NumBuffersMinusHolds; // Number of buffers that are currently available
292 
293  // Used by Sequence and Circular
294  BFU32 FramesMissed; // The number of frames missed during acquisition
295  BFU32 FramesCaptured; // The number of frames acquired during acquisition
296  BFU32 AqSetupOptions; // (BiAqEngJ,BiAqEngK),(IgnoreOverflows,AbortOnError,DisableAqErrorSig)
297  BFU32 FrameCount; // Counts frames including frames not completed because of overflow or HW ex.
298  BFU32 NumLinesAcquired; // The number of lines that werer acquired. Most times the ysize except for start/stop.
299  BFU32 BufferIndex; // The buffer currently being acquired into
300  BFBOOL IsResetting; // TRUE <=> Resetting acquisition
301 
302  // Used by Sequence
303  PBiSeqInfo pSeqInfoMem; // Pointer to the start of the block of memory used for buffer info.
304  PBiSeqInfo* SeqInfoArray; // Pointer to the sequence buffer info array;
305 
306  // Info for worker threads
307  Bd hBoard; // Board handle
308  RQTabHeadPtr QtabArray; // The array of QTABs
309  RQTabHeadPtrPtr QtabPtrArray;
310  CiSIGNAL Signal, StartStopSignal; // Signals for end of quad
311  CiSIGNAL ExceptionSignal; // Signals hardware exceptions
312  CiSIGNAL OverflowSignal; // Signals FIFO Overflow
313  BFU32 PrevIntCount; // Holds the previous interrupt count used in calculating missed frames in cicular mode.
314 
315  // Semaphore handles
316  HANDLE NotifyAqStart; // Semaphore to tell that Aq. has been started
317 
318  // These handles are used to communicate with BiSeqWaitDone
319  HANDLE BuffersFull; // Semaphore to tell us when the seq. capture is complete
320  HANDLE NotifyWaitDoneStop; // Semaphore to tell that Aq. has been stopped
321  HANDLE NotifyWaitDoneAbort; // Semaphore to tell that Aq. has been aborted
322  HANDLE WaitDoneArray[4]; // Waits for Abort, Stop, or Aq. complete in BiSeqWaitDone
323  HANDLE ThreadError; // Semaphore to tell when an error from any of the worker theads have occured
324  HANDLE ErrorWaitArray[4]; // Waits for a thread error, overflow or HW exception in InternalErrorWaitThread
325  BFU32 NumErr; // Number of ErrorWait handles
326 
327 
328  // These handle are used to communicate with BiSeqControl and BiCirControl
329  HANDLE NotifyControlStop; // Tells Bi*Control that acquisition has stopped
330  HANDLE NotifyControlAbort; // Tells Bi*Control that acquisition has aborted
331  HANDLE NotifyControlResume; // Tells Bi*Control that acquisition has resumed
332  HANDLE NotifyControlPause; // Tells Bi*Control that acquisition has paused
333 
334  HANDLE ErrorNotify; // Notifies BiSeqErrorWait that an error has occured
335  HANDLE WorkerThreadHandle; // Handle to the worker thread.
336  HANDLE ErrorThreadHandle; // Handle to the internal error thread.
337  HANDLE FrameDone; // Semaphore to tell when a frame has been acquired
338 
339  // Flags
340  BFBOOL AqPause; // Sequence Acquisition will pause when TRUE.
341  BFBOOL AqStop; // Flag to know that the acquisition was stopped
342  BFBOOL AqAbort; // Flag to know that the acquisition was aborted
343  BFBOOL AqStart; // Flag to know that the acquisition was started
344  BFU32 IsSeqBufStat; // Flag to know when calling BiSeqBufferStatus if valid.
345  BFBOOL Cleanedup; // Flag for SeqWaitError to exit function
346  BFBOOL HaveSignal; // Tells whether we created the signal
347  BFBOOL HaveStartStopSignal; // Tells whether were using start/stop or not
348  BFBOOL HaveExceptionSignal; // Tells whether we created the exception signal
349  BFBOOL HaveOverflowSignal; // Tells whether we created the overflow signal
350  BFBOOL CirBuffers; // True if using circular buffers
351  BFU32 MemoryAllocStatus; // Status of buffer memory:
352  // BufferAlloc <=> BiBufferAllocCam/BiBufferAlloc
353  // BufferAllocAligned <=> BiBufferAllocAlignedCam
354  // BufferAssign <=> BiBufferAssign
355 
356  // Error stack info
357  PBFU32 ErrorStack; // Pointer to the current entry in the stack
358  PBFU32 StackTop; // Top of the error stack
359  PBFU32 StackBot; // Bottom of the error stack
360 
361  // Handles to communicate with BiSeqWaitDoneFrame
362  HANDLE FrameDoneArray[4]; // Waits for Abort, Stop, or Aq. complete in BiSeqWaitDoneFrame
363  HANDLE FrameDoneStop; // Let BiSeqWaitDoneFrame know that Aq. has been stopped
364  HANDLE FrameDoneAbort; // Let BiSeqWaitDoneFrame know that Aq. has been aborted
365 
366  // For time stamping
367  BFTime InitTime; // Initilized time for high res time stamp.
368  BFBOOL UsingHiResTimer; // TRUE <=> Use high resolution timer
369  BFU64 LastIntTime; // The last hi res time stamp from the ISR
370  BFU32 CXPSrcTag; // Source Tag of this frame (CXP only in continuous image header record mode)
371  BFU32 CXPXOffset; // XOffset of this frame (CXP only in continuous image header record mode)
372  BFU32 CXPYOffset; // XOffset of this frame (CXP only in continuous image header record mode)
373 
374  // Call back Stuff
375  BFU32 State; // The state of the call back management thread
376  HANDLE Thread; // Handle to call back management thread
377  PBFVOID FuncPtr; // Call back function pointer
378  HANDLE SemHandle; // Handle to semaphore used to manage call back thread
379  PBFVOID pUserData; // Pointer to user defined structure
380 
381  // Pitch stuff
382  BFU32 Pitch; // Set to non-zero to use the non-default pitch
383 
384 }BIBA, *PBIBA;
385 
386 
387 typedef struct _BiErrors
388 {
389  int ErrorCode;
390  char FuncName[128];
391  char FailureDescript[256];
392 
393 }BiErrors;
394 
395 
396 // Call Back function pointer
397 typedef void (*BiCallBackFuncPtr) (Bd Board, PBIBA pBufArray, BiCirHandle CirHandle, PBFVOID pUserData);
398 
399 
400 #endif // __BIDEF__
struct _BiCirHandle BiCirHandle
void(* BiCallBackFuncPtr)(Bd Board, PBIBA pBufArray, BiCirHandle CirHandle, PBFVOID pUserData)
Definition: BiDef.h:397
struct _QueueNode BFQNode
struct _BiCirHandle * PBiCirHandle
unsigned long BFU32
Definition: BFTypeNT.h:55
unsigned long long BFU64
Definition: BFTypeNT.h:53
struct _QueueNode * PBFQNode
struct _BFBUFARY * PBIBA
unsigned long * PBFU32
Definition: BFTypeNT.h:55
struct _BiSeqInfo BiSeqInfo
struct _BiErrors BiErrors
void *** Bd
Definition: BFType.h:88
void * PBFVOID
Definition: BFTypeNT.h:32
struct _BiSeqInfo * PBiSeqInfo
struct _BFBUFARY BIBA
int BFBOOL
Definition: BFTypeNT.h:34