/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool
7.1.6 by Suren A. Chilingaryan
Provide single header for library
1
#ifndef _PCITOOL_PCILIB_H
2
#define _PCITOOL_PCILIB_H
6 by Suren A. Chilingaryan
Initial support for registers, infrastructure only
3
117 by Suren A. Chilingaryan
new event architecture, first trial
4
#include <sys/time.h>
236 by Suren A. Chilingaryan
Big redign of model structures
5
#include <stddef.h>
6 by Suren A. Chilingaryan
Initial support for registers, infrastructure only
6
#include <stdint.h>
247 by Suren A. Chilingaryan
New error reporting public interface
7
#include <stdarg.h>
6 by Suren A. Chilingaryan
Initial support for registers, infrastructure only
8
7.1.1 by Suren A. Chilingaryan
Initial support of IPECamera protocol
9
typedef struct pcilib_s pcilib_t;
117 by Suren A. Chilingaryan
new event architecture, first trial
10
typedef struct pcilib_event_context_s pcilib_context_t;
45 by root
North West Logick DMA implementation
11
253 by Suren A. Chilingaryan
Include version information in all API descriptions
12
typedef uint32_t pcilib_version_t;
13
7.1.1 by Suren A. Chilingaryan
Initial support of IPECamera protocol
14
typedef uint8_t pcilib_bar_t;			/**< Type holding the PCI Bar number */
236 by Suren A. Chilingaryan
Big redign of model structures
15
typedef uint16_t pcilib_register_t;		/**< Type holding the register position within the field listing registers in the model */
307 by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far)
16
typedef uint16_t pcilib_view_t;			/**< Type holding the register view position within view listing in the model */
17
typedef uint16_t pcilib_unit_t;			/**< Type holding the value unit position within unit listing in the model */
236 by Suren A. Chilingaryan
Big redign of model structures
18
typedef uint32_t pcilib_register_addr_t;	/**< Type holding the register address within address-space of BARs */
7.1.1 by Suren A. Chilingaryan
Initial support of IPECamera protocol
19
typedef uint8_t pcilib_register_size_t;		/**< Type holding the size in bits of the register */
330 by Suren A. Chilingaryan
Support for 64-bit registes
20
typedef uint64_t pcilib_register_value_t;	/**< Type holding the register value */
49 by Suren A. Chilingaryan
A bit of renaming
21
typedef uint8_t pcilib_dma_engine_addr_t;
22
typedef uint8_t pcilib_dma_engine_t;
50 by Suren A. Chilingaryan
Compilation fix
23
typedef uint64_t pcilib_event_id_t;
15 by Suren A. Chilingaryan
Infrastructure for event API
24
typedef uint32_t pcilib_event_t;
176 by Suren A. Chilingaryan
print results even if no frames grabbed
25
typedef uint64_t pcilib_timeout_t;		/**< In microseconds */
236 by Suren A. Chilingaryan
Big redign of model structures
26
typedef unsigned int pcilib_irq_hw_source_t;
27
typedef uint32_t pcilib_irq_source_t;
303 by Suren A. Chilingaryan
Initial integration of XML support
28
typedef struct _xmlNode pcilib_xml_node_t;
7.1.1 by Suren A. Chilingaryan
Initial support of IPECamera protocol
29
30
typedef enum {
250 by Suren A. Chilingaryan
Provide an interface for logging debug messages
31
    PCILIB_LOG_DEBUG = 0,			/**< Debug messages will be always printed as they should be filtered based on setting of corresponding environmental variable */
32
    PCILIB_LOG_INFO,				/**< Informational message are suppresed by default */
33
    PCILIB_LOG_WARNING,				/**< Warnings messages indicate that something unexpected happen, but application can continue */
34
    PCILIB_LOG_ERROR				/**< The error which is impossible to handle on this level of library */
247 by Suren A. Chilingaryan
New error reporting public interface
35
} pcilib_log_priority_t;
36
37
typedef enum {
319 by Suren A. Chilingaryan
Provide register listings in public API
38
    PCILIB_HOST_ENDIAN = 0,                     /**< The same byte ordering as on the host system running the driver */
39
    PCILIB_LITTLE_ENDIAN,                       /**< x86 is Little-endian, least significant bytes are at the lower addresses */
40
    PCILIB_BIG_ENDIAN                           /**< Old mainframes and network byte order, most significant bytes are at the lower addresses */
7.1.1 by Suren A. Chilingaryan
Initial support of IPECamera protocol
41
} pcilib_endianess_t;
42
43
typedef enum {
315 by Suren A. Chilingaryan
Support properties of arbitrary type
44
    PCILIB_ACCESS_R = 1,			/**< getting property is allowed */
45
    PCILIB_ACCESS_W = 2,			/**< setting property is allowed */
46
    PCILIB_ACCESS_RW = 3
47
} pcilib_access_mode_t;
48
49
typedef enum {
319 by Suren A. Chilingaryan
Provide register listings in public API
50
    PCILIB_REGISTER_R = 1,			/**< reading from register is allowed */
51
    PCILIB_REGISTER_W = 2,			/**< normal writting to register is allowed */
52
    PCILIB_REGISTER_RW = 3,
53
    PCILIB_REGISTER_W1C = 4,			/**< writting 1 resets the bit, writting 0 keeps the value */
54
    PCILIB_REGISTER_RW1C = 5,
55
    PCILIB_REGISTER_W1I = 8,			/**< writting 1 inversts the bit, writting 0 keeps the value */
56
    PCILIB_REGISTER_RW1I = 9,
346.1.9 by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory.
57
    PCILIB_REGISTER_INCONSISTENT = 0x1000		/**< dont check register value after set*/
319 by Suren A. Chilingaryan
Provide register listings in public API
58
} pcilib_register_mode_t;
59
60
typedef enum {
309 by Suren A. Chilingaryan
Base functions for views
61
    PCILIB_TYPE_INVALID = 0,                    /**< uninitialized */
62
    PCILIB_TYPE_DEFAULT = 0,			/**< default type */
63
    PCILIB_TYPE_STRING = 1,			/**< char* */
64
    PCILIB_TYPE_DOUBLE = 2,			/**< double */
65
    PCILIB_TYPE_LONG = 3
66
} pcilib_value_type_t;
307 by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far)
67
68
typedef enum {
236 by Suren A. Chilingaryan
Big redign of model structures
69
    PCILIB_DMA_IRQ = 1,
70
    PCILIB_EVENT_IRQ = 2
71
} pcilib_irq_type_t;
72
73
typedef enum {					/**< 0x8000 and up are reserved for driver-specific types */
74
    PCILIB_EVENT_DATA = 0,			/**< default data format */
75
    PCILIB_EVENT_RAW_DATA = 1			/**< raw data */
15 by Suren A. Chilingaryan
Infrastructure for event API
76
} pcilib_event_data_type_t;
77
45 by root
North West Logick DMA implementation
78
typedef enum {
236 by Suren A. Chilingaryan
Big redign of model structures
79
    PCILIB_DMA_TO_DEVICE = 1,
80
    PCILIB_DMA_FROM_DEVICE = 2,
81
    PCILIB_DMA_BIDIRECTIONAL = 3
82
} pcilib_dma_direction_t;
83
84
typedef enum {
45 by root
North West Logick DMA implementation
85
    PCILIB_DMA_FLAGS_DEFAULT = 0,
236 by Suren A. Chilingaryan
Big redign of model structures
86
    PCILIB_DMA_FLAG_EOP = 1,			/**< last buffer of the packet */
87
    PCILIB_DMA_FLAG_WAIT = 2,			/**< wait completion of write operation / wait for data during read operation */
88
    PCILIB_DMA_FLAG_MULTIPACKET = 4,		/**< read multiple packets */
89
    PCILIB_DMA_FLAG_PERSISTENT = 8,		/**< do not stop DMA engine on application termination / permanently close DMA engine on dma_stop */
343 by Suren A. Chilingaryan
Configure number of DMA buffers in IPEDMA and improve checking and reporting inconsistent kmem buffers while re-using
90
    PCILIB_DMA_FLAG_IGNORE_ERRORS = 16,		/**< do not crash on errors, but return appropriate error codes */
91
    PCILIB_DMA_FLAG_STOP = 32			/**< indicates that we actually calling pcilib_dma_start to stop persistent DMA engine */
45 by root
North West Logick DMA implementation
92
} pcilib_dma_flags_t;
93
47 by Suren A. Chilingaryan
Support FIFO reading/writting, code restructurization, few fixes
94
typedef enum {
315 by Suren A. Chilingaryan
Support properties of arbitrary type
95
    PCILIB_STREAMING_STOP = 0,                  /**< stop streaming */
324 by Suren A. Chilingaryan
Documentation update
96
    PCILIB_STREAMING_CONTINUE = 1,              /**< wait DMA timeout and return gracefuly if no new data appeared */
97
    PCILIB_STREAMING_WAIT = 2,                  /**< wait the specified timeout and return gracefuly if no new data appeared */
98
    PCILIB_STREAMING_CHECK = 3,                 /**< check if more data is available without waiting, return gracefuly if no data is ready */
99
    PCILIB_STREAMING_TIMEOUT_MASK = 3,          /**< mask specifying all timeout modes */
100
    PCILIB_STREAMING_FAIL = 4,                  /**< a flag indicating that the error should be generated if no data is available upon the timeout (whatever timeout mode is used) */
315 by Suren A. Chilingaryan
Support properties of arbitrary type
101
    PCILIB_STREAMING_REQ_FRAGMENT = 5,          /**< only fragment of a packet is read, wait for next fragment and fail if no data during DMA timeout */
324 by Suren A. Chilingaryan
Documentation update
102
    PCILIB_STREAMING_REQ_PACKET = 6             /**< wait for next packet and fail if no data during the specified timeout */
279 by Suren A. Chilingaryan
Make pcilib_streaming_action_t public
103
} pcilib_streaming_action_t;
104
105
typedef enum {
117 by Suren A. Chilingaryan
new event architecture, first trial
106
    PCILIB_EVENT_FLAGS_DEFAULT = 0,
145 by Suren A. Chilingaryan
Print more statistics
107
    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) */
119 by Suren A. Chilingaryan
Initial support of event streaming in cli
108
    PCILIB_EVENT_FLAG_STOP_ONLY = 1,		/**< Do not cleanup, just stop acquiring new frames, the cleanup should be requested afterwards */
126 by Suren A. Chilingaryan
multithread preprocessing of ipecamera frames and code reorganization
109
    PCILIB_EVENT_FLAG_EOF = 2,			/**< Indicates that it is the last part of the frame (not required) */
110
    PCILIB_EVENT_FLAG_PREPROCESS = 4		/**< Enables preprocessing of the raw data (decoding frames, etc.) */
117 by Suren A. Chilingaryan
new event architecture, first trial
111
} pcilib_event_flags_t;
112
113
typedef enum {
119 by Suren A. Chilingaryan
Initial support of event streaming in cli
114
    PCILIB_EVENT_INFO_FLAG_BROKEN = 1		/**< Indicates broken frames (if this flag is fales, the frame still can be broken) */
115
} pcilib_event_info_flags_t;
116
315 by Suren A. Chilingaryan
Support properties of arbitrary type
117
typedef enum {
118
    PCILIB_LIST_FLAGS_DEFAULT = 0,
119
    PCILIB_LIST_FLAG_CHILDS = 1                 /**< Request all sub-elements or indicated that sub-elements are available */
120
} pcilib_list_flags_t;
121
309 by Suren A. Chilingaryan
Base functions for views
122
typedef struct {
315 by Suren A. Chilingaryan
Support properties of arbitrary type
123
    pcilib_value_type_t type;                   /**< Current data type */
124
    const char *unit;                           /**< Units (if known) */
125
    const char *format;                         /**< requested printf format (may enforce using output in hex form) */
309 by Suren A. Chilingaryan
Base functions for views
126
127
    union {
315 by Suren A. Chilingaryan
Support properties of arbitrary type
128
	long ival;                              /**< The value if type = PCILIB_TYPE_LONG */
129
	double fval;                            /**< The value if type = PCILIB_TYPE_DOUBLE */
130
	const char *sval;                       /**< The value if type = PCILIB_TYPE_STRING, the pointer may point to static location or reference actual string in str or data */
309 by Suren A. Chilingaryan
Base functions for views
131
    };
132
133
        // This is a private part
315 by Suren A. Chilingaryan
Support properties of arbitrary type
134
    size_t size;                                /**< Size of the data */
135
    void *data;                                 /**< Arbitrary data, for instance actual string referenced by the sval */
136
    char str[16];                               /**< Used for shorter strings converted from integer/float types */
309 by Suren A. Chilingaryan
Base functions for views
137
} pcilib_value_t;
138
315 by Suren A. Chilingaryan
Support properties of arbitrary type
139
typedef struct {
319 by Suren A. Chilingaryan
Provide register listings in public API
140
    pcilib_register_value_t min, max;           /**< Minimum and maximum allowed values */
141
} pcilib_register_value_range_t;
142
143
typedef struct {
144
    pcilib_register_value_t value;              /**< This value will get assigned instead of the name */
145
    pcilib_register_value_t min, max;	        /**< the values in the specified range are aliased by name */
146
    const char *name; 				/**< corresponding string to value */
320 by Suren A. Chilingaryan
Add optional description in the value name-aliases
147
    const char *description;                    /**< longer description */
319 by Suren A. Chilingaryan
Provide register listings in public API
148
} pcilib_register_value_name_t;
149
150
typedef struct {
151
    pcilib_register_t id;                       /**< Direct register ID which can be used in API calls */
152
    const char *name;                           /**< The access name of the register */
153
    const char *description;                    /**< Brief description of the register */
154
    const char *bank;                           /**< The name of the bank register belongs to */
155
    pcilib_register_mode_t mode;                /**< Register access (ro/wo/rw) and how writting to register works (clearing/inverting set bits) */
156
    pcilib_register_value_t defvalue;           /**< Default register value */
157
    const pcilib_register_value_range_t *range; /**< Specifies default, minimum, and maximum values */
158
    const pcilib_register_value_name_t *values; /**< The list of enum names for the register value */
159
} pcilib_register_info_t;
160
161
typedef struct {
315 by Suren A. Chilingaryan
Support properties of arbitrary type
162
    const char *name;                           /**< Name of the property view */
163
    const char *path;                           /**< Full path to the property */
164
    const char *description;                    /**< Short description */
165
    pcilib_value_type_t type;                   /**< The default data type or PCILIB_TYPE_INVALID if directory */
166
    pcilib_access_mode_t mode;                  /**< Specifies if the view is read/write-only */
167
    pcilib_list_flags_t flags;                  /**< Indicates if have sub-folders, etc. */
168
    const char *unit;                           /**< Returned unit (if any) */
169
} pcilib_property_info_t;
170
319 by Suren A. Chilingaryan
Provide register listings in public API
171
typedef struct {
172
    pcilib_event_t type;
173
    uint64_t seqnum;				/**< we will add seqnum_overflow if required */
174
    uint64_t offset;				/**< nanoseconds */
175
    struct timeval timestamp;			/**< most accurate timestamp */
176
    pcilib_event_info_flags_t flags;		/**< flags */
177
} pcilib_event_info_t;
178
45 by root
North West Logick DMA implementation
179
7.1.1 by Suren A. Chilingaryan
Initial support of IPECamera protocol
180
#define PCILIB_BAR_DETECT 		((pcilib_bar_t)-1)
39 by root
Move to new FPGA design
181
#define PCILIB_BAR_INVALID		((pcilib_bar_t)-1)
275 by Suren A. Chilingaryan
Integration of software registers
182
#define PCILIB_BAR_NOBAR		((pcilib_bar_t)-2)
39 by root
Move to new FPGA design
183
#define PCILIB_BAR0			0
184
#define PCILIB_BAR1			1
62 by Suren A. Chilingaryan
Suppport DMA modes in console application (not functional yet)
185
#define PCILIB_DMA_ENGINE_INVALID	((pcilib_dma_engine_t)-1)
65 by Suren A. Chilingaryan
Separate NWL loopback code, provide DMA start/stop interfaces
186
#define PCILIB_DMA_ENGINE_ALL		((pcilib_dma_engine_t)-1)
187
#define PCILIB_DMA_FLAGS_DEFAULT	((pcilib_dma_flags_t)0)
62 by Suren A. Chilingaryan
Suppport DMA modes in console application (not functional yet)
188
#define PCILIB_DMA_ENGINE_ADDR_INVALID	((pcilib_dma_engine_addr_t)-1)
7.1.1 by Suren A. Chilingaryan
Initial support of IPECamera protocol
189
#define PCILIB_REGISTER_INVALID		((pcilib_register_t)-1)
332 by Suren A. Chilingaryan
Provide API calls for register and bank address resolution
190
#define PCILIB_REGISTER_ADDRESS_INVALID	((pcilib_register_addr_t)-1)
7.1.1 by Suren A. Chilingaryan
Initial support of IPECamera protocol
191
#define PCILIB_ADDRESS_INVALID		((uintptr_t)-1)
16 by Suren A. Chilingaryan
Prototype of IPECamera image protocol
192
#define PCILIB_EVENT0			1
193
#define PCILIB_EVENT1			2
194
#define PCILIB_EVENT2			4
195
#define PCILIB_EVENT3			8
196
#define PCILIB_EVENTS_ALL		((pcilib_event_t)-1)
29 by Suren A. Chilingaryan
Support non-callback way of getting events
197
#define PCILIB_EVENT_INVALID		((pcilib_event_t)-1)
123 by Suren A. Chilingaryan
Parse required event & data_type
198
#define PCILIB_EVENT_DATA_TYPE_INVALID	((pcilib_event_data_type_t)-1)
62 by Suren A. Chilingaryan
Suppport DMA modes in console application (not functional yet)
199
#define PCILIB_TIMEOUT_INFINITE		((pcilib_timeout_t)-1)
45 by root
North West Logick DMA implementation
200
#define PCILIB_TIMEOUT_IMMEDIATE	0
194 by Suren A. Chilingaryan
DMA-independent IRQ functions
201
#define PCILIB_IRQ_TYPE_ALL 		0
88 by Suren A. Chilingaryan
IRQ acknowledgement support in the engine API
202
#define PCILIB_IRQ_SOURCE_DEFAULT	0
236 by Suren A. Chilingaryan
Big redign of model structures
203
#define PCILIB_MODEL_DETECT		NULL
7.1.1 by Suren A. Chilingaryan
Initial support of IPECamera protocol
204
324 by Suren A. Chilingaryan
Documentation update
205
/**
206
 * Callback function called when pcilib wants to log a new message
207
 * @param[in,out] arg 	- logging context provided with pcilib_set_logger() call
208
 * @param[in] file	- source file generating the message
209
 * @param[in] line	- source line generating the message
210
 * @param[in] prio	- the message priority (messages with priority bellow the currently set loglevel are already filtered)
211
 * @param[in] msg 	- message or printf-style formating string
212
 * @param[in] va	- vairable parameters defined by formating string
213
 */
247 by Suren A. Chilingaryan
New error reporting public interface
214
typedef void (*pcilib_logger_t)(void *arg, const char *file, int line, pcilib_log_priority_t prio, const char *msg, va_list va);
215
324 by Suren A. Chilingaryan
Documentation update
216
/**
109 by Suren A. Chilingaryan
Improvements of DMA engine
217
 * Callback function called when new data is read by DMA streaming function
324 by Suren A. Chilingaryan
Documentation update
218
 * @param[in,out] ctx 	- DMA Engine context
219
 * @param[in] flags 	- DMA Flags
220
 * @param[in] bufsize 	- size of data in bytes
221
 * @param[in] buf 	- data
222
 * @return 		- #pcilib_streaming_action_t instructing how the streaming should continue or a negative error code in the case of error
109 by Suren A. Chilingaryan
Improvements of DMA engine
223
 */
224
typedef int (*pcilib_dma_callback_t)(void *ctx, pcilib_dma_flags_t flags, size_t bufsize, void *buf); 
324 by Suren A. Chilingaryan
Documentation update
225
226
/**
227
 * Callback function called when new event is generated by event engine
228
 * @param[in] event_id	- event id
229
 * @param[in] info	- event description (depending on event engine may provide additional fields on top of #pcilib_event_info_t)
230
 * @param[in,out] user	- User-specific data provided in pcilib_stream() call
231
 * @return 		- #pcilib_streaming_action_t instructing how the streaming should continue or a negative error code in the case of error
232
 */
233
typedef int (*pcilib_event_callback_t)(pcilib_event_id_t event_id, const pcilib_event_info_t *info, void *user);
234
235
/**
236
 * Callback function called when new portion of raw data is read by event engine
237
 * @param[in] event_id	- id of the event this data will be associated with if processing is successful
238
 * @param[in] info	- event description (depending on event engine may provide additional fields on top of #pcilib_event_info_t)
239
 * @param[in] flags	- may indicate if it is the last portion of data for current event 
240
 * @param[in] size	- size of data in bytes
241
 * @param[in,out] data	- data (the callback may modify the data, but the size should be kept of course)
242
 * @param[in,out] user	- User-specific data provided in pcilib_stream() call
243
 * @return 		- #pcilib_streaming_action_t instructing how the streaming should continue or a negative error code in the case of error
244
 */
245
typedef int (*pcilib_event_rawdata_callback_t)(pcilib_event_id_t event_id, const pcilib_event_info_t *info, pcilib_event_flags_t flags, size_t size, void *data, void *user);
50 by Suren A. Chilingaryan
Compilation fix
246
277 by Suren A. Chilingaryan
Keep C++ compilers happy
247
#ifdef __cplusplus
248
extern "C" {
249
#endif
250
324 by Suren A. Chilingaryan
Documentation update
251
/***********************************************************************************************************//**
252
 * \defgroup public_api_global Global Public API (logging, etc.)
253
 * Global functions which does not require existing pcilib context
254
 * @{
255
 */
256
257
/**
258
 * Replaces default logging function.
259
 * @param min_prio 	- messages with priority below \a min_prio will be ignored
260
 * @param logger	- configures a new logging function or restores the default one if NULL is passed
261
 * @param arg		- logging context, this parameter will be passed through to the \a logger
262
 * @return 		- error code or 0 on success
263
 */
247 by Suren A. Chilingaryan
New error reporting public interface
264
int pcilib_set_logger(pcilib_log_priority_t min_prio, pcilib_logger_t logger, void *arg);
6 by Suren A. Chilingaryan
Initial support for registers, infrastructure only
265
346.1.7 by Vasilii Chernov
Change error logging method in Python wrap. Move functions, that converts values between PyObject and pcilib_value_t to py.c
266
/**
267
 * Gets current logger function.
268
 */
269
pcilib_logger_t pcilib_get_logger();
270
271
/**
272
 * Gets current logger min priority.
273
 */
274
pcilib_log_priority_t pcilib_get_logger_min_prio();
275
276
/**
277
 * Gets current logger argument.
278
 */
279
void* pcilib_get_logger_argument();
280
324 by Suren A. Chilingaryan
Documentation update
281
/** public_api_global
282
 * @}
283
 */
284
285
286
/***********************************************************************************************************//**
287
 * \defgroup public_api Public API
288
 * Base pcilib functions which does not belong to the specific APIs
289
 * @{
290
 */
291
292
/**
293
 * Initializes pcilib context, detects model configuration, and populates model-specific registers.
294
 * Event and DMA engines will not be started automatically, but calls to pcilib_start() / pcilib_start_dma()
295
 * are provided for this purpose. In the end, the context should be cleaned using pcilib_stop().
296
 * @param[in] device	- path to the device file [/dev/fpga0]
297
 * @param[in] model	- specifies the model of hardware, autodetected if NULL is passed
298
 * @return 		- initialized context or NULL in the case of error
299
 */
236 by Suren A. Chilingaryan
Big redign of model structures
300
pcilib_t *pcilib_open(const char *device, const char *model);
324 by Suren A. Chilingaryan
Documentation update
301
302
/**
303
 * Destroy pcilib context and all memory associated with it. The function will stop event engine if necessary,
304
 * but DMA engine stay running if it was already running before pcilib_open() was called
305
 * @param[in,out] ctx 	- pcilib context
306
 */
7.1.1 by Suren A. Chilingaryan
Initial support of IPECamera protocol
307
void pcilib_close(pcilib_t *ctx);
308
324 by Suren A. Chilingaryan
Documentation update
309
/**
310
 * Should reset the hardware and software in default state. It is implementation-specific, but is not actively
311
 * used in existing implementations because the hardware is initialized from bash scripts which are often 
312
 * changed by Michele and his band. On the software side, it probably should reset all software registers
313
 * to default value and may be additionaly re-start and clear DMA. However, this is not implemented yet.
314
 * @param[in,out] ctx	- pcilib context
315
 * @return		- error code or 0 on success
316
 */ 
317
 
318
int pcilib_reset(pcilib_t *ctx);
319
320
/** public_api
321
 * @}
322
 */
323
324
325
/***********************************************************************************************************//**
326
 * \defgroup public_api_pci Public PCI API (MMIO)
327
 * API for manipulation with memory-mapped PCI BAR space
328
 * @{
329
 */
330
331
/**
332
 * Resolves the phisycal PCI address to a virtual address in the process address space.
333
 * The required BAR will be mapped if necessary.
334
 * @param[in,out] ctx	- pcilib context
335
 * @param[in] bar	- specifies the BAR address belong to, use PCILIB_BAR_DETECT for autodetection
336
 * @param[in] addr	- specifies the physical address on the PCI bus or offset in the BAR if \a bar is specified
337
 * @return		- the virtual address in the process address space or NULL in case of error
338
 */
339
char *pcilib_resolve_bar_address(pcilib_t *ctx, pcilib_bar_t bar, uintptr_t addr);	
340
341
/**
342
 * Performs PIO read from the PCI BAR. The BAR will be automatically mapped and unmapped if necessary.
343
 * @param[in,out] ctx	- pcilib context
344
 * @param[in] bar	- the BAR to read, use PCILIB_BAR_DETECT to detect bar by the specified physical address
345
 * @param[in] addr	- absolute physical address to read or the offset in the specified bar
345 by Suren A. Chilingaryan
64-bit access to BAR memory
346
 * @param[in] access	- word size (access width in bytes)
347
 * @param[in] n		- number of words to read
324 by Suren A. Chilingaryan
Documentation update
348
 * @param[out] buf	- the read data will be placed in this buffer
349
 * @return 		- error code or 0 on success
350
 */ 
345 by Suren A. Chilingaryan
64-bit access to BAR memory
351
int pcilib_read(pcilib_t *ctx, pcilib_bar_t bar, uintptr_t addr, uint8_t access, size_t n, void *buf);
324 by Suren A. Chilingaryan
Documentation update
352
353
/**
354
 * Performs PIO write to the PCI BAR. The BAR will be automatically mapped and unmapped if necessary.
355
 * @param[in,out] ctx	- pcilib context
356
 * @param[in] bar	- the BAR to write, use PCILIB_BAR_DETECT to detect bar by the specified physical address
357
 * @param[in] addr	- absolute physical address to write or the offset in the specified bar
345 by Suren A. Chilingaryan
64-bit access to BAR memory
358
 * @param[in] access	- word size (access width in bytes)
359
 * @param[in] n		- number of words to write
324 by Suren A. Chilingaryan
Documentation update
360
 * @param[out] buf	- the pointer to the data to be written
361
 * @return 		- error code or 0 on success
362
 */ 
345 by Suren A. Chilingaryan
64-bit access to BAR memory
363
int pcilib_write(pcilib_t *ctx, pcilib_bar_t bar, uintptr_t addr, uint8_t access, size_t n, void *buf);
324 by Suren A. Chilingaryan
Documentation update
364
365
/**
366
 * Performs PIO read from the PCI BAR. The specified address is treated as FIFO and will be read
367
 * \a n times. The BAR will be automatically mapped and unmapped if necessary.
368
 * @param[in,out] ctx	- pcilib context
369
 * @param[in] bar	- the BAR to read, use PCILIB_BAR_DETECT to detect bar by the specified physical address
370
 * @param[in] addr	- absolute physical address to read or the offset in the specified bar
371
 * @param[in] access	- the size of FIFO register in bytes (i.e. if `access = 4`, the 32-bit reads from FIFO will be performed)
372
 * @param[in] n		- specifies how many times the data should be read from FIFO
373
 * @param[out] buf	- the data will be placed in this buffer which should be at least `n * access` bytes long
374
 * @return 		- error code or 0 on success
375
 */ 
376
int pcilib_read_fifo(pcilib_t *ctx, pcilib_bar_t bar, uintptr_t addr, uint8_t access, size_t n, void *buf);
377
378
/**
379
 * Performs PIO write to the PCI BAR. The specified address is treated as FIFO and will be written
380
 * \a n times. The BAR will be automatically mapped and unmapped if necessary.
381
 * @param[in,out] ctx	- pcilib context
382
 * @param[in] bar	- the BAR to write, use PCILIB_BAR_DETECT to detect bar by the specified physical address
383
 * @param[in] addr	- absolute physical address to write or the offset in the specified bar
384
 * @param[in] access	- the size of FIFO register in bytes (i.e. if `access = 4`, the 32-bit writes to FIFO will be performed)
385
 * @param[in] n		- specifies how many times the data should be written to FIFO
386
 * @param[out] buf	- buffer to write which should be at least `n * access` bytes long
387
 * @return 		- error code or 0 on success
388
 */ 
389
int pcilib_write_fifo(pcilib_t *ctx, pcilib_bar_t bar, uintptr_t addr, uint8_t access, size_t n, void *buf);
390
391
/** public_api_pci
392
 * @}
393
 */
394
395
396
/***********************************************************************************************************//**
397
 * \defgroup public_api_register Public Register API 
398
 * API for register manipulations
399
 * @{
400
 */
401
402
/**
403
 * Returns the list of registers provided by the hardware model.
404
 * @param[in,out] ctx	- pcilib context
405
 * @param[in] bank	- if set, only register within the specified bank will be returned
406
 * @param[in] flags	- currently ignored
407
 * @return 		- the list of the register which should be cleaned with pcilib_free_register_info() or NULL in the case of error
408
 */
409
pcilib_register_info_t *pcilib_get_register_list(pcilib_t *ctx, const char *bank, pcilib_list_flags_t flags);
410
411
/**
412
 * Returns the information about the specified register
413
 * @param[in,out] ctx	- pcilib context
414
 * @param[in] bank	- indicates the bank where to look for register, autodetected if NULL is passed
415
 * @param[in] reg	- the name of the register
416
 * @param[in] flags	- currently ignored
417
 * @return 		- information about the specified register which should be cleaned with pcilib_free_register_info() or NULL in the case of error
418
 */
419
pcilib_register_info_t *pcilib_get_register_info(pcilib_t *ctx, const char *bank, const char *reg, pcilib_list_flags_t flags);
420
421
/**
422
 * Cleans up the memory occupied by register list returned from the pcilib_get_register_list() and pcilib_get_register_info() calls
423
 * @param[in,out] ctx	- pcilib context
424
 * @param[in,out] info	- buffer to clean
425
 */
426
void pcilib_free_register_info(pcilib_t *ctx, pcilib_register_info_t *info);
427
428
/**
429
 * Finds register id corresponding to the specified bank and register names. It is faster 
430
 * to access registers by id instead of names. Therefore, in long running applications it 
431
 * is preferred to resolve names of all required registers during initialization and access 
432
 * them using ids only. 
433
 * @param[in,out] ctx	- pcilib context
434
 * @param[in] bank	- should specify the bank name if register with the same name may occur in multiple banks, NULL otherwise
435
 * @param[in] reg	- the name of the register
436
 * @return 		- register id or PCILIB_REGISTER_INVALID if register is not found
437
 */
438
pcilib_register_t pcilib_find_register(pcilib_t *ctx, const char *bank, const char *reg);
439
440
/**
441
 * Extracts additional information about the specified register. The additional information
442
 * is model-specific and are provided as extra XML attributes in XML-described registers.
443
 * The available attributes are only restricted by used XSD schema.
444
 * @param[in,out] ctx	- pcilib context
445
 * @param[in] reg	- register id
446
 * @param[in] attr	- requested attribute name
447
 * @param[in,out] val	- the value of attribute is returned here (see \ref public_api_value),
448
 *			pcilib_clean_value() will be executed if \a val contains data. Therefore it should be always initialized to 0 before first use
449
 * @return		- error code or 0 on success
450
 */ 
451
int pcilib_get_register_attr_by_id(pcilib_t *ctx, pcilib_register_t reg, const char *attr, pcilib_value_t *val);
452
453
/**
454
 * Extracts additional information about the specified register. 
455
 * Equivalent to the pcilib_get_register_attr_by_id(), but first resolves register id using the specified bank and name.
456
 * @param[in,out] ctx	- pcilib context
457
 * @param[in] bank	- should specify the bank name if register with the same name may occur in multiple banks, NULL otherwise
458
 * @param[in] regname	- register name
459
 * @param[in] attr	- requested attribute name
460
 * @param[in,out] val	- the value of attribute is returned here (see \ref public_api_value),
461
 *			pcilib_clean_value() will be executed if \a val contains data. Therefore it should be always initialized to 0 before first use
462
 * @return		- error code or 0 on success
463
 */ 
464
int pcilib_get_register_attr(pcilib_t *ctx, const char *bank, const char *regname, const char *attr, pcilib_value_t *val);
465
466
/**
467
 * Reads one or multiple sequential registers from the specified register bank. This function may provide access 
468
 * to the undefined registers in the bank. In other cases, the pcilib_read_register() / pcilib_read_register_by_id() 
469
 * calls are preferred.
470
 * @param[in,out] ctx	- pcilib context
471
 * @param[in] bank	- the bank to read (should be specified, no autodetection)
472
 * @param[in] addr	- the register address within the bank, addresses are counted in bytes not registers (i.e. it is offset in bytes from the start of register bank)
473
 * @param[in] n		- number of registers to read; i.e. `n * register_size`  bytes will be read, where \a register_size is defined in the bank configuration (see #pcilib_register_bank_description_t)
474
 * @param[out] buf	- the buffer of `n * register_size` bytes long where the data will be stored
475
 * @return		- error code or 0 on success
476
 */
477
int pcilib_read_register_space(pcilib_t *ctx, const char *bank, pcilib_register_addr_t addr, size_t n, pcilib_register_value_t *buf);
478
479
/**
480
 * Writes one or multiple sequential registers from the specified register bank. This function may provide access 
481
 * to the undefined registers in the bank. In other cases, the pcilib_write_register() / pcilib_write_register_by_id() 
482
 * calls are preferred.
483
 * @param[in,out] ctx	- pcilib context
484
 * @param[in] bank	- the bank to write (should be specified, no autodetection)
485
 * @param[in] addr	- the register address within the bank, addresses are counted in bytes not registers (i.e. it is offset in bytes from the start of register bank)
486
 * @param[in] n		- number of registers to write; i.e. `n * register_size`  bytes will be written, where \a register_size is defined in the bank configuration (see #pcilib_register_bank_description_t)
487
 * @param[in] buf	- the buffer of `n * register_size` bytes long with the data
488
 * @return		- error code or 0 on success
489
 */
490
int pcilib_write_register_space(pcilib_t *ctx, const char *bank, pcilib_register_addr_t addr, size_t n, const pcilib_register_value_t *buf);
491
492
/**
493
 * Reads the specified register.
494
 * @param[in,out] ctx	- pcilib context
495
 * @param[in] reg	- register id
496
 * @param[out] value	- the register value is returned here
497
 * @return		- error code or 0 on success
498
 */ 
499
int pcilib_read_register_by_id(pcilib_t *ctx, pcilib_register_t reg, pcilib_register_value_t *value);
500
501
/**
502
 * Writes to the specified register.
503
 * @param[in,out] ctx	- pcilib context
504
 * @param[in] reg	- register id
505
 * @param[in] value	- the register value to write
506
 * @return		- error code or 0 on success
507
 */ 
508
int pcilib_write_register_by_id(pcilib_t *ctx, pcilib_register_t reg, pcilib_register_value_t value);
509
510
/**
511
 * Reads the specified register.
512
 * Equivalent to the pcilib_read_register_by_id(), but first resolves register id using the specified bank and name.
513
 * @param[in,out] ctx	- pcilib context
514
 * @param[in] bank	- should specify the bank name if register with the same name may occur in multiple banks, NULL otherwise
515
 * @param[in] regname	- the name of the register
516
 * @param[out] value	- the register value is returned here
517
 * @return		- error code or 0 on success
518
 */ 
519
int pcilib_read_register(pcilib_t *ctx, const char *bank, const char *regname, pcilib_register_value_t *value);
520
521
/**
522
 * Writes to the specified register.
523
 * Equivalent to the pcilib_write_register_by_id(), but first resolves register id using the specified bank and name.
524
 * @param[in,out] ctx	- pcilib context
525
 * @param[in] bank	- should specify the bank name if register with the same name may occur in multiple banks, NULL otherwise
526
 * @param[in] regname	- the name of the register
527
 * @param[in] value	- the register value to write
528
 * @return		- error code or 0 on success
529
 */ 
530
int pcilib_write_register(pcilib_t *ctx, const char *bank, const char *regname, pcilib_register_value_t value);
531
532
533
/**
534
 * Reads a view of the specified register. The views allow to convert values to standard units
535
 * or get self-explanatory names associated with the values (enums).
536
 * @param[in,out] ctx	- pcilib context
537
 * @param[in] reg	- register id
538
 * @param[in] view	- specifies the name of the view associated with register or desired units
539
 * @param[out] value	- the register value is returned here (see \ref public_api_value),
540
 *			pcilib_clean_value() will be executed if \a val contains data. Therefore it should be always initialized to 0 before first use.
541
 * @return		- error code or 0 on success
542
 */ 
543
int pcilib_read_register_view_by_id(pcilib_t *ctx, pcilib_register_t reg, const char *view, pcilib_value_t *value);
544
545
/**
546
 * Writes the specified register using value represented in the specified view. The views allow to convert values from standard units
547
 * or self-explanatory names associated with the values (enums).
548
 * @param[in,out] ctx	- pcilib context
549
 * @param[in] reg	- register id
550
 * @param[in] view	- specifies the name of the view associated with register or the used units
551
 * @param[in] value	- the register value in the specified view (see \ref public_api_value)
552
 * @return		- error code or 0 on success
553
 */ 
554
int pcilib_write_register_view_by_id(pcilib_t *ctx, pcilib_register_t reg, const char *view, const pcilib_value_t *value);
555
556
/**
557
 * Reads a view of the specified register. The views allow to convert values to standard units
558
 * or get self-explanatory names associated with the values (enums).
559
 * Equivalent to the pcilib_read_register_view_by_id(), but first resolves register id using the specified bank and name.
560
 * @param[in,out] ctx	- pcilib context
561
 * @param[in] bank	- should specify the bank name if register with the same name may occur in multiple banks, NULL otherwise
562
 * @param[in] regname	- the name of the register
563
 * @param[in] view	- specifies the name of the view associated with register or desired units
564
 * @param[out] value	- the register value is returned here (see \ref public_api_value),
565
 *			pcilib_clean_value() will be executed if \a val contains data. Therefore it should be always initialized to 0 before first use
566
 * @return		- error code or 0 on success
567
 */ 
568
int pcilib_read_register_view(pcilib_t *ctx, const char *bank, const char *regname, const char *view, pcilib_value_t *value);
569
570
571
/**
572
 * Writes the specified register using value represented in the specified view. The views allow to convert values from standard units
573
 * or self-explanatory names associated with the values (enums).
574
 * Equivalent to the pcilib_write_register_view_by_id(), but first resolves register id using the specified bank and name.
575
 * @param[in,out] ctx	- pcilib context
576
 * @param[in] bank	- should specify the bank name if register with the same name may occur in multiple banks, NULL otherwise
577
 * @param[in] regname	- the name of the register
578
 * @param[in] view	- specifies the name of the view associated with register or the used units
579
 * @param[in] value	- the register value in the specified view (see \ref public_api_value)
580
 * @return		- error code or 0 on success
581
 */ 
582
int pcilib_write_register_view(pcilib_t *ctx, const char *bank, const char *regname, const char *view, const pcilib_value_t *value);
583
584
/** public_api_register
585
 * @}
586
 */
587
588
/***********************************************************************************************************//**
589
 * \defgroup public_api_property Public Property API 
590
 * Properties is another abstraction on top of registers allowing arbitrary data types and computed registers
591
 * @{
592
 */
593
594
/**
595
 * Returns the list of properties available under the specified path
596
 * @param[in,out] ctx	- pcilib context
597
 * @param[in] branch	- path or NULL to return the top-level properties
598
 * @param[in] flags	- not used at the moment
599
 * @return 		- the list of the properties which should be cleaned with pcilib_free_property_info() or NULL in the case of error
600
 */
319 by Suren A. Chilingaryan
Provide register listings in public API
601
pcilib_property_info_t *pcilib_get_property_list(pcilib_t *ctx, const char *branch, pcilib_list_flags_t flags);
324 by Suren A. Chilingaryan
Documentation update
602
603
/**
604
 * Cleans up the memory occupied by property list returned from the pcilib_get_property_list() call
605
 * @param[in,out] ctx	- pcilib context
606
 * @param[in,out] info	- buffer to clean
607
 */
319 by Suren A. Chilingaryan
Provide register listings in public API
608
void pcilib_free_property_info(pcilib_t *ctx, pcilib_property_info_t *info);
324 by Suren A. Chilingaryan
Documentation update
609
610
/**
611
 * Extracts additional information about the specified register. 
612
 * Equivalent to the pcilib_get_register_attr_by_id(), but first resolves register id using the specified bank and name.
613
 * @param[in,out] ctx	- pcilib context
614
 * @param[in] prop	- property name (full name including path)
615
 * @param[in] attr	- requested attribute name
616
 * @param[in,out] val	- the value of attribute is returned here (see \ref public_api_value),
617
 *			pcilib_clean_value() will be executed if \a val contains data. Therefore it should be always initialized to 0 before first use
618
 * @return		- error code or 0 on success
619
 */ 
620
int pcilib_get_property_attr(pcilib_t *ctx, const char *prop, const char *attr, pcilib_value_t *val);
621
622
/**
623
 * Reads / computes the property value.
624
 * @param[in,out] ctx	- pcilib context
625
 * @param[in] prop	- property name (full name including path)
626
 * @param[out] val	- the register value is returned here (see \ref public_api_value),
627
 *			pcilib_clean_value() will be executed if \a val contains data. Therefore it should be always initialized to 0 before first use
628
 * @return		- error code or 0 on success
629
 */ 
630
int pcilib_get_property(pcilib_t *ctx, const char *prop, pcilib_value_t *val);
631
632
/**
633
 * Writes the property value or executes the code associated with property
634
 * @param[in,out] ctx	- pcilib context
635
 * @param[in] prop	- property name (full name including path)
636
 * @param[out] val	- the property value (see \ref public_api_value),
637
 * @return		- error code or 0 on success
638
 */ 
639
int pcilib_set_property(pcilib_t *ctx, const char *prop, const pcilib_value_t *val);
640
641
/** public_api_property
642
 * @}
643
 */
644
645
/***********************************************************************************************************//**
646
 * \defgroup public_api_dma Public DMA API
647
 * High speed interface for reading and writting unstructured data
648
 * @{
649
 */
650
651
/**
652
 * This function resolves the ID of DMA engine from its address and direction.
653
 * It is a bit confusing, but addresses should be able to represent bi-directional
654
 * DMA engines. Unfortunatelly, implementation often is limited to uni-directional
655
 * engines. In this case, two DMA engines with different IDs can be virtually 
656
 * combined in a DMA engine with the uniq address. This will allow user to specify
657
 * the same engine address in all types of accesses and we will resolve the appropriate 
658
 * engine ID depending on the requested direction.
659
 * @param[in,out] ctx	- pcilib context
660
 * @param[in] direction	- DMA direction (to/from device)
661
 * @param[in] dma	- address of DMA engine
662
 * @return		- ID of DMA engine or PCILIB_DMA_INVALID if the specified engine does not exist
663
 */
664
pcilib_dma_engine_t pcilib_find_dma_by_addr(pcilib_t *ctx, pcilib_dma_direction_t direction, pcilib_dma_engine_addr_t dma);
665
666
/**
667
 * Starts DMA engine. This call will allocate DMA buffers and pass their bus addresses to the hardware.
668
 *  - During the call, the C2S engine may start writting data. The written buffers are marked as
669
 * ready and can be read-out using pcilib_stream_dma() and pcilib_read_dma() calls. If no empty
670
 * buffers left, the C2S DMA engine will stall until some buffers are read out. 
671
 *  - The S2C engine waits until the data is pushed with pcilib_push_data() call
672
 *
673
 * After pcilib_start_dma() call, the pcilib_stop_dma() function should be necessarily called. However,
674
 * it will clean up the process memory, but only in some cases actually stop the DMA engine.
675
 * This depends on \a flags passed to both pcilib_start_dma() and pcilib_stop_dma() calls.
676
 * if PCILIB_DMA_FLAG_PERSISTENT flag is passed to the pcilib_start_dma(), the DMA engine
677
 * will remain running unless the same flag is also passed to the pcilib_stop_dma() call.
678
 * The allocated DMA buffers will stay intact and the hardware may continue reading / writting
679
 * data while there is space/data left. However, the other functions of DMA API should not
680
 * be called after pcilib_stop_dma() until new pcilib_start_dma() call is issued.
681
 *
682
 * The process- and thread-safety is implementation depedent. However, currently the process-
683
 * safety is ensured while accessing the kernel memory (todo: this may get complicated if we 
684
 * provide a way to perform DMA directly to the user-supplied pages). 
685
 * The thread-safety is not provided by currently implemented DMA engines. The DMA functions
686
 * may be called from multiple threads, but it is user responsibility to ensure that only a 
687
 * single DMA-related call is running. On other hand, the DMA and register APIs may be used
688
 * in parallel.
689
 *
690
 * @param[in,out] ctx	- pcilib context
691
 * @param[in] dma	- ID of DMA engine, the ID should first be resolved using pcilib_find_dma_by_addr()
692
 * @param[in] flags	- PCILIB_DMA_FLAG_PERSISTENT indicates that engine should be kept running after pcilib_stop_dma() call
693
 * @return 		- error code or 0 on success
694
 */
62 by Suren A. Chilingaryan
Suppport DMA modes in console application (not functional yet)
695
int pcilib_start_dma(pcilib_t *ctx, pcilib_dma_engine_t dma, pcilib_dma_flags_t flags);
324 by Suren A. Chilingaryan
Documentation update
696
697
/**
698
 * Stops DMA engine or just cleans up the process-specific memory buffers (see 
699
 * pcilib_start_dma() for details). No DMA API calls allowed after this point
700
 * until pcilib_start_dma() is called anew.
701
 *
702
 * @param[in,out] ctx	- pcilib context
703
 * @param[in] dma	- ID of DMA engine, the ID should first be resolved using pcilib_find_dma_by_addr()
704
 * @param[in] flags	- PCILIB_DMA_FLAG_PERSISTENT indicates that engine should be actually stopped independent of the flags passed to pcilib_start_dma() call
705
 * @return 		- error code or 0 on success
706
 */ 
62 by Suren A. Chilingaryan
Suppport DMA modes in console application (not functional yet)
707
int pcilib_stop_dma(pcilib_t *ctx, pcilib_dma_engine_t dma, pcilib_dma_flags_t flags);
88 by Suren A. Chilingaryan
IRQ acknowledgement support in the engine API
708
324 by Suren A. Chilingaryan
Documentation update
709
/**
710
 * Tries to drop all pending data in the DMA channel. It will drop not only data currently in the DMA buffers,
711
 * but will allow hardware to write more and will drop the newly written data as well. The standard DMA timeout 
712
 * is allowed to receive new data. If hardware continuously writes data, after #PCILIB_DMA_SKIP_TIMEOUT 
713
 * microseconds the function will exit with #PCILIB_ERROR_TIMEOUT error. 
714
 *
715
 * @param[in,out] ctx	- pcilib context
716
 * @param[in] dma	- ID of DMA engine, the ID should first be resolved using pcilib_find_dma_by_addr()
717
 * @return 		- error code or 0 on success
718
 */
719
int pcilib_skip_dma(pcilib_t *ctx, pcilib_dma_engine_t dma);
720
721
/**
722
 * Reads data from DMA buffers and pass it to the specified callback function. The return code of the callback
723
 * function determines if streaming should continue and how much to wait for next data to arrive before 
724
 * triggering timeout. 
725
 * The function is process- and thread-safe. The PCILIB_ERROR_BUSY will be returned immediately if DMA is used 
726
 * by another thread or process.
727
 *
728
 * The function waits the specified \a timeout microseconds for the first data. Afterwards, the waiting time
729
 * for next portion of data depends on the last return code \a (ret) from callback function. 
730
 * If `ret & PCILIB_STREAMING_TIMEOUT_MASK` is
731
 *   - PCILIB_STREAMING_STOP		- the streaming stops
732
 *   - PCILIB_STREAMING_CONTINUE	- the standard DMA timeout will be used to wait for a new data
733
 *   - PCILIB_STREAMING_WAIT		- the timeout specified in the function arguments will be used to wait for a new data
734
 *   - PCILIB_STREAMING_CHECK		- the function will return if new data is not available immediately
735
 * The function return code depends on the return code from the callback as well. If no data received within the specified 
736
 * timeout and no callback is called, the PCILIB_ERROR_TIMEOUT is returned. Otherwise, success is returned unless 
737
 * PCILIB_STREAMING_FAIL flag has been set in the callback return code before the timeout was triggered.
738
 * 
739
 * @param[in,out] ctx	- pcilib context
740
 * @param[in] dma	- ID of DMA engine, the ID should first be resolved using pcilib_find_dma_by_addr()
741
 * @param[in] addr	- instructs DMA to start reading at the specified address (not supported by existing DMA engines)
742
 * @param[in] size	- instructs DMA to read only \a size bytes (not supported by existing DMA engines)
743
 * @param[in] flags	- not used by existing DMA engines
744
 * @param[in] timeout	- specifies number of microseconds to wait before reporting timeout, special values #PCILIB_TIMEOUT_IMMEDIATE and #PCILIB_TIMEOUT_INFINITE are supported.
745
 * @param[in] cb	- callback function to call
746
 * @param[in,out] cbattr - passed through as the first parameter of callback function
747
 * @return 		- error code or 0 on success
748
 */
749
int pcilib_stream_dma(pcilib_t *ctx, pcilib_dma_engine_t dma, uintptr_t addr, size_t size, pcilib_dma_flags_t flags, pcilib_timeout_t timeout, pcilib_dma_callback_t cb, void *cbattr);
750
751
/**
752
 * Reads data from DMA until timeout is hit, a full DMA packet is read,  or the specified number of bytes are read.
753
 * The function is process- and thread-safe. The #PCILIB_ERROR_BUSY will be returned immediately if DMA is used 
754
 * by another thread or process.
755
 *
756
 * We can't read arbitrary number of bytes from DMA. A full DMA packet is always read. The DMA packet is not equal 
757
 * to DMA buffer, but may consist of multiple buffers and the size may vary during run time. This may cause problems
758
 * if not treated properly. While the number of actually read bytes is bellow the specified size, the function may
759
 * continue to read the data. But as the new packet is started, it should fit completely in the provided buffer space
760
 * or PCILIB_ERROR_TOOBIG error will be returned. Therefore, it is a good practice to read only a single packet at 
761
 * once and provide buffer capable to store the larges possible packet.
762
 *
763
 * Unless #PCILIB_DMA_FLAG_MULTIPACKET flag is specified, the function will stop after the first full packet is read.
764
 * Otherwise, the reading will continue until all `size` bytes are read or timeout is hit. The stanard DMA timeout
765
 * should be met while reading DMA buffers belonging to the same packet. Otherwise, PCILIB_ERROR_TIMEOUT is returned
766
 * and number of bytes read so far is returned in the `rdsize`.
767
 * If #PCILIB_DMA_FLAG_WAIT flag is specified, the number of microseconds specified in the `timeout` parameter are 
768
 * allowed for a new packet to come. If no new data arrived in the specified timeout, the function returns successfuly 
769
 * and number of read bytes is returned in the `rdsize`.
770
 *
771
 * We can't put the read data back into the DMA. Therefore, even in the case of error some data may be returned. The 
772
 * number of actually read bytes is always reported in `rdsize` and the specified amount of data is always written 
773
 * to the provided buffer.
774
 *
775
 * @param[in,out] ctx	- pcilib context
776
 * @param[in] dma	- ID of DMA engine, the ID should first be resolved using pcilib_find_dma_by_addr()
777
 * @param[in] addr	- instructs DMA to start reading at the specified address (not supported by existing DMA engines)
778
 * @param[in] size	- specifies how many bytes should be read
779
 * @param[in] flags	- Various flags controlling the function behavior
780
 *			  - #PCILIB_DMA_FLAG_MULTIPACKET indicates that multiple DMA packets will be read (not recommended, use pcilib_stream_dma() in this case)
781
 *			  - #PCILIB_DMA_FLAG_WAIT indicates that we need to wait the specified timeout between consequitive DMA packets (default DMA timeout is used otherwise)
782
 * @param[in] timeout	- specifies number of microseconds to wait before reporting timeout, special values #PCILIB_TIMEOUT_IMMEDIATE and #PCILIB_TIMEOUT_INFINITE are supported.
783
 *			This parameter specifies timeout between consequtive DMA packets, the standard DMA timeout is expected between buffers belonging to the same DMA packet.
784
 * @param[out] buf	- the buffer of \a size bytes long to store the data
785
 * @param[out] rdsize	- number of bytes which were actually read. The correct value will be reported in both case if function has finished successfully or if error has happened.
786
 * @return 		- error code or 0 on success. In both cases some data may be returned in the buffer, check `rdsize`.
787
 */
788
int pcilib_read_dma_custom(pcilib_t *ctx, pcilib_dma_engine_t dma, uintptr_t addr, size_t size, pcilib_dma_flags_t flags, pcilib_timeout_t timeout, void *buf, size_t *rdsize);
789
790
/**
791
 * Reads data from DMA until timeout is hit, a full DMA packet is read, or the specified number of bytes are read.
792
 * Please, check detailed explanation when reading is stopped in the description of pcilib_read_dma_custom().
793
 * The function is process- and thread-safe. The #PCILIB_ERROR_BUSY will be returned immediately if DMA is used 
794
 * by another thread or process. 
795
 *
796
 * The function actually executes the pcilib_read_dma_custom() without special flags and with default DMA timeout
797
 *
798
 * @param[in,out] ctx	- pcilib context
799
 * @param[in] dma	- ID of DMA engine, the ID should first be resolved using pcilib_find_dma_by_addr()
800
 * @param[in] addr	- instructs DMA to start reading at the specified address (not supported by existing DMA engines)
801
 * @param[in] size	- specifies how many bytes should be read
802
 * @param[out] buf	- the buffer of \a size bytes long to store the data
803
 * @param[out] rdsize	- number of bytes which were actually read. The correct value will be reported in both case if function has finished successfully or if error has happened.
804
 * @return 		- error code or 0 on success. In both cases some data may be returned in the buffer, check `rdsize`.
805
 */
806
int pcilib_read_dma(pcilib_t *ctx, pcilib_dma_engine_t dma, uintptr_t addr, size_t size, void *buf, size_t *rdsize);
807
808
/**
809
 * Pushes new data to the DMA engine. The actual behavior is implementation dependent. The successful exit does not mean
810
 * what all data have reached hardware, but only guarantees that it is stored in DMA buffers and the hardware is instructed
811
 * to start reading buffers. The function may return #PCILIB_ERROR_TIMEOUT is all DMA buffers are occupied and no buffers is
812
 * read by the hardware within the specified timeout. Even if an error is returned, part of the data may be already send to
813
 * DMA and can't be revoked back. Number of actually written bytes is always returned in the `wrsize`.
814
 *
815
 * The function is process- and thread-safe. The #PCILIB_ERROR_BUSY will be returned immediately if DMA is used 
816
 * by another thread or process.
817
 *
818
 * @param[in,out] ctx	- pcilib context
819
 * @param[in] dma	- ID of DMA engine, the ID should first be resolved using pcilib_find_dma_by_addr()
820
 * @param[in] addr	- instructs DMA to start writting at the specified address (not supported by existing DMA engines)
821
 * @param[in] size	- specifies how many bytes should be written
822
 * @param[in] flags	- Various flags controlling the function behavior
823
 *			  - #PCILIB_DMA_FLAG_EOP indicates that this is the last data in the DMA packet
824
 *			  - #PCILIB_DMA_FLAG_WAIT requires function to block until the data actually reach hardware. #PCILIB_ERROR_TIMEOUT may be returned if it takes longer when the specified timeout.
825
  * @param[in] timeout	- specifies number of microseconds to wait before reporting timeout, special values #PCILIB_TIMEOUT_IMMEDIATE and #PCILIB_TIMEOUT_INFINITE are supported.
826
 * @param[out] buf	- the buffer with the data
827
 * @param[out] wrsize	- number of bytes which were actually written. The correct value will be reported in both case if function has finished successfully or if error has happened.
828
 * @return 		- error code or 0 on success. In both cases some data may be written to the DMA, check `wrsize`.
829
 */
830
int pcilib_push_dma(pcilib_t *ctx, pcilib_dma_engine_t dma, uintptr_t addr, size_t size, pcilib_dma_flags_t flags, pcilib_timeout_t timeout, void *buf, size_t *wrsize);
831
832
833
/**
834
 * Pushes new data to the DMA engine and blocks until hardware gets it all.  Even if an error has occured, a 
835
 * part of the data may be already had send to DMA and can't be revoked back. Number of actually written bytes 
836
 * is always returned in the `wrsize`.
837
 *
838
 * The function is process- and thread-safe. The #PCILIB_ERROR_BUSY will be returned immediately if DMA is used 
839
 * by another thread or process.
840
841
 * The function actually executes the pcilib_push_dma() with #PCILIB_DMA_FLAG_EOP and #PCILIB_DMA_FLAG_WAIT flags set and
842
 * the default DMA timeout.
843
 *
844
 * @param[in,out] ctx	- pcilib context
845
 * @param[in] dma	- ID of DMA engine, the ID should first be resolved using pcilib_find_dma_by_addr()
846
 * @param[in] addr	- instructs DMA to start writting at the specified address (not supported by existing DMA engines)
847
 * @param[in] size	- specifies how many bytes should be written
848
 * @param[out] buf	- the buffer with the data
849
 * @param[out] wrsize	- number of bytes which were actually written. The correct value will be reported in both case if function has finished successfully or if error has happened.
850
 * @return 		- error code or 0 on success. In both cases some data may be written to the DMA, check `wrsize`.
851
 */
852
int pcilib_write_dma(pcilib_t *ctx, pcilib_dma_engine_t dma, uintptr_t addr, size_t size, void *buf, size_t *wrsize);
853
854
/**
855
 * Benchmarks the DMA implementation. The reported performance may be significantly affected by several environmental variables.
856
 *  - PCILIB_BENCHMARK_HARDWARE	 - if set will not copy the data out, but immediately drop as it lended in DMA buffers. This allows to remove influence of memcpy performance.
857
 *  - PCILIB_BENCHMARK_STREAMING - if set will not re-initialized the DMA on each iteration. If DMA is properly implemented this should have only marginal influence on performance
858
 *
859
 * The function is process- and thread-safe. The #PCILIB_ERROR_BUSY will be returned immediately if DMA is used 
860
 * by another thread or process.
861
 *
862
 * @param[in,out] ctx	- pcilib context
863
 * @param[in] dma	- Address of DMA engine
864
 * @param[in] addr	- Benchmark will read and write data at the specified address (ignored by existing DMA engines)
865
 * @param[in] size	- specifies how many bytes should be read and written at each iteration
866
 * @param[in] iterations - number of iterations to execute
867
 * @param[in] direction - Specifies if DMA reading or writting should be benchmarked, bi-directional benchmark is possible as well
868
 * @return		- bandwidth in MiB/s (Mebibytes per second)
869
 */
870
double pcilib_benchmark_dma(pcilib_t *ctx, pcilib_dma_engine_addr_t dma, uintptr_t addr, size_t size, size_t iterations, pcilib_dma_direction_t direction);
871
872
/** public_api_dma
873
 * @}
874
 */
875
876
/***********************************************************************************************************//**
877
 * \defgroup public_api_irq Public IRQ API
878
 * This is actually part of DMA API. IRQ handling is currently provided by DMA engine. 
879
 * However, the IRQs are barely used so far. Therefore, the API can be significantly changed when confronted with harsh reallity.
880
 * @{
881
 */
882
63 by Suren A. Chilingaryan
Provide IRQ enable/disable call
883
int pcilib_enable_irq(pcilib_t *ctx, pcilib_irq_type_t irq_type, pcilib_dma_flags_t flags);
62 by Suren A. Chilingaryan
Suppport DMA modes in console application (not functional yet)
884
int pcilib_disable_irq(pcilib_t *ctx, pcilib_dma_flags_t flags);
88 by Suren A. Chilingaryan
IRQ acknowledgement support in the engine API
885
int pcilib_wait_irq(pcilib_t *ctx, pcilib_irq_hw_source_t source, pcilib_timeout_t timeout, size_t *count);
324 by Suren A. Chilingaryan
Documentation update
886
int pcilib_acknowledge_irq(pcilib_t *ctx, pcilib_irq_type_t irq_type, pcilib_irq_source_t irq_source);
88 by Suren A. Chilingaryan
IRQ acknowledgement support in the engine API
887
int pcilib_clear_irq(pcilib_t *ctx, pcilib_irq_hw_source_t source);
55 by Suren A. Chilingaryan
IRQ support in NWL DMA engine
888
324 by Suren A. Chilingaryan
Documentation update
889
/** public_api_irq
890
 * @}
891
 */
892
893
/***********************************************************************************************************//**
894
 * \defgroup public_api_event Public Event API
895
 * High level API for reading the structured data from hardware
896
 * @{
897
 */
898
899
/**
900
 * Provides access to the context of event engine. This may be required to call implementation-specific
901
 * functions of event engine.
902
 * @param [in,out] ctx	- pcilib context
903
 * @return 		- context of event engine or NULL in the case of error. Depending on the implementation can be extension of pcilib_contex_t, it should be safe to type cast if you are running the correct engine.
904
 */
905
pcilib_context_t *pcilib_get_event_engine(pcilib_t *ctx);
906
907
/** 
908
 * Resolves the event ID based on its name.
909
 * @param [in,out] ctx	- pcilib context
910
 * @param [in] event	- the event name
911
 * @return		- the event ID or PCILIB_EVENT_INVALID if event is not found
912
 */
16 by Suren A. Chilingaryan
Prototype of IPECamera image protocol
913
pcilib_event_t pcilib_find_event(pcilib_t *ctx, const char *event);
324 by Suren A. Chilingaryan
Documentation update
914
915
916
/**
917
 * Analyzes current configuration, allocates necessary buffers and spawns required data processing threads. 
918
 * Depending on the implementation and the current configuration, the actual event grabbing may start already
919
 * here. In this case, the preprocessed events will be storred in the temporary buffers and may be lost if
920
 * pcilib_stop() is called before reading them out. Alternatively, the actual grabbing may only commend when
921
 * the pcilib_stream() or pcilib_get_next_event() functions are executed. 
922
 * The function is non-blocking and will return immediately after allocating required memory and spawning 
923
 * of the preprocessing threads. It is important to call pcilib_stop() in the end.
924
 *
925
 * The grabbing will stop automatically if conditions defined using pcilib_configure_autostop() function
926
 * are met. It also possible to stop grabbing using pcilib_stop() call at any moment.
927
 *
928
 * The process- and thread-safety is implementation depedent. However, normally the event engine will depend
929
 * on DMA and if DMA engine is process-safe it will ensure the process-safety for event engine as well.
930
 * The thread-safety is not directly ensured by currently implemented Event engines. The functions of Event
931
 * engine may be called from multiple threads, but it is the user responsibility to ensure that only a single
932
 * function of Event engine is running at each moment. On other hand, the Event and register APIs may be used
933
 * in parallel.
934
 *
935
 * @param[in,out] ctx	- pcilib context
936
 * @param[in] ev_mask	- specifies events to listen for, use #PCILIB_EVENTS_ALL to grab all events
937
 * @param[in] flags	- various implementation-specific flags controlling operation of event engine
938
 *			   - #PCILIB_EVENT_FLAG_PREPROCESS - requires event preprocessing (i.e. event data is decoded before it is requested, this is often required for multi-threaded processing)
939
 *			   - #PCILIB_EVENT_FLAG_RAW_DATA_ONLY - disables data processing at all, only raw data will be provided in this case
940
 * @return 		- error code or 0 on success
941
 */
942
int pcilib_start(pcilib_t *ctx, pcilib_event_t ev_mask, pcilib_event_flags_t flags);
943
 
944
945
/**
946
 * Stops event grabbing and optionally cleans up the used memory.
947
 * This function operates in two modes. If #PCILIB_EVENT_FLAG_STOP_ONLY flag is specified, the 
948
 * event grabbing is stopped, but all memory structures are kept intact. This also forces the
949
 * blocked pcilib_stream() and pcilib_get_next_event() to return after a short while. 
950
951
 * Unlike DMA engine, the event engine is not persistent and is always completely stopped when 
952
 * application is finished. Therefore, later the pcilib_stop() should be necessarily called 
953
 * again without #PCILIB_EVENT_FLAG_STOP_ONLY flag to commend full clean up and release all
954
 * used memory. Such call may only be issued when no threads are using Event engine any more. 
955
 * There should be no functions waiting for next event to appear and all of the obtained event 
956
 * data should be already returned back to the system.
957
 *
958
 * pcilib_stop executed with #PCILIB_EVENT_FLAG_STOP_ONLY is thread safe. The full version of
959
 * the function is not and should be never called in parallel with any other action of the
960
 * event engine. Actually, it is thread safe in the case of ipecamera, but this is not 
961
 * guaranteed for other event engines.
962
 *
963
 * @param[in,out] ctx	- pcilib context
964
 * @param[in] flags	- flags specifying operation mode
965
 *			   - #PCILIB_EVENT_FLAG_STOP_ONLY - instructs library to keep all the data structures intact and to onlystop the data grabbing
966
 * @return		- error code or 0 on success
967
 */
968
int pcilib_stop(pcilib_t *ctx, pcilib_event_flags_t flags);
969
970
/**
971
 * Streams the incomming events to the provided callback function. If Event engine is not started
972
 * yet, it will be started and terminated upon the completion of the call. The streaming will 
973
 * continue while Event engine is started and the callback function does not return an error (negative)
974
 * or #PCILIB_STREAMING_STOP. 
975
 *
976
 * The callback is called only when all the data associated with the event is received from hardware. 
977
 * So, the raw data is necessarily present, but availability of alternative data formats is
978
 * optional. Depending on the implementation and current configuration, the data decoding can be 
979
 * performed beforehand, in parallel with callback execution, or only them the data is 
980
 * requested with pcilib_get_data() or pcilib_copy_data() calls.
981
 *
982
 * The function is thread-safe. The multiple requests to pcilib_stream() and pcilib_get_next_event() 
983
 * will be automatically serialized by the event engine. The pcilib_stream() is running in the 
984
 * single thread and no new calls to callback are issued until currently executed callback 
985
 * returns. The client application may get hold on the data from multiple events simultaneously. 
986
 * However, the data could be overwritten meanwhile by the hardware. The pcilib_return_data() 
987
 * will inform if it has happened by returning #PCILIB_ERROR_OVERWRITTEN. 
988
 *
989
 * @param[in,out] ctx	- pcilib context
990
 * @param[in] callback	- callback function to call for each event, the streaming is stopped if it return #PCILIB_STREAMING_STOP or negative value indicating the error
991
 * @param[in,out] user	- used data is passed through as the last parameter of callback function
992
 * @return		- error code or 0 on success
993
 */
994
int pcilib_stream(pcilib_t *ctx, pcilib_event_callback_t callback, void *user);
995
996
/**
997
 * Waits until the next event is available. 
998
 * The event is only returned when all the data associated with the event is received from hardware.
999
 * So, the raw data is necessarily present, but availability of alternative data formats is
1000
 * optional. Depending on the implementation and current configuration, the data decoding can be 
1001
 * performed beforehand, in parallel, or only them the data is requested with pcilib_get_data() 
1002
 * or pcilib_copy_data() calls.
1003
 *
1004
 * The function is thread-safe. The multiple requests to pcilib_stream() and pcilib_get_next_event() 
1005
 * will be automatically serialized by the event engine. The client application may get hold on 
1006
 * the data from multiple events simultaneously. However, the data could be overwritten meanwhile 
1007
 * by the hardware. The pcilib_return_data() will inform if it has happened by returning 
1008
 * #PCILIB_ERROR_OVERWRITTEN. 
1009
 *
1010
 * @param[in,out] ctx	- pcilib context
1011
 * @param[in] timeout	- specifies number of microseconds to wait for next event before reporting timeout, special values #PCILIB_TIMEOUT_IMMEDIATE and #PCILIB_TIMEOUT_INFINITE are supported.
1012
 * @param[out] evid	- the event ID is returned in this parameter
1013
 * @param[in] info_size	- the size of the passed event info structure (the implementation of event engine may extend the standad #pcilib_event_info_t definition and provide extra information about the event.
1014
			If big enough info buffer is provided, this additional information will be copied as well. Otherwise only standard information is provided.
1015
 * @param[out] info	- The information about the recorded event is written to `info`
1016
 * @return		- error code or 0 on success
1017
 */
1018
int pcilib_get_next_event(pcilib_t *ctx, pcilib_timeout_t timeout, pcilib_event_id_t *evid, size_t info_size, pcilib_event_info_t *info);
1019
1020
/**
1021
 * Requests the streaming the rawdata from the event engine. The callback will be called 
1022
 * each time new DMA packet is received. It is the fastest way to acuqire data. 
1023
 * No memory copies performed and DMA buffers are directly passed to the specified callback. 
1024
 * However, to prevent data loss, no long processing is allowed is only expected to copy data 
1025
 * into the appropriate place and return control to the event engine.
1026
 *
1027
 * This function should be exectued before the grabbing is started with pcilib_start().
1028
 * The performance can be boosted further by disabling any data processing within the event
1029
 * engine. This is achieved by passing the #PCILIB_EVENT_FLAG_RAW_DATA_ONLY flag to pcilib_start() 
1030
 * function while starting the grabbing.
1031
 *
1032
 * @param[in,out] ctx	- pcilib context
1033
 * @param[in] callback	- callback function to call for each event, the streaming is stopped if it return #PCILIB_STREAMING_STOP or negative value indicating the error
1034
 * @param[in,out] user	- used data is passed through as the last parameter of callback function
1035
 * @return		- error code or 0 on success
1036
 */
1037
int pcilib_configure_rawdata_callback(pcilib_t *ctx, pcilib_event_rawdata_callback_t callback, void *user);
1038
1039
/**
1040
 * Configures conditions when the grabbing will be stopped automatically. The recording of new events may be 
1041
 * stopped after reaching max_events records or when the specified amount of time is elapsed whatever happens
1042
 * first. However, the pcilib_stop() function still must be called afterwards. 
1043
 *
1044
 * This function should be exectued before the grabbing is started with pcilib_start(). 
1045
 * NOTE that this options might not be respected if grabbing is started with the 
1046
 * #PCILIB_EVENT_FLAG_RAW_DATA_ONLY flag specified.
1047
 *
1048
 * @param[in,out] ctx	- pcilib context
1049
 * @param[in] max_events - specifies number of events after which the grabbing is stopped
1050
 * @param[in] duration	- specifies number of microseconds to run the grabbing, special values #PCILIB_TIMEOUT_IMMEDIATE and #PCILIB_TIMEOUT_INFINITE are supported.
1051
 * @return		- error code or 0 on success
1052
 */
1053
int pcilib_configure_autostop(pcilib_t *ctx, size_t max_events, pcilib_timeout_t duration);
1054
1055
/**
1056
 * Request the auto-triggering while grabbing. The software triggering is currently not supported (but planned).
1057
 * Therefore it is fully relied on hardware support. If no hardware support is available, #PCILIB_ERROR_NOTSUPPORTED
1058
 * will be returned. 
1059
 *
1060
 * This function should be exectued before the grabbing is started with pcilib_start().
1061
 *
1062
 * @param[in,out] ctx	- pcilib context
1063
 * @param[in] interval	- instructs hardware that each `interval` microseconds a new trigger should be issued
1064
 * @param[in] event	- specifies ID of the event which will be triggered
1065
 * @param[in] trigger_size - specifies the size of `trigger` buffer
1066
 * @param[in] trigger_data - this implementation-specific buffer which will be passed through to the Event engine
1067
 * @return		- error code or 0 on success
1068
 */
1069
int pcilib_configure_autotrigger(pcilib_t *ctx, pcilib_timeout_t interval, pcilib_event_t event, size_t trigger_size, void *trigger_data);
1070
1071
/** 
1072
 * Issues a single software trigger for the specified event. No hardware support is required. The function 
1073
 * is fully thread safe and can be called while other thread is blocked in the pcilib_stream() or pcilib_get_next_event()
1074
 * calls.
1075
 *
1076
 * @param[in,out] ctx	- pcilib context
1077
 * @param[in] event	- specifies ID of the event to trigger
1078
 * @param[in] trigger_size - specifies the size of `trigger` buffer
1079
 * @param[in] trigger_data - this implementation-specific buffer which will be passed through to the Event engine
1080
 * @return		- error code or 0 on success
1081
 */  
1082
int pcilib_trigger(pcilib_t *ctx, pcilib_event_t event, size_t trigger_size, void *trigger_data);
1083
1084
/** public_api_event
1085
 * @}
1086
 */
1087
1088
/***********************************************************************************************************//**
1089
 * \defgroup public_api_event_data Public Event Data API
1090
 * A part of Event API actually providing access to the data
1091
 * @{
1092
 */
1093
1094
/**
1095
 * Resolves the data type based on its name.
1096
 * @param[in,out] ctx	- pcilib context
1097
 * @param[in] event	- the ID of the event producing the data
1098
 * @param[in] data_type	- the name of data type
1099
 * @return		- the data type or PCILIB_EVENT_DATA_TYPE_INVALID if the specified type is not found 
1100
 */
117 by Suren A. Chilingaryan
new event architecture, first trial
1101
pcilib_event_data_type_t pcilib_find_event_data_type(pcilib_t *ctx, pcilib_event_t event, const char *data_type);
324 by Suren A. Chilingaryan
Documentation update
1102
1103
/**
1104
 * This is a simples way to grab the data from the event engine. The event engine is started, a software trigger
1105
 * for the specified event is issued if `timeout` is equal to PCILIB_TIMEOUT_IMMEDIATE, event is grabbed and the 
1106
 * default data is copied into the user buffer. Then, the grabbing is stopped.
1107
 * @param[in,out] ctx	- pcilib context
1108
 * @param[in] event	- the event to trigger and/or event mask to grab
1109
 * @param[in,out] size	- specifies the size of the provided buffer (if user supplies the buffer), the amount of data actually written is returned in this paramter
1110
 * @param[in,out] data  - Either contains a pointer to user-supplied buffer where the data will be written or pointer to NULL otherwise. 
1111
			In the later case, the pointer to newly allocated buffer will be returned in case of success. It is responsibility of the user to free the memory in this case.
1112
			In case of failure, the content of data is undefined.
1113
 * @param[in] timeout	- either is equal to #PCILIB_TIMEOUT_IMMEDIATE for immediate software trigger or specifies number of microseconds to wait for event triggered by hardware
1114
 * @return 		- error code or 0 on success
1115
 */
1116
int pcilib_grab(pcilib_t *ctx, pcilib_event_t event, size_t *size, void **data, pcilib_timeout_t timeout);
1117
1118
/**
1119
 * Copies the data of the specified type associated with the specified event into the provided buffer. May return #PCILIB_ERROR_OVERWRITTEN
1120
 * if the data was overwritten during the call.
1121
 *
1122
 * @param[in,out] ctx	- pcilib context
1123
 * @param[in] event_id	- specifies the ID of event to get data from
1124
 * @param[in] data_type	- specifies the desired type of data
1125
			  - PCILIB_EVENT_DATA will request the default data type
1126
			  - PCILIB_EVENT_RAW_DATA will request the raw data
1127
			  - The other types of data may be defined by event engine
1128
 * @param[in] size	- specifies the size of provided buffer in bytes
1129
 * @param[out] buf	- the data will be copied in this buffer if it is big enough, otherwise #PCILIB_ERROR_TOOBIG will be returned
1130
 * @param[out] retsize	- the number of actually written bytes will be returned in this parameter
1131
 * @return 		- error code or 0 on success
1132
 */ 
1133
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);
1134
1135
/**
1136
 * Copies the data of the specified type associated with the specified event into the provided buffer. May return #PCILIB_ERROR_OVERWRITTEN
1137
 * if the data was overwritten during the call. This is very similar to pcilib_copy_data(), but allows to specify implementation specific 
1138
 * argument explaining the requested data format.
1139
 *
1140
 * @param[in,out] ctx	- pcilib context
1141
 * @param[in] event_id	- specifies the ID of event to get data from
1142
 * @param[in] data_type	- specifies the desired type of data
1143
			  - PCILIB_EVENT_DATA will request the default data type
1144
			  - PCILIB_EVENT_RAW_DATA will request the raw data
1145
			  - The other types of data may be defined by event engine
1146
 * @param[in] arg_size	- specifies the size of `arg` in bytes
1147
 * @param[in] arg	- implementation-specific argument expalining the requested data format
1148
 * @param[in] size	- specifies the size of provided buffer in bytes
1149
 * @param[out] buf	- the data will be copied in this buffer if it is big enough, otherwise #PCILIB_ERROR_TOOBIG will be returned
1150
 * @param[out] retsize	- the number of actually written bytes will be returned in this parameter
1151
 * @return 		- error code or 0 on success
1152
 */ 
1153
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);
1154
1155
1156
/**
1157
 * Returns pointer to the data of the specified type associated with the specified event. The data should be returned back to the 
1158
 * Event engine using pcilib_return_data() call. WARNING: Current implementation may overwrite the data before the pcilib_return_data()
1159
 * call is executed. In this case the #PCILIB_ERROR_OVERWRITTEN error will be returned by pcilib_return_data() call. I guess this is 
1160
 * a bad idea and have to be changed. Meanwhile, for the ipecamera implementation the image data will be never overwritten. However, 
1161
 * the raw data may get overwritten and the error code of pcilib_return_data() has to be consulted.
1162
 * 
1163
 * @param[in,out] ctx	- pcilib context
1164
 * @param[in] event_id	- specifies the ID of event to get data from
1165
 * @param[in] data_type	- specifies the desired type of data
1166
			  - PCILIB_EVENT_DATA will request the default data type
1167
			  - PCILIB_EVENT_RAW_DATA will request the raw data
1168
			  - The other types of data may be defined by event engine
1169
 * @param[out] size_or_err - contain error code if function returns NULL or number of actually written bytes otherwise
1170
 * @return 		- the pointer to the requested data or NULL otherwise
1171
 */ 
1172
void *pcilib_get_data(pcilib_t *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, size_t *size_or_err);
1173
1174
/**
1175
 * Returns pointer to the data of the specified type associated with the specified event. The data should be returned back to the 
1176
 * Event engine using pcilib_return_data() call. WARNING: Current implementation may overwrite the data before the pcilib_return_data()
1177
 * call is executed, @see pcilib_get_data() for details. Overall this function is very similar to pcilib_get_data(), but allows to 
1178
 * specify implementation specific argument explaining the requested data format.
1179
 *
1180
 * @param[in,out] ctx	- pcilib context
1181
 * @param[in] event_id	- specifies the ID of event to get data from
1182
 * @param[in] data_type	- specifies the desired type of data
1183
			  - PCILIB_EVENT_DATA will request the default data type
1184
			  - PCILIB_EVENT_RAW_DATA will request the raw data
1185
			  - The other types of data may be defined by event engine
1186
 * @param[in] arg_size	- specifies the size of `arg` in bytes
1187
 * @param[in] arg	- implementation-specific argument expalining the requested data format
1188
 * @param[out] size_or_err - contain error code if function returns NULL or number of actually written bytes otherwise
1189
 * @return 		- the pointer to the requested data or NULL otherwise
1190
 */ 
1191
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_or_err);
1192
1193
1194
/*
1195
 * This function returns data obtained using pcilib_get_data() or pcilib_get_data_with_argument() calls. 
1196
 * It occasionally may return #PCILIB_ERROR_OVERWRITTEN error indicating that the data was overwritten 
1197
 * between pcilib_get_data() and pcilib_return_data() calls, @see pcilib_get_data() for details.
1198
 * @param[in,out] ctx	- pcilib context
1199
 * @param[in] event_id	- specifies the ID of event to get data from
1200
 * @param[in] data_type	- specifies the data type request in the pcilib_get_data() call
1201
 * @param[in,out] data	- specifies the buffer returned by pcilib_get_data() call
1202
 * @return		- #PCILIB_ERROR_OVERWRITTEN or 0 if data is still valid
1203
 */
1204
int pcilib_return_data(pcilib_t *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, void *data);
1205
1206
/** public_api_event_data
1207
 * @}
1208
 */
1209
1210
1211
/***********************************************************************************************************//**
1212
 * \defgroup public_api_value Polymorphic values
1213
 * API for manipulation of data formats and units
1214
 * @{
1215
 */
1216
1217
/**
1218
 * Destroys the polymorphic value and frees any extra used memory, but does not free #pcilib_value_t itself
1219
 * @param[in] ctx	- pcilib context
1220
 * @param[in,out] val	- initialized polymorphic value
1221
 */
309 by Suren A. Chilingaryan
Base functions for views
1222
void pcilib_clean_value(pcilib_t *ctx, pcilib_value_t *val);
324 by Suren A. Chilingaryan
Documentation update
1223
1224
/**
1225
 * Copies the polymorphic value. If `dst` already contains the value, cleans it first. 
1226
 * Therefore, before first usage the value should be always initialized to 0.
1227
 * @param[in] ctx	- pcilib context
1228
 * @param[in,out] dst	- initialized polymorphic value
1229
 * @param[in] src	- initialized polymorphic value
1230
 * @return		- 0 on success or memory error
1231
 */
309 by Suren A. Chilingaryan
Base functions for views
1232
int pcilib_copy_value(pcilib_t *ctx, pcilib_value_t *dst, const pcilib_value_t *src);
324 by Suren A. Chilingaryan
Documentation update
1233
1234
/**
1235
 * Initializes the polymorphic  value from floating-point number. If `val` already contains the value, cleans it first. 
1236
 * Therefore, before first usage the value should be always initialized to 0.
1237
 * @param[in] ctx	- pcilib context
1238
 * @param[in,out] val	- initialized polymorphic value
1239
 * @param[in] fval	- initializer
1240
 * @return		- 0 on success or memory error
1241
 */
309 by Suren A. Chilingaryan
Base functions for views
1242
int pcilib_set_value_from_float(pcilib_t *ctx, pcilib_value_t *val, double fval);
324 by Suren A. Chilingaryan
Documentation update
1243
1244
/**
1245
 * Initializes the polymorphic value from integer. If `val` already contains the value, cleans it first. 
1246
 * Therefore, before first usage the value should be always initialized to 0.
1247
 * @param[in] ctx	- pcilib context
1248
 * @param[in,out] val	- initialized polymorphic value
1249
 * @param[in] ival	- initializer
1250
 * @return		- 0 on success or memory error
1251
 */
309 by Suren A. Chilingaryan
Base functions for views
1252
int pcilib_set_value_from_int(pcilib_t *ctx, pcilib_value_t *val, long ival);
324 by Suren A. Chilingaryan
Documentation update
1253
1254
/**
1255
 * Initializes the polymorphic value from the register value. If `val` already contains the value, cleans it first. 
1256
 * Therefore, before first usage the value should be always initialized to 0.
1257
 * @param[in] ctx	- pcilib context
1258
 * @param[in,out] val	- initialized polymorphic value
1259
 * @param[in] regval	- initializer
1260
 * @return		- 0 on success or memory error
1261
 */
1262
int pcilib_set_value_from_register_value(pcilib_t *ctx, pcilib_value_t *val, pcilib_register_value_t regval);
1263
1264
/**
1265
 * Initializes the polymorphic value from the static string. The string is not copied, but only referenced.
1266
 * If `val` already contains the value, cleans it first. Therefore, before first usage the value should be always initialized to 0.
1267
 * @param[in] ctx	- pcilib context
1268
 * @param[in,out] val	- initialized polymorphic value
1269
 * @param[in] str	- initializer
1270
 * @return		- 0 on success or memory error
1271
 */
1272
int pcilib_set_value_from_static_string(pcilib_t *ctx, pcilib_value_t *val, const char *str);
1273
1274
/**
1275
 * Get the floating point value from the polymorphic type. May inmply impliced type conversion,
1276
 * for isntance parsing the number from the string. Will return 0. and report an error if
1277
 * conversion failed.
1278
 * @param[in] ctx	- pcilib context
1279
 * @param[in] val	- initialized polymorphic value of arbitrary type
1280
 * @param[out] err	- error code or 0 on sccuess
1281
 * @return		- the value or 0 in the case of error
1282
 */
312 by Suren A. Chilingaryan
Support transform views
1283
double pcilib_get_value_as_float(pcilib_t *ctx, const pcilib_value_t *val, int *err);
324 by Suren A. Chilingaryan
Documentation update
1284
1285
/**
1286
 * Get the integer value from the polymorphic type. May inmply impliced type conversion
1287
 * resulting in precision loss if the `val` stores floating-point number. The warning
1288
 * message will be printed in this case, but no error returned.
1289
 * @param[in] ctx	- pcilib context
1290
 * @param[in] val	- initialized polymorphic value of arbitrary type
1291
 * @param[out] err	- error code or 0 on sccuess
1292
 * @return		- the value or 0 in the case of error
1293
 */
312 by Suren A. Chilingaryan
Support transform views
1294
long pcilib_get_value_as_int(pcilib_t *ctx, const pcilib_value_t *val, int *err);
324 by Suren A. Chilingaryan
Documentation update
1295
1296
/**
1297
 * Get the integer value from the polymorphic type. May inmply impliced type conversion
1298
 * resulting in precision loss if the `val` stores floating-point number or complete 
1299
 * data corruption if negative number is stored.  The warning message will be printed 
1300
 * in this case, but no error returned.
1301
 * @param[in] ctx	- pcilib context
1302
 * @param[in] val	- initialized polymorphic value of arbitrary type
1303
 * @param[out] err	- error code or 0 on sccuess
1304
 * @return		- the value or 0 in the case of error
1305
 */
312 by Suren A. Chilingaryan
Support transform views
1306
pcilib_register_value_t pcilib_get_value_as_register_value(pcilib_t *ctx, const pcilib_value_t *val, int *err);
324 by Suren A. Chilingaryan
Documentation update
1307
1308
1309
/**
1310
 * Convert the units of the supplied polymorphic value. The error will be reported if currently used units of the 
1311
 * value are unknown, the requested conversion is not supported, or the value is not numeric.
1312
 * @param[in] ctx	- pcilib context
1313
 * @param[in,out] val	- initialized polymorphic value of any numeric type
1314
 * @param[in] unit_name	- the requested units
1315
 * @return err		- error code or 0 on sccuess
1316
 */
309 by Suren A. Chilingaryan
Base functions for views
1317
int pcilib_convert_value_unit(pcilib_t *ctx, pcilib_value_t *val, const char *unit_name);
324 by Suren A. Chilingaryan
Documentation update
1318
1319
/**
1320
 * Convert the type of the supplied polymorphic value. The error will be reported if conversion
1321
 * is not supported or failed due to non-conformant content.
1322
 * @param[in] ctx	- pcilib context
1323
 * @param[in,out] val	- initialized polymorphic value of any type
1324
 * @param[in] type	- the requested type
1325
 * @return err		- error code or 0 on sccuess
1326
 */
309 by Suren A. Chilingaryan
Base functions for views
1327
int pcilib_convert_value_type(pcilib_t *ctx, pcilib_value_t *val, pcilib_value_type_t type);
1328
324 by Suren A. Chilingaryan
Documentation update
1329
/** public_api_value
1330
 * @}
1331
 */
1332
15 by Suren A. Chilingaryan
Infrastructure for event API
1333
277 by Suren A. Chilingaryan
Keep C++ compilers happy
1334
#ifdef __cplusplus
1335
}
1336
#endif
1337
7.1.6 by Suren A. Chilingaryan
Provide single header for library
1338
#endif /* _PCITOOL_PCILIB_H */