heart33k 2017-01-12 07:21 采纳率: 0%
浏览 1353

CM4 NVIC优先级的问题

图片说明
图片说明
CM4的资料就给这么点说明,也百度过好多贴子,不明白该怎么操作,才能设置不同的优先级,还有就是怎么分主优先级和子优先级。
我理解是往NVIC->IP里写一个值(值是范围是0~7),值越大,该优先级就越小,不知道对不对

我所参考的源代码是MQX4.1的代码,文件名为nvic.c

 /*!
 * \brief   Initialize a specific interrupt in the cortex core nvic
 * 
 * \param[in] irq Interrupt number
 * \param[in] prior Interrupt priority 
 * \param[in] enable enable the interrupt now?
 *
 * \return uint32_t MQX_OK or error code
 */
_mqx_uint _nvic_int_init
   (
      // [IN] Interrupt number
      _mqx_uint irq,

      // [IN] Interrupt priority
      _mqx_uint prior,

      // [IN] enable the interrupt now?
      bool enable
   )
{
    VCORTEX_NVIC_STRUCT_PTR nvic = (VCORTEX_NVIC_STRUCT_PTR)&(((CORTEX_SCS_STRUCT_PTR)CORTEX_PRI_PERIPH_IN_BASE)->NVIC);
    _mqx_uint ext_irq_no = irq - 16;

    // check priority value, must be below maximal enabled/set value
    if (prior >= (1 << CORTEX_PRIOR_IMPL)) {
        return MQX_INVALID_PARAMETER;
    }

    if (irq >= PSP_INT_FIRST_INTERNAL && irq <= PSP_INT_LAST_INTERNAL) {
        nvic->PRIORITY[ext_irq_no >> 2] = (nvic->PRIORITY[ext_irq_no >> 2] & ~(0xff << ((ext_irq_no & 3) * 8))) | (((prior << CORTEX_PRIOR_SHIFT) & CORTEX_PRIOR_MASK) << ((ext_irq_no & 3) * 8));

        if (enable)
            _nvic_int_enable(irq);
        else
            _nvic_int_disable(irq);

    }
    else
        return MQX_INVALID_PARAMETER;

    return MQX_OK;
}

/*!
 * \brief Enable interrupt on cortex core NVIC
 * 
 * \param[in] irq Interrupt number 
 *
 * \return uint32_t MQX_OK or error code
 */
_mqx_uint _nvic_int_enable
   (
      // [IN] Interrupt number
      _mqx_uint  irq
   )
{
    VCORTEX_NVIC_STRUCT_PTR nvic = (VCORTEX_NVIC_STRUCT_PTR)&(((CORTEX_SCS_STRUCT_PTR)CORTEX_PRI_PERIPH_IN_BASE)->NVIC);
    uint32_t ext_irq_no = irq - 16;

    if (ext_irq_no >= PSP_INT_FIRST_INTERNAL && ext_irq_no <= PSP_INT_LAST_INTERNAL) {
        nvic->ENABLE[ext_irq_no >> 5] = 1 << (ext_irq_no & 0x1f);
    }
    else
        return MQX_INVALID_PARAMETER;

    return MQX_OK;
}

/*!
 * \brief Disable interrupt on cortex core NVIC
 * 
 * \param[in] irq Interrupt number
 *
 * \return uint32_t MQX_OK or error code
 */
_mqx_uint _nvic_int_disable
   (
      // [IN] Interrupt number
      _mqx_uint  irq
   )
{
    VCORTEX_NVIC_STRUCT_PTR nvic = (VCORTEX_NVIC_STRUCT_PTR)&(((CORTEX_SCS_STRUCT_PTR)CORTEX_PRI_PERIPH_IN_BASE)->NVIC);
    uint32_t ext_irq_no = irq - 16;

    if (ext_irq_no >= PSP_INT_FIRST_INTERNAL && ext_irq_no <= PSP_INT_LAST_INTERNAL) {
        nvic->DISABLE[ext_irq_no >> 5] = 1 << (ext_irq_no & 0x1f);
    }
    else
        return MQX_INVALID_PARAMETER;

    return MQX_OK;
}




  • 写回答

1条回答 默认 最新

  • dabocaiqq 2017-01-14 14:42
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题