Interrupt Manager
When the CPU is executing a task, an external event may occur that demands immediate attention. The CPU temporarily halts its current work, switches to address the event, and after processing it, returns to where it left off to resume its original task. This process is known as an interrupt.
Interrupts can halt the execution of a task, regardless of its priority. Therefore, interrupts are generally used to handle more urgent events.
Interrupt Switch
Interrupt Switch is used to prevent interrupts within a specific code section.
__enable_irq
: Enable interrupts.
__disable_irq
: Disable interrupts.
To use the above two functions, users need to include the header file core_cmFunc.h
.
Interrupt Vector Table
The Interrupt Vector Table is a data structure used to manage the addresses of interrupts.
RamVectorTableUpdate()
is used to modify this table.
The VECTORn_Type
in RamVectorTableUpdate()
could be found in vector_table.h
.
A brief demo:
void uart0_tx_handler(void)
{
uint16_t int_status = 0;
uint32_t line_status = 0;
int_status = UART_GetIID(UART0);
switch (int_status)
{
case UART_INT_ID_LINE_STATUS:
UART_INTConfig(UART0, UART_INT_LINE_STS, DISABLE);
line_status = UART0->LSR;
IO_PRINT_ERROR1("UART_INT_ID_LINE_STATUS:0x%x", line_status);
UART_INTConfig(UART0, UART_INT_LINE_STS, ENABLE);
break;
default:
break;
}
}
void uart_tx_test(UART_TypeDef *UARTx, TEST_UART_PARAMETER *uart_para)
{
RamVectorTableUpdate(UART0_VECTORn, uart0_tx_handler);
...
}
The IRQ_Fun
is recommended to be placed in RAM, which will result in faster response times.
Note
If
IRQ_Fun
is placed in RAM, it should not call functions on Flash, which may cause a hardfault.If
IRQ_Fun
needs to call Flash functions, it should be placed on Flash to ensure access to Fsslash correctly.
Interrupt Controller
The interrupt controller is one of the peripherals of the CPU. On one hand, it receives interrupt signals from other peripherals. On the other hand, it sends interrupt signals to the CPU. By programming the interrupt controller, users can configure the priority of interrupt sources, the trigger mode, and enable or disable sources, among other settings. In the Cortex-M series of controllers, a commonly used interrupt controller is the NVIC.
Users can use NVIC_Init
to configure the parameters for interrupts. See rtk876x_nvic.h
.
Demo:
NVIC_InitTypeDef nvic_init_struct;
nvic_init_struct.NVIC_IRQChannel = UART0_IRQn;
nvic_init_struct.NVIC_IRQChannelCmd = (FunctionalState)ENABLE;
nvic_init_struct.NVIC_IRQChannelPriority = 3;
NVIC_Init(&nvic_init_struct);
Note
NVIC_IRQChannelPriority
specifies the priority for the IRQ channel. The highest priority that can be set is 0.
If a higher-priority interrupt is detected, the processor will interrupt the current interrupt service (or normal program).