I have a question regarding synchronization between a task and an interrupt-routine using xSemaphoreTake and xSemaphoreGiveFromISR(…, …). My semaphore is created using the vSemaphoreCreateBinary() wrapper.
My task receives messages with data that are to be sent via. an uart. The uart write routine call the xSemaphoreTake(…,portMAX_DELAY) and triggers the TX interrupt to start sending data. Afterwards the task returns to “listening” for new messages (while the TX interrupt routine is active). After the last byte is sent in the interrupt context the xSemaphoreGiveFromISR() routine is called.
The idea is, that if a new messages arrives to the task while we still are transmitting data, the task will be suspended until the xSemaphoreGiveFromISR() is called from the interrupt routine.
Unfortunately this seems to crash my system and I cannot figure out why. Have I misunderstood the properties of the binary semaphore? Is it not possible to call xSemaphoreTake() multiple times on the binary semaphore to “stall” a task (if the semaphore is already taken)?
Using FreeRTOS 6.0.0 on a NEC 78K0R 1167 @ 14,7 MHz using IAR 4.70.