SAM4SD32 (SAM4S-EK2)
Loading...
Searching...
No Matches
Global interrupt management

This is a driver for global enabling and disabling of interrupts. More...

Topics

 Deprecated interrupt definitions
 

Macros

#define CONFIG_INTERRUPT_FORCE_INTC
 Force usage of the ASF INTC driver.

Functions

void cpu_irq_enter_critical (void)
void cpu_irq_leave_critical (void)

Variables

static volatile uint32_t cpu_irq_critical_section_counter
static volatile bool cpu_irq_prev_interrupt_state

Global interrupt flags

typedef uint32_t irqflags_t
 Type used for holding state of interrupt flag.
static irqflags_t cpu_irq_save (void)
 Get and clear the global interrupt flags.
static bool cpu_irq_is_enabled_flags (irqflags_t flags)
 Check if interrupts are globally enabled in supplied flags.
static void cpu_irq_restore (irqflags_t flags)
 Restore global interrupt flags.
#define cpu_irq_enable()
 Enable interrupts globally.
#define cpu_irq_disable()
 Disable interrupts globally.
#define cpu_irq_is_enabled()
 Check if interrupts are globally enabled.

Interrupt Service Routine definition

#define ISR(func)
 Define service routine.
#define irq_initialize_vectors()
 Initialize interrupt vectors.
#define irq_register_handler(int_num, int_prio)
 Register handler for interrupt.

Detailed Description

This is a driver for global enabling and disabling of interrupts.

Macro Definition Documentation

◆ CONFIG_INTERRUPT_FORCE_INTC

#define CONFIG_INTERRUPT_FORCE_INTC

Force usage of the ASF INTC driver.

Predefine this symbol when preprocessing to force the use of the ASF INTC driver. This is useful to ensure compatibility across compilers and shall be used only when required by the application needs.

Definition at line 68 of file interrupt.h.

◆ cpu_irq_disable

#define cpu_irq_disable ( )
Value:
do { \
__disable_irq(); \
__DMB(); \
g_interrupt_enabled = false; \
} while (0)

Disable interrupts globally.

Definition at line 123 of file interrupt_sam_nvic.h.

123# define cpu_irq_disable() \
124 do { \
125 __disable_irq(); \
126 __DMB(); \
127 g_interrupt_enabled = false; \
128 } while (0)

Referenced by cpu_irq_enter_critical(), and cpu_irq_save().

◆ cpu_irq_enable

#define cpu_irq_enable ( )
Value:
do { \
g_interrupt_enabled = true; \
__DMB(); \
__enable_irq(); \
} while (0)

Enable interrupts globally.

Definition at line 117 of file interrupt_sam_nvic.h.

117# define cpu_irq_enable() \
118 do { \
119 g_interrupt_enabled = true; \
120 __DMB(); \
121 __enable_irq(); \
122 } while (0)

Referenced by cpu_irq_leave_critical(), and cpu_irq_restore().

◆ cpu_irq_is_enabled

#define cpu_irq_is_enabled ( )
Value:
(__get_PRIMASK() == 0)

Check if interrupts are globally enabled.

Returns
True if interrupts are enabled.

Definition at line 136 of file interrupt_sam_nvic.h.

Referenced by cpu_irq_enter_critical(), and cpu_irq_save().

◆ irq_initialize_vectors

#define irq_initialize_vectors ( )
Value:
do { \
} while(0)

Initialize interrupt vectors.

For NVIC the interrupt vectors are put in vector table. So nothing to do to initialize them, except defined the vector function with right name.

This must be called prior to irq_register_handler.

Definition at line 89 of file interrupt_sam_nvic.h.

89# define irq_initialize_vectors() \
90 do { \
91 } while(0)

◆ irq_register_handler

#define irq_register_handler ( int_num,
int_prio )
Value:
NVIC_ClearPendingIRQ( (IRQn_Type)int_num); \
NVIC_SetPriority( (IRQn_Type)int_num, int_prio); \
NVIC_EnableIRQ( (IRQn_Type)int_num); \
enum IRQn IRQn_Type
< Interrupt Number Definition

Register handler for interrupt.

For NVIC the interrupt vectors are put in vector table. So nothing to do to register them, except defined the vector function with right name.

Usage:

irq_register_handler(foo_irq_handler);
#define irq_initialize_vectors()
Initialize interrupt vectors.
#define irq_register_handler(int_num, int_prio)
Register handler for interrupt.
Note
The function func must be defined with the ISR macro.
The functions prototypes can be found in the device exception header files (exceptions.h).

Definition at line 110 of file interrupt_sam_nvic.h.

110# define irq_register_handler(int_num, int_prio) \
111 NVIC_ClearPendingIRQ( (IRQn_Type)int_num); \
112 NVIC_SetPriority( (IRQn_Type)int_num, int_prio); \
113 NVIC_EnableIRQ( (IRQn_Type)int_num); \
114

◆ ISR

#define ISR ( func)
Value:
void func (void)

Define service routine.

Note
For NVIC devices the interrupt service routines are predefined to add to vector table in binary generation, so there is no service register at run time. The routine collections are in exceptions.h.

Usage:

ISR(foo_irq_handler)
{
// Function definition
...
}
#define ISR(func)
Define service routine.
Parameters
funcName for the function.

Definition at line 77 of file interrupt_sam_nvic.h.

77# define ISR(func) \
78 void func (void)

Typedef Documentation

◆ irqflags_t

typedef uint32_t irqflags_t

Type used for holding state of interrupt flag.

Definition at line 130 of file interrupt_sam_nvic.h.

Function Documentation

◆ cpu_irq_enter_critical()

void cpu_irq_enter_critical ( void )

Definition at line 47 of file interrupt_sam_nvic.c.

48{
50 if (cpu_irq_is_enabled()) {
53 } else {
54 /* Make sure the to save the prev state as false */
56 }
57
58 }
59
61}
static volatile bool cpu_irq_prev_interrupt_state
#define cpu_irq_disable()
Disable interrupts globally.
static volatile uint32_t cpu_irq_critical_section_counter
#define cpu_irq_is_enabled()
Check if interrupts are globally enabled.

References cpu_irq_critical_section_counter, cpu_irq_disable, cpu_irq_is_enabled, and cpu_irq_prev_interrupt_state.

◆ cpu_irq_is_enabled_flags()

bool cpu_irq_is_enabled_flags ( irqflags_t flags)
inlinestatic

Check if interrupts are globally enabled in supplied flags.

Parameters
flagsCurrents state of interrupt flags.
Returns
True if interrupts are enabled.

Definition at line 148 of file interrupt_sam_nvic.h.

149{
150 return (flags);
151}

Referenced by cpu_irq_restore().

◆ cpu_irq_leave_critical()

void cpu_irq_leave_critical ( void )

Definition at line 63 of file interrupt_sam_nvic.c.

64{
65 /* Check if the user is trying to leave a critical section when not in a critical section */
67
69
70 /* Only enable global interrupts when the counter reaches 0 and the state of the global interrupt flag
71 was enabled when entering critical state */
74 }
75}
#define cpu_irq_enable()
Enable interrupts globally.

References cpu_irq_critical_section_counter, cpu_irq_enable, and cpu_irq_prev_interrupt_state.

◆ cpu_irq_restore()

void cpu_irq_restore ( irqflags_t flags)
inlinestatic

Restore global interrupt flags.

Use in conjunction with cpu_irq_save.

Parameters
flagsState to set interrupt flag to.

Definition at line 153 of file interrupt_sam_nvic.h.

154{
155 if (cpu_irq_is_enabled_flags(flags))
157}
static bool cpu_irq_is_enabled_flags(irqflags_t flags)
Check if interrupts are globally enabled in supplied flags.

References cpu_irq_enable, and cpu_irq_is_enabled_flags().

◆ cpu_irq_save()

irqflags_t cpu_irq_save ( void )
inlinestatic

Get and clear the global interrupt flags.

Use in conjunction with cpu_irq_restore.

Returns
Current state of interrupt flags.
Note
This function leaves interrupts disabled.

Definition at line 141 of file interrupt_sam_nvic.h.

142{
143 volatile irqflags_t flags = cpu_irq_is_enabled();
145 return flags;
146}
uint32_t irqflags_t
Type used for holding state of interrupt flag.

References cpu_irq_disable, and cpu_irq_is_enabled.

Variable Documentation

◆ cpu_irq_critical_section_counter

volatile uint32_t cpu_irq_critical_section_counter
static

Definition at line 138 of file interrupt_sam_nvic.h.

Referenced by cpu_irq_enter_critical(), and cpu_irq_leave_critical().

◆ cpu_irq_prev_interrupt_state

volatile bool cpu_irq_prev_interrupt_state
static

Definition at line 139 of file interrupt_sam_nvic.h.

Referenced by cpu_irq_enter_critical(), and cpu_irq_leave_critical().