Generic functions to access the Interrupt Controller. More...
Content | |
IRQ Mode Bit-Masks | |
Configure interrupt line mode. | |
IRQ Priority Bit-Masks | |
Definitions used by interrupt priority functions. | |
Enumerations | |
enum | IRQn_Type { SGI0_IRQn = 0 , SGI1_IRQn = 1 , SGI2_IRQn = 2 , SGI3_IRQn = 3 , SGI4_IRQn = 4 , SGI5_IRQn = 5 , SGI6_IRQn = 6 , SGI7_IRQn = 7 , SGI8_IRQn = 8 , SGI9_IRQn = 9 , SGI10_IRQn = 10 , SGI11_IRQn = 11 , SGI12_IRQn = 12 , SGI13_IRQn = 13 , SGI14_IRQn = 14 , SGI15_IRQn = 15 , VirtualMaintenanceInterrupt_IRQn = 25 , HypervisorTimer_IRQn = 26 , VirtualTimer_IRQn = 27 , Legacy_nFIQ_IRQn = 28 , SecurePhyTimer_IRQn = 29 , NonSecurePhyTimer_IRQn = 30 , Legacy_nIRQ_IRQn = 31 } |
Definition of IRQn numbers. More... | |
Functions | |
int32_t | IRQ_Initialize (void) |
Initialize interrupt controller. | |
int32_t | IRQ_SetHandler (IRQn_ID_t irqn, IRQHandler_t handler) |
Register interrupt handler. | |
IRQHandler_t | IRQ_GetHandler (IRQn_ID_t irqn) |
Get the registered interrupt handler. | |
int32_t | IRQ_Enable (IRQn_ID_t irqn) |
Enable interrupt. | |
int32_t | IRQ_Disable (IRQn_ID_t irqn) |
Disable interrupt. | |
uint32_t | IRQ_GetEnableState (IRQn_ID_t irqn) |
Get interrupt enable state. | |
int32_t | IRQ_SetMode (IRQn_ID_t irqn, uint32_t mode) |
Configure interrupt request mode. | |
uint32_t | IRQ_GetMode (IRQn_ID_t irqn) |
Get interrupt mode configuration. | |
IRQn_ID_t | IRQ_GetActiveIRQ (void) |
Get ID number of current interrupt request (IRQ). | |
IRQn_ID_t | IRQ_GetActiveFIQ (void) |
Get ID number of current fast interrupt request (FIQ). | |
int32_t | IRQ_EndOfInterrupt (IRQn_ID_t irqn) |
Signal end of interrupt processing. | |
int32_t | IRQ_SetPending (IRQn_ID_t irqn) |
Set interrupt pending flag. | |
uint32_t | IRQ_GetPending (IRQn_ID_t irqn) |
Get interrupt pending flag. | |
int32_t | IRQ_ClearPending (IRQn_ID_t irqn) |
Clear interrupt pending flag. | |
int32_t | IRQ_SetPriority (IRQn_ID_t irqn, uint32_t priority) |
Set interrupt priority value. | |
uint32_t | IRQ_GetPriority (IRQn_ID_t irqn) |
Get interrupt priority. | |
int32_t | IRQ_SetPriorityMask (uint32_t priority) |
Set priority masking threshold. | |
uint32_t | IRQ_GetPriorityMask (void) |
Get priority masking threshold. | |
int32_t | IRQ_SetPriorityGroupBits (uint32_t bits) |
Set priority grouping field split point. | |
uint32_t | IRQ_GetPriorityGroupBits (void) |
Get priority grouping field split point. | |
Generic functions to access the Interrupt Controller.
This section describes the device agnostic interrupt API viable for a wide range of specific interrupt controllers. The IRQ Controller API allows interrupt dependend applications to be easily portable across a wide range of controllers.
weak
functions thus it can easily be overwritten by an alternative user implementation if needed.The Armv7-A architecture defines a common set of first level exceptions, see table below.
Exception | CMSIS Handler | Offset | Description |
---|---|---|---|
Reset | Reset_Handler | 0x0000 | First instruction executed after reset. |
Undefined Instruction (Undef) | Undef_Handler | 0x0004 | Signals usage of an illegal instructions. |
Supervisor Call (SVC) | SVC_Handler | 0x0008 | Issued by software using SVC instruction. |
Prefetch Abort (PAbt) | PAbt_Handler | 0x000C | Signals a memory abort on istruction fetch. |
Data Abort (DAbt) | DAbt_Handler | 0x0010 | Signals a memory abort on data read or write. |
Hyp Trap | (NOP) | 0x0014 | Hypervisor instruction trap, only available with Virtualization Extensions. |
IRQ interrupt | IRQ_Handler | 0x0018 | Interrupt Request (typically from Interrupt Controller) |
FIQ interrupt | FIQ_Handler | 0x001C | Fast Interrupt Request (typically from Interrupt Controller) |
By default those handlers are defined as weak empty functions by the device specific startup code. Software and peripheral interrupts are all handled by one of the both central interrupt handlers (IRQ and FIQ). These needs to be implemented application specific. If an RTOS is used the interrupt handlers are typically provided by the RTOS, e.g. when using CMSIS-RTX.
The interrupts available depends on the actual device in use. According to CMSIS specification the interrupts are defined in IRQn_Type in Device Header File <Device.h>. Using the generic IRQ API one can easily enable and disable interrupts, set up priorities, modes and preemption rules, and register interrupt callbacks.
Example:
enum IRQn_Type |
Definition of IRQn numbers.
The core exception enumeration names for IRQn values are defined in the Device Header File <Device.h>.
The table below describes the core exception names in Cortex-A core.
int32_t IRQ_ClearPending | ( | IRQn_ID_t | irqn | ) |
Clear interrupt pending flag.
[in] | irqn | interrupt ID number |
This function clears the pending status of the interrupt identified by the irqn parameter.
For Arm GIC the default implementation looks like the following example:
int32_t IRQ_Disable | ( | IRQn_ID_t | irqn | ) |
Disable interrupt.
[in] | irqn | interrupt ID number |
This function disables forwarding of the corresponding interrupt to the CPU.
For Arm GIC the default implementation looks like the following example:
int32_t IRQ_Enable | ( | IRQn_ID_t | irqn | ) |
Enable interrupt.
[in] | irqn | interrupt ID number |
This function enables forwarding of the corresponding interrupt to the CPU.
For Arm GIC the default implementation looks like the following example:
int32_t IRQ_EndOfInterrupt | ( | IRQn_ID_t | irqn | ) |
Signal end of interrupt processing.
[in] | irqn | interrupt ID number |
This function informs the interrupt controller that the interrupt service routine processing of the currently active interrupt request is completed.
The parameter irqn should specify the value previously returned by the IRQ_GetActiveIRQ or IRQ_GetActiveFIQ functions.
For Arm GIC the default implementation looks like the following example:
IRQn_ID_t IRQ_GetActiveFIQ | ( | void | ) |
Get ID number of current fast interrupt request (FIQ).
This function retrieves the interrupt ID number of current FIQ source and acknowledges the interrupt.
For Arm GIC the default implementation looks like the following example:
IRQn_ID_t IRQ_GetActiveIRQ | ( | void | ) |
Get ID number of current interrupt request (IRQ).
This function retrieves the interrupt ID number of current IRQ source and acknowledges the interrupt.
For Arm GIC the default implementation looks like the following example:
uint32_t IRQ_GetEnableState | ( | IRQn_ID_t | irqn | ) |
Get interrupt enable state.
[in] | irqn | interrupt ID number |
This function retrieves the interrupt enable status of the interrupt identified by the irqn parameter.
Interrupt enable status can be either disabled (0) or enabled (1). Disabled status is returned for interrupts which cannot be identified by irqn.
For Arm GIC the default implementation looks like the following example:
IRQHandler_t IRQ_GetHandler | ( | IRQn_ID_t | irqn | ) |
Get the registered interrupt handler.
[in] | irqn | interrupt ID number |
This function retrieves address of the interrupt handler callback function corresponding to the specified interrupt ID number.
For Arm GIC the default implementation looks like the following example:
uint32_t IRQ_GetMode | ( | IRQn_ID_t | irqn | ) |
Get interrupt mode configuration.
[in] | irqn | interrupt ID number |
This function retrieves interrupt mode configuration of the interrupt identified by the irqn parameter. IRQ_MODE_ERROR is returned for interrupts which cannot be identified by irqn.
For Arm GIC the default implementation looks like the following example:
uint32_t IRQ_GetPending | ( | IRQn_ID_t | irqn | ) |
Get interrupt pending flag.
[in] | irqn | interrupt ID number |
This function retrieves the pending status of the interrupt identified by the irqn parameter.
Interrupt pending status can be either not pending (0) or pending (1). Not pending status is returned for interrupts which cannot be identified by irqn.
For Arm GIC the default implementation looks like the following example:
uint32_t IRQ_GetPriority | ( | IRQn_ID_t | irqn | ) |
Get interrupt priority.
[in] | irqn | interrupt ID number |
This function retrieves the priority of the interrupt identified by the irqn parameter.
The valid priority value can be from zero (0) to the value of IRQ_PRIORITY_Msk. IRQ_PRIORITY_ERROR bit is set in returned value for interrupts which cannot be identified by irqn.
For Arm GIC the default implementation looks like the following example:
uint32_t IRQ_GetPriorityGroupBits | ( | void | ) |
Get priority grouping field split point.
This function retrieves the number of MSB bits used to determine whether a pending interrupt has sufficient priority to preempt a currently active interrupt.
IRQ_PRIORITY_ERROR value is returned when priority grouping is not supported.
For Arm GIC the default implementation looks like the following example:
uint32_t IRQ_GetPriorityMask | ( | void | ) |
Get priority masking threshold.
This function retrieves the priority masking threshold for the current processor.
IRQ_PRIORITY_ERROR value is returned if priority masking is not supported.
For Arm GIC the default implementation looks like the following example:
int32_t IRQ_Initialize | ( | void | ) |
Initialize interrupt controller.
This function initializes interrupt controller.
It disables all interrupt sources, clears all pending interrupts, sets interrupt priorities to highest priority and configures priority mask to lowest priority. IRQ and FIQ signal lines should be enabled and all interrupt handlers should be set to NULL.
For Arm GIC the default implementation looks like the following example:
int32_t IRQ_SetHandler | ( | IRQn_ID_t | irqn, |
IRQHandler_t | handler | ||
) |
Register interrupt handler.
[in] | irqn | interrupt ID number |
[in] | handler | interrupt handler function address |
This function registers address of the interrupt handler callback function corresponding to the specified interrupt ID number.
For Arm GIC the default implementation looks like the following example:
int32_t IRQ_SetMode | ( | IRQn_ID_t | irqn, |
uint32_t | mode | ||
) |
Configure interrupt request mode.
[in] | irqn | interrupt ID number |
[in] | mode | mode configuration |
This function configures the interrupt triggering mode, type, secure access and target CPUs of the interrupt (see IRQ Mode Bit-Masks) identified by the irqn parameter.
For Arm GIC the default implementation looks like the following example:
int32_t IRQ_SetPending | ( | IRQn_ID_t | irqn | ) |
Set interrupt pending flag.
[in] | irqn | interrupt ID number |
This function sets the pending status of the interrupt identified by the irqn parameter.
For Arm GIC the default implementation looks like the following example:
int32_t IRQ_SetPriority | ( | IRQn_ID_t | irqn, |
uint32_t | priority | ||
) |
Set interrupt priority value.
[in] | irqn | interrupt ID number |
[in] | priority | interrupt priority value |
This function sets the priority of the interrupt identified by the irqn parameter.
Higher priority numbers have lower priority. The highest interrupt priority has priority value 0, while the lowest value depends on the number of implemented priority levels.
The number of implemented priority bits can be determined by setting value IRQ_PRIORITY_Msk to arbitrary irqn and by retrieving the actual stored value with IRQ_GetPriority function.
For Arm GIC the default implementation looks like the following example:
int32_t IRQ_SetPriorityGroupBits | ( | uint32_t | bits | ) |
Set priority grouping field split point.
[in] | bits | number of MSB bits included in the group priority field comparison |
This function sets the number of MSB priority bits used to determine whether a pending interrupt has sufficient priority to preempt a currently active interrupt.
The number of implemented group priority bits can be determined by setting value IRQ_PRIORITY_Msk and by retrieving the actual stored value with IRQ_GetPriorityGroupBits function. Function returns error status -1 if priority grouping is not supported.
For Arm GIC the default implementation looks like the following example:
int32_t IRQ_SetPriorityMask | ( | uint32_t | priority | ) |
Set priority masking threshold.
[in] | priority | priority masking threshold value |
This function sets the priority masking threshold for the current processor.
It ensures that only interrupts with a higher priority than priority threshold value are signaled to the target processor. Function returns error status -1 if priority masking is not supported.
For Arm GIC the default implementation looks like the following example: