-
Notifications
You must be signed in to change notification settings - Fork 2
interrupt design #3
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
Comments
One thing is to keep in mind that low-end MCUs may not have a reconfigurable interrupt table (I believe some Cortex-M0s fall into this category?). What about good old static data? I've been meaning to look into that anyway, but here's how it would work in "conventional" languages:
Let's assume that 2. is some sort of buffer, the interrupt handler receives data and puts it into said buffer and the main thread wants to read it periodically. On first glance, this setup is fairly unsafe as the interrupt may fire before the buffer is initialized. In a real-world applications, this is often easily solved by not powering on the components that generate the interrupt before the buffer has been initialized. It would be good if we could express this constraint somehow, note that there may be different mechanisms at work here (not powering on vs masking the interrupts by default). If we were to start using the static-buffer style of fixed interrupt handlers, we have to fix two issues: Not handling interrupts before we are ready to do so (i.e. the buffer has been initialized) and transferring ownership of resources into interrupt handlers. Note that buffer initialization here can mean as little as ensuring that the buffer is properly zero'd first -- puting an We could also encode initialization state in the type system to varying degrees. Alas, I need to read up more on how static data is handled first. |
Right. So that is a fourth solution. We can probably wrap the first three solutions in a way that they can be applied on top of the fourth solution by making the static data a pointer to the closure. But yes, that will require some runtime cost like unwrapping. |
We definitely want to start using interrupts at some point. It's trivial to simply put a function into the interrupt table, but that function then has neither state nor a way to communicate with anything. I say we first figure out the way we want to use interrupts, and then solve how that can be done. So this issue is just here for the API.
Obviously closures come into mind when thinking about code that should be run when an interrupt triggers. There's several ways we could use them:
add a handler for the entire program lifetime
add a handler that borrows parts of the surroundings
add a handler and a state object that you'll get back afterwards
I don't think we need to decide on either of the three, they can work simultaneously.
Anything else in the possible design space?
The text was updated successfully, but these errors were encountered: