-
Notifications
You must be signed in to change notification settings - Fork 518
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
[p2] fixes INTERRUPTS_01_isisr_willpreempt_servicedirqn test #2486
Conversation
|
||
if (handler == nullptr && (flags & HAL_INTERRUPT_DIRECT_FLAG_RESTORE)) { | ||
// Restore | ||
// HAL_Core_Restore_Interrupt(irqn); | ||
uint32_t old_handler = hal_interrupts_handler_backup[IRQN_TO_IDX(irqn)]; |
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.
This is a bit fragile in the fact that you can call this with handler=nullptr and HAL_INTERRUPT_DIRECT_FLAG_RESTORE
when there is no backed-up handler and it will nuke the existing entry in VTOR. Consider a few approaches:
- Back up entire VTOR on first use if `!memcmp(hal_interrupts_handler_backup, 0, sizeof(hal_interrupts_handler_backup))
- Perhaps use some struct for backup instead and store the state along with backed-up ISR function
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.
Or considering use std::pair(irqn, handler)
along with vector()
.
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.
I'd avoid using vector
here due to dynamic allocations. VTOR size is known and negligible, so we can keep the whole thing preallocated.
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.
Is there ever a valid use case to have a NULL interrupt handler? Can I just check if the backed up handler is not null, and only restore it if something has been saved?
b0c7539
to
768b834
Compare
hal/src/rtl872x/interrupts_hal.cpp
Outdated
isrs[IRQN_TO_IDX(irqn)] = (uint32_t)handler; | ||
// If there is currently a handler backup: Return error | ||
if (hal_interrupts_handler_backup[IRQN_TO_IDX(irqn)]) { | ||
error = SYSTEM_ERROR_NOT_SUPPORTED; |
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.
It might actually simplify the logic if I use goto
to bail out rather than have to check for error conditions? I cant return
here because I need to re-enable interrupts.
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.
Use CHECK_TRUE
/CHECK_FALSE
then, much better than goto
, so:
CHECK_FALSE(hal_interrupts_handler_backup[IRQN_TO_IDX(irqn)], SYSTEM_ERROR_ALREADY_EXISTS);
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.
Ah yes, those macros are handy. Unfortunately I need to re-enable interrupts before exiting. ill just do that and return SYSTEM_ERROR_ALREADY_EXISTS
. I think thats cleaner than adding a return variable and checking it, etc.
0bc48ae
to
1fdc5d2
Compare
hal/src/rtl872x/interrupts_hal.cpp
Outdated
isrs[IRQN_TO_IDX(irqn)] = (uint32_t)handler; | ||
// If there is currently a handler backup: Return error | ||
if (hal_interrupts_handler_backup[IRQN_TO_IDX(irqn)]) { | ||
error = SYSTEM_ERROR_NOT_SUPPORTED; |
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.
Use CHECK_TRUE
/CHECK_FALSE
then, much better than goto
, so:
CHECK_FALSE(hal_interrupts_handler_backup[IRQN_TO_IDX(irqn)], SYSTEM_ERROR_ALREADY_EXISTS);
Return error if overriding handler multiple times.
4f5cea4
to
acfb1e1
Compare
Problem
INTERRUPTS_01_isisr_willpreempt_servicedirqn
test fails on P2 due to unimplemented HALSolution
Use an array to backup any overridden ISR handlers. When override is removed, restore the backup.
There are other parts of the HAL that are still unimplemented, namely
HAL_Core_Restore_Interrupt()
and thelink_interrupt_vectors_location
RAM table in general duringHAL_Core_Config()
.This PR is still a WIP to facilitate discussion on how to approach these problems.
Steps to Test
Run
wiring/no_fixture
, specificallyINTERRUPTS_01_isisr_willpreempt_servicedirqn
Example App
Run
wiring/no_fixture
References
Links to the Community, Docs, Other Issues, etc..
Completeness