1
1
#ifndef _PCITOOL_PCILIB_H
2
2
#define _PCITOOL_PCILIB_H
4
#define PCILIB_MAX_BANKS 6
5
#define PCILIB_MAX_DMA_ENGINES 32
7
4
#include <sys/time.h>
10
#define pcilib_memcpy pcilib_memcpy32
11
#define pcilib_datacpy pcilib_datacpy32
13
8
typedef struct pcilib_s pcilib_t;
14
9
typedef struct pcilib_event_context_s pcilib_context_t;
15
typedef struct pcilib_dma_context_s pcilib_dma_context_t;
18
typedef struct pcilib_dma_api_description_s pcilib_dma_api_description_t;
19
typedef struct pcilib_event_api_description_s pcilib_event_api_description_t;
20
typedef struct pcilib_protocol_description_s pcilib_protocol_description_t;
21
typedef unsigned int pcilib_irq_hw_source_t;
22
typedef uint32_t pcilib_irq_source_t;
24
11
typedef uint8_t pcilib_bar_t; /**< Type holding the PCI Bar number */
25
typedef uint8_t pcilib_register_t; /**< Type holding the register ID within the Bank */
26
typedef uint32_t pcilib_register_addr_t; /**< Type holding the register ID within the Bank */
27
typedef uint8_t pcilib_register_bank_t; /**< Type holding the register bank number */
28
typedef uint8_t pcilib_register_bank_addr_t; /**< Type holding the register bank number */
12
typedef uint16_t pcilib_register_t; /**< Type holding the register position within the field listing registers in the model */
13
typedef uint32_t pcilib_register_addr_t; /**< Type holding the register address within address-space of BARs */
29
14
typedef uint8_t pcilib_register_size_t; /**< Type holding the size in bits of the register */
30
15
typedef uint32_t pcilib_register_value_t; /**< Type holding the register value */
31
16
typedef uint8_t pcilib_dma_engine_addr_t;
41
28
} pcilib_endianess_t;
46
PCILIB_MODEL_IPECAMERA,
51
PCILIB_REGISTER_R = 1,
52
PCILIB_REGISTER_W = 2,
53
PCILIB_REGISTER_RW = 3,
54
PCILIB_REGISTER_W1C = 4, /**< writting 1 resets the flag */
55
PCILIB_REGISTER_RW1C = 5
56
} pcilib_register_mode_t;
59
PCILIB_DEFAULT_PROTOCOL,
60
IPECAMERA_REGISTER_PROTOCOL
61
} pcilib_register_protocol_t;
64
PCILIB_EVENT_DATA = 0, /**< default data format */
65
PCILIB_EVENT_RAW_DATA = 1 /**< raw data */
35
typedef enum { /**< 0x8000 and up are reserved for driver-specific types */
36
PCILIB_EVENT_DATA = 0, /**< default data format */
37
PCILIB_EVENT_RAW_DATA = 1 /**< raw data */
66
38
} pcilib_event_data_type_t;
41
PCILIB_DMA_TO_DEVICE = 1,
42
PCILIB_DMA_FROM_DEVICE = 2,
43
PCILIB_DMA_BIDIRECTIONAL = 3
44
} pcilib_dma_direction_t;
69
47
PCILIB_DMA_FLAGS_DEFAULT = 0,
70
PCILIB_DMA_FLAG_EOP = 1, /**< last buffer of the packet */
71
PCILIB_DMA_FLAG_WAIT = 2, /**< wait completion of write operation / wait for data during read operation */
72
PCILIB_DMA_FLAG_MULTIPACKET = 4, /**< read multiple packets */
73
PCILIB_DMA_FLAG_PERSISTENT = 8, /**< do not stop DMA engine on application termination / permanently close DMA engine on dma_stop */
74
PCILIB_DMA_FLAG_IGNORE_ERRORS = 16 /**< do not crash on errors, but return appropriate error codes */
48
PCILIB_DMA_FLAG_EOP = 1, /**< last buffer of the packet */
49
PCILIB_DMA_FLAG_WAIT = 2, /**< wait completion of write operation / wait for data during read operation */
50
PCILIB_DMA_FLAG_MULTIPACKET = 4, /**< read multiple packets */
51
PCILIB_DMA_FLAG_PERSISTENT = 8, /**< do not stop DMA engine on application termination / permanently close DMA engine on dma_stop */
52
PCILIB_DMA_FLAG_IGNORE_ERRORS = 16 /**< do not crash on errors, but return appropriate error codes */
75
53
} pcilib_dma_flags_t;
78
PCILIB_STREAMING_STOP = 0, /**< stop streaming */
79
PCILIB_STREAMING_CONTINUE = 1, /**< wait the default DMA timeout for a new data */
80
PCILIB_STREAMING_WAIT = 2, /**< wait the specified timeout for a new data */
81
PCILIB_STREAMING_CHECK = 3, /**< do not wait for the data, bail out imideatly if no data ready */
82
PCILIB_STREAMING_FAIL = 4, /**< fail if data is not available on timeout */
83
PCILIB_STREAMING_REQ_FRAGMENT = 5, /**< only fragment of a packet is read, wait for next fragment and fail if no data during DMA timeout */
84
PCILIB_STREAMING_REQ_PACKET = 6, /**< wait for next packet and fail if no data during the specified timeout */
85
PCILIB_STREAMING_TIMEOUT_MASK = 3 /**< mask specifying all timeout modes */
86
} pcilib_streaming_action_t;
90
56
PCILIB_EVENT_FLAGS_DEFAULT = 0,
91
57
PCILIB_EVENT_FLAG_RAW_DATA_ONLY = 1, /**< Do not parse data, just read raw and pass it to rawdata callback. If passed to rawdata callback, idicates the data is not identified as event (most probably just padding) */
92
58
PCILIB_EVENT_FLAG_STOP_ONLY = 1, /**< Do not cleanup, just stop acquiring new frames, the cleanup should be requested afterwards */
98
64
PCILIB_EVENT_INFO_FLAG_BROKEN = 1 /**< Indicates broken frames (if this flag is fales, the frame still can be broken) */
99
65
} pcilib_event_info_flags_t;
102
PCILIB_REGISTER_STANDARD = 0,
103
PCILIB_REGISTER_FIFO,
105
} pcilib_register_type_t;
69
uint64_t seqnum; /**< we will add seqnum_overflow if required */
70
uint64_t offset; /**< nanoseconds */
71
struct timeval timestamp; /**< most accurate timestamp */
72
pcilib_event_info_flags_t flags; /**< flags */
73
} pcilib_event_info_t;
107
76
#define PCILIB_BAR_DETECT ((pcilib_bar_t)-1)
108
77
#define PCILIB_BAR_INVALID ((pcilib_bar_t)-1)
114
83
#define PCILIB_DMA_ENGINE_ADDR_INVALID ((pcilib_dma_engine_addr_t)-1)
115
84
#define PCILIB_REGISTER_INVALID ((pcilib_register_t)-1)
116
85
#define PCILIB_ADDRESS_INVALID ((uintptr_t)-1)
117
#define PCILIB_REGISTER_BANK_INVALID ((pcilib_register_bank_t)-1)
118
#define PCILIB_REGISTER_BANK0 0
119
#define PCILIB_REGISTER_BANK1 1
120
#define PCILIB_REGISTER_BANK2 2
121
#define PCILIB_REGISTER_BANK3 3
122
#define PCILIB_REGISTER_BANK_DMA 128
123
86
#define PCILIB_EVENT0 1
124
87
#define PCILIB_EVENT1 2
125
88
#define PCILIB_EVENT2 4
131
94
#define PCILIB_TIMEOUT_IMMEDIATE 0
132
95
#define PCILIB_IRQ_TYPE_ALL 0
133
96
#define PCILIB_IRQ_SOURCE_DEFAULT 0
134
#define PCILIB_REGISTER_NO_BITS 0
135
#define PCILIB_REGISTER_ALL_BITS ((pcilib_register_value_t)-1)
97
#define PCILIB_MODEL_DETECT NULL
139
uint64_t seqnum; /**< we will add seqnum_overflow if required */
140
uint64_t offset; /**< nanoseconds */
141
struct timeval timestamp; /**< most accurate timestamp */
142
pcilib_event_info_flags_t flags; /**< flags */
143
} pcilib_event_info_t;
146
101
* Callback function called when new data is read by DMA streaming function
161
116
typedef int (*pcilib_event_callback_t)(pcilib_event_id_t event_id, pcilib_event_info_t *info, void *user);
162
117
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);
165
pcilib_register_bank_addr_t addr;
167
pcilib_bar_t bar; // optional
170
pcilib_register_protocol_t protocol;
172
uintptr_t read_addr; // or offset if bar specified
173
uintptr_t write_addr; // or offset if bar specified
174
uint8_t raw_endianess;
181
const char *description;
182
} pcilib_register_bank_description_t;
185
pcilib_register_addr_t addr;
186
pcilib_register_size_t offset;
187
pcilib_register_size_t bits;
188
pcilib_register_value_t defvalue;
189
pcilib_register_value_t rwmask; /**< 1 - read before write bits, 0 - zero should be written to preserve value
190
Used to define how external bits of PCILIB_REGISTER_BITS registers are treated.
191
Currently it is a bit confusing, we may find a better way in the next release */
192
pcilib_register_mode_t mode;
193
pcilib_register_type_t type;
195
pcilib_register_bank_t bank;
198
const char *description;
199
} pcilib_register_description_t;
207
pcilib_register_bank_addr_t bank;
209
} pcilib_register_range_t;
214
const char *description;
215
} pcilib_event_description_t;
218
pcilib_event_data_type_t data_type;
221
const char *description;
222
} pcilib_event_data_type_description_t;
230
PCILIB_DMA_TO_DEVICE = 1,
231
PCILIB_DMA_FROM_DEVICE = 2,
232
PCILIB_DMA_BIDIRECTIONAL = 3
233
} pcilib_dma_direction_t;
236
PCILIB_DMA_TYPE_BLOCK,
237
PCILIB_DMA_TYPE_PACKET,
238
PCILIB_DMA_TYPE_UNKNOWN
239
} pcilib_dma_engine_type_t;
242
pcilib_dma_engine_addr_t addr;
243
pcilib_dma_engine_type_t type;
244
pcilib_dma_direction_t direction;
246
} pcilib_dma_engine_description_t;
249
pcilib_dma_engine_description_t *engines[PCILIB_MAX_DMA_ENGINES + 1];
256
pcilib_register_description_t *registers;
257
pcilib_register_bank_description_t *banks;
258
pcilib_register_range_t *ranges;
259
pcilib_event_description_t *events;
260
pcilib_event_data_type_description_t *data_types;
262
pcilib_dma_api_description_t *dma_api;
263
pcilib_event_api_description_t *event_api;
264
} pcilib_model_description_t;
266
121
int pcilib_set_error_handler(void (*err)(const char *msg, ...), void (*warn)(const char *msg, ...));
268
pcilib_model_t pcilib_get_model(pcilib_t *ctx);
269
pcilib_model_description_t *pcilib_get_model_description(pcilib_t *ctx);
270
pcilib_context_t *pcilib_get_implementation_context(pcilib_t *ctx);
272
pcilib_t *pcilib_open(const char *device, pcilib_model_t model);
123
pcilib_t *pcilib_open(const char *device, const char *model);
273
124
void pcilib_close(pcilib_t *ctx);
275
126
int pcilib_start_dma(pcilib_t *ctx, pcilib_dma_engine_t dma, pcilib_dma_flags_t flags);
288
139
char *pcilib_resolve_register_address(pcilib_t *ctx, pcilib_bar_t bar, uintptr_t addr); // addr is offset if bar is specified
289
140
char *pcilib_resolve_data_space(pcilib_t *ctx, uintptr_t addr, size_t *size);
291
pcilib_register_bank_t pcilib_find_bank_by_addr(pcilib_t *ctx, pcilib_register_bank_addr_t bank);
292
pcilib_register_bank_t pcilib_find_bank_by_name(pcilib_t *ctx, const char *bankname);
293
pcilib_register_bank_t pcilib_find_bank(pcilib_t *ctx, const char *bank);
294
142
pcilib_register_t pcilib_find_register(pcilib_t *ctx, const char *bank, const char *reg);
295
143
pcilib_event_t pcilib_find_event(pcilib_t *ctx, const char *event);
296
144
pcilib_event_data_type_t pcilib_find_event_data_type(pcilib_t *ctx, pcilib_event_t event, const char *data_type);