打印

NVIC_SetPriorityGrouping 与NVIC_PriorityGroupConfig函数的区别

[复制链接]
12856|7
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
lanseshuijing|  楼主 | 2013-9-10 17:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 lanseshuijing 于 2013-9-10 18:04 编辑

所用单片机 arm m4
其中一个函数NVIC_SetPriorityGrouping 中断优先级分组分为8组 此函数在core_cm4.h文件中代码如下
Set Priority Grouping

  This function sets the priority grouping field using the required unlock sequence.
  The parameter PriorityGroup is assigned to the field SCB->AIRCR [10:8] PRIGROUP field.
  Only values from 0..7 are used.
  In case of a conflict between priority grouping and available
  priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set.

    \param [in]      PriorityGroup  Priority grouping field
*/

static __INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
{
  uint32_t reg_value;
  uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07);               /* only values 0..7 are used          */

  reg_value  =  SCB->AIRCR;                                                   /* read old register configuration    */
  reg_value &= ~(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk);             /* clear bits to change               */
  reg_value  =  (reg_value                                 |
                ((uint32_t)0x5FA << SCB_AIRCR_VECTKEY_Pos) |
                (PriorityGroupTmp << 8));                                     /* Insert write key and priorty group */
  SCB->AIRCR =  reg_value;
}
另外一个函数NVIC_PriorityGroupConfig分组分成5组 在 misc.c文件中
代码如下
@brief  Configures the priority grouping: pre-emption priority and subpriority.
  * @param  NVIC_PriorityGroup: specifies the priority grouping bits length.
  *   This parameter can be one of the following values:
  *     @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority
  *                                4 bits for subpriority
  *     @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority
  *                                3 bits for subpriority
  *     @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority
  *                                2 bits for subpriority
  *     @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority
  *                                1 bits for subpriority
  *     @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority
  *                                0 bits for subpriority
  * @NOTE   When the NVIC_PriorityGroup_0 is selected, IRQ pre-emption is no more possible.
  *         The pending IRQ priority will be managed only by the subpriority.
  * @retval None
  */

void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
{
  /* Check the parameters */
  assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));
  
/* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */
  SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;
}
为什么有这么两组分组方式?同样都是对SCB->AIRCR 操作啊?谁能帮忙解释一下
沙发
hkcj| | 2013-9-10 18:36 | 只看该作者
不是很了解  帮你顶一个  呼唤一下香主吧

使用特权

评论回复
板凳
wnwnwn| | 2013-12-4 10:34 | 只看该作者
In case of a conflict between priority grouping and available priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set.

我觉得这句话说明了两个函数的区别,NVIC_SetPriorityGrouping()的参数可以是0..7,但是函数会根据芯片本身的“可用优先级位”来进行设置,例如只支持0..4个分组,如果设置为5.6.7的话,就会设置成0组。不知道我的理解对不对。。

使用特权

评论回复
地板
feilusia| | 2013-12-4 11:07 | 只看该作者
那是因为 M3内核允许8bit做优先级分组设置,而STM32只有4bit可以设置。

使用特权

评论回复
5
wnwnwn| | 2013-12-4 12:22 | 只看该作者
feilusia 发表于 2013-12-4 11:07
那是因为 M3内核允许8bit做优先级分组设置,而STM32只有4bit可以设置。

受教了!:handshake

使用特权

评论回复
6
zook0k| | 2014-10-24 10:41 | 只看该作者
学习

使用特权

评论回复
7
喆3喆| | 2015-10-16 20:37 | 只看该作者

使用特权

评论回复
8
xuanhuanzi| | 2020-4-19 23:20 | 只看该作者
对这个不懂。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

93

主题

749

帖子

4

粉丝