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;
}