I want to read out RS232 data periodically. I have created an interrupt for this purpose. However, my RS232 functions need semaphores. I found out that I cannot execute a TX(Thread X) function in the interrupt. What do I have to do to make my TX function work inside the interrupt?
CodePudding user response:
If your RTOS provides a way to do it, then use that. If not, then here's some other options:
- Disable the specific interrupt from the background program during variable access.
- In case interrupts aren't interruptible on your MCU, you could implement a "poor man's mutex" described here: https://electronics.stackexchange.com/questions/409545/using-volatile-in-embedded-c-development/409570#409570
- Use inline assembler and ensure reads/writes are done in a single instruction.
There's also a very bad idea/last resort, and that is to toggle the global interrupt mask.
CodePudding user response:
First, make sure you are calling _tx_thread_context_save and _tx_thread_context_restore at the beginning and end of your ISR, respectively. See here for more information: https://docs.microsoft.com/en-us/azure/rtos/threadx/chapter3#isr-template Second, you cannot create a semaphore in an interrupt, so make sure you create it elsewhere.