Waking a task after reading a buffer of data

Hi all, I need to read/write data from/to device (SPI) in buffered mode. I have a user task T calling a ‘read’ function to get data from SPI through the ISR routine. I was inspired from ‘serial.c’ example and so I put dataIN and dataOUT queue. In the dataIN queue the ISR routine puts new data coming from device (with xQueueSendFromISR), meanwhile the user task T are waiting for them (with xQueueReceive). How can I wake the task T immediatly after the end of the ISR routine? I don’t understand the usage of the parameter xTaskWokenByPost (the last parameter) of xQueueSendFromISR, if I have a user task waiting for data on a queue, is it possible to make it wait for N queue elements?

Waking a task after reading a buffer of data

If you followed the serial example then xTaskWokenByPost will get automatically set to true if the received data caused a task to unblock – provided the task that unblocked has a higher priority than the task that was interrupted. If at the end of your ISR you find xTaskWokenByPost is true you can call the context switch function (how this is done depends on your port, but just copy the serial example again).  When you call the context switch function the ISR will return to the unblocked task, rather than the task that was interrupted.  This is what you want because it is now the highest priority task that is able to execute. If you want the unblocked task to execute when N data elements are available then you have some choices: 1) Don’t block the task on the queue, but instead suspend the task, then when N data bytes are available unsuspend the task from within the ISR.  The ISR will need to keep a count of how many data items are available. 2) Instead of queueing individual data items, queue a structure that contains N data items.  This way the ISR will only post onto the queue (and wake the task) when all N items are available. 3) Some combination of the above. Basically it sounds like you want a bit more intelligence in your ISR so it can control your tasks more efficiently.

Waking a task after reading a buffer of data

Thank u very much for your advices. I’m going to try…