Problem: my code is getting crash within few seconds after my activation of timer input capture interrupt
I have used freeRTOS for freescale HCS12X series microcontroller and developed code for periodic tasks and for interrupt task (porting code taken from HCS12HCS12XCodeWarrior_OAF).
Interrupt been implemented with handler task support. Syncronization has been implmented via semaphore and queue concept. As of now i have
created three interrupts.
1. RTI interrupt for Timer tick generation (RTI- Real Time iInterrupt)
2. Timer over flow interrupt for my use. There is no semaphore and queue have been used inside this routine so portYIELD function is not used within the ISR.
3. Timer input capture interrupt, used queue concept. It has a handler task to receive the queue and calling some function.
Actually my code is getting crash within few seconds after my activation of timer input capture interrupt(generated square wave using function generator with frequency about 1Hz to 2Khz). i follow the procedure given in freerTOs manual for implementing ISR and handler function. Perhaps i disable the handler funcion to stop receiving the queue data to know portYIELD would be the reason for crash. But still the problem exist.
I have posted my code below.
define portYIELD() __asm( "swi" );
/* ISR routine */
_interrupt VectorNumberVtim1ch4 void MLTimer1Ch4ISR (void)
if( TIM1_TIOS_IOS4 == (Bool)0)
parameter.timer = TIMER_1;
parameter.channel = CHANNEL_4;
parameter.timer_count = TIM1_TC4;
timer1_Overflow = 0;
/* Future use - Code for Output Compare */
xQueueSendToBackFromISR (ML_TIMER_CAPTURE_HANDLE, ¶meter, &pxHigherPriorityTaskWoken);
/* Blocked task, waiting for this Queue has priority higher than the interrupted task */
if(pxHigherPriorityTaskWoken == pdTRUE)
/* ISR hnadler task 3*/
static void ISRHandleQueueFunction (void pvParameters)
/ Accessing task configuration through task parameters /
taskparameter = (SLISRHandleConfig *)pvParameters;
/ Queue data receive from interrupt service routine */
returnflag = xQueueReceive(taskparameter->handlename, &taskparameter;portMAX_DELAY);
/* Task calling */
_interrupt VectorNumberVswi void vPortYield (void)
//void vPortYield (void)
/* RTI interrupt for Tiemr tick generation */
_interrupt VectorNumberVrti void TimerTick_ISR (void)
#if configUSEPREEMPTION == 1
/* A context switch might happen so save the context. */
/* Increment the tick ... */
if( xTaskIncrementTick() != pdFALSE )
CRGFLG_RTIF = (Bool)1;
/* Restore the context of a task - which may be a different task
to that interrupted. */
CRGFLG_RTIF = (Bool)1;
Note:I have not used interrupt nesting in my project. configMAXSYSCALLINTERRUPT_PRIORITY is not avilable in my project.
Sorry, I am confused. Which architecture are you running this on? You mentioned an HSC12, which is a rather old port (although also a simple port so should be ok). If so, did you start with the demo in the FreeRTOS download and follow the instructions for that demo to create interrupts, etc.? There should be no need for you to be doing things like defining your own yield macros, they are already defined by the port layer.
Have you done things like turn on stack overflow checking, defining configASSERT(), etc.?
I am using MC9S12XHY256 freescale microcontroller (HCS12X architecture). So the demo project is not fit for this HCS12X architecture. I have taken the micro controller porting code from the below link.
If the timer input capture interrupt is disabled (which has xQueueSendToBackFromISR function call), all the periodic tasks are running without any issues. Perhaps if i enable timer interrupt then the code is getting crash after a period of time.
Kindly let me know what could be cause of the issue. You can refer the code i have shared in my previous post.
Did you find any solution to this? I'm trying to find a bug in some old software which looks very much like what you are describing. I am using MCS9S12XEQ512 running FreeRTOS 8.1.2 and the "CW/OAF" HCS12X port version. The task context switching works fine as long as there is no other IRQs. Once I enable other (timer) interrupts which don't even call any FreeRTOS functions, the application crashes after a while at random places with smashed stack. Something seems to go wrong with the portSAVECONTEXT / vTaskSwitchContext / portRESTORECONTEXT when there are more pending interrupts waiting at the same time as a context switch (i.e. jumping to another ISR after context switch in vPortTickInterrupt). We are not using nested interrupts.
In my case, the solution was to add the "D/E/G/P/R PAGE Register is used" in CW/Compiler/Code Generation (HC12 Compiler 126.96.36.19903 options : "-CpDPAGE -CpGPAGE -CpEPAGE -CpPPAGE -CpRPAGE") for all other interrupts. I didn't find it documented anywhere, but the compiler will then add the assembly instructions to save/restore the mentioned registers when entring/exiting any ISR. Also I am using the portYIELD (swi) only, also from ISR's (ISRs are using stack).
Many of the ISR are using xQueueSendToBackFromISR and other FreeRTOS calls. After this change, no more crashes have been recorded.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.