Priority clash - RTOS interrupts vs Micro interrupts

deepakseshan wrote on Thursday, October 31, 2019:

Hello All,

**#define LED_ON1_TASK_PRIORITY 1
#define HEARTBEAT_TASK_PRIORITY 3

void vLEDon1_Task (void pvParameters) (Task 1)
{
(void) pvParameters;

for(;;)
{
   IfxStmDemo_run();    //flashing LED using Micro System timer and Timer Interrupt priority is 10
	}

}

void vLEDHeartbeatTask (void pvParameters ) ** (Task 2)*
{
unsigned long xLastFlashTime;
unsigned xFlashRate = 500;
( void ) pvParameters;

// Calculate the LED and flash rate.
portENTER_CRITICAL();
{
	//...
}
portEXIT_CRITICAL();

// We need to initialise xLastFlashTime prior to the first call to vTaskDelayUntil().
xLastFlashTime = xTaskGetTickCount();

for(;;)
{
	// Delay for half the flash period then turn the LED on.
	LED_TOGGLE(3);  

	vTaskDelayUntil( &xLastFlashTime, xFlashRate );
}

}
xTaskCreate( vLEDon1_Task, “LED ON1”, 128, NULL, LED_ON1_TASK_PRIORITY, NULL ); // task 1 - That functiom flashes LED timer interrupt for 100 ms rate.

xTaskCreate( vLEDHeartbeatTask, “LED”, 128, NULL, HEARTBEAT_TASK_PRIORITY, NULL ); // task 2 - normal toggle using taskdelay()


By looking at the above code, When i try to run the program, Eventhough Task 2 has got Higher RTOS priority, the program Excecutes Task 1 due to STM timer interrupt priority is high as Micro interrupt.
I also tried to introduce Taskdelay() function in Task 1 where both Tasks are stopped running.
I also tried to give both task equal priority but again both tasks stopped working.

Note:- ** #define configKERNEL_INTERRUPT_PRIORITY 2** The RTOS priority number 2 is defined in the Micro interrupt vector table as same priority (2) which is a timer interrupt for running scheduler.

How to manage RTOS interrupts against the Micro interrupt?

Please do not hesitate to ask me for more informationif required.

Kind regads,
Deepak

rtel wrote on Thursday, October 31, 2019:

As task 2 spends most of its time in the delayed state, I would expect
task 1 to execute at any other time, so it is not clear why that is
unexpected. The interrupt priority has no impact on task priorities -
so the interrupt could have a really high priority or a really low
priority, it will still interrupt the tasks.

If I can summarise your description to simply that task 2 doesn’t run,
and if I block task 1 that one doesn’t run either, then my first guess
would be that the tick interrupt isn’t executing. If the tick interrupt
is not executing then time will not be moving forward and the block
times will never expire.

Try breaking the code in the debugger to see what it is doing - it will
either of crashed completely or the idle task will be running - what
value does the xTickCount value have? If it is low then the clock is
probably not running at the frequency you think it is. If it is zero
then the tick interrupt is not running.

deepakseshan wrote on Thursday, October 31, 2019:

Hello Richard,
Yes, you are absolutely correct with the simplified description, To get the Tickcount value should i need to use this xTaskGetTickCount(); inside the task function? and
please share me how to capture or see the idle task running,
Kindly shed some light

deepakseshan wrote on Thursday, October 31, 2019:

hello Richard,
I can locate the tick count value from tasks.c file.
PRIVILEGED_DATA static volatile portTickType xTickCount = ( portTickType ) 0U;

is this right? please

rtel wrote on Thursday, October 31, 2019:

Yes that is right - just view it in the debugger to check its value.

For your other question about how to see the idle task running - if
neither of your application tasks are running (and there are no other
tasks) then the Idle task will be running. So when you stop in the
debugger you will already be in the idle task.

deepakseshan wrote on Thursday, October 31, 2019:

i can see the value of xticks from the debugger as 33554432.

rtel wrote on Thursday, October 31, 2019:

That looks like a very high number - how long was it running before you
did that? Is the value changing? Does it start at zero before the
scheduler starts?

Also, do you follow the recommendations on this page
https://www.freertos.org/FAQHelp.html regarding having stack overflow
detection on, checking for malloc fails using the malloc failed hook,
having configASSERT() defined, etc.

deepakseshan wrote on Thursday, October 31, 2019:

yes, it is running for quite sometime, but when I rest it and check the value of xTicks using debbuger, it shows the same value.
I also found one more thing, from the above code, I removed the Timer function "StmDemorun();"and make a LED toggle function with vTaskDelya(); bot the task are running at the different Task delays.

void vLEDon1_Task (void *pvParameters)
{
(void) pvParameters;

for(;;)
{

     // IfxStmDemo_run(); // Commented the Timer function
      LED_TOGGLE(5);
    vTaskDelay(200);
}

}

void vLEDHeartbeatTask (void *pvParameters )
{
unsigned long xLastFlashTime;
unsigned xFlashRate = 100;
( void ) pvParameters;

// Calculate the LED and flash rate.
portENTER_CRITICAL();
{
	//...
}
portEXIT_CRITICAL();

// We need to initialise xLastFlashTime prior to the first call
xLastFlashTime = xTaskGetTickCount();
for(;;)
{
	// Delay for half the flash period then turn the LED on.
	LED_TOGGLE(3);

	vTaskDelay(250);
	//vTaskDelayUntil( &xLastFlashTime, xFlashRate );
}

}

This code work it seems , I can see both LEDs are flashing in two different task with its own delay time. But when I insert my tiumer function, it traps.

deepakseshan wrote on Thursday, October 31, 2019:

And also I tried to use the “printf” function in the task function as well and again the both the stack when into idle state it seems. What mistake I am doing here?

rtel wrote on Thursday, October 31, 2019:

It would seem to be something in the timer function itself then.