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



Posted by mkrug on August 31, 2007

I discovered something interesting with a HC12 (did the adoption to the existing HCS12 port on my own) that I can not explain at the moment.

I have a CAN interrupt receive service routine. If I overload the HC12 with high CAN message frequency the application crashs at the call of: portTASK_SWITCH_FROM_ISR() at the end of the interrupt service routine. If I replace it with portYIELD() it works perfectly. I looked to the stack pointer and it points on the same adress, regardless which of the task switch functions I am calling, right at the beginning and just before exiting the service routine. I use only 'static' variables in the service routine. Surprisingly the code for portTASK_SWITCH_FROM_ISR and portYIELD is exactly the same. The only difference in calling portYield is that within the interrupt service routine an other one (portYIELD) is called because the swi instruction is used. So an additional entry and exit to interrupt service routines are performed.

Anyone an idea what makes the difference ?

Best Regards


Posted by Dave on August 31, 2007
Just reading the docs for the port I see "Note that portTASK_SWITCH_FROM_ISR() should only ever be used at the very end of an ISR and only when the ISR does not declare any non static local variables. If the ISR does use local variables then a call to portYIELD() can be used in place of the portTASK_SWITCH_FROM_ISR() macro." As your vars are static you are not using local variables.

It does not say that portTASK_SWITCH_FROM_ISR() should not be used when there are no local variables.

Is you call the last thing done in the ISR?


Posted by mkrug on August 31, 2007
Hello Again,

below you find the original ISR code. I commented out the portTASK_SWITCH_FROM_ISR() command. In any case you can see that it is the very last command in the ISR. IDHIT, CORFLG and pdTRUE are global Variables. The local used ones are defined as 'static'.


static unsigned char xYieldRequired = pdFALSE;
static unsigned char temp_reg_rec;

temp_reg_rec = C0RFLG;
temp_reg_rec = temp_reg_rec | 0x01;
C0RFLG = temp_reg_rec;

switch (IDHIT)
case 0x00:
/* CAN 0x100 was received */
xYieldRequired = xSemaphoreGiveFromISR( xSemaphoreCANID100, pdFALSE );
case 0x01:
/* CAN 0x108 was received */
xYieldRequired = xSemaphoreGiveFromISR( xSemaphoreCANID108, pdFALSE );
case 0x02:
/* CAN 0x118 was received */
xYieldRequired = xSemaphoreGiveFromISR( xSemaphoreCANID118, pdFALSE );
case 0x03:
/* CAN 0x158 was received */
xYieldRequired = xSemaphoreGiveFromISR( xSemaphoreCANID158, pdFALSE );

if( xYieldRequired == pdTRUE )
//portTASK_SWITCH_FROM_ISR(); surprisingly does not 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