Quality RTOS & Embedded Software

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


Multiple calls xQueueSendFromISR

Posted by Guillermo Prandi on January 23, 2006
Hi. I am using FreeRTOS in a LPC2138 board. Since I've been having some problems with interrupts, I've been wondering: what happens if my ISR, using xQueueSendFromISR, is executed two consecutive times with no other code in between? It will call xQueueSendFromISR with xTaskPreviouslyWoken in both executions, and perhaps the first time it got a pdTRUE. This is -I think- equivalent to calling xQueueSendFromISR twice in the same ISR execution with xTaskPreviouslyWoken == pdFALSE in both calls.


RE: Multiple calls xQueueSendFromISR

Posted by Richard on January 23, 2006
I think this depends on how your interrupt is executed twice.

xTaskPreviouslyWoken is an (optional) method of ensuring that an interrupt only wakes one task per interrupt - if this is the behaviour you want.

As an example, assume you have a serial port interrupt that processes received characters and there happens to be two characters in the buffer when the interrupt fires. There are also two tasks waiting on the queue for characters to be available:

If your ISR contains a loop as

____xTaskPreviouslyWoken = false;

____while( buffer_not_empty )

then the loop will execute twice. The first time xTaskPreviouslyWoken will be false, so posting to the queue will wake the task higher priority of the two waiting tasks. The next time round the loop (to get the second character from the buffer) xTaskPreviouslyWoken will be true, so the second task will not be woken but remain suspended on the queue. Now there is one task woken and two characters available in the queue so it assumed that the single task will read both characters from the queue.

Now if you write your ISR as

____xTaskPreviouslyWoken = false;


Only one character is taken out of the buffer each time the ISR fires - so as there are two characters in the buffer the ISR will fire twice. Each time it fires xTaskPreviouslyWoken is set to false, resulting in one task being woken on the first ISR execution and the other task being woken on the second execution.

Now you will have two tasks reading the characters. Whether this is want you want or not is completely application dependent. A task may read a single character then sleep - allowing the other task to ready the other character. Conversely a task may read both characters, meaning the queue is empty when the second task runs.

Of coarse none of this matters if you only have a single task waiting on the queue at a time - which would be normal in most applications. Otherwise it is best to check the return value of xQueueReceive to see if a character was actually read from the queue.


RE: Multiple calls xQueueSendFromISR

Posted by Guillermo Prandi on January 23, 2006
Thank you, Richard.

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

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

Latest News

FreeRTOS v10.2.0 is available for immediate download. MIT licensed, and including RISC-V and ARMv8-M (Cortex-M33) demos.

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

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

Cadence Tensilica Cortes

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