cancel
Showing results for 
Search instead for 
Did you mean: 

NVIC priority group, preemption and sub priority.

durgesh777
Associate II
Posted on December 18, 2011 at 17:11

What is the meaning of Preemppriority and subpriority?

If the number allocated to them is higher, does it mean that they are prioritized for the service than the

others which are allocated less number or it is the opposite?

Do i need to categorize Priority Groups if i have several interrupt service routine?

I have the following priorities in my program:

TIM2 (HIGH Priority)

DMA (HIGH Priority)

EXTI7 (HIGH Priority)

TIM1 (HIGH Priority)

EXTI0 (LOW Priority)

TIM4 (Low Priority)

Among the HIGH PRIORITY TIM2 and DMA should not be made to wait at all.

In my program i wrote:

NVIC_PriorityGroupConfig(NVIC_PriorityGroupConfig[NVIC_PriorityGroup_2];

  NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;

 

  NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

  NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;

 

  NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;

 

  NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;

 

  NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;

 

Lines irrelevant to the discussion are avoided. Should i edit the NVIC_PriorityGroup??

I request some-one to help me on this.

Thanks in advance.

#nvic-priority-group
5 REPLIES 5
Posted on December 18, 2011 at 19:17

I'm sure this gets good coverage in ARM's manuals, and Joseph Yiu's Cortex M3 book.

If you want and interrupt to interrupt another interrupt you need a lower PreEmption level.

Interrupts within the *same* PreEmption level will be serviced based on the lowest SubPriority,  but will be delayed until those ahead complete.

The goal is NOT to have PreEmption = SubPriority, but to understand what interrupts are occurring, and which you have the preference to service first, to the extent you can control that.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
infoinfo989
Associate III
Posted on December 18, 2011 at 20:57

In addition to what Clive references, I also found the comment block in misc.c to be helpful.

ionutF
Associate III
Posted on February 09, 2016 at 13:01

So if I set the group to 0 , I will have 4 bits meaning 16 priorities levels to asign for my interrupts

for group 1 : I will have 1 bit for preemption(P) 3 for subpriority(s)

P:0 s: 0,1,2,3,4,5,6,7

P:1 s: 0,1,2,3,4,5,6,7

for group 2 I will have 2 bits for preemption (P) and 2 bits for subpriority (s) :  

P: 0 s: 0, 1 ,2, 3

P 1 s: 0, 1 ,2, 3

P 2  s: 0, 1 ,2, 3

P 3  s: 0, 1 ,2, 3

An irq with (P,s)=(0,1) will wait to be executed for an irq with  (P,s)= (0,0). Also al other irqs with  (P,s)=(x,y);  x>0, y=0..3 wil wait after irq with (P,s)=(0,1)

Is that correct?

ionutF
Associate III
Posted on February 09, 2016 at 13:05

And another question : when the group is set to zero , do I have to set the Preemption priority for my IRQs ? 

The same question when the group is 4 , do I have to set the subpriority for my IRQs?

Posted on February 09, 2016 at 16:30

I would set unused structure fields to zero.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..