# xTaskNotifyFromISR Causing Interrupt Jitter

**URL:** <https://forums.freertos.org/t/xtasknotifyfromisr-causing-interrupt-jitter/10767>\
**Category:** Kernel\
**Created:** [September 25, 2020, 9:02am UTC](https://forums.freertos.org/t/xtasknotifyfromisr-causing-interrupt-jitter/10767 "2020-09-25T09:02:08Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![RyanK](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@RyanK](https://forums.freertos.org/u/RyanK)\
**Post date:** [September 25, 2020, 9:02am UTC](https://forums.freertos.org/t/xtasknotifyfromisr-causing-interrupt-jitter/10767/1 "2020-09-25T09:02:08Z")

</div>

Hi All,

I’m currently experiencing some undesirable behaviour that I wouldn’t expect when using xTaskNotifyFromISR. Hoping someone might be able to explain why.

I have some hardware based timers on a XMC4800 generating interrupts that I’m using to control the state of some other hardware. These interrupts are time critical and must have low jitter (\<1us). Therefore they have a high priority below the configLIBRARY\_MAX\_SYSCALL\_INTERRUPT\_PRIORITY.

I also have a lot of ADC data to process on the same device. Four ADC’s that are storing their results in their conversion complete interrupts and then I am using xTaskNotifyFromISR as an events group to hand over to a FreeRTOS task to average and convert the results. It’s worth mentioning that these interrupts have a priority lower than the configLIBRARY\_MAX\_SYSCALL\_INTERRUPT\_PRIORITY.

Since using xTaskNotifyFromISR to process the ADC results I have noticed considerable jitter on my high priority interrupts (5 - 10us). Removing the call from ADC result interrupt causes it to go away.

I chose to use xTaskNotifyFromISR as an events group as from what I understand it’s considerably quicker than using an actual event group. And from what I have read and understand of configLIBRARY\_MAX\_SYSCALL\_INTERRUPT\_PRIORITY, the scheduler should not affect the interrupts with a priority greater than it. So why when I use xTaskNotifyFromISR in my ADC interrupts am I seeing my high priority interrupts performance affected.

I would like to avoid having to do all of my ADC processing in the interrupt as this is generally discouraged. Although unless I can get to the bottom of the scheduler causing the jitter I am going to be left with no choice.

Kind Regards,  
Ryan

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [September 25, 2020, 10:36am UTC](https://forums.freertos.org/t/xtasknotifyfromisr-causing-interrupt-jitter/10767/2 "2020-09-25T10:36:58Z")

</div>

Are nested interrupts supported / used ?

---

<div class="post-metadata">

**Author:** ![RyanK](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@RyanK](https://forums.freertos.org/u/RyanK)\
**Post date:** [September 25, 2020, 10:40am UTC](https://forums.freertos.org/t/xtasknotifyfromisr-causing-interrupt-jitter/10767/3 "2020-09-25T10:40:22Z")

</div>

Hi,

Yes nested interrupts are supported. It’s a ARM Cortex M4 based device (Infineon XMC4800).

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [September 25, 2020, 11:06am UTC](https://forums.freertos.org/t/xtasknotifyfromisr-causing-interrupt-jitter/10767/4 "2020-09-25T11:06:39Z")

</div>

Well, if nesting is used and the INT prios are right (which might be confusing for Cortex-M3/4) along with FreeRTOS config like configLIBRARY\_MAX\_SYSCALL\_INTERRUPT\_PRIORITY, there should be no jitter caused by lower prio ISRs …  
Maybe double check the INT related config/ NVIC config to be sure things are setup as you need.

> **[RTOS for ARM Cortex-M](https://www.freertos.org/RTOS-Cortex-M3-M4.html)**
>
> Setting RTOS interrupt priorities on a ARM Cortex-M microcontroller

---

<div class="post-metadata">

**Author:** ![RyanK](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@RyanK](https://forums.freertos.org/u/RyanK)\
**Post date:** [September 25, 2020, 12:27pm UTC](https://forums.freertos.org/t/xtasknotifyfromisr-causing-interrupt-jitter/10767/6 "2020-09-25T12:27:59Z")

</div>

Hi,

Thanks for the response. Just had another read of the document you suggested. I’m prity confident things are configured correctly.

I have the high priority time critical interrupts currently configured between 7 - 11.

The ADC result interrupts are between 50 - 54.

#define configPRIO\_BITS 6 /\* 63 priority levels \*/

#define configLIBRARY\_LOWEST\_INTERRUPT\_PRIORITY 0x3f

#define configLIBRARY\_MAX\_SYSCALL\_INTERRUPT\_PRIORITY 0x0c

#define configKERNEL\_INTERRUPT\_PRIORITY   
( configLIBRARY\_LOWEST\_INTERRUPT\_PRIORITY \<\< (8 - configPRIO\_BITS) )

#define configMAX\_SYSCALL\_INTERRUPT\_PRIORITY   
( configLIBRARY\_MAX\_SYSCALL\_INTERRUPT\_PRIORITY \<\< (8 - configPRIO\_BITS) )

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [September 25, 2020, 1:05pm UTC](https://forums.freertos.org/t/xtasknotifyfromisr-causing-interrupt-jitter/10767/7 "2020-09-25T13:05:09Z")

</div>

Hmm … looks fine.  
Just to be sure: NVIC\_SetPriorityGrouping is set to 0 as as recommended ?  
Otherwise to be honest I’ve no idea what the problem might be ☹  
Some guys had issues with multiple FreeRTOSConfig.h files in their project space including a wrong one, but I assume that’s not the problem in your case.

---

<div class="post-metadata">

**Author:** ![RyanK](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@RyanK](https://forums.freertos.org/u/RyanK)\
**Post date:** [September 25, 2020, 1:57pm UTC](https://forums.freertos.org/t/xtasknotifyfromisr-causing-interrupt-jitter/10767/8 "2020-09-25T13:57:07Z")

</div>

Priority grouping was set to 1. Setting it to 0 hasn’t improved things though. Is that a FreeRTOS recommendation on ensuring it is set to 0? Wasn’t aware of that.  
Yes definitely only the one FreeRTOSConfig.h file included in the project.

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [September 25, 2020, 2:29pm UTC](https://forums.freertos.org/t/xtasknotifyfromisr-causing-interrupt-jitter/10767/9 "2020-09-25T14:29:07Z")

</div>

… found it … it’s probably also documented somewhere.  
in CM3/CM4F port.c - vPortValidateInterruptPriority():

```auto
...
		/* Priority grouping: The interrupt controller (NVIC) allows the bits
		that define each interrupt's priority to be split between bits that
		define the interrupt's pre-emption priority bits and bits that define
		the interrupt's sub-priority. For simplicity all bits must be defined
		to be pre-emption priority bits. The following assertion will fail if
		this is not the case (if some bits represent a sub-priority).

		If the application only uses CMSIS libraries for interrupt
		configuration then the correct setting can be achieved on all Cortex-M
		devices by calling NVIC_SetPriorityGrouping( 0 ); before starting the
		scheduler. Note however that some vendor specific peripheral libraries
		assume a non-zero priority group setting, in which cases using a value
		of zero will result in unpredictable behaviour. */
		configASSERT( ( portAIRCR_REG & portPRIORITY_GROUP_MASK ) <= ulMaxPRIGROUPValue );

```

While we’re at it. You’re using a decent FreeRTOS version with or w/o a 3rd party SDK (like ST HAL) ?

---

<div class="post-metadata">

**Author:** ![RyanK](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@RyanK](https://forums.freertos.org/u/RyanK)\
**Post date:** [September 28, 2020, 6:27am UTC](https://forums.freertos.org/t/xtasknotifyfromisr-causing-interrupt-jitter/10767/10 "2020-09-28T06:27:15Z")

</div>

So setting the priority grouping to 0 just ensures no sub priorities can be used then? All my sub priorities are set to 0.

I using FreeRTOS V10.3.1 with the Infineon DAVE libraries.

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [September 28, 2020, 7:06am UTC](https://forums.freertos.org/t/xtasknotifyfromisr-causing-interrupt-jitter/10767/11 "2020-09-28T07:06:42Z")

</div>

Sorry, I didn’t use sub-priorities yet and had also no need to do so. I just followed the default route 😉  
No idea what’s going on. If the interrupt prio partitioning and FreeRTOS configuration is right, the high prio interrupts outside the FreeRTOS world/range are not affected by FreeRTOS in any way.  
This could be verified the simple way by using portDISABLE\_INTERRUPTS() for testing and checking if the timers are still serviced.  
Are you sure that nowhere in your ADC post processing code global ` __disable_irq/__ enable_irq` are used (disable/enable ALL interrupts) ?

---

<div class="post-metadata">

**Author:** ![RyanK](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@RyanK](https://forums.freertos.org/u/RyanK)\
**Post date:** [September 28, 2020, 10:27am UTC](https://forums.freertos.org/t/xtasknotifyfromisr-causing-interrupt-jitter/10767/12 "2020-09-28T10:27:59Z")

</div>

No worries. I also have never made use of the sub priorities, just thought it was worth mentioning that they weren’t being used in this case.  
I have just run some tests using taskENTER\_CRITICAL(), effectively disabling all of the interrupts lower than the MAX\_SYSCALL\_INTERRUPT\_PRIORITY. I placed it just after where I start the timers. The timers continued to be serviced but ADC interrupts and scheduler stopped as expected. Confirming MAX\_SYSCALL\_INTERRUPT\_PRIORITY is working as I would expect.

At the moment I have commented out all of the post processing code in the task, so the ADC result interrupts are just notifying an empty task at the moment. So defiantly no ` __disable_irq/__ enable_irq` being used in any of my code, unless the task notification itself makes use of them?

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [September 28, 2020, 1:01pm UTC](https://forums.freertos.org/t/xtasknotifyfromisr-causing-interrupt-jitter/10767/13 "2020-09-28T13:01:18Z")

</div>

FreeRTOS code at least for CortexM3/4F/7 doesn’t globally disable interrupts and make use of the MAX\_SYSCALL\_INTERRUPT\_PRIORITY based interrupt (BASEPRI) masking.

---

<div class="post-metadata">

**Author:** ![RyanK](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@RyanK](https://forums.freertos.org/u/RyanK)\
**Post date:** [September 29, 2020, 1:26pm UTC](https://forums.freertos.org/t/xtasknotifyfromisr-causing-interrupt-jitter/10767/14 "2020-09-29T13:26:13Z")

</div>

Turns out the jitter isn’t being caused by FreeRTOS and is actually due to the Segger Systemview source code that was in my project. I haven’t figured out yet why the Systemview integration is causing it, although removing it from the project has sorted the problem.

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [September 29, 2020, 1:31pm UTC](https://forums.freertos.org/t/xtasknotifyfromisr-causing-interrupt-jitter/10767/15 "2020-09-29T13:31:24Z")

</div>

Thanks for reporting Ryan ! Good to know … and being warned 🙂

---

<div class="post-metadata">

**Author:** ![RyanK](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@RyanK](https://forums.freertos.org/u/RyanK)\
**Post date:** [September 29, 2020, 1:52pm UTC](https://forums.freertos.org/t/xtasknotifyfromisr-causing-interrupt-jitter/10767/16 "2020-09-29T13:52:51Z")

</div>

No worries, will update if I ever get to the bottom of why. Thanks for your help.

---

<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:** [September 29, 2020, 2:38pm UTC](https://forums.freertos.org/t/xtasknotifyfromisr-causing-interrupt-jitter/10767/17 "2020-09-29T14:38:20Z")

</div>

If you think how these debuggers work on Cortex parts, a very high priority interrupt switches into firm code embedded in the processor to send the needed information out the debug port, there actions will necessarily cause some timing jitter.
