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
    关注
    评论

报告相同问题?

悬赏问题

  • ¥20 matlab计算中误差
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊