2 * UDI Driver helper macros
4 #ifndef _UDI_HELPERS_H_
5 #define _UDI_HELPERS_H_
8 # define DEBUG_OUT(fmt, v...) udi_debug_printf("%s: "fmt"\n", __func__ ,## v)
10 # define DEBUG_OUT(...) do{}while(0)
13 #define ARRAY_COUNT(arr) (sizeof(arr)/sizeof(arr[0]))
15 #define __EXPJOIN(a,b) a##b
16 #define _EXPJOIN(a,b) __EXPJOIN(a,b)
17 #define _EXPLODE(params...) params
18 #define _ADDGCB(params...) (udi_cb_t *gcb, params)
19 #define CONTIN(suffix, call, args, params) extern void _EXPJOIN(suffix##$,__LINE__) _ADDGCB params;\
20 call( _EXPJOIN(suffix##$,__LINE__), gcb, _EXPLODE args); } \
21 void _EXPJOIN(suffix##$,__LINE__) _ADDGCB params { \
22 rdata_t *rdata = gcb->context; \
25 /* Copied from http://projectudi.cvs.sourceforge.net/viewvc/projectudi/udiref/driver/udi_dpt/udi_dpt.h */
26 #define UDIH_SET_ATTR_BOOLEAN(attr, name, val) \
27 udi_strcpy((attr)->attr_name, (name)); \
28 (attr)->attr_type = UDI_ATTR_BOOLEAN; \
29 (attr)->attr_length = sizeof(udi_boolean_t); \
30 UDI_ATTR32_SET((attr)->attr_value, (val))
32 #define UDIH_SET_ATTR32(attr, name, val) \
33 udi_strcpy((attr)->attr_name, (name)); \
34 (attr)->attr_type = UDI_ATTR_UBIT32; \
35 (attr)->attr_length = sizeof(udi_ubit32_t); \
36 UDI_ATTR32_SET((attr)->attr_value, (val))
38 #define UDIH_SET_ATTR_ARRAY8(attr, name, val, len) \
39 udi_strcpy((attr)->attr_name, (name)); \
40 (attr)->attr_type = UDI_ATTR_ARRAY8; \
41 (attr)->attr_length = (len); \
42 udi_memcpy((attr)->attr_value, (val), (len))
44 #define UDIH_SET_ATTR_STRING(attr, name, val, len) \
45 udi_strcpy((attr)->attr_name, (name)); \
46 (attr)->attr_type = UDI_ATTR_STRING; \
47 (attr)->attr_length = (len); \
48 udi_strncpy_rtrim((char *)(attr)->attr_value, (val), (len))
49 #define UDIH_SET_ATTR_STRFMT(attr, name, maxlen, fmt, v...) \
50 udi_strcpy((attr)->attr_name, (name)); \
51 (attr)->attr_type = UDI_ATTR_STRING; \
52 (attr)->attr_length = udi_snprintf((char *)(attr)->attr_value, (maxlen), (fmt) ,## v )
55 * \brief UDI PIO Helpers
58 udi_pio_trans_t *trans_list;
59 udi_ubit16_t list_length;
60 udi_ubit16_t pio_attributes;
61 udi_ubit32_t regset_idx;
62 udi_ubit32_t base_offset;
65 #define UDIH_PIO_OPS_ENTRY(list, attr, regset, base, len) {list, ARRAY_COUNT(list), attr, regset, base, len}