# FreeRTOS Interrupt priority

**URL:** <https://forums.freertos.org/t/freertos-interrupt-priority/13673>\
**Category:** Kernel\
**Tags:** tutorial\
**Created:** [October 13, 2021, 1:34pm UTC](https://forums.freertos.org/t/freertos-interrupt-priority/13673 "2021-10-13T13:34:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cavagiu](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cavagiu](https://forums.freertos.org/u/cavagiu)\
**Post date:** [October 13, 2021, 1:34pm UTC](https://forums.freertos.org/t/freertos-interrupt-priority/13673/1 "2021-10-13T13:34:34Z")

</div>

Hello All.  
I have a porting of FreeRTOS on Cortex-R52 and I have some doubts about the right priority assigned to the interrupts.

In my applications, typically all the ISR, registered by the peripherals, have a priority greater then the configMAX\_API\_CALL\_INTERRUPT\_PRIORITY.  
I understand, these ISR never be delayed by anything the kernel is doing, can nest, but cannot use any safe API.  
Note that the priority is directly used for programming the GIC registers.  
Actually, these ISR (for all my IP) will never call “FromISR” functions in my applications but…  
Q1) is there any example of a driver that needs to call safe API inside own ISR?

Q2) For ARM, the higher numeric interrupt priority values indicates the lower logical interrupt priorities. I have not clear if the meaning configMAX\_API\_CALL\_INTERRUPT\_PRIORITY remains the same. I mean, this is still the logic:

 ![image](https://d2v6vdsk2p900z.cloudfront.net/original/2X/c/c62a0fe3895667d39faf01b781a502adc1265feb.png)

Q3) the System Timer should have the lowest priority as reported in the _port.c_. In my FreeRTOS, the configMAX\_API\_CALL\_INTERRUPT\_PRIORITY = 8, then peripheral registers the handler with prio \> 8, but the FreeRTOS\_Tick\_Handler has 4. Is it correct?

Many thanks in advance.  
Regards  
peppe

---

<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 13, 2021, 3:44pm UTC](https://forums.freertos.org/t/freertos-interrupt-priority/13673/2 "2021-10-13T15:44:11Z")

</div>

> [@cavagiu](#):
>
> Q1) is there any example of a driver that needs to call safe API inside own ISR?

Are you looking for a code example, or just asking under what conditions would a driver need to call an API inside an ISR?

When you are using a simple priority based preemptive scheduler, such the FreeRTOS scheduler, you don’t want a task to be polling for IO because by polling it is preventing any lower priority task from running. Instead you want the task to wait in the Blocked state until the IO is available - in which case the FreeRTOS API is used in the ISR to unblock the task when data is available. There are many ways of doing this, so let me know if I’m missing the point of your question.

> [@cavagiu](#):
>
> Q2) For ARM, the higher numeric interrupt priority values indicates the lower logical interrupt priorities. I have not clear if the meaning configMAX\_API\_CALL\_INTERRUPT\_PRIORITY remains the same. I mean, this is still the logic:

The max system/api call interrupt priority always sets the highest LOGICAL interrupt priority from which an API can be called. As you say, on ARM systems the lower the numeric interrupt priority the higher its LOGICAL priority - so on ARM systems, if configMAX\_API\_CALL\_INTERRUPT\_PRIORITY is set to x, then interrupts with a NUMERICAL priority value greater or equal to x can call the ISR safe API, because interrupts with a NUMERICAL value greater or equal to x have a lower LOGICAL interrupt priority. Generally this is much easer to understand on non-ARM systems because then high numerical value means high logical value.

> [@cavagiu](#):
>
> Q3) the System Timer should have the lowest priority as reported in the _port.c_. In my FreeRTOS, the configMAX\_API\_CALL\_INTERRUPT\_PRIORITY = 8, then peripheral registers the handler with prio \> 8, but the FreeRTOS\_Tick\_Handler has 4. Is it correct?

If the max API call priority is 8 the, on an ARM system, I would expect the tick hander to have a priority numerically greater than or equal to 8. In that case, and without re-reading all the docs, 4 would not see to be a good value because it has a logically higher priority than 8.

---

<div class="post-metadata">

**Author:** ![cavagiu](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cavagiu](https://forums.freertos.org/u/cavagiu)\
**Post date:** [October 13, 2021, 4:26pm UTC](https://forums.freertos.org/t/freertos-interrupt-priority/13673/3 "2021-10-13T16:26:58Z")

</div>

Hi Richard  
many thx for your prompt feedback and you covered my questions. Really appreciated.

I have another question.

Experimenting with my Ethernet driver, I implemented the Tx/Rx inside the ISR w/o invoking any Task. I mean, for example the incoming frames are passed to the TCPIP stack from the ETH ISR.  
So I implemented the xSendEventStructToIPTaskFromISR.  
When I refill the RX resources I should invoke functions like: pxGetNetworkBufferWithDescriptor and pvPortMalloc (depending on ZERO copy) I guess they are not designed to be called at interrupt time. What do you think, maybe I should use queue? Or is it better and simpler to fallback to a task implementation based?

Best regards  
peppe

---

<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 13, 2021, 4:50pm UTC](https://forums.freertos.org/t/freertos-interrupt-priority/13673/4 "2021-10-13T16:50:01Z")

</div>

It is best for these things to be deferred to a task - you can look at other MAC drivers in the distribution to see how that is done. Generally (although it depends on the individual system), you would have the priority of the TCP/IP task above the priority of the application tasks, and the priority of the task that handles MAC events at a higher priority than the TCP/IP task.

If you have the task that handles MAC events at a very high priority then it can spend most of its time waiting for the MAC ISR to tell it there is something to do. The MAC ISR can do that by sending the task a direct to task notification, then yielding in the ISR, so the MAC ISR interrupts one task, but returns directly to the task that is handling the MAC ISR, so the MAC processing occurs immediately, just as if it were done in the ISR itself.

---

<div class="post-metadata">

**Author:** ![cavagiu](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cavagiu](https://forums.freertos.org/u/cavagiu)\
**Post date:** [October 14, 2021, 4:48am UTC](https://forums.freertos.org/t/freertos-interrupt-priority/13673/5 "2021-10-14T04:48:36Z")

</div>

thx a lot, all is clear.

regards  
peppe

---

<div class="post-metadata">

**Author:** ![jiangpengyuan](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/jiangpengyuan/32/5145_2.png) [@jiangpengyuan](https://forums.freertos.org/u/jiangpengyuan)\
**Post date:** [December 2, 2024, 3:52am UTC](https://forums.freertos.org/t/freertos-interrupt-priority/13673/6 "2024-12-02T03:52:29Z")

</div>

On ARM Cortex A the interrupt, which uses FreeRTOS API calls, has to have a priority setting lower than the _configMAX\_API\_CALL\_INTERTUPT\_PRIORITY_ which means that the number has to be bigger than that value of this config paramater. Also, I had to use the _portPRIORITY\_SHIFT_ when setting the interrupt priority because I think there is some masking taking place and not all interrupt value bits are valid to use. SO after setting my priority setting code to following the interrupt fired nicely and there were no assertion errors:  
`// set the priority of IRQ_F2P[0:0] to 0x04 (highest 0xF8, lowest 0x00) and a trigger for a rising edge 0x3.XScuGic_SetPriorityTriggerType(&xInterruptController, INT_ID, (configMAX_API_CALL_INTERRUPT_PRIORITY \+ 1) << portPRIORITY_SHIFT, 0x3);`

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [December 2, 2024, 5:16am UTC](https://forums.freertos.org/t/freertos-interrupt-priority/13673/7 "2024-12-02T05:16:51Z")

</div>

Thank you for sharing!
