In the ongoing quest to scavenge yet another byte of useful memory one option is to recover the stack used by main() once the scheduler has been started. Effectively the main() routine is treated as a task that runs once and is then deleted, allowing its stack to be allocated to another task.
While trying to think of a way to do this on the MSP430 architecture have thought of an alternative that might make sense:
Reuse the main() stack as a stack exclusively for the use of ISR’s.
The logic goes like this: Some ISRs are light-weight in their stack usage, but if the ISR calls other routine(s) and/or performs a lot of calculations then their use of the stack can blow out quite a lot. Threads need to have sufficient stack space to accommodate each ISR’s requirements; which can occur at any time. So if an ISR requires 40 bytes of stack, then all threads need to have an extra 40 bytes added to their stack space. This gets worse if you have multiple ISRs in the application.
As a suggested alternative, ISRs that require a lot of stack could point the SP into an ISR only stack space (perhaps reuseing main()'s stack). If this works it would mean that:
- the stack used by main() gets to be reused
- the stack space allocated to each thread can be reduced.
Am not suggesting that this need to be done for all ISRs, just the memory hungry ones.
Implementation details would require handling of the case when one ISR interrupts another ISR, but that should be fairly easy?
Can anyone else spot anything else that can go wrong with this before aLUNZ launches into trying it? (For instance, will these SP shenanigans be compatable with cQueueSendFromISR() and cQueueReceiveFromISR()? aLUNZ thinks so, but has yet to walk through the code to make sure).