Quality RTOS & Embedded Software

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


Sending queue from a ISR??

Posted by Thomas Johansen on May 19, 2010

I have problems sending messages from a ISR to a task.
Im using RTOS 5.1.2, KEIL and a LPC2478 MCU.

On a external interrupt I do have to invoke a task. The task is waiting on a massage with a xQueueReceive(). The message is send from the ISR with the xQueueSendToFrontFromISR() function. But the waiting task never gets invoked. The xQueueSendToFrontFromISR() returns pdPASS. See the code used below.

I know the task in running ok. Setting a timeout in the xQueueReceive() makes the function return on the expected time.

The first time I call xQueueReceive(), after a reset, the function right away with the status pdTRUE. But a message was never send? Next time the xQueueReceive() is called the function blocks. Any idea why?

Must I use another receive function when using xQueueSendToFrontFromISR???
Is there a better way of getting a hardware interrupt to a task?

void ExternalInterruptInit(void)
// Creating queue
static xQueueHandle xExternal;
xExternal= xQueueCreate( 1, sizeof(portCHAR) );
// Init interrupt, GPIO etc.

/ ISR for external interrupt - Key pressed
void KeyPressedISRHandler (void)
portBASE_TYPE status;
// Key state
BYTE byKeyDown = 0;
// Token
portBASE_TYPE xHigherPriorityTaskWoken;
// Send event
byKeyDown = 1;
status = xQueueSendToFrontFromISR( xExternal, &byKeyDown, &xHigherPriorityTaskWoken );
// Clear interrupt
// Acknowledge interrupt
VICVectAddr = 0;
// Did sending to the queue unblock a higher priority task?
portEXIT_SWITCHING_ISR( xHigherPriorityTaskWoken );

// Task for external interrupt events
static void ExternalIntTask(void *pvParameters)
// Forever
// Wait interrupt
if( pdTRUE == xQueueReceive( xExternal, &byDummy, portMAX_DELAY) ) // Blocks....
// Do stuff here...


RE: Sending queue from a ISR??

Posted by MEdwards on May 19, 2010
The code is hard to read because the formatting has been lost. It is possible to post using the 'codify text' tags to keep the indents.

ExternalInterruptInit() is creating a queue, but xExternal is static so cannot be accessed from outside of the function. I'm not sure how you access it in the interrupt handler.

xHigherPriorityTaskWoken should be initialised to 0 before it is used.

Other than that I cannot see anything wrong.

(just noticed the closing so don't know where the formatting went)

RE: Sending queue from a ISR??

Posted by Rohit Grover on May 22, 2010

I'm facing a similar problem using a binary semaphore to synchronize between an ISR and a task. It was suggested to me that I should set the priority of the ISR to be <= configMAX_SYSCALL_PRIORITY; but in my case that did not help. Were you able to resolve your issue? if so, could you please mention how? Thanks.

RE: Sending queue from a ISR??

Posted by woops_ on May 23, 2010
Look for FromISR in Demo\CORTEX_LPC1768_GCC_Rowley\webserver\emac.c for examples.

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

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


FreeRTOS and other embedded software careers at AWS.

Latest News

FreeRTOS kernel V10.0.1 is available for immediate download. Now MIT licensed.

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