-
Notifications
You must be signed in to change notification settings - Fork 2.1k
cpu/atmega_common: __exit_isr thread_yield #8988
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
Changes from all commits
80b02e5
9b63117
fe92771
0e49186
40c1839
9135963
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -35,7 +35,6 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "periph/uart.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @brief Maximum percentage error in calculated baud before switching to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * double speed transmission (U2X) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -90,6 +89,7 @@ static void _update_brr(uart_t uart, uint16_t brr, bool double_speed) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static void _set_brr(uart_t uart, uint32_t baudrate) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint16_t brr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #if defined(UART_STDIO_BAUDRATE) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* UBRR_VALUE and USE_2X are statically computed from <util/setbaud.h> */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (baudrate == UART_STDIO_BAUDRATE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -115,7 +115,7 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* register interrupt context */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isr_ctx[uart].rx_cb = rx_cb; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isr_ctx[uart].arg = arg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isr_ctx[uart].arg = arg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* disable and reset UART */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dev[uart]->CSRB = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -134,14 +134,13 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dev[uart]->CSRB = (1 << TXEN0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return UART_OK; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void uart_write(uart_t uart, const uint8_t *data, size_t len) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (size_t i = 0; i < len; i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while (!(dev[uart]->CSRA & (1 << UDRE0))) {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while (!(dev[uart]->CSRA & (1 << UDRE0))) {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dev[uart]->DR = data[i]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -160,46 +159,37 @@ void uart_poweroff(uart_t uart) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static inline void isr_handler(int num) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __enter_isr(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isr_ctx[num].rx_cb(isr_ctx[num].arg, dev[num]->DR); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (sched_context_switch_request) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| thread_yield(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| thread_yield_isr(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __exit_isr(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #ifdef UART_0_ISR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ISR(UART_0_ISR, ISR_BLOCK) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __enter_isr(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer the original design where enter isr is the first line of each ISR
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this just a preference or are there any reasons. As i see there is no benefit in settings the I change it as it is like this in all other interrupt handler and thought it would also increase consistency.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personal preference. The consistency helps when reviewing the code and also reduces the risk of missing it if someone uses this periph driver as a template for some other driver for the same CPU.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gebart maybe we just have a language problem as consistency translates into two different meanings in german, depending of the context. Do you mean consistency in regard as it stays as it was or consistency as it is similar to other code of the atmegas? RIOT/cpu/atmega_common/periph/gpio.c Lines 264 to 274 in 22aa6b9
RIOT/cpu/atmega_common/periph/timer.c Lines 169 to 189 in 22aa6b9
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess you are right regarding consistency. I am not very engaged in the atmega development, sorry. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isr_handler(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __exit_isr(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif /* UART_0_ISR */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #ifdef UART_1_ISR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ISR(UART_1_ISR, ISR_BLOCK) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __enter_isr(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isr_handler(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __exit_isr(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif /* UART_1_ISR */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #ifdef UART_2_ISR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ISR(UART_2_ISR, ISR_BLOCK) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __enter_isr(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isr_handler(2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __exit_isr(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif /* UART_2_ISR */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #ifdef UART_3_ISR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ISR(UART_3_ISR, ISR_BLOCK) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __enter_isr(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isr_handler(3); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __exit_isr(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif /* UART_3_ISR */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated