Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


Problems Resuming a Task from an ISR

Posted by Eric Burkhart on September 6, 2008
I'm currently using FreeRTOS on Atmel's AVR32 UC3 Serieas and am trying to resume a task from an ISR. Here is my ISR:

__attribute__ ((naked))
static void dataready_int_handler(void)
portBASE_TYPE xYieldRequired = pdFALSE;

//Tell the processing task to start
xYieldRequired = xTaskResumeFromISR( xQuantumHandle );




This code gets to the switch context once, and then on every subsequent call of xTaskResumeFromISR, it says no context switch is necessary because prvIsTaskSuspended says xQuantumHandle is not suspended (but I'm quite sure it's not running, and there is always one item in the xSuspendedTaskList).

The suspicious code is in prvIsTaskSuspended:

/* Is the task we are attempting to resume actually in the
suspended list? */
if( listIS_CONTAINED_WITHIN( &xSuspendedTaskList, &( pxTCB->xGenericListItem ) ) != pdFALSE )
/* Has the task already been resumed from within an ISR? */
if( listIS_CONTAINED_WITHIN( &xPendingReadyList, &( pxTCB->xEventListItem ) ) != pdTRUE )

It gets past the first check that the task is in the suspended list, but after this pxTCB changes to 0x00. Any thoughts on what might cause this or something I could be doing wrong?


RE: Problems Resuming a Task from an ISR

Posted by Dave on September 6, 2008
First thing is, is it valid to call ENTER_CRITICAL() EXIT_CRITICAL() in an interrupt on an AVR32. I don't know anything about the port so maybe it is but this would not be normal for most port.

Second, if you are using the task suspension mechanism to control an event handler task by unsuspending the task in the interrupt then having the task suspend itself, I would recommend switching to use a semaphore instead. The task suspension mechanism will not work because interrupt occurring before the task has suspended itself will simply be lost because the interrupt is trying to unsuspend a task that is not yet suspended. When the task next suspends itself it will not be unsuspended until the following interrupt.

From the documentation http://www.freertos.org/taskresumefromisr.html "vTaskResumeFromISR() should not be used to synchronise a task with an interrupt if there is a chance that the interrupt could arrive prior to the task being suspended - as this can lead to interrupts being missed. Use of a semaphore as a synchronisation mechanism would avoid this eventuality."

Look at the example on this page instead http://www.freertos.org/a00124.html. You might even want to use a counting semaphore depending on the characteristics of you application.

RE: Problems Resuming a Task from an ISR

Posted by Eric Burkhart on September 8, 2008
You're right, I don't know that it is valid to call ENTER_CRITICAL() EXIT_CRITICAL() in an interrupt, but on second thought other interrupts are automatically masked anyways in an ISR here.

I was thinking about using a semaphore, but I was concerned that it would be much slower. This application has a periodic interrupt to tell it to read data from another chip. The window to read data is very small (and missing a read occasionally is tolerable) so I thought this may be a bit faster. Other than missing some interrupts, is there any fundamental reason that this mechanism doesn't work?

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

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists