NVIC 的全称是 Nested Vectored Interrupt Controller
这种中断控制器支持将不同的中断设置不同的优先级,高优先级的中断能够打断当前正在执行的低优先级的ISR。
Nested interrupts are automatically handled by the NVIC. Once the priority levels of each interrupt are programmed, the NVIC handles the interrupt prioritisation and masks out same or lower priority interrupts when an Interrupt Service Routine is running. If a higher priority interrupt takes place, it will pre-empt the running ISR to allow the higher priority ISR to be executed as soon as possible[Comments from Ulaganathan Srinivasan]
在操作系统环境中,都是多任务的。在有一些任务处理中,需要进去critical section。这些任务和中断也有关系。
在FreeRTOS中,对中断的处理是采用如下策略:
configMAX_SYSCALL_INTERRUPT_PRIORITY
configKERNEL_INTERRUPT_PRIORITY
在嵌入式操作系统中,任务和中断处理存在一种耦合。
所以,在autosar的操作系统中,把中断分成了两类。
Category 1: 中断(和操作系统调度相关的除外)不被OS处理。此时isr不能够使用大多数os的服务。
Category 2: 中断的主要任务会交给OS,由OS当成普通的任务去处理。
可见嵌入式的实时操作系统对中断的处理是非常重要的。