The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
TARGET_SAMR21G18A/TOOLCHAIN_ARM_STD/interrupt_sam_nvic.h@171:3a7713b1edbc, 2018-11-08 (annotated)
- Committer:
- AnnaBridge
- Date:
- Thu Nov 08 11:45:42 2018 +0000
- Revision:
- 171:3a7713b1edbc
- Parent:
- TARGET_SAMD21G18A/TARGET_Atmel/common/utils/interrupt/interrupt_sam_nvic.h@111:4336505e4b1c
mbed library. Release version 164
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kojto | 111:4336505e4b1c | 1 | #ifndef UTILS_INTERRUPT_INTERRUPT_H |
Kojto | 111:4336505e4b1c | 2 | #define UTILS_INTERRUPT_INTERRUPT_H |
Kojto | 111:4336505e4b1c | 3 | |
Kojto | 111:4336505e4b1c | 4 | #include <compiler.h> |
Kojto | 111:4336505e4b1c | 5 | #include <parts.h> |
Kojto | 111:4336505e4b1c | 6 | |
Kojto | 111:4336505e4b1c | 7 | #ifdef __cplusplus |
Kojto | 111:4336505e4b1c | 8 | extern "C" { |
Kojto | 111:4336505e4b1c | 9 | #endif |
Kojto | 111:4336505e4b1c | 10 | |
Kojto | 111:4336505e4b1c | 11 | /** |
Kojto | 111:4336505e4b1c | 12 | * \weakgroup interrupt_group |
Kojto | 111:4336505e4b1c | 13 | * |
Kojto | 111:4336505e4b1c | 14 | * @{ |
Kojto | 111:4336505e4b1c | 15 | */ |
Kojto | 111:4336505e4b1c | 16 | |
Kojto | 111:4336505e4b1c | 17 | /** |
Kojto | 111:4336505e4b1c | 18 | * \name Interrupt Service Routine definition |
Kojto | 111:4336505e4b1c | 19 | * |
Kojto | 111:4336505e4b1c | 20 | * @{ |
Kojto | 111:4336505e4b1c | 21 | */ |
Kojto | 111:4336505e4b1c | 22 | |
Kojto | 111:4336505e4b1c | 23 | /** |
Kojto | 111:4336505e4b1c | 24 | * \brief Define service routine |
Kojto | 111:4336505e4b1c | 25 | * |
Kojto | 111:4336505e4b1c | 26 | * \note For NVIC devices the interrupt service routines are predefined to |
Kojto | 111:4336505e4b1c | 27 | * add to vector table in binary generation, so there is no service |
Kojto | 111:4336505e4b1c | 28 | * register at run time. The routine collections are in exceptions.h. |
Kojto | 111:4336505e4b1c | 29 | * |
Kojto | 111:4336505e4b1c | 30 | * Usage: |
Kojto | 111:4336505e4b1c | 31 | * \code |
Kojto | 111:4336505e4b1c | 32 | ISR(foo_irq_handler) |
Kojto | 111:4336505e4b1c | 33 | { |
Kojto | 111:4336505e4b1c | 34 | // Function definition |
Kojto | 111:4336505e4b1c | 35 | ... |
Kojto | 111:4336505e4b1c | 36 | } |
Kojto | 111:4336505e4b1c | 37 | \endcode |
Kojto | 111:4336505e4b1c | 38 | * |
Kojto | 111:4336505e4b1c | 39 | * \param func Name for the function. |
Kojto | 111:4336505e4b1c | 40 | */ |
Kojto | 111:4336505e4b1c | 41 | # define ISR(func) \ |
Kojto | 111:4336505e4b1c | 42 | void func (void) |
Kojto | 111:4336505e4b1c | 43 | |
Kojto | 111:4336505e4b1c | 44 | /** |
Kojto | 111:4336505e4b1c | 45 | * \brief Initialize interrupt vectors |
Kojto | 111:4336505e4b1c | 46 | * |
Kojto | 111:4336505e4b1c | 47 | * For NVIC the interrupt vectors are put in vector table. So nothing |
Kojto | 111:4336505e4b1c | 48 | * to do to initialize them, except defined the vector function with |
Kojto | 111:4336505e4b1c | 49 | * right name. |
Kojto | 111:4336505e4b1c | 50 | * |
Kojto | 111:4336505e4b1c | 51 | * This must be called prior to \ref irq_register_handler. |
Kojto | 111:4336505e4b1c | 52 | */ |
Kojto | 111:4336505e4b1c | 53 | # define irq_initialize_vectors() \ |
Kojto | 111:4336505e4b1c | 54 | do { \ |
Kojto | 111:4336505e4b1c | 55 | } while(0) |
Kojto | 111:4336505e4b1c | 56 | |
Kojto | 111:4336505e4b1c | 57 | /** |
Kojto | 111:4336505e4b1c | 58 | * \brief Register handler for interrupt |
Kojto | 111:4336505e4b1c | 59 | * |
Kojto | 111:4336505e4b1c | 60 | * For NVIC the interrupt vectors are put in vector table. So nothing |
Kojto | 111:4336505e4b1c | 61 | * to do to register them, except defined the vector function with |
Kojto | 111:4336505e4b1c | 62 | * right name. |
Kojto | 111:4336505e4b1c | 63 | * |
Kojto | 111:4336505e4b1c | 64 | * Usage: |
Kojto | 111:4336505e4b1c | 65 | * \code |
Kojto | 111:4336505e4b1c | 66 | irq_initialize_vectors(); |
Kojto | 111:4336505e4b1c | 67 | irq_register_handler(foo_irq_handler); |
Kojto | 111:4336505e4b1c | 68 | \endcode |
Kojto | 111:4336505e4b1c | 69 | * |
Kojto | 111:4336505e4b1c | 70 | * \note The function \a func must be defined with the \ref ISR macro. |
Kojto | 111:4336505e4b1c | 71 | * \note The functions prototypes can be found in the device exception header |
Kojto | 111:4336505e4b1c | 72 | * files (exceptions.h). |
Kojto | 111:4336505e4b1c | 73 | */ |
Kojto | 111:4336505e4b1c | 74 | # define irq_register_handler(int_num, int_prio) \ |
Kojto | 111:4336505e4b1c | 75 | NVIC_ClearPendingIRQ( (IRQn_Type)int_num); \ |
Kojto | 111:4336505e4b1c | 76 | NVIC_SetPriority( (IRQn_Type)int_num, int_prio); \ |
Kojto | 111:4336505e4b1c | 77 | NVIC_EnableIRQ( (IRQn_Type)int_num); \ |
Kojto | 111:4336505e4b1c | 78 | |
Kojto | 111:4336505e4b1c | 79 | //@} |
Kojto | 111:4336505e4b1c | 80 | |
Kojto | 111:4336505e4b1c | 81 | # define cpu_irq_enable() \ |
Kojto | 111:4336505e4b1c | 82 | do { \ |
Kojto | 111:4336505e4b1c | 83 | g_interrupt_enabled = true; \ |
Kojto | 111:4336505e4b1c | 84 | __DMB(); \ |
Kojto | 111:4336505e4b1c | 85 | __enable_irq(); \ |
Kojto | 111:4336505e4b1c | 86 | } while (0) |
Kojto | 111:4336505e4b1c | 87 | # define cpu_irq_disable() \ |
Kojto | 111:4336505e4b1c | 88 | do { \ |
Kojto | 111:4336505e4b1c | 89 | __disable_irq(); \ |
Kojto | 111:4336505e4b1c | 90 | __DMB(); \ |
Kojto | 111:4336505e4b1c | 91 | g_interrupt_enabled = false; \ |
Kojto | 111:4336505e4b1c | 92 | } while (0) |
Kojto | 111:4336505e4b1c | 93 | |
Kojto | 111:4336505e4b1c | 94 | typedef uint32_t irqflags_t; |
Kojto | 111:4336505e4b1c | 95 | |
Kojto | 111:4336505e4b1c | 96 | #if !defined(__DOXYGEN__) |
Kojto | 111:4336505e4b1c | 97 | extern volatile bool g_interrupt_enabled; |
Kojto | 111:4336505e4b1c | 98 | #endif |
Kojto | 111:4336505e4b1c | 99 | |
Kojto | 111:4336505e4b1c | 100 | #define cpu_irq_is_enabled() (__get_PRIMASK() == 0) |
Kojto | 111:4336505e4b1c | 101 | |
Kojto | 111:4336505e4b1c | 102 | static volatile uint32_t cpu_irq_critical_section_counter; |
Kojto | 111:4336505e4b1c | 103 | static volatile bool cpu_irq_prev_interrupt_state; |
Kojto | 111:4336505e4b1c | 104 | |
Kojto | 111:4336505e4b1c | 105 | static inline irqflags_t cpu_irq_save(void) |
Kojto | 111:4336505e4b1c | 106 | { |
Kojto | 111:4336505e4b1c | 107 | irqflags_t flags = cpu_irq_is_enabled(); |
Kojto | 111:4336505e4b1c | 108 | cpu_irq_disable(); |
Kojto | 111:4336505e4b1c | 109 | return flags; |
Kojto | 111:4336505e4b1c | 110 | } |
Kojto | 111:4336505e4b1c | 111 | |
Kojto | 111:4336505e4b1c | 112 | static inline bool cpu_irq_is_enabled_flags(irqflags_t flags) |
Kojto | 111:4336505e4b1c | 113 | { |
Kojto | 111:4336505e4b1c | 114 | return (flags); |
Kojto | 111:4336505e4b1c | 115 | } |
Kojto | 111:4336505e4b1c | 116 | |
Kojto | 111:4336505e4b1c | 117 | static inline void cpu_irq_restore(irqflags_t flags) |
Kojto | 111:4336505e4b1c | 118 | { |
Kojto | 111:4336505e4b1c | 119 | if (cpu_irq_is_enabled_flags(flags)) |
Kojto | 111:4336505e4b1c | 120 | cpu_irq_enable(); |
Kojto | 111:4336505e4b1c | 121 | } |
Kojto | 111:4336505e4b1c | 122 | |
Kojto | 111:4336505e4b1c | 123 | void cpu_irq_enter_critical(void); |
Kojto | 111:4336505e4b1c | 124 | void cpu_irq_leave_critical(void); |
Kojto | 111:4336505e4b1c | 125 | |
Kojto | 111:4336505e4b1c | 126 | /** |
Kojto | 111:4336505e4b1c | 127 | * \weakgroup interrupt_deprecated_group |
Kojto | 111:4336505e4b1c | 128 | * @{ |
Kojto | 111:4336505e4b1c | 129 | */ |
Kojto | 111:4336505e4b1c | 130 | |
Kojto | 111:4336505e4b1c | 131 | #define Enable_global_interrupt() cpu_irq_enable() |
Kojto | 111:4336505e4b1c | 132 | #define Disable_global_interrupt() cpu_irq_disable() |
Kojto | 111:4336505e4b1c | 133 | #define Is_global_interrupt_enabled() cpu_irq_is_enabled() |
Kojto | 111:4336505e4b1c | 134 | |
Kojto | 111:4336505e4b1c | 135 | //@} |
Kojto | 111:4336505e4b1c | 136 | |
Kojto | 111:4336505e4b1c | 137 | //@} |
Kojto | 111:4336505e4b1c | 138 | |
Kojto | 111:4336505e4b1c | 139 | #ifdef __cplusplus |
Kojto | 111:4336505e4b1c | 140 | } |
Kojto | 111:4336505e4b1c | 141 | #endif |
Kojto | 111:4336505e4b1c | 142 | |
Kojto | 111:4336505e4b1c | 143 | #endif /* UTILS_INTERRUPT_INTERRUPT_H */ |