# Daemon task and priority

**URL:** <https://forums.freertos.org/t/daemon-task-and-priority/11688>\
**Category:** Kernel\
**Created:** [February 3, 2021, 6:54pm UTC](https://forums.freertos.org/t/daemon-task-and-priority/11688 "2021-02-03T18:54:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mission](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@mission](https://forums.freertos.org/u/mission)\
**Post date:** [February 3, 2021, 6:54pm UTC](https://forums.freertos.org/t/daemon-task-and-priority/11688/1 "2021-02-03T18:54:38Z")

</div>

Hello,

From FreeRTOSConfig.h

```auto
#define configMAX_PRIORITIES 16
#define configTIMER_TASK_PRIORITY 3

```

The range of available priorities is 0 to (configMAX\_PRIORITIES – 1)  
Questions:

1. Why don’t we say available priorities is 0 to confgMAX\_PRIORITIES ?
2. Since Daemon Task would handle the ISR work should it’s priority be the highest among the tasks?

---

<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:** [February 3, 2021, 7:23pm UTC](https://forums.freertos.org/t/daemon-task-and-priority/11688/2 "2021-02-03T19:23:00Z")

</div>

> Why don’t we say available priorities is 0 to confgMAX\_PRIORITIES ?

Because ready list is an array of size `confgMAX_PRIORITIES` which is indexed by priorities (and hence priorities are from `0` to `confgMAX_PRIORITIES - 1`) : [https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/tasks.c#L344](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/tasks.c#L344)

> Since Daemon Task would handle the ISR work should it’s priority be the highest among the tasks?

I am not sure what do you mean by the ISR work but yes, timer task usually should be of the highest priority if the application requires that the commands sent to the timer service task and expired timers get processed immediately. You can read more about FreeRTOS software timer here: [FreeRTOS - RTOS software timer functionality and features description](https://www.freertos.org/RTOS-software-timer.html)

Thanks.

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [February 3, 2021, 8:46pm UTC](https://forums.freertos.org/t/daemon-task-and-priority/11688/3 "2021-02-03T20:46:47Z")

</div>

As Gaurav says, configMAX\_PRIORITIES is the maximum number of discrete priorities, which are numbered 0 to configMAX\_PRIORITIES-1. This is a very common 0 based indexing phenomenon.

configTIMER\_TASK\_PRIORITY is typically set to configMAX\_PRIORITIES-1, because as you say it might be used for pending a function from an ISR (but it also might not be). It is not forced to be that because some systems might have tasks that are more urgent than the timers and pended functions. I would find the value of 3 out of 16 to be rather unusual, and you would need to ask (if possible) the designer that setup that program that way.

---

<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:** [February 3, 2021, 7:05pm UTC](https://forums.freertos.org/t/daemon-task-and-priority/11688/4 "2021-02-03T19:05:27Z")

</div>

configMAX\_PRIORITIES sets the total number of priorities in the system, and as the lowest priority is 0 rather than 1, the highest priority is (configMAX\_PRIORITIES – 1).

Any constant that starts “config” is for you to set, so you can set configTIMER\_TASK\_PRIORITY to the value needed by your application, and it is very common to set this to the highest possible priority. There are some applications that don’t want it to be that high though. Some of the FreeRTOS tests are probably a good example, where some of the internal timing checks can fail if the measured time gets extended because it got interrupted by the execution of a software timer at a higher priority.
