mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Fri Jul 17 09:15:10 2015 +0100
Revision:
592:a274ee790e56
Parent:
579:53297373a894
Synchronized with git revision e7144f83a8d75df80c4877936b6ffe552b0be9e6

Full URL: https://github.com/mbedmicro/mbed/commit/e7144f83a8d75df80c4877936b6ffe552b0be9e6/

More API implementation for SAMR21

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 579:53297373a894 1 #ifndef EXTINT_H_INCLUDED
mbed_official 579:53297373a894 2 #define EXTINT_H_INCLUDED
mbed_official 579:53297373a894 3
mbed_official 579:53297373a894 4 /**
mbed_official 579:53297373a894 5 * \defgroup asfdoc_sam0_extint_group SAM External Interrupt Driver (EXTINT)
mbed_official 579:53297373a894 6 *
mbed_official 579:53297373a894 7 * This driver for Atmel庐 | SMART SAM devices provides an interface for the configuration
mbed_official 579:53297373a894 8 * and management of external interrupts generated by the physical device pins,
mbed_official 579:53297373a894 9 * including edge detection. The following driver API modes are covered by this
mbed_official 579:53297373a894 10 * manual:
mbed_official 579:53297373a894 11 *
mbed_official 579:53297373a894 12 * - Polled APIs
mbed_official 579:53297373a894 13 * \if EXTINT_CALLBACK_MODE
mbed_official 579:53297373a894 14 * - Callback APIs
mbed_official 579:53297373a894 15 * \endif
mbed_official 579:53297373a894 16 *
mbed_official 579:53297373a894 17 * The following peripherals are used by this module:
mbed_official 579:53297373a894 18 * - EIC (External Interrupt Controller)
mbed_official 579:53297373a894 19 *
mbed_official 579:53297373a894 20 * The following devices can use this module:
mbed_official 579:53297373a894 21 * - Atmel | SMART SAM D20/D21
mbed_official 579:53297373a894 22 * - Atmel | SMART SAM R21
mbed_official 579:53297373a894 23 * - Atmel | SMART SAM D10/D11
mbed_official 579:53297373a894 24 * - Atmel | SMART SAM L21
mbed_official 579:53297373a894 25 *
mbed_official 579:53297373a894 26 * The outline of this documentation is as follows:
mbed_official 579:53297373a894 27 * - \ref asfdoc_sam0_extint_prerequisites
mbed_official 579:53297373a894 28 * - \ref asfdoc_sam0_extint_module_overview
mbed_official 579:53297373a894 29 * - \ref asfdoc_sam0_extint_special_considerations
mbed_official 579:53297373a894 30 * - \ref asfdoc_sam0_extint_extra_info
mbed_official 579:53297373a894 31 * - \ref asfdoc_sam0_extint_examples
mbed_official 579:53297373a894 32 * - \ref asfdoc_sam0_extint_api_overview
mbed_official 579:53297373a894 33 *
mbed_official 579:53297373a894 34 *
mbed_official 579:53297373a894 35 * \section asfdoc_sam0_extint_prerequisites Prerequisites
mbed_official 579:53297373a894 36 *
mbed_official 579:53297373a894 37 * There are no prerequisites for this module.
mbed_official 579:53297373a894 38 *
mbed_official 579:53297373a894 39 *
mbed_official 579:53297373a894 40 * \section asfdoc_sam0_extint_module_overview Module Overview
mbed_official 579:53297373a894 41 *
mbed_official 579:53297373a894 42 * The External Interrupt (EXTINT) module provides a method of asynchronously
mbed_official 579:53297373a894 43 * detecting rising edge, falling edge or specific level detection on individual
mbed_official 579:53297373a894 44 * I/O pins of a device. This detection can then be used to trigger a software
mbed_official 579:53297373a894 45 * interrupt or event, or polled for later use if required. External interrupts
mbed_official 579:53297373a894 46 * can also optionally be used to automatically wake up the device from sleep
mbed_official 579:53297373a894 47 * mode, allowing the device to conserve power while still being able to react
mbed_official 579:53297373a894 48 * to an external stimulus in a timely manner.
mbed_official 579:53297373a894 49 *
mbed_official 579:53297373a894 50 * \subsection asfdoc_sam0_extint_logical_channels Logical Channels
mbed_official 579:53297373a894 51 * The External Interrupt module contains a number of logical channels, each of
mbed_official 579:53297373a894 52 * which is capable of being individually configured for a given pin routing,
mbed_official 579:53297373a894 53 * detection mode, and filtering/wake up characteristics.
mbed_official 579:53297373a894 54 *
mbed_official 579:53297373a894 55 * Each individual logical external interrupt channel may be routed to a single
mbed_official 579:53297373a894 56 * physical device I/O pin in order to detect a particular edge or level of the
mbed_official 579:53297373a894 57 * incoming signal.
mbed_official 579:53297373a894 58 *
mbed_official 579:53297373a894 59 * \subsection asfdoc_sam0_extint_module_overview_nmi_chanel NMI Channels
mbed_official 579:53297373a894 60 *
mbed_official 579:53297373a894 61 * One or more Non Maskable Interrupt (NMI) channels are provided within each
mbed_official 579:53297373a894 62 * physical External Interrupt Controller module, allowing a single physical pin
mbed_official 579:53297373a894 63 * of the device to fire a single NMI interrupt in response to a particular
mbed_official 579:53297373a894 64 * edge or level stimulus. A NMI cannot, as the name suggests, be disabled in
mbed_official 579:53297373a894 65 * firmware and will take precedence over any in-progress interrupt sources.
mbed_official 579:53297373a894 66 *
mbed_official 579:53297373a894 67 * NMIs can be used to implement critical device features such as forced
mbed_official 579:53297373a894 68 * software reset or other functionality where the action should be executed in
mbed_official 579:53297373a894 69 * preference to all other running code with a minimum amount of latency.
mbed_official 579:53297373a894 70 *
mbed_official 579:53297373a894 71 * \subsection asfdoc_sam0_extint_module_overview_filtering Input Filtering and Detection
mbed_official 579:53297373a894 72 *
mbed_official 579:53297373a894 73 * To reduce the possibility of noise or other transient signals causing
mbed_official 579:53297373a894 74 * unwanted device wake-ups, interrupts and/or events via an external interrupt
mbed_official 579:53297373a894 75 * channel, a hardware signal filter can be enabled on individual channels. This
mbed_official 579:53297373a894 76 * filter provides a Majority-of-Three voter filter on the incoming signal, so
mbed_official 579:53297373a894 77 * that the input state is considered to be the majority vote of three
mbed_official 579:53297373a894 78 * subsequent samples of the pin input buffer. The possible sampled input and
mbed_official 579:53297373a894 79 * resulting filtered output when the filter is enabled is shown in
mbed_official 579:53297373a894 80 * \ref asfdoc_sam0_extint_filter_table "the table below".
mbed_official 579:53297373a894 81 *
mbed_official 579:53297373a894 82 * \anchor asfdoc_sam0_extint_filter_table
mbed_official 579:53297373a894 83 * <table>
mbed_official 579:53297373a894 84 * <caption>Sampled Input and Rresulting Filtered Output</caption>
mbed_official 579:53297373a894 85 * <tr>
mbed_official 579:53297373a894 86 * <th>Input Sample 1</th>
mbed_official 579:53297373a894 87 * <th>Input Sample 2</th>
mbed_official 579:53297373a894 88 * <th>Input Sample 3</th>
mbed_official 579:53297373a894 89 * <th>Filtered Output</th>
mbed_official 579:53297373a894 90 * </tr>
mbed_official 579:53297373a894 91 * <tr>
mbed_official 579:53297373a894 92 * <td>0</td> <td>0</td> <td>0</td> <td>0</td>
mbed_official 579:53297373a894 93 * </tr>
mbed_official 579:53297373a894 94 * <tr>
mbed_official 579:53297373a894 95 * <td>0</td> <td>0</td> <td>1</td> <td>0</td>
mbed_official 579:53297373a894 96 * </tr>
mbed_official 579:53297373a894 97 * <tr>
mbed_official 579:53297373a894 98 * <td>0</td> <td>1</td> <td>0</td> <td>0</td>
mbed_official 579:53297373a894 99 * </tr>
mbed_official 579:53297373a894 100 * <tr>
mbed_official 579:53297373a894 101 * <td>0</td> <td>1</td> <td>1</td> <td>1</td>
mbed_official 579:53297373a894 102 * </tr>
mbed_official 579:53297373a894 103 * <tr>
mbed_official 579:53297373a894 104 * <td>1</td> <td>0</td> <td>0</td> <td>0</td>
mbed_official 579:53297373a894 105 * </tr>
mbed_official 579:53297373a894 106 * <tr>
mbed_official 579:53297373a894 107 * <td>1</td> <td>0</td> <td>1</td> <td>1</td>
mbed_official 579:53297373a894 108 * </tr>
mbed_official 579:53297373a894 109 * <tr>
mbed_official 579:53297373a894 110 * <td>1</td> <td>1</td> <td>0</td> <td>1</td>
mbed_official 579:53297373a894 111 * </tr>
mbed_official 579:53297373a894 112 * <tr>
mbed_official 579:53297373a894 113 * <td>1</td> <td>1</td> <td>1</td> <td>1</td>
mbed_official 579:53297373a894 114 * </tr>
mbed_official 579:53297373a894 115 * </table>
mbed_official 579:53297373a894 116 *
mbed_official 579:53297373a894 117 * \subsection asfdoc_sam0_extint_module_overview_events Events and Interrupts
mbed_official 579:53297373a894 118 *
mbed_official 579:53297373a894 119 * Channel detection states may be polled inside the application for synchronous
mbed_official 579:53297373a894 120 * detection, or events and interrupts may be used for asynchronous behavior.
mbed_official 579:53297373a894 121 * Each channel can be configured to give an asynchronous hardware event (which
mbed_official 579:53297373a894 122 * may in turn trigger actions in other hardware modules) or an asynchronous
mbed_official 579:53297373a894 123 * software interrupt.
mbed_official 579:53297373a894 124 *
mbed_official 579:53297373a894 125 * \note The connection of events between modules requires the use of the
mbed_official 579:53297373a894 126 * \ref asfdoc_sam0_events_group "SAM Event System Driver (EVENTS)"
mbed_official 579:53297373a894 127 * to route output event of one module to the input event of another.
mbed_official 579:53297373a894 128 * For more information on event routing, refer to the event driver
mbed_official 579:53297373a894 129 * documentation.
mbed_official 579:53297373a894 130 *
mbed_official 579:53297373a894 131 * \subsection asfdoc_sam0_extint_module_overview_physical Physical Connection
mbed_official 579:53297373a894 132 *
mbed_official 579:53297373a894 133 * \ref asfdoc_sam0_extint_int_connections "The diagram below" shows how this
mbed_official 579:53297373a894 134 * module is interconnected within the device.
mbed_official 579:53297373a894 135 *
mbed_official 579:53297373a894 136 * \anchor asfdoc_sam0_extint_int_connections
mbed_official 579:53297373a894 137 * \dot
mbed_official 579:53297373a894 138 * digraph overview {
mbed_official 579:53297373a894 139 * node [label="Port Pad" shape=square] pad;
mbed_official 579:53297373a894 140 *
mbed_official 579:53297373a894 141 * subgraph driver {
mbed_official 579:53297373a894 142 * node [label="Peripheral MUX" shape=trapezium] pinmux;
mbed_official 579:53297373a894 143 * node [label="EIC Module" shape=ellipse] eic;
mbed_official 579:53297373a894 144 * node [label="Other Peripheral Modules" shape=ellipse style=filled fillcolor=lightgray] peripherals;
mbed_official 579:53297373a894 145 * }
mbed_official 579:53297373a894 146 *
mbed_official 579:53297373a894 147 * pinmux -> eic;
mbed_official 579:53297373a894 148 * pad -> pinmux;
mbed_official 579:53297373a894 149 * pinmux -> peripherals;
mbed_official 579:53297373a894 150 * }
mbed_official 579:53297373a894 151 * \enddot
mbed_official 579:53297373a894 152 *
mbed_official 579:53297373a894 153 * \section asfdoc_sam0_extint_special_considerations Special Considerations
mbed_official 579:53297373a894 154 *
mbed_official 579:53297373a894 155 * Not all devices support disabling of the NMI channel(s) detection mode - see
mbed_official 579:53297373a894 156 * your device datasheet.
mbed_official 579:53297373a894 157 *
mbed_official 579:53297373a894 158 *
mbed_official 579:53297373a894 159 * \section asfdoc_sam0_extint_extra_info Extra Information
mbed_official 579:53297373a894 160 *
mbed_official 579:53297373a894 161 * For extra information, see \ref asfdoc_sam0_extint_extra. This includes:
mbed_official 579:53297373a894 162 * - \ref asfdoc_sam0_extint_extra_acronyms
mbed_official 579:53297373a894 163 * - \ref asfdoc_sam0_extint_extra_dependencies
mbed_official 579:53297373a894 164 * - \ref asfdoc_sam0_extint_extra_errata
mbed_official 579:53297373a894 165 * - \ref asfdoc_sam0_extint_extra_history
mbed_official 579:53297373a894 166 *
mbed_official 579:53297373a894 167 *
mbed_official 579:53297373a894 168 * \section asfdoc_sam0_extint_examples Examples
mbed_official 579:53297373a894 169 *
mbed_official 579:53297373a894 170 * For a list of examples related to this driver, see
mbed_official 579:53297373a894 171 * \ref asfdoc_sam0_extint_exqsg.
mbed_official 579:53297373a894 172 *
mbed_official 579:53297373a894 173 *
mbed_official 579:53297373a894 174 * \section asfdoc_sam0_extint_api_overview API Overview
mbed_official 579:53297373a894 175 * @{
mbed_official 579:53297373a894 176 */
mbed_official 579:53297373a894 177
mbed_official 579:53297373a894 178 #include <compiler.h>
mbed_official 579:53297373a894 179 #include <pinmux.h>
mbed_official 579:53297373a894 180
mbed_official 579:53297373a894 181 #ifdef __cplusplus
mbed_official 579:53297373a894 182 extern "C" {
mbed_official 579:53297373a894 183 #endif
mbed_official 579:53297373a894 184
mbed_official 579:53297373a894 185 /**
mbed_official 579:53297373a894 186 * \brief External interrupt edge detection configuration enum.
mbed_official 579:53297373a894 187 *
mbed_official 579:53297373a894 188 * Enum for the possible signal edge detection modes of the External
mbed_official 579:53297373a894 189 * Interrupt Controller module.
mbed_official 579:53297373a894 190 */
mbed_official 579:53297373a894 191 enum extint_detect {
mbed_official 579:53297373a894 192 /** No edge detection. Not allowed as a NMI detection mode on some
mbed_official 579:53297373a894 193 * devices. */
mbed_official 579:53297373a894 194 EXTINT_DETECT_NONE = 0,
mbed_official 579:53297373a894 195 /** Detect rising signal edges. */
mbed_official 579:53297373a894 196 EXTINT_DETECT_RISING = 1,
mbed_official 579:53297373a894 197 /** Detect falling signal edges. */
mbed_official 579:53297373a894 198 EXTINT_DETECT_FALLING = 2,
mbed_official 579:53297373a894 199 /** Detect both signal edges. */
mbed_official 579:53297373a894 200 EXTINT_DETECT_BOTH = 3,
mbed_official 579:53297373a894 201 /** Detect high signal levels. */
mbed_official 579:53297373a894 202 EXTINT_DETECT_HIGH = 4,
mbed_official 579:53297373a894 203 /** Detect low signal levels. */
mbed_official 579:53297373a894 204 EXTINT_DETECT_LOW = 5,
mbed_official 579:53297373a894 205 };
mbed_official 579:53297373a894 206
mbed_official 579:53297373a894 207 /**
mbed_official 579:53297373a894 208 * \brief External interrupt internal pull configuration enum.
mbed_official 579:53297373a894 209 *
mbed_official 579:53297373a894 210 * Enum for the possible pin internal pull configurations.
mbed_official 579:53297373a894 211 *
mbed_official 579:53297373a894 212 * \note Disabling the internal pull resistor is not recommended if the driver
mbed_official 579:53297373a894 213 * is used in interrupt (callback) mode, due the possibility of floating
mbed_official 579:53297373a894 214 * inputs generating continuous interrupts.
mbed_official 579:53297373a894 215 */
mbed_official 579:53297373a894 216 enum extint_pull {
mbed_official 579:53297373a894 217 /** Internal pull-up resistor is enabled on the pin. */
mbed_official 579:53297373a894 218 EXTINT_PULL_UP = SYSTEM_PINMUX_PIN_PULL_UP,
mbed_official 579:53297373a894 219 /** Internal pull-down resistor is enabled on the pin. */
mbed_official 579:53297373a894 220 EXTINT_PULL_DOWN = SYSTEM_PINMUX_PIN_PULL_DOWN,
mbed_official 579:53297373a894 221 /** Internal pull resistor is disconnected from the pin. */
mbed_official 579:53297373a894 222 EXTINT_PULL_NONE = SYSTEM_PINMUX_PIN_PULL_NONE,
mbed_official 579:53297373a894 223 };
mbed_official 579:53297373a894 224
mbed_official 579:53297373a894 225 /** The EIC is clocked by GCLK_EIC. */
mbed_official 579:53297373a894 226 #define EXTINT_CLK_GCLK 0
mbed_official 579:53297373a894 227 /** The EIC is clocked by CLK_ULP32K. */
mbed_official 579:53297373a894 228 #define EXTINT_CLK_ULP32K 1
mbed_official 579:53297373a894 229
mbed_official 579:53297373a894 230 /**
mbed_official 579:53297373a894 231 * \brief External Interrupt Controller channel configuration structure.
mbed_official 579:53297373a894 232 *
mbed_official 579:53297373a894 233 * Configuration structure for the edge detection mode of an external
mbed_official 579:53297373a894 234 * interrupt channel.
mbed_official 579:53297373a894 235 */
mbed_official 579:53297373a894 236 struct extint_chan_conf {
mbed_official 579:53297373a894 237 /** GPIO pin the NMI should be connected to. */
mbed_official 579:53297373a894 238 uint32_t gpio_pin;
mbed_official 579:53297373a894 239 /** MUX position the GPIO pin should be configured to. */
mbed_official 579:53297373a894 240 uint32_t gpio_pin_mux;
mbed_official 579:53297373a894 241 /** Internal pull to enable on the input pin. */
mbed_official 579:53297373a894 242 enum extint_pull gpio_pin_pull;
mbed_official 579:53297373a894 243 #if (SAML21)
mbed_official 579:53297373a894 244 /** Enable asynchronous edge detection. */
mbed_official 579:53297373a894 245 bool enable_async_edge_detection;
mbed_official 579:53297373a894 246 #else
mbed_official 579:53297373a894 247 /** Wake up the device if the channel interrupt fires during sleep mode. */
mbed_official 579:53297373a894 248 bool wake_if_sleeping;
mbed_official 579:53297373a894 249 #endif
mbed_official 579:53297373a894 250 /** Filter the raw input signal to prevent noise from triggering an
mbed_official 579:53297373a894 251 * interrupt accidentally, using a 3 sample majority filter. */
mbed_official 579:53297373a894 252 bool filter_input_signal;
mbed_official 579:53297373a894 253 /** Edge detection mode to use. */
mbed_official 579:53297373a894 254 enum extint_detect detection_criteria;
mbed_official 579:53297373a894 255 };
mbed_official 579:53297373a894 256
mbed_official 579:53297373a894 257 /**
mbed_official 579:53297373a894 258 * \brief External Interrupt event enable/disable structure.
mbed_official 579:53297373a894 259 *
mbed_official 579:53297373a894 260 * Event flags for the \ref extint_enable_events() and
mbed_official 579:53297373a894 261 * \ref extint_disable_events().
mbed_official 579:53297373a894 262 */
mbed_official 579:53297373a894 263 struct extint_events {
mbed_official 579:53297373a894 264 /** If \c true, an event will be generated when an external interrupt
mbed_official 579:53297373a894 265 * channel detection state changes. */
mbed_official 579:53297373a894 266 bool generate_event_on_detect[32 * EIC_INST_NUM];
mbed_official 579:53297373a894 267 };
mbed_official 579:53297373a894 268
mbed_official 579:53297373a894 269 /**
mbed_official 579:53297373a894 270 * \brief External Interrupt Controller NMI configuration structure.
mbed_official 579:53297373a894 271 *
mbed_official 579:53297373a894 272 * Configuration structure for the edge detection mode of an external
mbed_official 579:53297373a894 273 * interrupt NMI channel.
mbed_official 579:53297373a894 274 */
mbed_official 579:53297373a894 275 struct extint_nmi_conf {
mbed_official 579:53297373a894 276 /** GPIO pin the NMI should be connected to. */
mbed_official 579:53297373a894 277 uint32_t gpio_pin;
mbed_official 579:53297373a894 278 /** MUX position the GPIO pin should be configured to. */
mbed_official 579:53297373a894 279 uint32_t gpio_pin_mux;
mbed_official 579:53297373a894 280 /** Internal pull to enable on the input pin. */
mbed_official 579:53297373a894 281 enum extint_pull gpio_pin_pull;
mbed_official 579:53297373a894 282 /** Filter the raw input signal to prevent noise from triggering an
mbed_official 579:53297373a894 283 * interrupt accidentally, using a 3 sample majority filter. */
mbed_official 579:53297373a894 284 bool filter_input_signal;
mbed_official 579:53297373a894 285 /** Edge detection mode to use. Not all devices support all possible
mbed_official 579:53297373a894 286 * detection modes for NMIs.
mbed_official 579:53297373a894 287 */
mbed_official 579:53297373a894 288 enum extint_detect detection_criteria;
mbed_official 579:53297373a894 289 #if (SAML21)
mbed_official 579:53297373a894 290 /** Enable asynchronous edge detection. */
mbed_official 579:53297373a894 291 bool enable_async_edge_detection;
mbed_official 579:53297373a894 292 #endif
mbed_official 579:53297373a894 293 };
mbed_official 579:53297373a894 294 // TEMP: Commented by V
mbed_official 579:53297373a894 295 //#if EXTINT_CALLBACK_MODE == true
mbed_official 579:53297373a894 296 /** Type definition for an EXTINT module callback function. */
mbed_official 579:53297373a894 297 typedef void (*extint_callback_t)(void);
mbed_official 579:53297373a894 298
mbed_official 579:53297373a894 299 #ifndef EIC_NUMBER_OF_INTERRUPTS
mbed_official 579:53297373a894 300 # define EIC_NUMBER_OF_INTERRUPTS 16
mbed_official 579:53297373a894 301 #endif
mbed_official 579:53297373a894 302 //#endif
mbed_official 579:53297373a894 303
mbed_official 579:53297373a894 304 #if !defined(__DOXYGEN__)
mbed_official 579:53297373a894 305 /** \internal
mbed_official 579:53297373a894 306 * Internal EXTINT module device instance structure definition.
mbed_official 579:53297373a894 307 */
mbed_official 579:53297373a894 308 struct _extint_module {
mbed_official 579:53297373a894 309 // TEMP: Commented by V
mbed_official 579:53297373a894 310 //# if EXTINT_CALLBACK_MODE == true
mbed_official 579:53297373a894 311 /** Asynchronous channel callback table, for user-registered handlers. */
mbed_official 579:53297373a894 312 extint_callback_t callbacks[EIC_NUMBER_OF_INTERRUPTS];
mbed_official 579:53297373a894 313 //# else
mbed_official 579:53297373a894 314 /** Dummy value to ensure the struct has at least one member */
mbed_official 579:53297373a894 315 // uint8_t _dummy;
mbed_official 579:53297373a894 316 //# endif
mbed_official 579:53297373a894 317 };
mbed_official 579:53297373a894 318
mbed_official 579:53297373a894 319 /**
mbed_official 579:53297373a894 320 * \brief Retrieves the base EIC module address from a given channel number.
mbed_official 579:53297373a894 321 *
mbed_official 579:53297373a894 322 * Retrieves the base address of a EIC hardware module associated with the
mbed_official 579:53297373a894 323 * given external interrupt channel.
mbed_official 579:53297373a894 324 *
mbed_official 579:53297373a894 325 * \param[in] channel External interrupt channel index to convert
mbed_official 579:53297373a894 326 *
mbed_official 579:53297373a894 327 * \return Base address of the associated EIC module.
mbed_official 579:53297373a894 328 */
mbed_official 579:53297373a894 329 static inline Eic * _extint_get_eic_from_channel(
mbed_official 579:53297373a894 330 const uint8_t channel)
mbed_official 579:53297373a894 331 {
mbed_official 579:53297373a894 332 uint8_t eic_index = (channel / 32);
mbed_official 579:53297373a894 333
mbed_official 579:53297373a894 334 if (eic_index < EIC_INST_NUM) {
mbed_official 579:53297373a894 335 /* Array of available EICs. */
mbed_official 579:53297373a894 336 Eic *const eics[EIC_INST_NUM] = EIC_INSTS;
mbed_official 579:53297373a894 337
mbed_official 579:53297373a894 338 return eics[eic_index];
mbed_official 579:53297373a894 339 } else {
mbed_official 579:53297373a894 340 Assert(false);
mbed_official 579:53297373a894 341 return NULL;
mbed_official 579:53297373a894 342 }
mbed_official 579:53297373a894 343 }
mbed_official 579:53297373a894 344
mbed_official 579:53297373a894 345 /**
mbed_official 579:53297373a894 346 * \brief Retrieves the base EIC module address from a given NMI channel number.
mbed_official 579:53297373a894 347 *
mbed_official 579:53297373a894 348 * Retrieves the base address of a EIC hardware module associated with the
mbed_official 579:53297373a894 349 * given non-maskable external interrupt channel.
mbed_official 579:53297373a894 350 *
mbed_official 579:53297373a894 351 * \param[in] nmi_channel Non-Maskable interrupt channel index to convert
mbed_official 579:53297373a894 352 *
mbed_official 579:53297373a894 353 * \return Base address of the associated EIC module.
mbed_official 579:53297373a894 354 */
mbed_official 579:53297373a894 355 static inline Eic * _extint_get_eic_from_nmi(
mbed_official 579:53297373a894 356 const uint8_t nmi_channel)
mbed_official 579:53297373a894 357 {
mbed_official 579:53297373a894 358 uint8_t eic_index = nmi_channel;
mbed_official 579:53297373a894 359
mbed_official 579:53297373a894 360 if (eic_index < EIC_INST_NUM) {
mbed_official 579:53297373a894 361 /* Array of available EICs. */
mbed_official 579:53297373a894 362 Eic *const eics[EIC_INST_NUM] = EIC_INSTS;
mbed_official 579:53297373a894 363
mbed_official 579:53297373a894 364 return eics[eic_index];
mbed_official 579:53297373a894 365 } else {
mbed_official 579:53297373a894 366 Assert(false);
mbed_official 579:53297373a894 367 return NULL;
mbed_official 579:53297373a894 368 }
mbed_official 579:53297373a894 369 }
mbed_official 579:53297373a894 370 #endif
mbed_official 579:53297373a894 371
mbed_official 579:53297373a894 372 /** \name Event Management
mbed_official 579:53297373a894 373 * @{
mbed_official 579:53297373a894 374 */
mbed_official 579:53297373a894 375
mbed_official 579:53297373a894 376 void extint_enable_events(
mbed_official 579:53297373a894 377 struct extint_events *const events);
mbed_official 579:53297373a894 378
mbed_official 579:53297373a894 379 void extint_disable_events(
mbed_official 579:53297373a894 380 struct extint_events *const events);
mbed_official 579:53297373a894 381
mbed_official 579:53297373a894 382 /** @} */
mbed_official 579:53297373a894 383
mbed_official 579:53297373a894 384 /** \name Configuration and Initialization (Channel)
mbed_official 579:53297373a894 385 * @{
mbed_official 579:53297373a894 386 */
mbed_official 579:53297373a894 387
mbed_official 579:53297373a894 388 void extint_chan_get_config_defaults(
mbed_official 579:53297373a894 389 struct extint_chan_conf *const config);
mbed_official 579:53297373a894 390
mbed_official 579:53297373a894 391 void extint_chan_set_config(
mbed_official 579:53297373a894 392 const uint8_t channel,
mbed_official 579:53297373a894 393 const struct extint_chan_conf *const config);
mbed_official 579:53297373a894 394
mbed_official 579:53297373a894 395 /** @} */
mbed_official 579:53297373a894 396
mbed_official 579:53297373a894 397 /** \name Configuration and Initialization (NMI)
mbed_official 579:53297373a894 398 * @{
mbed_official 579:53297373a894 399 */
mbed_official 579:53297373a894 400
mbed_official 579:53297373a894 401 /**
mbed_official 579:53297373a894 402 * \brief Initializes an External Interrupt NMI channel configuration structure to defaults.
mbed_official 579:53297373a894 403 *
mbed_official 579:53297373a894 404 * Initializes a given External Interrupt NMI channel configuration structure
mbed_official 579:53297373a894 405 * to a set of known default values. This function should be called on all new
mbed_official 579:53297373a894 406 * instances of these configuration structures before being modified by the
mbed_official 579:53297373a894 407 * user application.
mbed_official 579:53297373a894 408 *
mbed_official 579:53297373a894 409 * The default configuration is as follows:
mbed_official 579:53297373a894 410 * \li Input filtering disabled
mbed_official 579:53297373a894 411 * \li Detect falling edges of a signal
mbed_official 579:53297373a894 412 * \li Asynchronous edge detection is disabled
mbed_official 579:53297373a894 413 *
mbed_official 579:53297373a894 414 * \param[out] config Configuration structure to initialize to default values
mbed_official 579:53297373a894 415 */
mbed_official 579:53297373a894 416 static inline void extint_nmi_get_config_defaults(
mbed_official 579:53297373a894 417 struct extint_nmi_conf *const config)
mbed_official 579:53297373a894 418 {
mbed_official 579:53297373a894 419 /* Sanity check arguments */
mbed_official 579:53297373a894 420 Assert(config);
mbed_official 579:53297373a894 421
mbed_official 579:53297373a894 422 /* Default configuration values */
mbed_official 579:53297373a894 423 config->gpio_pin = 0;
mbed_official 579:53297373a894 424 config->gpio_pin_mux = 0;
mbed_official 579:53297373a894 425 config->gpio_pin_pull = EXTINT_PULL_UP;
mbed_official 579:53297373a894 426 config->filter_input_signal = false;
mbed_official 579:53297373a894 427 config->detection_criteria = EXTINT_DETECT_FALLING;
mbed_official 579:53297373a894 428 #if (SAML21)
mbed_official 579:53297373a894 429 config->enable_async_edge_detection = false;
mbed_official 579:53297373a894 430 #endif
mbed_official 579:53297373a894 431
mbed_official 579:53297373a894 432 }
mbed_official 579:53297373a894 433
mbed_official 579:53297373a894 434 enum status_code extint_nmi_set_config(
mbed_official 579:53297373a894 435 const uint8_t nmi_channel,
mbed_official 579:53297373a894 436 const struct extint_nmi_conf *const config);
mbed_official 579:53297373a894 437
mbed_official 579:53297373a894 438 /** @} */
mbed_official 579:53297373a894 439
mbed_official 579:53297373a894 440 /** \name Detection testing and clearing (channel)
mbed_official 579:53297373a894 441 * @{
mbed_official 579:53297373a894 442 */
mbed_official 579:53297373a894 443
mbed_official 579:53297373a894 444 /**
mbed_official 579:53297373a894 445 * \brief Retrieves the edge detection state of a configured channel.
mbed_official 579:53297373a894 446 *
mbed_official 579:53297373a894 447 * Reads the current state of a configured channel, and determines
mbed_official 579:53297373a894 448 * if the detection criteria of the channel has been met.
mbed_official 579:53297373a894 449 *
mbed_official 579:53297373a894 450 * \param[in] channel External Interrupt channel index to check
mbed_official 579:53297373a894 451 *
mbed_official 579:53297373a894 452 * \return Status of the requested channel's edge detection state.
mbed_official 579:53297373a894 453 * \retval true If the channel's edge/level detection criteria was met
mbed_official 579:53297373a894 454 * \retval false If the channel has not detected its configured criteria
mbed_official 579:53297373a894 455 */
mbed_official 579:53297373a894 456 static inline bool extint_chan_is_detected(
mbed_official 579:53297373a894 457 const uint8_t channel)
mbed_official 579:53297373a894 458 {
mbed_official 579:53297373a894 459 Eic *const eic_module = _extint_get_eic_from_channel(channel);
mbed_official 579:53297373a894 460 uint32_t eic_mask = (1UL << (channel % 32));
mbed_official 579:53297373a894 461
mbed_official 579:53297373a894 462 return (eic_module->INTFLAG.reg & eic_mask);
mbed_official 579:53297373a894 463 }
mbed_official 579:53297373a894 464
mbed_official 579:53297373a894 465 /**
mbed_official 579:53297373a894 466 * \brief Clears the edge detection state of a configured channel.
mbed_official 579:53297373a894 467 *
mbed_official 579:53297373a894 468 * Clears the current state of a configured channel, readying it for
mbed_official 579:53297373a894 469 * the next level or edge detection.
mbed_official 579:53297373a894 470 *
mbed_official 579:53297373a894 471 * \param[in] channel External Interrupt channel index to check
mbed_official 579:53297373a894 472 */
mbed_official 579:53297373a894 473 static inline void extint_chan_clear_detected(
mbed_official 579:53297373a894 474 const uint8_t channel)
mbed_official 579:53297373a894 475 {
mbed_official 579:53297373a894 476 Eic *const eic_module = _extint_get_eic_from_channel(channel);
mbed_official 579:53297373a894 477 uint32_t eic_mask = (1UL << (channel % 32));
mbed_official 579:53297373a894 478
mbed_official 579:53297373a894 479 eic_module->INTFLAG.reg = eic_mask;
mbed_official 579:53297373a894 480 }
mbed_official 579:53297373a894 481
mbed_official 579:53297373a894 482 /** @} */
mbed_official 579:53297373a894 483
mbed_official 579:53297373a894 484 /** \name Detection Testing and Clearing (NMI)
mbed_official 579:53297373a894 485 * @{
mbed_official 579:53297373a894 486 */
mbed_official 579:53297373a894 487
mbed_official 579:53297373a894 488 /**
mbed_official 579:53297373a894 489 * \brief Retrieves the edge detection state of a configured NMI channel.
mbed_official 579:53297373a894 490 *
mbed_official 579:53297373a894 491 * Reads the current state of a configured NMI channel, and determines
mbed_official 579:53297373a894 492 * if the detection criteria of the NMI channel has been met.
mbed_official 579:53297373a894 493 *
mbed_official 579:53297373a894 494 * \param[in] nmi_channel External Interrupt NMI channel index to check
mbed_official 579:53297373a894 495 *
mbed_official 579:53297373a894 496 * \return Status of the requested NMI channel's edge detection state.
mbed_official 579:53297373a894 497 * \retval true If the NMI channel's edge/level detection criteria was met
mbed_official 579:53297373a894 498 * \retval false If the NMI channel has not detected its configured criteria
mbed_official 579:53297373a894 499 */
mbed_official 579:53297373a894 500 static inline bool extint_nmi_is_detected(
mbed_official 579:53297373a894 501 const uint8_t nmi_channel)
mbed_official 579:53297373a894 502 {
mbed_official 579:53297373a894 503 Eic *const eic_module = _extint_get_eic_from_nmi(nmi_channel);
mbed_official 579:53297373a894 504
mbed_official 579:53297373a894 505 return (eic_module->NMIFLAG.reg & EIC_NMIFLAG_NMI);
mbed_official 579:53297373a894 506 }
mbed_official 579:53297373a894 507
mbed_official 579:53297373a894 508 /**
mbed_official 579:53297373a894 509 * \brief Clears the edge detection state of a configured NMI channel.
mbed_official 579:53297373a894 510 *
mbed_official 579:53297373a894 511 * Clears the current state of a configured NMI channel, readying it for
mbed_official 579:53297373a894 512 * the next level or edge detection.
mbed_official 579:53297373a894 513 *
mbed_official 579:53297373a894 514 * \param[in] nmi_channel External Interrupt NMI channel index to check
mbed_official 579:53297373a894 515 */
mbed_official 579:53297373a894 516 static inline void extint_nmi_clear_detected(
mbed_official 579:53297373a894 517 const uint8_t nmi_channel)
mbed_official 579:53297373a894 518 {
mbed_official 579:53297373a894 519 Eic *const eic_module = _extint_get_eic_from_nmi(nmi_channel);
mbed_official 579:53297373a894 520
mbed_official 579:53297373a894 521 eic_module->NMIFLAG.reg = EIC_NMIFLAG_NMI;
mbed_official 579:53297373a894 522 }
mbed_official 579:53297373a894 523
mbed_official 579:53297373a894 524 /** @} */
mbed_official 579:53297373a894 525
mbed_official 579:53297373a894 526 #ifdef __cplusplus
mbed_official 579:53297373a894 527 }
mbed_official 579:53297373a894 528 #endif
mbed_official 579:53297373a894 529
mbed_official 579:53297373a894 530 /** @} */
mbed_official 579:53297373a894 531 // TEMP: Commented by V
mbed_official 579:53297373a894 532 //#if EXTINT_CALLBACK_MODE == true
mbed_official 579:53297373a894 533 # include "extint_callback.h"
mbed_official 579:53297373a894 534 //#endif
mbed_official 579:53297373a894 535
mbed_official 579:53297373a894 536 /**
mbed_official 579:53297373a894 537 * \page asfdoc_sam0_extint_extra Extra Information for EXTINT Driver
mbed_official 579:53297373a894 538 *
mbed_official 579:53297373a894 539 * \section asfdoc_sam0_extint_extra_acronyms Acronyms
mbed_official 579:53297373a894 540 * The table below presents the acronyms used in this module:
mbed_official 579:53297373a894 541 *
mbed_official 579:53297373a894 542 * <table>
mbed_official 579:53297373a894 543 * <tr>
mbed_official 579:53297373a894 544 * <th>Acronym</th>
mbed_official 579:53297373a894 545 * <th>Description</th>
mbed_official 579:53297373a894 546 * </tr>
mbed_official 579:53297373a894 547 * <tr>
mbed_official 579:53297373a894 548 * <td>EIC</td>
mbed_official 579:53297373a894 549 * <td>External Interrupt Controller</td>
mbed_official 579:53297373a894 550 * </tr>
mbed_official 579:53297373a894 551 * <tr>
mbed_official 579:53297373a894 552 * <td>MUX</td>
mbed_official 579:53297373a894 553 * <td>Multiplexer</td>
mbed_official 579:53297373a894 554 * </tr>
mbed_official 579:53297373a894 555 * <tr>
mbed_official 579:53297373a894 556 * <td>NMI</td>
mbed_official 579:53297373a894 557 * <td>Non-Maskable Interrupt</td>
mbed_official 579:53297373a894 558 * </tr>
mbed_official 579:53297373a894 559 * </table>
mbed_official 579:53297373a894 560 *
mbed_official 579:53297373a894 561 *
mbed_official 579:53297373a894 562 * \section asfdoc_sam0_extint_extra_dependencies Dependencies
mbed_official 579:53297373a894 563 * This driver has the following dependencies:
mbed_official 579:53297373a894 564 *
mbed_official 579:53297373a894 565 * - \ref asfdoc_sam0_system_pinmux_group "System Pin Multiplexer Driver"
mbed_official 579:53297373a894 566 *
mbed_official 579:53297373a894 567 *
mbed_official 579:53297373a894 568 * \section asfdoc_sam0_extint_extra_errata Errata
mbed_official 579:53297373a894 569 * There are no errata related to this driver.
mbed_official 579:53297373a894 570 *
mbed_official 579:53297373a894 571 *
mbed_official 579:53297373a894 572 * \section asfdoc_sam0_extint_extra_history Module History
mbed_official 579:53297373a894 573 * An overview of the module history is presented in the table below, with
mbed_official 579:53297373a894 574 * details on the enhancements and fixes made to the module since its first
mbed_official 579:53297373a894 575 * release. The current version of this corresponds to the newest version in
mbed_official 579:53297373a894 576 * the table.
mbed_official 579:53297373a894 577 *
mbed_official 579:53297373a894 578 * <table>
mbed_official 579:53297373a894 579 * <tr>
mbed_official 579:53297373a894 580 * <th>Changelog</th>
mbed_official 579:53297373a894 581 * </tr>
mbed_official 579:53297373a894 582 * <tr>
mbed_official 579:53297373a894 583 * <td>Add SAML21 support</td>
mbed_official 579:53297373a894 584 * </tr>
mbed_official 579:53297373a894 585 * <tr>
mbed_official 579:53297373a894 586 * <td>Add SAMR21 support</td>
mbed_official 579:53297373a894 587 * </tr>
mbed_official 579:53297373a894 588 * <tr>
mbed_official 579:53297373a894 589 * <td>
mbed_official 579:53297373a894 590 * \li Driver updated to follow driver type convention.
mbed_official 579:53297373a894 591 * \li Removed \c %extint_reset(), \c %extint_disable() and
mbed_official 579:53297373a894 592 * \c extint_enable() functions. Added internal function
mbed_official 579:53297373a894 593 * \c %_system_extint_init().
mbed_official 579:53297373a894 594 * \li Added configuration EXTINT_CLOCK_SOURCE in conf_extint.h.
mbed_official 579:53297373a894 595 * \li Removed configuration EXTINT_CALLBACKS_MAX in conf_extint.h, and
mbed_official 579:53297373a894 596 * added channel parameter in the register functions
mbed_official 579:53297373a894 597 * \c %extint_register_callback() and \c %extint_unregister_callback().
mbed_official 579:53297373a894 598 * </td>
mbed_official 579:53297373a894 599 * </tr>
mbed_official 579:53297373a894 600 * <tr>
mbed_official 579:53297373a894 601 * <td>Updated interrupt handler to clear interrupt flag before calling
mbed_official 579:53297373a894 602 * callback function.</td>
mbed_official 579:53297373a894 603 * </tr>
mbed_official 579:53297373a894 604 * <tr>
mbed_official 579:53297373a894 605 * <td>Updated initialization function to also enable the digital interface
mbed_official 579:53297373a894 606 * clock to the module if it is disabled.</td>
mbed_official 579:53297373a894 607 * </tr>
mbed_official 579:53297373a894 608 * <tr>
mbed_official 579:53297373a894 609 * <td>Initial Release</td>
mbed_official 579:53297373a894 610 * </tr>
mbed_official 579:53297373a894 611 * </table>
mbed_official 579:53297373a894 612 */
mbed_official 579:53297373a894 613
mbed_official 579:53297373a894 614 /**
mbed_official 579:53297373a894 615 * \page asfdoc_sam0_extint_exqsg Examples for EXTINT Driver
mbed_official 579:53297373a894 616 *
mbed_official 579:53297373a894 617 * This is a list of the available Quick Start guides (QSGs) and example
mbed_official 579:53297373a894 618 * applications for \ref asfdoc_sam0_extint_group.
mbed_official 579:53297373a894 619 * QSGs are simple examples with step-by-step instructions to configure and
mbed_official 579:53297373a894 620 * use this driver in a selection of use cases. Note that QSGs can be compiled
mbed_official 579:53297373a894 621 * as a standalone application or be added to the user application.
mbed_official 579:53297373a894 622 *
mbed_official 579:53297373a894 623 * - \subpage asfdoc_sam0_extint_basic_use_case
mbed_official 579:53297373a894 624 * \if EXTINT_CALLBACK_MODE
mbed_official 579:53297373a894 625 * - \subpage asfdoc_sam0_extint_callback_use_case
mbed_official 579:53297373a894 626 * \endif
mbed_official 579:53297373a894 627 *
mbed_official 579:53297373a894 628 * \page asfdoc_sam0_extint_document_revision_history Document Revision History
mbed_official 579:53297373a894 629 *
mbed_official 579:53297373a894 630 * <table>
mbed_official 579:53297373a894 631 * <tr>
mbed_official 579:53297373a894 632 * <th>Doc. Rev.</td>
mbed_official 579:53297373a894 633 * <th>Date</td>
mbed_official 579:53297373a894 634 * <th>Comments</td>
mbed_official 579:53297373a894 635 * </tr>
mbed_official 579:53297373a894 636 * <tr>
mbed_official 579:53297373a894 637 * <td>E</td>
mbed_official 579:53297373a894 638 * <td>12/2014</td>
mbed_official 579:53297373a894 639 * <td>Added support for SAML21.</td>
mbed_official 579:53297373a894 640 * </tr>
mbed_official 579:53297373a894 641 * <tr>
mbed_official 579:53297373a894 642 * <td>D</td>
mbed_official 579:53297373a894 643 * <td>12/2014</td>
mbed_official 579:53297373a894 644 * <td>Added support for SAMR21 and SAMD10/D11.</td>
mbed_official 579:53297373a894 645 * </tr>
mbed_official 579:53297373a894 646 * <tr>
mbed_official 579:53297373a894 647 * <td>C</td>
mbed_official 579:53297373a894 648 * <td>01/2014</td>
mbed_official 579:53297373a894 649 * <td>Added support for SAMD21.</td>
mbed_official 579:53297373a894 650 * </tr>
mbed_official 579:53297373a894 651 * <tr>
mbed_official 579:53297373a894 652 * <td>B</td>
mbed_official 579:53297373a894 653 * <td>06/2013</td>
mbed_official 579:53297373a894 654 * <td>Added additional documentation on the event system. Corrected
mbed_official 579:53297373a894 655 * documentation typos.</td>
mbed_official 579:53297373a894 656 * </tr>
mbed_official 579:53297373a894 657 * <tr>
mbed_official 579:53297373a894 658 * <td>A</td>
mbed_official 579:53297373a894 659 * <td>06/2013</td>
mbed_official 579:53297373a894 660 * <td>Initial release</td>
mbed_official 579:53297373a894 661 * </tr>
mbed_official 579:53297373a894 662 * </table>
mbed_official 579:53297373a894 663 */
mbed_official 579:53297373a894 664
mbed_official 579:53297373a894 665 #endif