I am developing some register mapping for cross-platform code. You chose C99 as the standard in ChibiOS 3, and that's a wise choice IMHO. C99 provides the stdint.h header with portable integer types, but the standard still lacks any portable way to determine the architecture endianness at compile time. There are some nice tricks, but they don't work in the preprocessor.
So, what I ask to you is: are you willing to put a preprocessor symbol to tell the endianness of the ported architecture? I think it will be a very useful addition to ChibiOS, because that way it is possible to generate register type mappings with portable unions, by declaring bit fields in both orders, and compiling only the target one.
For example, in ch.h (or elsewere):
Code: Select all
#define CH_ENDIANNESS_LITTLE 0x1234
#define CH_ENDIANNESS_BIG 0x4321
In the port header:
Code: Select all
#define CH_ENDIANNESS CH_ENDIANNESS_LITTLE
In user library code:
Code: Select all
union mybitfield {
#if CH_ENDIANNESS == CH_ENDIANNESS_LITTLE
uint8_t lsb : 1;
uint8_t msb : 1;
#elif CH_ENDIANNESS == CH_ENDIANNESS_BIG
uint8_t msb : 1;
uint8_t lsb : 1;
#else
#error "Unknown CH_ENDIANNESS value"
#endif
};
Do you think this will be useful? I would also write a library for endianness conversion into the community repository if needed (something like the htons() and related stuff).
Since protocols and low-level access to data structures is common in the embedded field, such features are very appreciated and easy to use.
If there is already a way to do that, my fault