Add alternate bitfield padding option#654
Conversation
Adds configuration option CFG_TUSB_ALT_BIT_PACKING_ALIGNMENT, which substitutes bitfield variable " : 0" padding syntax with an unused variable of size equal to the remaining number of bits. This change resolves aligned access issues for some platforms. Default behavior is original if the option is not explicitly enabled.
|
thank you for your PR, would you mind telling me what is your platform you are working. unnamed zero size is pretty much std padding in C language. |
|
I am working on the XCore platform. Unnamed zero size is indeed standard; However, I found that the compiler for XCore currently will cause a hardware exception when trying to access a bitfield under certain alignment conditions. |
hathach
left a comment
There was a problem hiding this comment.
Thanks for the PR, actually, the bitfield size = 0 is due to my laziness. Since you already counted the unused size, there is no need to introduce the new macro CFG_TUSB_ALT_BIT_PACKING_ALIGNMENT, we should just always use it which is more explicit (therefore more portable). Would you mind updating the PR accordingly.
PS: also it is better to use the TU_RESERVED instead of unused, it expands to unique token name. But it is optional.
Removes CFG_TUSB_ALT_BIT_PACKING_ALIGNMENT, and makes the manual padding behavior standard. Replaced unused variable name with TU_RESERVED.
hathach
left a comment
There was a problem hiding this comment.
look great, thank you for your PR.
Adds configuration option CFG_TUSB_ALT_BIT_PACKING_ALIGNMENT, which substitutes bitfield variable " : 0" padding syntax with an unused variable of size equal to the remaining number of bits.
This change is intended to resolve aligned access issues for some platforms.
The default behaviour is original if the option is not explicitly enabled. Consequently, this change should not affect existing applications.