flit / argon-rtos

Argon RTOS: tiny embedded C/C++ RTOS for Cortex-M
BSD 3-Clause "New" or "Revised" License
64 stars 14 forks source link

IRQ handler stack #6

Closed diggit closed 6 years ago

diggit commented 6 years ago

Hi, AFAIK IRQ handlers use current active thread stack. That means, every thread must have large enough stack to accommodate all IRQ requirements.

Is there any function which IRQ handler can call to switch to custom stack and then back?

flit commented 6 years ago

Hi @diggit, IRQ handlers use the Main stack (MSP), while threads use the Process stack (PSP). So you don't need to worry about allocating enough room for IRQ handlers on every thread stack. (This is one of the nice ways in which the Cortex-M architecture was designed with RTOSes in mind.)

Unless you are using ar_main_thread.cpp (which requires IAR or armcc), your application will enter main() running on the Main stack. So the stack size that you specify in the link descriptor file (.ld, .sct, or .icf) will become the Main stack upon which IRQs execute, after you call ar_kernel_run().

Note that the MSP is not reset when the kernel starts. So whatever amount of Main stack is used up to the point where ar_kernel_run() is called is lost.

diggit commented 6 years ago

Thanks for explanation @flit! I never read docs about RTOS support on cortex M processor deeply enough. Smarter every day...