We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I'm using Keil uVision5 and an LPC1768 on an MCB1700 dev board.
I am writing a simple RTOS, and I have implemented two methods of context switching - one co-operative using a yield() function and one pre-emptive using SysTick. I just spent a while debugging a hardfault and long story short the SysTick context switcher would periodically fire in the middle of a cooperative context switch, which messed up my various stacks and led to the hard fault.
I have tried using __disable_irq() at the top of my yield function then re-enabling IRQ just before I do the switch (which happens in handler mode for various reasons), but that didn't fix anything. I have currently kludged together a solution where I have a global boolean that the yield function sets to false while it's doing its thing. If that boolean is false, the SysTick switcher just returns.
I would like to disable the SysTick interrupt during a yield, but it seems that __disable_irq isn't the way to do it. Does anyone have any suggestions?