-
Notifications
You must be signed in to change notification settings - Fork 132
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
Implementation of interrupt hooks #308
base: develop
Are you sure you want to change the base?
Conversation
Do a
Making the |
I tried to apply some optimizations on that but so far had no success. The compiler also doesn't drop the call to the empty functions, which is weird. I read that it would only drop it, if the function is static, but as it is declared weak, we can't declare the hooks static. I really don't get why the compiler does not completely optimize out empty functions as they don't do anything. So here is an idea on how to optimize this: We could use lbuild to enable the hooks by adding an option something like What do you think? |
What I don't like about
Isn't this just another way to implement #307 though? You could implement UART callbacks as an optional lbuild feature, but they are then UART driver specific with UART driver semantics (ie. callback for receiving a byte, not callback for getting an IRQ). I'd be ok with that (analogue for SPI, I2C, ADC etc). Or a way to hook NVIC interrupts, but then it would need to be a generic mechanism that's transparent to any driver using these IRQs too. In general, allowing to define drivers callbacks that then get executed in an (nested) interrupt context is a very, very good recipe for a lot of concurrency bugs. I've never ever seen it work well. |
Hmm isn't that also the case for the EXTI ISRs? However, I see your point. So should we drop the custom ISR hooks? |
I need to think about this some more, I find this problem very interesting since it probably hasn't been solved many times before. There's also a tangent relation to the RTFM scheduler concept. |
So second try on the interrupt hooks. 😄
This approach will do the interrupt handling in three steps. First it calls the entry hook, then the main method and at last the exit hook. The two hooks are defined as weak, empty functions, that can be redefined in the user code.
To enable the hook, the ISR macro in the driver just has to be changed from
MODM_ISR
toMODM_ISR_HOOKS
. This macro will be compatible to the old interrupt handling but additionally creates the two hook methods.To implement the hooks there are two macros:
MODM_ISR_ENTRY_HOOK
to implement the entry hook andMODM_ISR_EXIT_HOOK
to implement the exit hook.I added an example for the Nucleo-F042 that toggles the LED whenever a byte has been received via the UART.