PSoC FreeRTOS Task Notify | 赛普拉斯半导体
PSoC FreeRTOS Task Notify
[re-printed from https://iotexpert.com]
I have been writing a bunch of articles about implementing PSoC FreeRTOS so, this morning I was reading the FreeRTOS manual (yes I am one of those…) and I noticed a section in the API guide that I hadn’t see before… Task Notifications. Every task in the FreeRTOS has a built in 32-bit integer notification value. This value is super light weight and can be used like a task specific counting semaphore, or a signaling bit mask, or binary semaphore. The API includes:
It seems like this API is good for the situations when your Semaphore has a specific task target in mind. I thought that this would be a perfect scheme to have a PSoC FreeRTOS UART ISR signal the UART Handling task that there is data available to do something with.
Setup the PSoC FreeRTOS Project
I start this process by making a copy of “1-BlinkingLED” (which already has all of the FreeRTOS stuff in it) and naming it “9-TaskNotify”. Then I add a UART to the schematic and name it “UART”
I attach the UART to the right pins on the CY8CKIT-044 kit.
Next I turn on the interrupt which will be called when there is data in the receive FIFO.
PSoC FreeRTOS UART Code
Now that the schematic is all configured I update my firmware. The function “uartHandler” is called when there is data in the UART RX FIFO. It turns of the interrupts for the UART (which I will turn back on after I have cleared the data in the input buffer), clears the interrupt (so that it will stop pending) and then sends the notification to the UART_Task.
The UART Task just registers the handler… then while(1)’s until the end of time. It waits for a notification, then reads data out of the RX fifo and puts out, then re-enables the interrupts.
// disable the interrupt
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
void UART_Task( void *arg)
c = UART_UartGetChar();
// clear & re-enable the interrupt