/alps/ipecamera

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/ipecamera

« back to all changes in this revision

Viewing changes to ipecamera/private.h

  • Committer: Suren A. Chilingaryan
  • Date: 2011-12-12 04:45:35 UTC
  • Revision ID: csa@dside.dyndns.org-20111212044535-6no1q7g230i8uvlv
multithread preprocessing of ipecamera frames and code reorganization

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef _IPECAMERA_PRIVATE_H
 
2
#define _IPECAMERA_PRIVATE_H
 
3
 
 
4
#include "ipecamera.h"
 
5
 
 
6
#define IPECAMERA_BUG_EXTRA_DATA
 
7
#define IPECAMERA_BUG_MULTIFRAME_PACKETS
 
8
#define IPECAMERA_BUG_INCOMPLETE_PACKETS
 
9
 
 
10
#define IPECAMERA_DEFAULT_BUFFER_SIZE 64        //**< should be power of 2 */
 
11
#define IPECAMERA_RESERVE_BUFFERS 2             //**< Return Frame is Lost error, if requested frame will be overwritten after specified number of frames
 
12
#define IPECAMERA_SLEEP_TIME 250000             //**< Michele thinks 250 should be enough, but reset failing in this case */
 
13
#define IPECAMERA_NEXT_FRAME_DELAY 1000         //**< Michele requires 30000 to sync between End Of Readout and next Frame Req */
 
14
#define IPECAMERA_WAIT_FRAME_RCVD_TIME 0        //**< by Uros ,wait 6 ms */
 
15
#define IPECAMERA_NOFRAME_SLEEP 100
 
16
#define IPECAMERA_NOFRAME_PREPROC_SLEEP 100
 
17
 
 
18
#define IPECAMERA_MAX_LINES 1088
 
19
#define IPECAMERA_EXPECTED_STATUS 0x08409FFFF
 
20
#define IPECAMERA_END_OF_SEQUENCE 0x1F001001
 
21
 
 
22
#define IPECAMERA_MAX_CHANNELS 16
 
23
#define IPECAMERA_PIXELS_PER_CHANNEL 128
 
24
#define IPECAMERA_WIDTH (IPECAMERA_MAX_CHANNELS * IPECAMERA_PIXELS_PER_CHANNEL)
 
25
 
 
26
#define IPECAMERA_FRAME_REQUEST                 0x1E9
 
27
#define IPECAMERA_READOUT_FLAG                  0x200
 
28
#define IPECAMERA_READOUT                       0x3E1
 
29
#define IPECAMERA_IDLE                          0x1E1
 
30
#define IPECAMERA_START_INTERNAL_STIMULI        0x1F1
 
31
 
 
32
 
 
33
typedef uint32_t ipecamera_payload_t;
 
34
 
 
35
typedef struct {
 
36
    pcilib_event_id_t evid;
 
37
    struct timeval timestamp;
 
38
} ipecamera_autostop_t;
 
39
 
 
40
typedef struct {
 
41
    size_t i;
 
42
    pthread_t thread;
 
43
    ipecamera_t *ipecamera;
 
44
    
 
45
    int started;                        /**< flag indicating that join & cleanup is required */
 
46
} ipecamera_preprocessor_t;
 
47
 
 
48
 
 
49
typedef struct {
 
50
    ipecamera_event_info_t event;       /**< this structure is overwritten by the reader thread, we need a copy */
 
51
    pthread_rwlock_t mutex;             /**< this mutex protects reconstructed buffers only, the raw data, event_info, etc. will be overwritten by reader thread anyway */
 
52
} ipecamera_frame_t;
 
53
 
 
54
struct ipecamera_s {
 
55
    pcilib_context_t event;
 
56
    ufo_decoder ipedec;
 
57
 
 
58
    char *data;
 
59
    ipecamera_pixel_t *image;
 
60
    size_t size;
 
61
 
 
62
    pcilib_event_callback_t cb;
 
63
    void *cb_user;
 
64
 
 
65
    pcilib_event_id_t event_id;
 
66
    pcilib_event_id_t preproc_id;
 
67
    pcilib_event_id_t reported_id;
 
68
    
 
69
    pcilib_dma_engine_t rdma, wdma;
 
70
 
 
71
    pcilib_register_t packet_len_reg;
 
72
    pcilib_register_t control_reg, status_reg;
 
73
    pcilib_register_t start_reg, end_reg;
 
74
    pcilib_register_t n_lines_reg;
 
75
    uint16_t line_reg;
 
76
    pcilib_register_t exposure_reg;
 
77
    pcilib_register_t flip_reg;
 
78
 
 
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
 
 
83
    int run_reader;             /**< Instructs the reader thread to stop processing */
 
84
    int run_streamer;           /**< Indicates request to stop streaming events and can be set by reader_thread upon exit or by user request */
 
85
    int run_preprocessors;      /**< Instructs preprocessors to exit */
 
86
    
 
87
    ipecamera_autostop_t autostop;
 
88
 
 
89
    struct timeval autostop_time;
 
90
 
 
91
    size_t buffer_size;         /**< How many images to store */
 
92
    size_t buffer_pos;          /**< Current image offset in the buffer, due to synchronization reasons should not be used outside of reader_thread */
 
93
    size_t cur_size;            /**< Already written part of data in bytes */
 
94
    size_t raw_size;            /**< Size of raw data in bytes */
 
95
    size_t full_size;           /**< Size of raw data including the padding */
 
96
    size_t padded_size;         /**< Size of buffer for raw data, including the padding for performance */
 
97
    
 
98
    size_t image_size;          /**< Size of a single image in bytes */
 
99
    
 
100
    int width, height;
 
101
 
 
102
    
 
103
//    void *raw_buffer;
 
104
    void *buffer;
 
105
    ipecamera_change_mask_t *cmask;
 
106
    ipecamera_frame_t *frame;
 
107
    
 
108
 
 
109
    ipecamera_image_dimensions_t dim;
 
110
 
 
111
    pthread_t rthread;
 
112
    
 
113
    size_t n_preproc;
 
114
    ipecamera_preprocessor_t *preproc;
 
115
    pthread_mutex_t preproc_mutex;
 
116
    
 
117
    int preproc_mutex_destroy;
 
118
    int frame_mutex_destroy;
 
119
};
 
120
 
 
121
#endif /* _IPECAMERA_PRIVATE_H */