首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

Cortex-M3 异常和中断---基于NXP LPC177x/8x(4)

Cortex-M3 异常和中断---基于NXP LPC177x/8x(4)

2.1 设置异常/中断的优先级2.1.1 系统异常优先级设置        SHPR1-SHPR3寄存器用于设置有可编程优先级的系统异常,可设置的优先级为0到31。SHPR1-SHPR3可按字节访问。为了提高软件效率,CMSIS简化了SCB寄存器的表述。在CMSIS中,字节数组SHP[0] 到SHP[12]对应于寄存器SHPR1至SHPR3。
表2-3:SHPR1寄存器的位分配

名称

功能
[31:24]
PRI_7

保留

[23:16]
PRI_6

系统处理程序6的优先级,用法Fault

[15:8]
PRI_5

系统处理程序5的优先级,总线Fault

[7:0]
PRI_4

系统处理程序4的优先级,存储器管理Fault

表2-3:SHPR2寄存器的位分配

名称

功能

[31:24]

PRI_11

系统处理程序11的优先级,SVCall

[23:0]

-

保留

表2-4:SHPR3寄存器的位分配

名称

功能

[31:24]

PRI_15

系统处理程序15的优先级,SysTick 异常

[23:16]

PRI_14

系统处理程序14的优先级,PendSV

[15:0]

-

保留

注:每个PRI_N域为8位宽,但是处理器仅实现每个域的位[7:3],位[2:0]读取值为零并忽略写入值
2.1.2 外设中断优先级设置         LPC177x/8x微处理器的中断优先寄存器IPR0~IPR10用于设置外设中断优先级,控制41个外设中断。每个IPRx可以按字节访问,在CMSIS中,字节数组IP[0] 到IP[40]对应于寄存器IPR0~IPR10。
2.1.3 系统异常/外设中断优先级设置C代码   1: /**   2: * @brief  Set the priority for an interrupt   3: *             4: * @param  IRQn      The number of the interrupt for set priority   5: * @param  priority  The priority to set    6: *   7: * Set the priority for the specified interrupt. The interrupt   8: * number can be positive to specify an external (device specific)   9: * interrupt, or negative to specify an internal (core) interrupt.  10: *  11: * Note: The priority cannot be set for every core interrupt. */  12: static __INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)  13: {  14:   if(IRQn < 0) {   /* set Priority for Cortex-M3 System Interrupts */  15:     SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff);  16:   }   17:   else {   /* set Priority for device specific Interrupts  */  18:     NVIC->IP[(uint32_t)(IRQn)] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff);      19:   }          20: }
继承事业,薪火相传
返回列表