# Priority clash - RTOS interrupts vs Micro interrupts

**URL:** <https://forums.freertos.org/t/priority-clash-rtos-interrupts-vs-micro-interrupts/8142>\
**Category:** Kernel\
**Created:** [October 31, 2019, 5:23pm UTC](https://forums.freertos.org/t/priority-clash-rtos-interrupts-vs-micro-interrupts/8142 "2019-10-31T17:23:48Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 31, 2019, 5:23pm UTC](https://forums.freertos.org/t/priority-clash-rtos-interrupts-vs-micro-interrupts/8142/1 "2019-10-31T17:23:48Z")

</div>

**[deepakseshan](https://sourceforge.net/u/deepakseshan/)** wrote on [Thursday, October 31, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/706fe4e474/#b7f4):

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

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [October 31, 2019, 5:32pm UTC](https://forums.freertos.org/t/priority-clash-rtos-interrupts-vs-micro-interrupts/8142/2 "2019-10-31T17:32:53Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, October 31, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/706fe4e474/#b7f4/26b4):

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.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 31, 2019, 6:27pm UTC](https://forums.freertos.org/t/priority-clash-rtos-interrupts-vs-micro-interrupts/8142/3 "2019-10-31T18:27:58Z")

</div>

**[deepakseshan](https://sourceforge.net/u/deepakseshan/)** wrote on [Thursday, October 31, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/706fe4e474/#c1bd):

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

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 31, 2019, 7:14pm UTC](https://forums.freertos.org/t/priority-clash-rtos-interrupts-vs-micro-interrupts/8142/4 "2019-10-31T19:14:53Z")

</div>

**[deepakseshan](https://sourceforge.net/u/deepakseshan/)** wrote on [Thursday, October 31, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/706fe4e474/#486c):

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

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [October 31, 2019, 8:42pm UTC](https://forums.freertos.org/t/priority-clash-rtos-interrupts-vs-micro-interrupts/8142/5 "2019-10-31T20:42:21Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, October 31, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/706fe4e474/#486c/8e93):

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.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 31, 2019, 10:10pm UTC](https://forums.freertos.org/t/priority-clash-rtos-interrupts-vs-micro-interrupts/8142/6 "2019-10-31T22:10:30Z")

</div>

**[deepakseshan](https://sourceforge.net/u/deepakseshan/)** wrote on [Thursday, October 31, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/706fe4e474/#6939):

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

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [October 31, 2019, 10:25pm UTC](https://forums.freertos.org/t/priority-clash-rtos-interrupts-vs-micro-interrupts/8142/7 "2019-10-31T22:25:55Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, October 31, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/706fe4e474/#6939/aac1):

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](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.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 31, 2019, 10:56pm UTC](https://forums.freertos.org/t/priority-clash-rtos-interrupts-vs-micro-interrupts/8142/8 "2019-10-31T22:56:04Z")

</div>

**[deepakseshan](https://sourceforge.net/u/deepakseshan/)** wrote on [Thursday, October 31, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/706fe4e474/#9dac):

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.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 31, 2019, 11:23pm UTC](https://forums.freertos.org/t/priority-clash-rtos-interrupts-vs-micro-interrupts/8142/9 "2019-10-31T23:23:04Z")

</div>

**[deepakseshan](https://sourceforge.net/u/deepakseshan/)** wrote on [Thursday, October 31, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/706fe4e474/#fc3b):

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?

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [October 31, 2019, 11:37pm UTC](https://forums.freertos.org/t/priority-clash-rtos-interrupts-vs-micro-interrupts/8142/10 "2019-10-31T23:37:04Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, October 31, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/706fe4e474/#fc3b/6420):

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