We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi there,
I am having some doubt with NVIC_EncodePriority() function.
In my case implemented priority bits are __NVIC_PRIO_BITS = 4.
If I need to implement 3 bits for preempt priority and 1 bit for sub priority, How this NVIC_EncodePriority() going to help me with this?
The below code returning 6, then 0b0110 means what is it helpful for me in any case how to use this function?
#include <stdio.h>#include <stdint.h>#define __NVIC_PRIO_BITS (4)
uint32_t NVIC_EncodePriority (uint32_t , uint32_t , uint32_t);int main() { // Write C code here printf("%d",NVIC_EncodePriority(1,6,2));
return 0;}
uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority){ uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ uint32_t PreemptPriorityBits; uint32_t SubPriorityBits;
PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp); SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS));
return ( ((PreemptPriority & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL)) << SubPriorityBits) | ((SubPriority & (uint32_t)((1UL << (SubPriorityBits )) - 1UL))) );}