|
|
UDI_MBSET, UDI_MBSET_2, UDI_MBSET_3, UDI_MBSET_4
Multi-byte deposit helper macros
#include <udi.h>#define UDI_MBSET(N, structp, field, val) \ UDI_MBSET_##N (structp, field, val) #define UDI_MBSET_2(structp, field, val) \ ((structp)->field##0 = (val) & 0xff, \ (structp)->field##1 = ((val) >> 8) & 0xff) #define UDI_MBSET_3(structp, field, val) \ ((structp)->field##0 = (val) & 0xff, \ (structp)->field##1 = ((val) >> 8) & 0xff, \ (structp)->field##2 = ((val) >> 16) & 0xff) #define UDI_MBSET_4(structp, field, val) \ ((structp)->field##0 = (val) & 0xff, \ (structp)->field##1 = ((val) >> 8) & 0xff, \ (structp)->field##2 = ((val) >> 16) & 0xff, \ (structp)->field##3 = ((val) >> 24) & 0xff)ARGUMENTS N is the number of bytes in the corresponding multi-byte quantity.
structp is a pointer to a structure that contains N single-byte (and byte-aligned) members whose names are field0, field1, ... fieldn (n=N-1), which together represent an N-byte quantity in the structure.
field is the base name of a sequence of members in structp. The name of each member in the sequence is field followed by a decimal number in the range 0..N-1; this number represents the byte number in a multi-byte quantity, with byte 0 being the least significant byte. Each of these structure members must be of type udi_ubit8_t.
val is the value to deposit into the multi-byte quantity in the structure pointed to by structp and corresponding to field. This value must be of an unsigned data type, such as udi_ubit16_t.
DESCRIPTION These macros are used to deposit a value into a multi-byte quantity in a structure which has been constructed according to the byte-by-byte layout rules given in Section 22.2.1.1. The structure is pointed to by the structp argument, and the multi-byte quantities are represented by a sequence of fields in the structure whose names are based on the field argument.
As described above, the structp argument is a pointer to a structure that contains N single-byte (and byte-aligned) members whose names are field0, field1, ... fieldn (n=N-1), which together represent an N-byte quantity in the structure. field0 is the least significant byte; fieldn is the most significant.
UDI_MBSET deposits val into the N-byte unsigned quantity represented by field in the structure pointed to by structp. UDI_MBSET_2, UDI_MBSET_3, and UDI_MBSET_4, deposit into 2, 3, and 4-byte quantities, respectively.
These macros don't translate well into functional interfaces, so no corresponding functional interfaces are given.
22.2.3 Endian-Swapping Utilities
UDI provides two basic macros for endian translation of a single 16-bit or 32-bit integer: UDI_ENDIAN_SWAP16 and UDI_ENDIAN_SWAP32, respectively. The utility function udi_endian_swap provides for the endian conversion of greater than 32-bit integers; this function has a rep_count and stride parameter, allowing for multiple byte-swaps of a given size in a single call. This can be used to byte-swap each element in an array (as shown by the UDI_ENDIAN_SWAP_ARRAY macro), or to perform more complex sequences of byte-swaps across sub-elements of an array of structures.
Note - Except for use with DMA-able shared control structures (described in the UDI Physical I/O Specification), drivers should use the byte-by-byte structure layout rather than using these utilities, since the relationship between driver and device endianness is not indicated in any UDI-specified fashion, either at compile time or at run time.