tx_semaphore inside a Interrupt

785 Views Asked by At

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?

2

There are 2 best solutions below

0
On

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://learn.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.

1
On

If your RTOS provides a way to do it, then use that. If not, then here's some other options:

There's also a very bad idea/last resort, and that is to toggle the global interrupt mask.