/alps/pcitool

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

« back to all changes in this revision

Viewing changes to pcilib.h

  • Committer: Suren A. Chilingaryan
  • Date: 2011-12-08 02:47:23 UTC
  • Revision ID: csa@dside.dyndns.org-20111208024723-ym9uf3uoll6ym2a9
new event architecture, first trial

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#define PCILIB_MAX_BANKS 6
5
5
#define PCILIB_MAX_DMA_ENGINES 32
6
6
 
 
7
#include <sys/time.h>
7
8
#include <stdint.h>
8
9
 
9
10
#define pcilib_memcpy pcilib_memcpy32
10
11
#define pcilib_datacpy pcilib_datacpy32
11
12
 
12
13
typedef struct pcilib_s pcilib_t;
13
 
typedef void pcilib_context_t;
 
14
typedef struct pcilib_event_context_s pcilib_context_t;
14
15
typedef struct pcilib_dma_context_s pcilib_dma_context_t;
15
16
 
16
17
 
72
73
} pcilib_dma_flags_t;
73
74
 
74
75
typedef enum {
 
76
    PCILIB_STREAMING_STOP = 0,          /**< stop streaming */
 
77
    PCILIB_STREAMING_CONTINUE = 1,      /**< wait the default DMA timeout for a new data */
 
78
    PCILIB_STREAMING_WAIT = 2,          /**< wait the specified timeout for a new data */
 
79
    PCILIB_STREAMING_CHECK = 3,         /**< do not wait for the data, bail out imideatly if no data ready */
 
80
    PCILIB_STREAMING_FAIL = 4,          /**< fail if data is not available on timeout */
 
81
    PCILIB_STREAMING_REQ_FRAGMENT = 5,  /**< only fragment of a packet is read, wait for next fragment and fail if no data during DMA timeout */
 
82
    PCILIB_STREAMING_REQ_PACKET = 6,    /**< wait for next packet and fail if no data during the specified timeout */
 
83
    PCILIB_STREAMING_TIMEOUT_MASK = 3   /**< mask specifying all timeout modes */
 
84
} pcilib_streaming_action;
 
85
 
 
86
 
 
87
typedef enum {
 
88
    PCILIB_EVENT_FLAGS_DEFAULT = 0,
 
89
    PCILIB_EVENT_FLAG_RAW_DATA_ONLY = 1,
 
90
    PCILIB_EVENT_FLAG_EOF = 2
 
91
} pcilib_event_flags_t;
 
92
 
 
93
typedef enum {
75
94
    PCILIB_REGISTER_STANDARD = 0,
76
95
    PCILIB_REGISTER_FIFO,
77
96
    PCILIB_REGISTER_BITS
99
118
#define PCILIB_EVENT3                   8
100
119
#define PCILIB_EVENTS_ALL               ((pcilib_event_t)-1)
101
120
#define PCILIB_EVENT_INVALID            ((pcilib_event_t)-1)
102
 
#define PCILIB_EVENT_ID_INVALID         0
 
121
//#define PCILIB_EVENT_ID_INVALID               0
103
122
#define PCILIB_TIMEOUT_INFINITE         ((pcilib_timeout_t)-1)
104
123
#define PCILIB_TIMEOUT_IMMEDIATE        0
105
124
#define PCILIB_TIMEOUT_TRIGGER          0
106
125
#define PCILIB_IRQ_SOURCE_DEFAULT       0
107
126
 
 
127
 
 
128
typedef struct {
 
129
    pcilib_event_t type;
 
130
    uint64_t seqnum;            /* we will add seqnum_overflow if required */
 
131
    uint64_t offset;            /* nanoseconds */
 
132
    struct timeval timestamp;   /* most accurate timestamp */
 
133
} pcilib_event_info_t;
 
134
 
108
135
/**<
109
136
 * Callback function called when new data is read by DMA streaming function
110
137
 * @ctx - DMA Engine context
113
140
 * @buf - data
114
141
 * @returns 
115
142
 * <0 - error, stop streaming (the value is negative error code)
116
 
 *  0 - stop streaming
117
 
 *  1 - wait & read next buffer, fail if no data
118
 
 *  2 - wait & read next buffer, but don't fail if timeout expired
119
 
 *  3 - read next buffer if available (don't wait), don't fail
 
143
 *  0 - stop streaming (PCILIB_STREAMING_STOP)
 
144
 *  1 - wait DMA timeout and return gracefuly if no data (PCILIB_STREAMING_CONTINUE)
 
145
 *  2 - wait the specified timeout and return gracefuly if no data (PCILIB_STREAMING_WAIT)
 
146
 *  3 - check if more data is available without waiting, return gracefuly if not (PCILIB_STREAMING_CHECK)
 
147
 *  5 - wait DMA timeout and fail if no data (PCILIB_STREAMING_REQ_FRAGMENT)
 
148
 *  6 - wait the specified timeout and fail if no data (PCILIB_STREAMING_REQ_PACKET)
120
149
 */
121
150
typedef int (*pcilib_dma_callback_t)(void *ctx, pcilib_dma_flags_t flags, size_t bufsize, void *buf); 
122
 
typedef int (*pcilib_event_callback_t)(pcilib_event_t event, pcilib_event_id_t event_id, void *user);
 
151
typedef int (*pcilib_event_callback_t)(pcilib_event_id_t event_id, pcilib_event_info_t *info, void *user);
 
152
typedef int (*pcilib_event_rawdata_callback_t)(pcilib_event_id_t event_id, pcilib_event_info_t *info, pcilib_event_flags_t flags, size_t size, void *data, void *user);
123
153
 
124
154
typedef struct {
125
155
    pcilib_register_bank_addr_t addr;
167
197
} pcilib_register_range_t;
168
198
 
169
199
typedef struct {
 
200
    pcilib_event_t evid;
170
201
    const char *name;
171
202
    const char *description;
172
203
} pcilib_event_description_t;
173
204
 
 
205
typedef struct {
 
206
    pcilib_event_data_type_t data_type;
 
207
    pcilib_event_t evid;
 
208
    const char *name;
 
209
    const char *description;
 
210
} pcilib_event_data_type_description_t;
 
211
 
174
212
typedef enum {
175
213
    PCILIB_DMA_IRQ = 1,
176
214
    PCILIB_EVENT_IRQ = 2
207
245
    pcilib_register_bank_description_t *banks;
208
246
    pcilib_register_range_t *ranges;
209
247
    pcilib_event_description_t *events;
 
248
    pcilib_event_data_type_description_t *data_types;
210
249
 
211
250
    pcilib_dma_api_description_t *dma_api;    
212
251
    pcilib_event_api_description_t *event_api;
242
281
pcilib_register_bank_t pcilib_find_bank(pcilib_t *ctx, const char *bank);
243
282
pcilib_register_t pcilib_find_register(pcilib_t *ctx, const char *bank, const char *reg);
244
283
pcilib_event_t pcilib_find_event(pcilib_t *ctx, const char *event);
 
284
pcilib_event_data_type_t pcilib_find_event_data_type(pcilib_t *ctx, pcilib_event_t event, const char *data_type);
245
285
pcilib_dma_engine_t pcilib_find_dma_by_addr(pcilib_t *ctx, pcilib_dma_direction_t direction, pcilib_dma_engine_addr_t dma);
246
286
 
247
287
int pcilib_read(pcilib_t *ctx, pcilib_bar_t bar, uintptr_t addr, size_t size, void *buf);
265
305
int pcilib_write_register(pcilib_t *ctx, const char *bank, const char *regname, pcilib_register_value_t value);
266
306
 
267
307
int pcilib_reset(pcilib_t *ctx);
268
 
int pcilib_start(pcilib_t *ctx, pcilib_event_t event_mask, void *callback, void *user);
269
 
int pcilib_stop(pcilib_t *ctx);
270
 
 
271
308
int pcilib_trigger(pcilib_t *ctx, pcilib_event_t event, size_t trigger_size, void *trigger_data);
272
309
 
273
 
pcilib_event_id_t pcilib_get_next_event(pcilib_t *ctx, pcilib_event_t event_mask, pcilib_timeout_t timeout);
 
310
/*
 
311
 * The recording of new events will be stopped after reaching max_events records
 
312
 * or when the specified amount of time is elapsed. However, the @pcilib_stop
 
313
 * function should be called still. 
 
314
 * NOTE: This options may not be respected if the PCILIB_EVENT_FLAG_RAW_DATA_ONLY
 
315
 * is specified.
 
316
 */
 
317
int pcilib_configure_autostop(pcilib_t *ctx, size_t max_events, pcilib_timeout_t duration);
 
318
/*
 
319
 * Request streaming the rawdata from the event engine. It is fastest way to acuqire data.
 
320
 * No memory copies will be performed and DMA buffers will be directly passed to the user
 
321
 * callback. However, to prevent data loss, no processing should be done on the data. The
 
322
 * user callback is only expected to copy data into the appropriate place and return control
 
323
 * to the event engine.
 
324
 * The performance can be boosted further by disabling any data processing within the event
 
325
 * engine. Just pass PCILIB_EVENT_FLAG_RAW_DATA_ONLY flag to the @pcilib_start function.
 
326
 */
 
327
int pcilib_configure_rawdata_callback(pcilib_t *ctx, pcilib_event_rawdata_callback_t callback, void *user);
 
328
 
 
329
int pcilib_start(pcilib_t *ctx, pcilib_event_t event_mask, pcilib_event_flags_t flags);
 
330
int pcilib_stop(pcilib_t *ctx, pcilib_event_flags_t flags);
 
331
int pcilib_stream(pcilib_t *ctx, pcilib_event_callback_t callback, void *user);
 
332
 
 
333
int pcilib_get_next_event(pcilib_t *ctx, pcilib_timeout_t timeout, pcilib_event_id_t *evid, pcilib_event_info_t **info);
 
334
int pcilib_copy_data(pcilib_t *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, size_t size, void *buf, size_t *retsize);
 
335
int pcilib_copy_data_with_argument(pcilib_t *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, size_t arg_size, void *arg, size_t size, void *buf, size_t *retsize);
274
336
void *pcilib_get_data(pcilib_t *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, size_t *size);
275
337
void *pcilib_get_data_with_argument(pcilib_t *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, size_t arg_size, void *arg, size_t *size);
 
338
 
276
339
/*
277
340
 * This function is provided to find potentially corrupted data. If the data is overwritten by 
278
 
 * the time return_data is called it will return error.
 
341
 * the time return_data is called it will return error. 
279
342
 */
280
 
int pcilib_return_data(pcilib_t *ctx, pcilib_event_id_t event_id);
 
343
int pcilib_return_data(pcilib_t *ctx, pcilib_event_id_t event_id, void *data);
 
344
 
 
345
 
281
346
 
282
347
/*
283
348
 * @param data - will be allocated and shuld be freed if NULL, otherwise used and size should contain correct size.