/alps/ipecamera

To get this branch, use:
bzr branch http://darksoft.org/webbzr/alps/ipecamera

« back to all changes in this revision

Viewing changes to private.h

  • Committer: Suren A. Chilingaryan
  • Date: 2015-07-23 16:36:04 UTC
  • Revision ID: csa@suren.me-20150723163604-5ot6xjmom62zbosy
Support for new CMOSIS 20MPix camera

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
#include <pcilib/model.h>
6
6
#include <pcilib/debug.h>
7
7
#include "ipecamera.h"
 
8
#include "env.h"
8
9
 
9
10
#define IPECAMERA_DEBUG
10
11
#ifdef IPECAMERA_DEBUG
12
13
# define IPECAMERA_DEBUG_BROKEN_FRAMES          //**< Store broken frames in the specified directory */
13
14
# define IPECAMERA_DEBUG_RAW_PACKETS            //**< Store all raw packets read from DMA grouped in frames */
14
15
# define IPECAMERA_DEBUG_HARDWARE               //**< Produce various debugging information about ipecamera operation */
 
16
# define IPECAMERA_DEBUG_FRAME_HEADERS          //**< Print frame headers & footers */
15
17
#endif /* IPECAMERA_DEBUG */
16
18
 
17
 
//#define IPECAMERA_BUG_MISSING_PAYLOAD         //**< CMOSIS fails to provide a first payload for each frame, therefore the frame is 32 bit shorter */
 
19
#define IPECAMERA_BUG_MISSING_PAYLOAD           //**< CMOSIS fails to provide a first payload for each frame, therefore the frame is 32 bit shorter */
18
20
#define IPECAMERA_BUG_MULTIFRAME_PACKETS        //**< This is by design, start of packet comes directly after the end of last one in streaming mode */
19
21
//#define IPECAMERA_BUG_INCOMPLETE_PACKETS      //**< Support incomplete packets, i.e. check for frame magic even if full frame size is not reached yet (slow) */
20
22
//#define IPECAMERA_ANNOUNCE_READY              //**< Announce new event only after the reconstruction is done */
35
37
#define IPECAMERA_NOFRAME_SLEEP 100             //**< Sleep while polling for a new frame in reader */
36
38
#define IPECAMERA_NOFRAME_PREPROC_SLEEP 100     //**< Sleep while polling for a new frame in pre-processor */
37
39
 
38
 
//#define IPECAMERA_MAX_LINES 1088
39
 
#define IPECAMERA_MAX_LINES 2048
40
40
#define IPECAMERA_EXPECTED_STATUS_4 0x08409FFFF
41
41
#define IPECAMERA_EXPECTED_STATUS 0x08449FFFF
42
42
 
43
43
#define IPECAMERA_END_OF_SEQUENCE 0x1F001001
44
44
 
45
 
#define IPECAMERA_MAX_CHANNELS 16
46
 
#define IPECAMERA_PIXELS_PER_CHANNEL 128
47
 
#define IPECAMERA_WIDTH (IPECAMERA_MAX_CHANNELS * IPECAMERA_PIXELS_PER_CHANNEL)
 
45
 
 
46
#define CMOSIS_FRAME_HEADER_SIZE        8 * sizeof(ipecamera_payload_t)
 
47
#define CMOSIS_FRAME_TAIL_SIZE          8 * sizeof(ipecamera_payload_t)
 
48
 
 
49
#define CMOSIS_MAX_CHANNELS 16
 
50
#define CMOSIS_PIXELS_PER_CHANNEL 128
 
51
#define CMOSIS_WIDTH (CMOSIS_MAX_CHANNELS * CMOSIS_PIXELS_PER_CHANNEL)
 
52
//#define IPECAMERA_MAX_LINES 1088
 
53
#define CMOSIS_MAX_LINES 2048
 
54
#define CMOSIS20_MAX_CHANNELS 8
 
55
#define CMOSIS20_PIXELS_PER_CHANNEL 640
 
56
#define CMOSIS20_WIDTH (CMOSIS20_MAX_CHANNELS * CMOSIS20_PIXELS_PER_CHANNEL)
 
57
#define CMOSIS20_MAX_LINES 3840
48
58
 
49
59
#define IPECAMERA_FRAME_REQUEST                 0x80000209 // 0x1E9
50
60
#define IPECAMERA_IDLE                          0x80000201 // 0x1E1
57
67
#define IPECAMERA_MODE_11_BIT_ADC               1
58
68
#define IPECAMERA_MODE_10_BIT_ADC               0
59
69
 
 
70
 
60
71
#ifdef IPECAMERA_DEBUG_RAW_FRAMES
61
 
# define IPECAMERA_DEBUG_RAW_FRAMES_MESSAGE(function, ...) pcilib_debug_message (#function, __FILE__, __LINE__, __VA_ARGS__) 
62
 
# define IPECAMERA_DEBUG_RAW_FRAMES_BUFFER(function, ...) pcilib_debug_data_buffer (#function, __VA_ARGS__) 
 
72
# define IPECAMERA_DEBUG_RAW_FRAMES_MESSAGE(function, ...)  if (ipecamera_getenv(function##_ENV, #function)) { pcilib_debug_message (#function, __FILE__, __LINE__, __VA_ARGS__); }
 
73
# define IPECAMERA_DEBUG_RAW_FRAMES_BUFFER(function, ...)  if (ipecamera_getenv(function##_ENV, #function)) { pcilib_debug_data_buffer (#function, __VA_ARGS__); }
63
74
#else /* IPECAMERA_DEBUG_RAW_FRAMES */
64
75
# define IPECAMERA_DEBUG_RAW_FRAMES_MESSAGE(function, ...)
65
76
# define IPECAMERA_DEBUG_RAW_FRAMES_BUFFER(function, ...)
66
77
#endif /* IPECAMERA_DEBUG_RAW_FRAMES */
67
78
 
68
79
#ifdef IPECAMERA_DEBUG_BROKEN_FRAMES
69
 
# define IPECAMERA_DEBUG_BROKEN_FRAMES_MESSAGE(function, ...) pcilib_debug_message (#function, __FILE__, __LINE__, __VA_ARGS__) 
70
 
# define IPECAMERA_DEBUG_BROKEN_FRAMES_BUFFER(function, ...) pcilib_debug_data_buffer (#function, __VA_ARGS__) 
 
80
# define IPECAMERA_DEBUG_BROKEN_FRAMES_MESSAGE(function, ...) if (ipecamera_getenv(function##_ENV, #function)) { pcilib_debug_message (#function, __FILE__, __LINE__, __VA_ARGS__); }
 
81
# define IPECAMERA_DEBUG_BROKEN_FRAMES_BUFFER(function, ...) if (ipecamera_getenv(function##_ENV, #function)) { pcilib_debug_data_buffer (#function, __VA_ARGS__); }
71
82
#else /* IPECAMERA_DEBUG_BROKEN_FRAMES */
72
83
# define IPECAMERA_DEBUG_BROKEN_FRAMES_MESSAGE(function, ...)
73
84
# define IPECAMERA_DEBUG_BROKEN_FRAMES_BUFFER(function, ...)
74
85
#endif /* IPECAMERA_DEBUG_BROKEN_FRAMES */
75
86
 
76
87
#ifdef IPECAMERA_DEBUG_RAW_PACKETS
77
 
# define IPECAMERA_DEBUG_RAW_PACKETS_MESSAGE(function, ...) pcilib_debug_message (#function, __FILE__, __LINE__, __VA_ARGS__) 
78
 
# define IPECAMERA_DEBUG_RAW_PACKETS_BUFFER(function, ...) pcilib_debug_data_buffer (#function, __VA_ARGS__) 
 
88
# define IPECAMERA_DEBUG_RAW_PACKETS_MESSAGE(function, ...) if (ipecamera_getenv(function##_ENV, #function)) { pcilib_debug_message (#function, __FILE__, __LINE__, __VA_ARGS__); }
 
89
# define IPECAMERA_DEBUG_RAW_PACKETS_BUFFER(function, ...) if (ipecamera_getenv(function##_ENV, #function)) { pcilib_debug_data_buffer (#function, __VA_ARGS__); }
79
90
#else /* IPECAMERA_DEBUG_RAW_PACKETS */
80
91
# define IPECAMERA_DEBUG_RAW_PACKETS_MESSAGE(function, ...)
81
92
# define IPECAMERA_DEBUG_RAW_PACKETS_BUFFER(function, ...)
82
93
#endif /* IPECAMERA_DEBUG_RAW_PACKETS */
83
94
 
84
95
#ifdef IPECAMERA_DEBUG_HARDWARE
85
 
# define IPECAMERA_DEBUG_HARDWARE_MESSAGE(function, ...) pcilib_debug_message (#function, __FILE__, __LINE__, __VA_ARGS__) 
86
 
# define IPECAMERA_DEBUG_HARDWARE_BUFFER(function, ...) pcilib_debug_data_buffer (#function, __VA_ARGS__) 
 
96
# define IPECAMERA_DEBUG_HARDWARE_MESSAGE(function, ...) if (ipecamera_getenv(function##_ENV, #function)) { pcilib_debug_message (#function, __FILE__, __LINE__, __VA_ARGS__); }
 
97
# define IPECAMERA_DEBUG_HARDWARE_BUFFER(function, ...) if (ipecamera_getenv(function##_ENV, #function)) { pcilib_debug_data_buffer (#function, __VA_ARGS__); }
87
98
#else /* IPECAMERA_DEBUG_HARDWARE */
88
99
# define IPECAMERA_DEBUG_HARDWARE_MESSAGE(function, ...)
89
100
# define IPECAMERA_DEBUG_HARDWARE_BUFFER(function, ...)
90
101
#endif /* IPECAMERA_DEBUG_HARDWARE */
91
102
 
 
103
#ifdef IPECAMERA_DEBUG_FRAME_HEADERS
 
104
# define IPECAMERA_DEBUG_FRAME_HEADERS_MESSAGE(function, ...)  if (ipecamera_getenv(function##_ENV, #function)) { pcilib_debug_message (#function, __FILE__, __LINE__, __VA_ARGS__); }
 
105
# define IPECAMERA_DEBUG_FRAME_HEADERS_BUFFER(function, ...)  if (ipecamera_getenv(function##_ENV, #function)) { pcilib_debug_data_buffer (#function, __VA_ARGS__); }
 
106
#else /* IPECAMERA_DEBUG_RAW_FRAMES */
 
107
# define IPECAMERA_DEBUG_FRAME_HEADERS_MESSAGE(function, ...)
 
108
# define IPECAMERA_DEBUG_FRAME_HEADERS_BUFFER(function, ...)
 
109
#endif /* IPECAMERA_DEBUG_RAW_FRAMES */
 
110
 
92
111
 
93
112
#define ipecamera_debug(function, ...) \
94
113
    IPECAMERA_DEBUG_##function##_MESSAGE(IPECAMERA_DEBUG_##function, PCILIB_LOG_DEFAULT, __VA_ARGS__)
99
118
 
100
119
typedef uint32_t ipecamera_payload_t;
101
120
 
 
121
typedef enum {
 
122
    IPECAMERA_FIRMWARE_UNKNOWN = 0,
 
123
    IPECAMERA_FIRMWARE_UFO5 = 5,
 
124
    IPECAMERA_FIRMWARE_CMOSIS20 = 6
 
125
} ipecamera_firmware_t;
 
126
 
 
127
typedef enum {
 
128
    IPECAMERA_FORMAT_CMOSIS = 5,
 
129
    IPECAMERA_FORMAT_CMOSIS20 = 6,
 
130
    IPECAMERA_FORMAT_POLARIS = 7
 
131
} ipecamera_format_t;
 
132
 
102
133
typedef struct {
103
134
    pcilib_event_id_t evid;
104
135
    struct timeval timestamp;
146
177
    pcilib_register_t max_frames_reg;
147
178
    pcilib_register_t num_frames_reg;
148
179
 
149
 
    int started;                /**< Camera is in grabbing mode (start function is called) */
150
 
    int streaming;              /**< Camera is in streaming mode (we are within stream call) */
151
 
    int parse_data;             /**< Indicates if some processing of the data is required, otherwise only rawdata_callback will be called */
 
180
    int started;                        /**< Camera is in grabbing mode (start function is called) */
 
181
    int streaming;                      /**< Camera is in streaming mode (we are within stream call) */
 
182
    int parse_data;                     /**< Indicates if some processing of the data is required, otherwise only rawdata_callback will be called */
152
183
 
153
184
    volatile int run_reader;            /**< Instructs the reader thread to stop processing */
154
185
    volatile int run_streamer;          /**< Indicates request to stop streaming events and can be set by reader_thread upon exit or by user request */
159
190
    struct timeval autostop_time;
160
191
    struct timeval next_trigger;        /**< The minimal delay between trigger signals is mandatory, this indicates time when next trigger is possible */
161
192
 
162
 
    size_t buffer_size;         /**< How many images to store */
163
 
    size_t buffer_pos;          /**< Current image offset in the buffer, due to synchronization reasons should not be used outside of reader_thread */
164
 
    size_t cur_size;            /**< Already written part of data in bytes */
165
 
    size_t raw_size;            /**< Expected maximum size of raw data in bytes */
166
 
    size_t padded_size;         /**< Expected maximum size of buffer for raw data, including additional padding */
167
 
    size_t roi_raw_size;        /**< Expected size (for currently configured ROI) of raw data in bytes */
168
 
    size_t roi_padded_size;     /**< Expected size (for currently configured ROI) of buffer for raw data, including additional padding */
169
 
    
170
 
    size_t image_size;          /**< Size of a single image in bytes */
171
 
    
172
 
    size_t max_frames;          /**< Maximal number of frames what may be buffered in camera DDR memory */
173
 
    int firmware;               /**< Firmware version */
174
 
    int cmosis_outputs;         /**< Number of active cmosis outputs: 4 or 16 */
 
193
    size_t buffer_size;                 /**< How many images to store */
 
194
    size_t buffer_pos;                  /**< Current image offset in the buffer, due to synchronization reasons should not be used outside of reader_thread */
 
195
    size_t cur_size;                    /**< Already written part of data in bytes */
 
196
    size_t raw_size;                    /**< Expected maximum size of raw data in bytes */
 
197
    size_t padded_size;                 /**< Expected maximum size of buffer for raw data, including additional padding */
 
198
    size_t roi_raw_size;                /**< Expected size (for currently configured ROI) of raw data in bytes */
 
199
    size_t roi_padded_size;             /**< Expected size (for currently configured ROI) of buffer for raw data, including additional padding */
 
200
    
 
201
    size_t image_size;                  /**< Size of a single image in bytes */
 
202
    
 
203
    size_t max_frames;                  /**< Maximal number of frames what may be buffered in camera DDR memory */
 
204
    ipecamera_firmware_t firmware;      /**< Firmware type */
 
205
    int cmosis_outputs;                 /**< Number of active cmosis outputs: 4 or 16 */
175
206
    int width, height;
176
207
 
177
208