-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
twai: Don't abort on interrupt allocation failure (IDFGH-10231) #11494
Conversation
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.
@nebkat Thanks for your contribution, the requested changes looks reasonable to me.
I would probably want to rearrange the order of operations in the twai_driver_install()
so that all resource allocations are done at the start. Furthermore, would you be able to target this PR for the master branch (it would work better with our backporting workflow)?
@@ -446,7 +449,8 @@ esp_err_t twai_driver_install(const twai_general_config_t *g_config, const twai_ | |||
|
|||
//Allocate GPIO and Interrupts | |||
twai_configure_gpio(g_config->tx_io, g_config->rx_io, g_config->clkout_io, g_config->bus_off_io); | |||
ESP_ERROR_CHECK(esp_intr_alloc(ETS_TWAI_INTR_SOURCE, g_config->intr_flags, twai_intr_handler_main, NULL, &p_twai_obj->isr_handle)); | |||
ret = esp_intr_alloc(ETS_TWAI_INTR_SOURCE, g_config->intr_flags, twai_intr_handler_main, NULL, &p_twai_obj->isr_handle); |
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.
Prefer if we
- Allocated interrupts immediately after allocating the driver object. This way, if any resource allocation fails, we can return early
- Added the
ESP_INTR_FLAG_INTRDISABLED
flag so that an allocated interrupt remains disabled until we explicitly enable it usingesp_intr_enable()
So something like...
ret = esp_intr_alloc(ETS_TWAI_INTR_SOURCE, g_config->intr_flags, twai_intr_handler_main, NULL, &p_twai_obj->isr_handle); | |
//Create a TWAI object (including queues and semaphores) | |
p_twai_obj_dummy = twai_alloc_driver_obj(g_config->tx_queue_len, g_config->rx_queue_len); | |
TWAI_CHECK(p_twai_obj_dummy != NULL, ESP_ERR_NO_MEM); | |
//Allocate interrupt for TWAI driver | |
intr_handle_t isr_hdl; | |
ret = esp_intr_alloc(ETS_TWAI_INTR_SOURCE, g_config->intr_flags | ESP_INTR_FLAG_INTRDISABLED, twai_intr_handler_main, NULL, &isr_hdl); | |
if (ret != ESP_OK) { | |
ESP_LOGE(TWAI_TAG, "Interrupt allocation failed"); | |
goto intr_alloc_err; | |
} |
Sorry never got around to finishing this, thanks for the change! |
@nebkat No worries. I've made some modifications to your PR commit, but commit author is still attributed to you. Thanks for the contribution |
…lure This commit updates twai_driver_install() so that an error is returned when esp_intr_alloc() fails, instead of aborting. Closes #11494 [darian@espressif.com: Refactored object allocation and free procedures] [darian@espressif.com: Updated commit message] Signed-off-by: Darian Leung <darian@espressif.com>
…lure This commit updates twai_driver_install() so that an error is returned when esp_intr_alloc() fails, instead of aborting. Closes #11494 [darian@espressif.com: Refactored object allocation and free procedures] [darian@espressif.com: Updated commit message] Signed-off-by: Darian Leung <darian@espressif.com>
twai_driver_install()
currently aborts if there is a failure allocation the interrupt handler, unlike for example UART driver which simply returns the error code:esp-idf/components/driver/uart/uart.c
Lines 1588 to 1591 in d00e7b5
With this change execution can continue even if the allocation fails.