cancel
Showing results for 
Search instead for 
Did you mean: 

method for calculating interrupt priority level, PRI_n

jeff239955_stm1
Associate II
Posted on July 15, 2008 at 07:03

method for calculating interrupt priority level, PRI_n

3 REPLIES 3
jeff239955_stm1
Associate II
Posted on May 17, 2011 at 12:39

I was wondering if anyone could explain how to find the priority number, PRI_n of an interrupt given pre-emption priority, subpriority, and PRIGROUP (3-7 for STM32).

I understand the PRI_n is the priority for the interrupt and its range is 0 to 255. I took some examples from the STM32 library but I do not understand them.

Putting some example numbers into NVIC_Init of the STM32 library returns the following PRI_n numbers.

Code:

<BR>PRIGROUP = 3: four bits of pre-emption priority, four bits of subpriority. <BR>Pre-emption,Subpriority = PRI_n My predicted value of PRI_N <BR>0,1 = 0 1 (0*16+1 = 1) <BR>0,2 = 0 2 (0*16+2 = 2) <BR>0,5 = 0 5 (0*16+5 = 5) <BR>1,0 = 16 16 (1*16+0 = 16) <BR>1,1 = 17 16 (1*16+1 = 17) <BR>1,5 = 21 16 (1*16+5 = 21) <BR>2,0 = 32 16 (2*16+0 = 32) <BR>2,1 = 32 16 (2*16+1 = 33) <BR>

Code:

<BR>PRIGROUP = 4: three bits of pre-emption priority, five bits of subpriority. <BR>Pre-emption,Subpriority = PRI_n My predicted value of PRI_N <BR>0,0 = 0 0 (0*8+0 = 0) <BR>0,1 = 16 1 (0*8+1 = 1) <BR>0,2 = 0 2 (0*8+2 = 2) <BR>0,5 = 0 5 (0*8+5 = 5) <BR>1,0 = 32 8 (1*8+0 = 😎 <BR>1,1 = 48 9 (1*8+1 = 9) <BR>1,5 = 48 13 (1*8+5 = 13) <BR>2,0 = 64 16 (2*8+0 = 16) <BR>2,1 = 80 17 (2*8+1 = 17) <BR>

I predicted PRI_N would be equal to (Pre-emption)*(pre-emption_bits) + (subpriority) as I showed above but I must be wrong. Can anyone explain how to get the value of PRI_n?

[ This message was edited by: jeff.heiss on 13-07-2008 23:30 ]

lanchon
Associate II
Posted on May 17, 2011 at 12:39

> the PRI_n is the priority for the interrupt and its range is 0 to 255

the number of bits expressing priority is configurable in the cortex core. in the STM32, it's set to 4 bits. look for a recent previous thread.

tibo
Associate II
Posted on May 17, 2011 at 12:39

Priority and subpriority are using the MSB and therefore should be in steps of 16 (eg. 0x10, 0x20, 0x30, etc.) because of the fixed number of priority levels (= 16) in the priority level register.

The value is: ((priority < (group + 1)) + (subpriority < 4))

In your example 1: number of subpriority bits are 0, so there are no subpriorities. The correct result should be 0,0,0,16,16,16,32,32. In your example 2: number of subpriority bits are 1, subpriority 2 or 5 are not supported.

You can find more detailed info in ''The Definitive Guide to them ARM Cortex-M3'', from Joseph Yiu, page 117ff.