Skip to content

Add macro for unaligned access.#758

Closed
HiFiPhile wants to merge 1 commit into
hathach:masterfrom
HiFiPhile:unaligned
Closed

Add macro for unaligned access.#758
HiFiPhile wants to merge 1 commit into
hathach:masterfrom
HiFiPhile:unaligned

Conversation

@HiFiPhile
Copy link
Copy Markdown
Collaborator

Describe the PR
A proposition for unaligned access macro.

Then we can refactor unaligned accesses, for example:

uint16_t total_len;
// Use offsetof to avoid pointer to the odd/misaligned address
memcpy(&total_len, (uint8_t*) desc_bos + offsetof(tusb_desc_bos_t, wTotalLength), 2);

Into

uint16_t total_len;
TU_UNALIGNED_GET(total_len, &desc_bos->wTotalLength, uint16_t);

Additional context
It should works on TI compiler, need test.

@hathach
Copy link
Copy Markdown
Owner

hathach commented Mar 29, 2021

thank you for your PR, it looks good. However, I think this shouldn't be part of the compiler. I am thinking to have an typdef for tu_unaligned_uint32_t then using static inline function for the assignment. I will make an PR to demonstrate the idea.

UPDATE: ah I see, zephyr use macro so that it can be opt-out when using with MCU that can do unaligned access like m3, m4

@hathach
Copy link
Copy Markdown
Owner

hathach commented Apr 6, 2021

closed in favor of #772

@hathach hathach closed this Apr 6, 2021
@HiFiPhile HiFiPhile deleted the unaligned branch July 22, 2021 15:14
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.

2 participants