Currently, working with interrupts is a bit of a pain, as you can't really do much in the ISR without breaking anything, and even a ticker will mess things up if it interrupts your code at a bad time, especially if a segment of code is supposed to execute atomically. Currently I have a bitmask thing going on, where the ISR just sets the appropiate interrupt bit and the bit is handled in the main loop, but... without a scheduler an OS, it means you end up polling the mask and the interrupts don't really work like "interrupts" anymore.
For example, I have some basic code that monitors 4 interrupts, and on rise, it updates a HD44780 based display. The problem is that each button starts a task that I'd like to be interrupted if a button is pressed, and the code contains printfs and other stuff that you can't really stuff into the ISR (not without the HD44780 breaking due to corruption anyway)...
So I've been looking to implement a simple scheduler which would provide basic threading and some synchronization primitives, without the fun of a full blown OS.
Features such as:
Threading
Semaphores
Events
Mutexes
Critical Sections
It'd be really nice for example to wrap the HD44780 code in a critical section... and make ISTs to handle interrupts.
Anyone do any work on this? Or if there's a way to take care of this without all this work, I'd like to know!
Currently, working with interrupts is a bit of a pain, as you can't really do much in the ISR without breaking anything, and even a ticker will mess things up if it interrupts your code at a bad time, especially if a segment of code is supposed to execute atomically. Currently I have a bitmask thing going on, where the ISR just sets the appropiate interrupt bit and the bit is handled in the main loop, but... without a scheduler an OS, it means you end up polling the mask and the interrupts don't really work like "interrupts" anymore.
For example, I have some basic code that monitors 4 interrupts, and on rise, it updates a HD44780 based display. The problem is that each button starts a task that I'd like to be interrupted if a button is pressed, and the code contains printfs and other stuff that you can't really stuff into the ISR (not without the HD44780 breaking due to corruption anyway)...
So I've been looking to implement a simple scheduler which would provide basic threading and some synchronization primitives, without the fun of a full blown OS.
Features such as:
Threading
Semaphores
Events
Mutexes
Critical Sections
It'd be really nice for example to wrap the HD44780 code in a critical section... and make ISTs to handle interrupts.
Anyone do any work on this? Or if there's a way to take care of this without all this work, I'd like to know!