/**
* <b>NVIC中断控制器。</b>
* <p>功能:中断优先级、使能。
* @param NVIC_PriorityGroup 中断分组
* @param NVIC_IRQn 中断处理程序
* @param NVIC_Priority 中断优先级
* [url=home.php?mod=space&uid=895143]@version[/url] 1.0.2014.0228
* <p>移植!
* [url=home.php?mod=space&uid=187600]@author[/url] Dylan
* [url=home.php?mod=space&uid=8537]@see[/url] Javadoc注释/Eclipse编辑
*/
void NVIC_GroupSet(uint32_t NVIC_PriorityGroup, int16_t NVIC_IRQn, uint16_t NVIC_Priority)
{
#if defined (STM32F100) || defined (STM32F101) || defined (STM32F103) || defined (STM32F10X_HD)
assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));//检测分组有效性
SCB->AIRCR = (uint32_t)0x05FA0000 | NVIC_PriorityGroup;//先键入钥匙(uint32_t)0x05FA0000,然后设置分组
NVIC->ISER[((NVIC_IRQn)>>5)] = (1<<((NVIC_IRQn)&0x1F));//使能中断
//每组只能存4个,得到组地址(NVIC_IRQn>>2)
//在组内的偏移(NVIC_IRQn&0x3),得到偏移的确切位置*8+4
if(NVIC_IRQn < 0) /* set Priority for Cortex-M3 System Interrupts */
{
SCB->SHP[((NVIC_IRQn)&0xF)-4] = ((NVIC_Priority<<4)&0xFF);
}
else//配置外设中断优先级,优先级高->低(0-0xFF)
{
NVIC->IP[(NVIC_IRQn)] = ((NVIC_Priority<<4)&0xFF);//设置响应优先级和抢断优先级,格式为0x?0(?=0~F)
}
#else
#warning "Make sure needn't define STM32F10X etc. ?"
#endif
}
|