Skip to content

Add alternate bitfield padding option#654

Merged
hathach merged 2 commits into
hathach:masterfrom
xmos-jmccarthy:master
Feb 19, 2021
Merged

Add alternate bitfield padding option#654
hathach merged 2 commits into
hathach:masterfrom
xmos-jmccarthy:master

Conversation

@xmos-jmccarthy
Copy link
Copy Markdown
Contributor

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.

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.
@hathach
Copy link
Copy Markdown
Owner

hathach commented Feb 17, 2021

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.

@xmos-jmccarthy
Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Owner

@hathach hathach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Copy Markdown
Owner

@hathach hathach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look great, thank you for your PR.

@hathach hathach merged commit 044d29c into hathach:master Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants