Hi. I am developing small RTOS and I need to switch to thread mode from handler mode to do something, and this has to be done in thread mode.
I am testing RTOS on Cortex-M3 and M7 for a moment. I know that in hardware is set to exit handler mode if "magic value" is loaded to PC and the execution is transferred back to the point it was interrupted. But before that I need to do something and it has to be done in Thread mode.
Is any way to switch from Handler mode to Thread mode by writing to the registers? Or any other options?
I looked in documentation and it is not obvious to me if this is possible.
Thank you.
Alex
Loading the "Magic Value" into the PC does not transfer back to the point that it was interrupted.
What it does is use the appropriate stack pointer to restore the context from and continues running from there.
This may seem like it is the same thing as you said, and in many cases it is, but IF you change the stack pointer or change values on the stack, it can (and is) quite different.
To change to a different thread, this is exactly what you would do. You would change the Stack pointer that will be used to restore the context from when you leave the Handler_Mode.
Hi Robert.
Thanks for your reply.
I was too short when I was talking about "Magic value".
But my threads are short lived and started as tasks with some priority and die, and can be restarted. The same stack is used. Only one stack is used. These tasks are started by Interrupts. Any ideas on that, how to exit handler mode?
Thank you
OK. I think you are short again.
What does Short lived mean to you?
What does die mean to you?
Do you need to save any state information between starting and restarting a task?
Maybe what you could use is a priority queue that is processed by the PendSV interrupt?
Thanks for your replay. I think I need to use PendSV. I don't see other way.