Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Waking a task after reading a buffer of data

Posted by Nobody/Anonymous on December 27, 2005
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?

RE: Waking a task after reading a buffer of data

Posted by Nobody/Anonymous on December 27, 2005
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.

RE: Waking a task after reading a buffer of d

Posted by Nobody/Anonymous on January 3, 2006
Thank u very much for your advices.

I'm going to try...

[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

Version 10.1.0 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers


STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner