Sending queue from a ISR??

tjohansen wrote on Wednesday, 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...


edwards3 wrote on Wednesday, 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)

rgrover1 wrote on Saturday, 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.

woops_ wrote on Sunday, May 23, 2010:

Look for FromISR in Demo\CORTEX_LPC1768_GCC_Rowley\webserver\emac.c for examples.