#ifndef _PCIDEV_PRIVATE_H #define _PCIDEV_PRIVATE_H #include #include #include #include #include "events.h" #include "pcidev.h" #include "env.h" #define PCIDEV_DEBUG #ifdef PCIDEV_DEBUG # define PCIDEV_DEBUG_RAW_FRAMES //**< Store all raw frames */ # define IPECAMERA_DEBUG_BROKEN_FRAMES //**< Store broken frames in the specified directory */ # define PCIDEV_DEBUG_RAW_PACKETS //**< Store all raw packets read from DMA grouped in frames */ # define PCIDEV_DEBUG_HARDWARE //**< Produce various debugging information about pcidev operation */ # define IPECAMERA_DEBUG_FRAME_HEADERS //**< Print frame headers & footers */ # define PCIDEV_DEBUG_API //**< Debug IPECamera API calls */ #endif /* PCIDEV_DEBUG */ #define PCIDEV_DEFAULT_BUFFER_SIZE 256 //**< number of buffers in a ring buffer, should be power of 2 */ #define PCIDEV_INTEGRATION_PERIOD 5 //**< the duration of integration period, in microseconds */ #define PCIDEV_EVENT_SIZE 256 //**< the size of event data in bytes, always 256 in this example */ #define PCIDEV_NOEVENT_SLEEP 100 //**< Sleep while polling for a new frame in reader */ #define PCIDEV_DMA_TIMEOUT 50000 //**< Default DMA timeout in microseconds */ #ifdef PCIDEV_DEBUG_RAW_FRAMES # define PCIDEV_DEBUG_RAW_FRAMES_MESSAGE(function, ...) if (pcidev_getenv(function##_ENV, #function)) { pcilib_debug_message (#function, __FILE__, __LINE__, __VA_ARGS__); } # define PCIDEV_DEBUG_RAW_FRAMES_BUFFER(function, ...) if (pcidev_getenv(function##_ENV, #function)) { pcilib_debug_data_buffer (#function, __VA_ARGS__); } #else /* PCIDEV_DEBUG_RAW_FRAMES */ # define PCIDEV_DEBUG_RAW_FRAMES_MESSAGE(function, ...) # define PCIDEV_DEBUG_RAW_FRAMES_BUFFER(function, ...) #endif /* PCIDEV_DEBUG_RAW_FRAMES */ #ifdef IPECAMERA_DEBUG_BROKEN_FRAMES # define IPECAMERA_DEBUG_BROKEN_FRAMES_MESSAGE(function, ...) if (pcidev_getenv(function##_ENV, #function)) { pcilib_debug_message (#function, __FILE__, __LINE__, __VA_ARGS__); } # define IPECAMERA_DEBUG_BROKEN_FRAMES_BUFFER(function, ...) if (pcidev_getenv(function##_ENV, #function)) { pcilib_debug_data_buffer (#function, __VA_ARGS__); } #else /* IPECAMERA_DEBUG_BROKEN_FRAMES */ # define IPECAMERA_DEBUG_BROKEN_FRAMES_MESSAGE(function, ...) # define IPECAMERA_DEBUG_BROKEN_FRAMES_BUFFER(function, ...) #endif /* IPECAMERA_DEBUG_BROKEN_FRAMES */ #ifdef PCIDEV_DEBUG_RAW_PACKETS # define PCIDEV_DEBUG_RAW_PACKETS_MESSAGE(function, ...) if (pcidev_getenv(function##_ENV, #function)) { pcilib_debug_message (#function, __FILE__, __LINE__, __VA_ARGS__); } # define PCIDEV_DEBUG_RAW_PACKETS_BUFFER(function, ...) if (pcidev_getenv(function##_ENV, #function)) { pcilib_debug_data_buffer (#function, __VA_ARGS__); } #else /* PCIDEV_DEBUG_RAW_PACKETS */ # define PCIDEV_DEBUG_RAW_PACKETS_MESSAGE(function, ...) # define PCIDEV_DEBUG_RAW_PACKETS_BUFFER(function, ...) #endif /* PCIDEV_DEBUG_RAW_PACKETS */ #ifdef PCIDEV_DEBUG_HARDWARE # define PCIDEV_DEBUG_HARDWARE_MESSAGE(function, ...) if (pcidev_getenv(function##_ENV, #function)) { pcilib_debug_message (#function, __FILE__, __LINE__, __VA_ARGS__); } # define PCIDEV_DEBUG_HARDWARE_BUFFER(function, ...) if (pcidev_getenv(function##_ENV, #function)) { pcilib_debug_data_buffer (#function, __VA_ARGS__); } #else /* PCIDEV_DEBUG_HARDWARE */ # define PCIDEV_DEBUG_HARDWARE_MESSAGE(function, ...) # define PCIDEV_DEBUG_HARDWARE_BUFFER(function, ...) #endif /* PCIDEV_DEBUG_HARDWARE */ #ifdef PCIDEV_DEBUG_FRAME_HEADERS # define PCIDEV_DEBUG_FRAME_HEADERS_MESSAGE(function, ...) if (pcidev_getenv(function##_ENV, #function)) { pcilib_debug_message (#function, __FILE__, __LINE__, __VA_ARGS__); } # define PCIDEV_DEBUG_FRAME_HEADERS_BUFFER(function, ...) if (pcidev_getenv(function##_ENV, #function)) { pcilib_debug_data_buffer (#function, __VA_ARGS__); } #else /* PCIDEV_DEBUG_RAW_FRAMES */ # define PCIDEV_DEBUG_FRAME_HEADERS_MESSAGE(function, ...) # define PCIDEV_DEBUG_FRAME_HEADERS_BUFFER(function, ...) #endif /* PCIDEV_DEBUG_RAW_FRAMES */ #ifdef PCIDEV_DEBUG_API # define PCIDEV_DEBUG_API_MESSAGE(function, ...) if (pcidev_getenv(function##_ENV, #function)) { pcilib_debug_message (#function, __FILE__, __LINE__, __VA_ARGS__); } # define PCIDEV_DEBUG_API_BUFFER(function, ...) if (pcidev_getenv(function##_ENV, #function)) { pcilib_debug_data_buffer (#function, __VA_ARGS__); } #else /* PCIDEV_DEBUG_API */ # define PCIDEV_DEBUG_API_MESSAGE(function, ...) # define PCIDEV_DEBUG_API_BUFFER(function, ...) #endif /* PCIDEV_DEBUG_API */ #define pcidev_debug(function, ...) \ PCIDEV_DEBUG_##function##_MESSAGE(PCIDEV_DEBUG_##function, PCILIB_LOG_DEFAULT, __VA_ARGS__) #define pcidev_debug_buffer(function, ...) \ PCIDEV_DEBUG_##function##_BUFFER(PCIDEV_DEBUG_##function, __VA_ARGS__) typedef uint32_t pcidev_payload_t; typedef struct { pcilib_event_id_t evid; struct timeval timestamp; } pcidev_autostop_t; typedef struct { pcidev_event_info_t event; /**< this structure is overwritten by the reader thread, we need a copy */ pthread_rwlock_t mutex; /**< this mutex protects reconstructed buffers only, the raw data, event_info, etc. will be overwritten by reader thread anyway */ } pcidev_event_t; struct pcidev_s { pcilib_context_t pcictx; pcilib_lock_t *run_lock; /**< Lock protecting global camera operation */ pcilib_lock_t *stream_lock; /**< Lock protecting stream/next_frame operations */ pcilib_lock_t *trigger_lock; /**< Lock protecting stream/next_frame operations */ int run_locked; /**< Flag indicating if camera is currently locked */ int stream_locked; /**< Flag indicating if camera is currently locked */ int trigger_locked; /**< Flag indicating if camera is currently locked */ char *data; size_t size; volatile pcilib_event_id_t event_id; volatile pcilib_event_id_t preproc_id; pcilib_event_id_t reported_id; pcilib_dma_engine_t rdma; int started; /**< Camera is in grabbing mode (start function is called) */ int streaming; /**< Camera is in streaming mode (we are within stream call) */ int process_data; /**< Indicates if some processing of the data is required, otherwise only rawdata_callback will be called */ volatile int run_streamer; /**< Indicates request to stop streaming events and can be set by reader_thread upon exit or by user request */ pcidev_autostop_t autostop; struct timeval eio_timestamp; size_t buffer_size; /**< How many images to store */ size_t buffer_pos; /**< Current image offset in the buffer, due to synchronization reasons should not be used outside of reader_thread */ size_t event_size; /**< Size of raw event data in bytes */ void *buffer; /**< Ring buffer for event data. Here we consider only a single type of events */ pcidev_event_t *event; /**< Description of events. */ int event_mutex_destroy; }; #endif /* _PCIDEV_PRIVATE_H */