I am creating a RTOS kernel and need to use the PendSV handler for context switching. I trigger the PendSV handler by doing : 0xE000ED04 = (0x1 << 28);. This sets the PendSVset register to 1, so theoretically, the handler should trigger. I do disable interrupts before triggering and enable after triggering. After the enabling PendSV should trigger. The priority is the lowest 0xFF and the systick handler priority is 0x00. I am not sure what is going on and why the pendsv handler is not running. I am using an TI-MSP432 controller and I figure maybe its the way the controller is handling the interrupt?
It is set in vectpending, vectpending is 001110 which is 14 for pendsv.
If anybody can help, I'd greatly appreciate it.
Have you tried something simple like this (throwaway code experiments are crucial for bare-metal development, try without the rest of the project and all the over-complications)
call with
and in my case that has some uart output:
And can then move on to this:
and see
which tells me that PendSV is cleared when it goes to the handler.
As far as priority goes, the docs say pendsv and svc are equal, so
and
note:
then we get
An eternity of time for the pendsv to fire but because the svc call is equal per the documentation then it cannot, until svc call returns. You can do this with interrupts as well, but the exceptions should be higher than the interrupts? Check the docs.
No reason why your experience should be different than mine on your cortex-m. If pendsv is not happening then divide and conquer. Divide the problem in half. Take the current code and start removing stuff working toward nothing. Do that for a bit. Start from almost nothing having the pendsv firing then start adding stuff, work toward the middle where you find what seems to cause it, understanding that even if you find it, that may not be IT. That is IT for the gutted code, you may have created another situation.
Reading and throwaway code experiments are well over 99% of your time with bare-metal. Writing of the final program is a very small percentage of your time.
Have you done these things to see how interrupt handlers or other things you are doing has affected pendsv success? What is the ICSR register showing you after you set pendsv?
How much time is in the systick or other equal level handlers relative to clock cycles left for pendsv, have you insured in your system level design that there are free clocks for the handlers to all have time.
If you want to do the thread swap in the systick handler then either just do it or use svc perhaps and not pendsv.