private.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #ifndef _IPECAMERA_PRIVATE_H
  2. #define _IPECAMERA_PRIVATE_H
  3. #include <pthread.h>
  4. #include <pcilib/model.h>
  5. #include "ipecamera.h"
  6. //#define IPECAMERA_BUG_EXTRA_DATA
  7. #define IPECAMERA_BUG_MULTIFRAME_PACKETS //**< this is by design, start of packet comes directly after the end of last one in streaming mode */
  8. //#define IPECAMERA_BUG_INCOMPLETE_PACKETS
  9. #define IPECAMERA_BUG_POSTPONED_READ
  10. #define IPECAMERA_DEBUG_BROKEN_FRAMES "/mnt/frames"
  11. //#define IPECAMERA_DEBUG_RAW_PACKETS "/mnt/frames"
  12. //#define IPECAMERA_ANNOUNCE_READY //**< announce new event only after the reconstruction is done */
  13. #define IPECAMERA_REGISTER_TIMEOUT 10000 //**< us */
  14. #define IPECAMERA_DMA_TIMEOUT 50000 //**< us */
  15. #define IPECAMERA_DEFAULT_BUFFER_SIZE 64 //**< should be power of 2 */
  16. #define IPECAMERA_RESERVE_BUFFERS 2 //**< Return Frame is Lost error, if requested frame will be overwritten after specified number of frames
  17. #define IPECAMERA_SLEEP_TIME 250000 //**< Michele thinks 250 should be enough, but reset failing in this case */
  18. #define IPECAMERA_NEXT_FRAME_DELAY 1000 //**< Michele requires 30000 to sync between End Of Readout and next Frame Req */
  19. #define IPECAMERA_WAIT_FRAME_RCVD_TIME 0 //**< by Uros ,wait 6 ms */
  20. #define IPECAMERA_TRIGGER_WAIT_IDLE 200000 //**< In trigger call allow specified timeout for camera to get out of busy state. Set 0 to fail immideatly */
  21. #define IPECAMERA_READ_STATUS_DELAY 1000 //**< According to Uros, 1ms delay needed before consequitive reads from status registers */
  22. #define IPECAMERA_NOFRAME_SLEEP 100
  23. #define IPECAMERA_NOFRAME_PREPROC_SLEEP 100
  24. //#define IPECAMERA_MAX_LINES 1088
  25. #define IPECAMERA_MAX_LINES 2048
  26. #define IPECAMERA_EXPECTED_STATUS_4 0x08409FFFF
  27. #define IPECAMERA_EXPECTED_STATUS 0x08449FFFF
  28. #define IPECAMERA_END_OF_SEQUENCE 0x1F001001
  29. #define IPECAMERA_MAX_CHANNELS 16
  30. #define IPECAMERA_PIXELS_PER_CHANNEL 128
  31. #define IPECAMERA_WIDTH (IPECAMERA_MAX_CHANNELS * IPECAMERA_PIXELS_PER_CHANNEL)
  32. #define IPECAMERA_FRAME_REQUEST 0x80000209 // 0x1E9
  33. #define IPECAMERA_IDLE 0x80000201 // 0x1E1
  34. #define IPECAMERA_START_INTERNAL_STIMULI 0x1F1
  35. #define IPECAMERA_MODE_16_CHAN_IO 0
  36. #define IPECAMERA_MODE_4_CHAN_IO 2
  37. #define IPECAMERA_MODE_12_BIT_ADC 2
  38. #define IPECAMERA_MODE_11_BIT_ADC 1
  39. #define IPECAMERA_MODE_10_BIT_ADC 0
  40. typedef uint32_t ipecamera_payload_t;
  41. typedef struct {
  42. pcilib_event_id_t evid;
  43. struct timeval timestamp;
  44. } ipecamera_autostop_t;
  45. typedef struct {
  46. size_t i;
  47. pthread_t thread;
  48. ipecamera_t *ipecamera;
  49. int started; /**< flag indicating that join & cleanup is required */
  50. } ipecamera_preprocessor_t;
  51. typedef struct {
  52. ipecamera_event_info_t event; /**< this structure is overwritten by the reader thread, we need a copy */
  53. pthread_rwlock_t mutex; /**< this mutex protects reconstructed buffers only, the raw data, event_info, etc. will be overwritten by reader thread anyway */
  54. } ipecamera_frame_t;
  55. struct ipecamera_s {
  56. pcilib_context_t event;
  57. UfoDecoder *ipedec;
  58. char *data;
  59. ipecamera_pixel_t *image;
  60. size_t size;
  61. pcilib_event_callback_t cb;
  62. void *cb_user;
  63. volatile pcilib_event_id_t event_id;
  64. volatile pcilib_event_id_t preproc_id;
  65. pcilib_event_id_t reported_id;
  66. pcilib_dma_engine_t rdma, wdma;
  67. pcilib_register_t packet_len_reg;
  68. pcilib_register_t control_reg, status_reg;
  69. pcilib_register_t status2_reg, status3_reg;
  70. pcilib_register_t n_lines_reg;
  71. uint16_t line_reg;
  72. pcilib_register_t exposure_reg;
  73. pcilib_register_t flip_reg;
  74. pcilib_register_t firmware_version_reg;
  75. pcilib_register_t adc_resolution_reg;
  76. pcilib_register_t output_mode_reg;
  77. pcilib_register_t max_frames_reg;
  78. pcilib_register_t num_frames_reg;
  79. int started; /**< Camera is in grabbing mode (start function is called) */
  80. int streaming; /**< Camera is in streaming mode (we are within stream call) */
  81. int parse_data; /**< Indicates if some processing of the data is required, otherwise only rawdata_callback will be called */
  82. volatile int run_reader; /**< Instructs the reader thread to stop processing */
  83. volatile int run_streamer; /**< Indicates request to stop streaming events and can be set by reader_thread upon exit or by user request */
  84. volatile int run_preprocessors; /**< Instructs preprocessors to exit */
  85. ipecamera_autostop_t autostop;
  86. struct timeval autostop_time;
  87. struct timeval next_trigger; /**< The minimal delay between trigger signals is mandatory, this indicates time when next trigger is possible */
  88. size_t buffer_size; /**< How many images to store */
  89. size_t buffer_pos; /**< Current image offset in the buffer, due to synchronization reasons should not be used outside of reader_thread */
  90. size_t cur_size; /**< Already written part of data in bytes */
  91. size_t raw_size; /**< Expected maximum size of raw data in bytes */
  92. size_t full_size; /**< Expected maximum size of raw data including the padding */
  93. size_t padded_size; /**< Expected maximum size of buffer for raw data, including additional padding due to the ipecamera bugs */
  94. size_t cur_raw_size; /**< Expected size (for currently configured ROI) of raw data in bytes */
  95. size_t cur_full_size; /**< Expected size (for currently configured ROI) of raw data including the padding */
  96. size_t cur_padded_size; /**< Expected size (for currently configured ROI) of buffer for raw data, including additional padding due to the ipecamera bugs */
  97. size_t image_size; /**< Size of a single image in bytes */
  98. size_t max_frames; /**< Maximal number of frames what may be buffered in camera DDR memory */
  99. int firmware; /**< Firmware version */
  100. int cmosis_outputs; /**< Number of active cmosis outputs: 4 or 16 */
  101. int width, height;
  102. // void *raw_buffer;
  103. void *buffer;
  104. ipecamera_change_mask_t *cmask;
  105. ipecamera_frame_t *frame;
  106. ipecamera_image_dimensions_t dim;
  107. pthread_t rthread;
  108. size_t n_preproc;
  109. ipecamera_preprocessor_t *preproc;
  110. pthread_mutex_t preproc_mutex;
  111. int preproc_mutex_destroy;
  112. int frame_mutex_destroy;
  113. };
  114. #endif /* _IPECAMERA_PRIVATE_H */