-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SI4460 incorrectly assumes packed structs #34
Comments
Thanks for bringing this up! |
Only after I lodged this issue I realised that it did not matter for the D7AP stack. I stumbled over this as I was testing a new radio against each of the apps, including I agree it is better to keep the struct unpacked, even if only for aligned access. A quick check of the C99 standard does not mention anything about using flexible array members in this way so it seems to be undefined behaviour. As for making packet sizes a CMake option, while nice to have, it's only an issue for memory-constrained systems and the current configuration is fine. In this case to avoid further confusion, the |
Hi Simon, Maarten Sent from my Samsung Galaxy smartphone. -------- Original message -------- Only after I lodged this issue I realised that it did not matter for the D7AP stack. I stumbled over this as I was testing a new radio against each of the apps, including radio_ping. I agree it is better to keep the struct unpacked, even if only for aligned access. A quick check of the C99 standard does not mention anything about using flexible array members in this way so it seems to be undefined behaviour. As for making packet sizes a CMake option, while nice to have, it's only an issue for memory-constrained systems and the current configuration is fine. In this case to avoid further confusion, the radio_ping app should be removed--the phy_test app does pretty much the same thing anyway. Thanks for the clarification. — |
The SI4460 code assumes the
hw_radio_packet_t
struct is packed, but the packed attribute was removed in commit 761cf7c in September 2015. As a result, three padding bytes are added to the end of the struct, and members of an enclosing struct (e.g.packet_struct_t
in theradio_ping
app) begin on a word boundary.The SI4460 calculates the length of data to transmit correctly, but assumes that
hw_radio_packet_t
is packed and loads the Tx FIFO with the contents of thedata
flexible array member, which points to the length byte, the three padding bytes, then the remainder of the enclosing struct. The last three bytes of data are not transmitted.When the packed attribute was removed, it was replaced with a comment regarding alignment on Cortex-M0, so this might be a tricky one to fix. It should also be noted that the requirement for
hw_radio_packet_t
to be packed also requires all enclosing structs to be packed, which includes structs defined at the app layer. As the requirement for packing is implicit, this may be a source of bugs for the unaware.The text was updated successfully, but these errors were encountered: