mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Wed Jul 01 09:45:11 2015 +0100
Revision:
579:53297373a894
Child:
592:a274ee790e56
Synchronized with git revision d5b4d2ab9c47edb4dc5776e7177b0c2263459081

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

Initial version of drivers for SAMR21

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 579:53297373a894 1 /**
mbed_official 579:53297373a894 2 * \file
mbed_official 579:53297373a894 3 *
mbed_official 579:53297373a894 4 * \brief SAM External Interrupt Driver
mbed_official 579:53297373a894 5 *
mbed_official 579:53297373a894 6 * Copyright (C) 2012-2014 Atmel Corporation. All rights reserved.
mbed_official 579:53297373a894 7 *
mbed_official 579:53297373a894 8 * \asf_license_start
mbed_official 579:53297373a894 9 *
mbed_official 579:53297373a894 10 * \page License
mbed_official 579:53297373a894 11 *
mbed_official 579:53297373a894 12 * Redistribution and use in source and binary forms, with or without
mbed_official 579:53297373a894 13 * modification, are permitted provided that the following conditions are met:
mbed_official 579:53297373a894 14 *
mbed_official 579:53297373a894 15 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 579:53297373a894 16 * this list of conditions and the following disclaimer.
mbed_official 579:53297373a894 17 *
mbed_official 579:53297373a894 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 579:53297373a894 19 * this list of conditions and the following disclaimer in the documentation
mbed_official 579:53297373a894 20 * and/or other materials provided with the distribution.
mbed_official 579:53297373a894 21 *
mbed_official 579:53297373a894 22 * 3. The name of Atmel may not be used to endorse or promote products derived
mbed_official 579:53297373a894 23 * from this software without specific prior written permission.
mbed_official 579:53297373a894 24 *
mbed_official 579:53297373a894 25 * 4. This software may only be redistributed and used in connection with an
mbed_official 579:53297373a894 26 * Atmel microcontroller product.
mbed_official 579:53297373a894 27 *
mbed_official 579:53297373a894 28 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
mbed_official 579:53297373a894 29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
mbed_official 579:53297373a894 30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
mbed_official 579:53297373a894 31 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
mbed_official 579:53297373a894 32 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 579:53297373a894 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
mbed_official 579:53297373a894 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
mbed_official 579:53297373a894 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
mbed_official 579:53297373a894 36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
mbed_official 579:53297373a894 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbed_official 579:53297373a894 38 * POSSIBILITY OF SUCH DAMAGE.
mbed_official 579:53297373a894 39 *
mbed_official 579:53297373a894 40 * \asf_license_stop
mbed_official 579:53297373a894 41 *
mbed_official 579:53297373a894 42 */
mbed_official 579:53297373a894 43 /**
mbed_official 579:53297373a894 44 * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
mbed_official 579:53297373a894 45 */
mbed_official 579:53297373a894 46 #include <system.h>
mbed_official 579:53297373a894 47 #include <system_interrupt.h>
mbed_official 579:53297373a894 48 #include <extint.h>
mbed_official 579:53297373a894 49 #include <conf_extint.h>
mbed_official 579:53297373a894 50
mbed_official 579:53297373a894 51 #if !defined(EXTINT_CLOCK_SOURCE) || defined(__DOXYGEN__)
mbed_official 579:53297373a894 52 # warning EXTINT_CLOCK_SOURCE is not defined, assuming GCLK_GENERATOR_0.
mbed_official 579:53297373a894 53
mbed_official 579:53297373a894 54 /** Configuration option, setting the EIC clock source which can be used for
mbed_official 579:53297373a894 55 * EIC edge detection or filtering. This option may be overridden in the module
mbed_official 579:53297373a894 56 * configuration header file \c conf_extint.h.
mbed_official 579:53297373a894 57 */
mbed_official 579:53297373a894 58 # define EXTINT_CLOCK_SOURCE GCLK_GENERATOR_0
mbed_official 579:53297373a894 59 #endif
mbed_official 579:53297373a894 60
mbed_official 579:53297373a894 61 /**
mbed_official 579:53297373a894 62 * \internal
mbed_official 579:53297373a894 63 * Internal driver device instance struct.
mbed_official 579:53297373a894 64 */
mbed_official 579:53297373a894 65 struct _extint_module _extint_dev;
mbed_official 579:53297373a894 66
mbed_official 579:53297373a894 67 /**
mbed_official 579:53297373a894 68 * \brief Determin if the general clock is required
mbed_official 579:53297373a894 69 *
mbed_official 579:53297373a894 70 * \param[in] filter_input_signal Filter the raw input signal to prevent noise
mbed_official 579:53297373a894 71 * \param[in] detection_criteria Edge detection mode to use (\ref extint_detect)
mbed_official 579:53297373a894 72 */
mbed_official 579:53297373a894 73 #define _extint_is_gclk_required(filter_input_signal, detection_criteria) \
mbed_official 579:53297373a894 74 ((filter_input_signal) ? true : (\
mbed_official 579:53297373a894 75 (EXTINT_DETECT_RISING == (detection_criteria)) ? true : (\
mbed_official 579:53297373a894 76 (EXTINT_DETECT_FALLING == (detection_criteria)) ? true : (\
mbed_official 579:53297373a894 77 (EXTINT_DETECT_BOTH == (detection_criteria)) ? true : false))))
mbed_official 579:53297373a894 78
mbed_official 579:53297373a894 79 static void _extint_enable(void);
mbed_official 579:53297373a894 80 static void _extint_disable(void);
mbed_official 579:53297373a894 81
mbed_official 579:53297373a894 82 /**
mbed_official 579:53297373a894 83 * \brief Determines if the hardware module(s) are currently synchronizing to the bus.
mbed_official 579:53297373a894 84 *
mbed_official 579:53297373a894 85 * Checks to see if the underlying hardware peripheral module(s) are currently
mbed_official 579:53297373a894 86 * synchronizing across multiple clock domains to the hardware bus, This
mbed_official 579:53297373a894 87 * function can be used to delay further operations on a module until such time
mbed_official 579:53297373a894 88 * that it is ready, to prevent blocking delays for synchronization in the
mbed_official 579:53297373a894 89 * user application.
mbed_official 579:53297373a894 90 *
mbed_official 579:53297373a894 91 * \return Synchronization status of the underlying hardware module(s).
mbed_official 579:53297373a894 92 *
mbed_official 579:53297373a894 93 * \retval true If the module synchronization is ongoing
mbed_official 579:53297373a894 94 * \retval false If the module has completed synchronization
mbed_official 579:53297373a894 95 */
mbed_official 579:53297373a894 96 static inline bool extint_is_syncing(void)
mbed_official 579:53297373a894 97 {
mbed_official 579:53297373a894 98 Eic *const eics[EIC_INST_NUM] = EIC_INSTS;
mbed_official 579:53297373a894 99
mbed_official 579:53297373a894 100 for (uint32_t i = 0; i < EIC_INST_NUM; i++) {
mbed_official 579:53297373a894 101 if (eics[i]->STATUS.reg & EIC_STATUS_SYNCBUSY) {
mbed_official 579:53297373a894 102 return true;
mbed_official 579:53297373a894 103 }
mbed_official 579:53297373a894 104 }
mbed_official 579:53297373a894 105 return false;
mbed_official 579:53297373a894 106 }
mbed_official 579:53297373a894 107 /**
mbed_official 579:53297373a894 108 * \internal
mbed_official 579:53297373a894 109 * \brief Initializes and enables the External Interrupt driver.
mbed_official 579:53297373a894 110 *
mbed_official 579:53297373a894 111 * Enable the clocks used by External Interrupt driver.
mbed_official 579:53297373a894 112 *
mbed_official 579:53297373a894 113 * Resets the External Interrupt driver, resetting all hardware
mbed_official 579:53297373a894 114 * module registers to their power-on defaults, then enable it for further use.
mbed_official 579:53297373a894 115 *
mbed_official 579:53297373a894 116 * Reset the callback list if callback mode is used.
mbed_official 579:53297373a894 117 *
mbed_official 579:53297373a894 118 * This function must be called before attempting to use any NMI or standard
mbed_official 579:53297373a894 119 * external interrupt channel functions.
mbed_official 579:53297373a894 120 *
mbed_official 579:53297373a894 121 * \note When SYSTEM module is used, this function will be invoked by
mbed_official 579:53297373a894 122 * \ref system_init() automatically if the module is included.
mbed_official 579:53297373a894 123 */
mbed_official 579:53297373a894 124 void _system_extint_init(void);
mbed_official 579:53297373a894 125 void _system_extint_init(void)
mbed_official 579:53297373a894 126 {
mbed_official 579:53297373a894 127 Eic *const eics[EIC_INST_NUM] = EIC_INSTS;
mbed_official 579:53297373a894 128
mbed_official 579:53297373a894 129 /* Turn on the digital interface clock */
mbed_official 579:53297373a894 130 system_apb_clock_set_mask(SYSTEM_CLOCK_APB_APBA, PM_APBAMASK_EIC);
mbed_official 579:53297373a894 131
mbed_official 579:53297373a894 132 /* Configure the generic clock for the module and enable it */
mbed_official 579:53297373a894 133 struct system_gclk_chan_config gclk_chan_conf;
mbed_official 579:53297373a894 134 system_gclk_chan_get_config_defaults(&gclk_chan_conf);
mbed_official 579:53297373a894 135 gclk_chan_conf.source_generator = EXTINT_CLOCK_SOURCE;
mbed_official 579:53297373a894 136 system_gclk_chan_set_config(EIC_GCLK_ID, &gclk_chan_conf);
mbed_official 579:53297373a894 137
mbed_official 579:53297373a894 138 /* Enable the clock anyway, since when needed it will be requested
mbed_official 579:53297373a894 139 * by External Interrupt driver */
mbed_official 579:53297373a894 140 system_gclk_chan_enable(EIC_GCLK_ID);
mbed_official 579:53297373a894 141
mbed_official 579:53297373a894 142 /* Reset all EIC hardware modules. */
mbed_official 579:53297373a894 143 for (uint32_t i = 0; i < EIC_INST_NUM; i++) {
mbed_official 579:53297373a894 144 eics[i]->CTRL.reg |= EIC_CTRL_SWRST;
mbed_official 579:53297373a894 145 }
mbed_official 579:53297373a894 146
mbed_official 579:53297373a894 147 while (extint_is_syncing()) {
mbed_official 579:53297373a894 148 /* Wait for all hardware modules to complete synchronization */
mbed_official 579:53297373a894 149 }
mbed_official 579:53297373a894 150
mbed_official 579:53297373a894 151 /* Reset the software module */
mbed_official 579:53297373a894 152 // TEMP: Commented by V
mbed_official 579:53297373a894 153 //#if EXTINT_CALLBACK_MODE == true
mbed_official 579:53297373a894 154 /* Clear callback registration table */
mbed_official 579:53297373a894 155 for (uint8_t j = 0; j < EIC_NUMBER_OF_INTERRUPTS; j++) {
mbed_official 579:53297373a894 156 _extint_dev.callbacks[j] = NULL;
mbed_official 579:53297373a894 157 }
mbed_official 579:53297373a894 158 system_interrupt_enable(SYSTEM_INTERRUPT_MODULE_EIC);
mbed_official 579:53297373a894 159 //#endif
mbed_official 579:53297373a894 160
mbed_official 579:53297373a894 161 /* Enables the driver for further use */
mbed_official 579:53297373a894 162 _extint_enable();
mbed_official 579:53297373a894 163 }
mbed_official 579:53297373a894 164
mbed_official 579:53297373a894 165 /**
mbed_official 579:53297373a894 166 * \internal
mbed_official 579:53297373a894 167 * \brief Enables the External Interrupt driver.
mbed_official 579:53297373a894 168 *
mbed_official 579:53297373a894 169 * Enables EIC modules.
mbed_official 579:53297373a894 170 * Registered callback list will not be affected if callback mode is used.
mbed_official 579:53297373a894 171 */
mbed_official 579:53297373a894 172 void _extint_enable(void)
mbed_official 579:53297373a894 173 {
mbed_official 579:53297373a894 174 Eic *const eics[EIC_INST_NUM] = EIC_INSTS;
mbed_official 579:53297373a894 175
mbed_official 579:53297373a894 176 /* Enable all EIC hardware modules. */
mbed_official 579:53297373a894 177 for (uint32_t i = 0; i < EIC_INST_NUM; i++) {
mbed_official 579:53297373a894 178 eics[i]->CTRL.reg |= EIC_CTRL_ENABLE;
mbed_official 579:53297373a894 179 }
mbed_official 579:53297373a894 180
mbed_official 579:53297373a894 181 while (extint_is_syncing()) {
mbed_official 579:53297373a894 182 /* Wait for all hardware modules to complete synchronization */
mbed_official 579:53297373a894 183 }
mbed_official 579:53297373a894 184 }
mbed_official 579:53297373a894 185
mbed_official 579:53297373a894 186 /**
mbed_official 579:53297373a894 187 * \internal
mbed_official 579:53297373a894 188 * \brief Disables the External Interrupt driver.
mbed_official 579:53297373a894 189 *
mbed_official 579:53297373a894 190 * Disables EIC modules that were previously started via a call to
mbed_official 579:53297373a894 191 * \ref _extint_enable().
mbed_official 579:53297373a894 192 * Registered callback list will not be affected if callback mode is used.
mbed_official 579:53297373a894 193 */
mbed_official 579:53297373a894 194 void _extint_disable(void)
mbed_official 579:53297373a894 195 {
mbed_official 579:53297373a894 196 Eic *const eics[EIC_INST_NUM] = EIC_INSTS;
mbed_official 579:53297373a894 197
mbed_official 579:53297373a894 198 /* Disable all EIC hardware modules. */
mbed_official 579:53297373a894 199 for (uint32_t i = 0; i < EIC_INST_NUM; i++) {
mbed_official 579:53297373a894 200 eics[i]->CTRL.reg &= ~EIC_CTRL_ENABLE;
mbed_official 579:53297373a894 201 }
mbed_official 579:53297373a894 202
mbed_official 579:53297373a894 203 while (extint_is_syncing()) {
mbed_official 579:53297373a894 204 /* Wait for all hardware modules to complete synchronization */
mbed_official 579:53297373a894 205 }
mbed_official 579:53297373a894 206 }
mbed_official 579:53297373a894 207
mbed_official 579:53297373a894 208 /**
mbed_official 579:53297373a894 209 * \brief Initializes an External Interrupt channel configuration structure to defaults.
mbed_official 579:53297373a894 210 *
mbed_official 579:53297373a894 211 * Initializes a given External Interrupt channel configuration structure to a
mbed_official 579:53297373a894 212 * set of known default values. This function should be called on all new
mbed_official 579:53297373a894 213 * instances of these configuration structures before being modified by the
mbed_official 579:53297373a894 214 * user application.
mbed_official 579:53297373a894 215 *
mbed_official 579:53297373a894 216 * The default configuration is as follows:
mbed_official 579:53297373a894 217 * \li Wake the device if an edge detection occurs whilst in sleep
mbed_official 579:53297373a894 218 * \li Input filtering disabled
mbed_official 579:53297373a894 219 * \li Internal pull-up enabled
mbed_official 579:53297373a894 220 * \li Detect falling edges of a signal
mbed_official 579:53297373a894 221 *
mbed_official 579:53297373a894 222 * \param[out] config Configuration structure to initialize to default values
mbed_official 579:53297373a894 223 */
mbed_official 579:53297373a894 224 void extint_chan_get_config_defaults(
mbed_official 579:53297373a894 225 struct extint_chan_conf *const config)
mbed_official 579:53297373a894 226 {
mbed_official 579:53297373a894 227 /* Sanity check arguments */
mbed_official 579:53297373a894 228 Assert(config);
mbed_official 579:53297373a894 229
mbed_official 579:53297373a894 230 /* Default configuration values */
mbed_official 579:53297373a894 231 config->gpio_pin = 0;
mbed_official 579:53297373a894 232 config->gpio_pin_mux = 0;
mbed_official 579:53297373a894 233 config->gpio_pin_pull = EXTINT_PULL_UP;
mbed_official 579:53297373a894 234 config->wake_if_sleeping = true;
mbed_official 579:53297373a894 235 config->filter_input_signal = false;
mbed_official 579:53297373a894 236 config->detection_criteria = EXTINT_DETECT_FALLING;
mbed_official 579:53297373a894 237 }
mbed_official 579:53297373a894 238
mbed_official 579:53297373a894 239 /**
mbed_official 579:53297373a894 240 * \brief Writes an External Interrupt channel configuration to the hardware module.
mbed_official 579:53297373a894 241 *
mbed_official 579:53297373a894 242 * Writes out a given configuration of an External Interrupt channel
mbed_official 579:53297373a894 243 * configuration to the hardware module. If the channel is already configured,
mbed_official 579:53297373a894 244 * the new configuration will replace the existing one.
mbed_official 579:53297373a894 245 *
mbed_official 579:53297373a894 246 * \param[in] channel External Interrupt channel to configure
mbed_official 579:53297373a894 247 * \param[in] config Configuration settings for the channel
mbed_official 579:53297373a894 248
mbed_official 579:53297373a894 249 */
mbed_official 579:53297373a894 250 void extint_chan_set_config(
mbed_official 579:53297373a894 251 const uint8_t channel,
mbed_official 579:53297373a894 252 const struct extint_chan_conf *const config)
mbed_official 579:53297373a894 253 {
mbed_official 579:53297373a894 254 /* Sanity check arguments */
mbed_official 579:53297373a894 255 Assert(config);
mbed_official 579:53297373a894 256 /* Sanity check clock requirements */
mbed_official 579:53297373a894 257 Assert(!(!system_gclk_gen_is_enabled(EXTINT_CLOCK_SOURCE) &&
mbed_official 579:53297373a894 258 _extint_is_gclk_required(config->filter_input_signal,
mbed_official 579:53297373a894 259 config->detection_criteria)));
mbed_official 579:53297373a894 260
mbed_official 579:53297373a894 261 struct system_pinmux_config pinmux_config;
mbed_official 579:53297373a894 262 system_pinmux_get_config_defaults(&pinmux_config);
mbed_official 579:53297373a894 263
mbed_official 579:53297373a894 264 pinmux_config.mux_position = config->gpio_pin_mux;
mbed_official 579:53297373a894 265 pinmux_config.direction = SYSTEM_PINMUX_PIN_DIR_INPUT;
mbed_official 579:53297373a894 266 pinmux_config.input_pull = (enum system_pinmux_pin_pull)config->gpio_pin_pull;
mbed_official 579:53297373a894 267 system_pinmux_pin_set_config(config->gpio_pin, &pinmux_config);
mbed_official 579:53297373a894 268
mbed_official 579:53297373a894 269 /* Get a pointer to the module hardware instance */
mbed_official 579:53297373a894 270 Eic *const EIC_module = _extint_get_eic_from_channel(channel);
mbed_official 579:53297373a894 271
mbed_official 579:53297373a894 272 uint32_t config_pos = (4 * (channel % 8));
mbed_official 579:53297373a894 273 uint32_t new_config;
mbed_official 579:53297373a894 274
mbed_official 579:53297373a894 275 /* Determine the channel's new edge detection configuration */
mbed_official 579:53297373a894 276 new_config = (config->detection_criteria << EIC_CONFIG_SENSE0_Pos);
mbed_official 579:53297373a894 277
mbed_official 579:53297373a894 278 /* Enable the hardware signal filter if requested in the config */
mbed_official 579:53297373a894 279 if (config->filter_input_signal) {
mbed_official 579:53297373a894 280 new_config |= EIC_CONFIG_FILTEN0;
mbed_official 579:53297373a894 281 }
mbed_official 579:53297373a894 282
mbed_official 579:53297373a894 283 /* Clear the existing and set the new channel configuration */
mbed_official 579:53297373a894 284 EIC_module->CONFIG[channel / 8].reg
mbed_official 579:53297373a894 285 = (EIC_module->CONFIG[channel / 8].reg &
mbed_official 579:53297373a894 286 ~((EIC_CONFIG_SENSE0_Msk | EIC_CONFIG_FILTEN0) << config_pos)) |
mbed_official 579:53297373a894 287 (new_config << config_pos);
mbed_official 579:53297373a894 288
mbed_official 579:53297373a894 289 /* Set the channel's new wake up mode setting */
mbed_official 579:53297373a894 290 if (config->wake_if_sleeping) {
mbed_official 579:53297373a894 291 EIC_module->WAKEUP.reg |= (1UL << channel);
mbed_official 579:53297373a894 292 } else {
mbed_official 579:53297373a894 293 EIC_module->WAKEUP.reg &= ~(1UL << channel);
mbed_official 579:53297373a894 294 }
mbed_official 579:53297373a894 295 }
mbed_official 579:53297373a894 296
mbed_official 579:53297373a894 297 /**
mbed_official 579:53297373a894 298 * \brief Writes an External Interrupt NMI channel configuration to the hardware module.
mbed_official 579:53297373a894 299 *
mbed_official 579:53297373a894 300 * Writes out a given configuration of an External Interrupt NMI channel
mbed_official 579:53297373a894 301 * configuration to the hardware module. If the channel is already configured,
mbed_official 579:53297373a894 302 * the new configuration will replace the existing one.
mbed_official 579:53297373a894 303 *
mbed_official 579:53297373a894 304 * \param[in] nmi_channel External Interrupt NMI channel to configure
mbed_official 579:53297373a894 305 * \param[in] config Configuration settings for the channel
mbed_official 579:53297373a894 306 *
mbed_official 579:53297373a894 307 * \returns Status code indicating the success or failure of the request.
mbed_official 579:53297373a894 308 * \retval STATUS_OK Configuration succeeded
mbed_official 579:53297373a894 309 * \retval STATUS_ERR_PIN_MUX_INVALID An invalid pinmux value was supplied
mbed_official 579:53297373a894 310 * \retval STATUS_ERR_BAD_FORMAT An invalid detection mode was requested
mbed_official 579:53297373a894 311 */
mbed_official 579:53297373a894 312 enum status_code extint_nmi_set_config(
mbed_official 579:53297373a894 313 const uint8_t nmi_channel,
mbed_official 579:53297373a894 314 const struct extint_nmi_conf *const config)
mbed_official 579:53297373a894 315 {
mbed_official 579:53297373a894 316 /* Sanity check arguments */
mbed_official 579:53297373a894 317 Assert(config);
mbed_official 579:53297373a894 318 /* Sanity check clock requirements */
mbed_official 579:53297373a894 319 Assert(!(!system_gclk_gen_is_enabled(EXTINT_CLOCK_SOURCE) &&
mbed_official 579:53297373a894 320 _extint_is_gclk_required(config->filter_input_signal,
mbed_official 579:53297373a894 321 config->detection_criteria)));
mbed_official 579:53297373a894 322
mbed_official 579:53297373a894 323 struct system_pinmux_config pinmux_config;
mbed_official 579:53297373a894 324 system_pinmux_get_config_defaults(&pinmux_config);
mbed_official 579:53297373a894 325
mbed_official 579:53297373a894 326 pinmux_config.mux_position = config->gpio_pin_mux;
mbed_official 579:53297373a894 327 pinmux_config.direction = SYSTEM_PINMUX_PIN_DIR_INPUT;
mbed_official 579:53297373a894 328 pinmux_config.input_pull = SYSTEM_PINMUX_PIN_PULL_UP;
mbed_official 579:53297373a894 329 pinmux_config.input_pull = (enum system_pinmux_pin_pull)config->gpio_pin_pull;
mbed_official 579:53297373a894 330 system_pinmux_pin_set_config(config->gpio_pin, &pinmux_config);
mbed_official 579:53297373a894 331
mbed_official 579:53297373a894 332 /* Get a pointer to the module hardware instance */
mbed_official 579:53297373a894 333 Eic *const EIC_module = _extint_get_eic_from_channel(nmi_channel);
mbed_official 579:53297373a894 334
mbed_official 579:53297373a894 335 uint32_t new_config;
mbed_official 579:53297373a894 336
mbed_official 579:53297373a894 337 /* Determine the NMI's new edge detection configuration */
mbed_official 579:53297373a894 338 new_config = (config->detection_criteria << EIC_NMICTRL_NMISENSE_Pos);
mbed_official 579:53297373a894 339
mbed_official 579:53297373a894 340 /* Enable the hardware signal filter if requested in the config */
mbed_official 579:53297373a894 341 if (config->filter_input_signal) {
mbed_official 579:53297373a894 342 new_config |= EIC_NMICTRL_NMIFILTEN;
mbed_official 579:53297373a894 343 }
mbed_official 579:53297373a894 344
mbed_official 579:53297373a894 345 /* Disable EIC and general clock to configure NMI */
mbed_official 579:53297373a894 346 _extint_disable();
mbed_official 579:53297373a894 347 system_gclk_chan_disable(EIC_GCLK_ID);
mbed_official 579:53297373a894 348
mbed_official 579:53297373a894 349 EIC_module->NMICTRL.reg = new_config;
mbed_official 579:53297373a894 350
mbed_official 579:53297373a894 351 /* Enable the general clock and EIC after configure NMI */
mbed_official 579:53297373a894 352 system_gclk_chan_enable(EIC_GCLK_ID);
mbed_official 579:53297373a894 353 _extint_enable();
mbed_official 579:53297373a894 354
mbed_official 579:53297373a894 355 return STATUS_OK;
mbed_official 579:53297373a894 356 }
mbed_official 579:53297373a894 357
mbed_official 579:53297373a894 358 /**
mbed_official 579:53297373a894 359 * \brief Enables an External Interrupt event output.
mbed_official 579:53297373a894 360 *
mbed_official 579:53297373a894 361 * Enables one or more output events from the External Interrupt module. See
mbed_official 579:53297373a894 362 * \ref extint_events "here" for a list of events this module supports.
mbed_official 579:53297373a894 363 *
mbed_official 579:53297373a894 364 * \note Events cannot be altered while the module is enabled.
mbed_official 579:53297373a894 365 *
mbed_official 579:53297373a894 366 * \param[in] events Struct containing flags of events to enable
mbed_official 579:53297373a894 367 */
mbed_official 579:53297373a894 368 void extint_enable_events(
mbed_official 579:53297373a894 369 struct extint_events *const events)
mbed_official 579:53297373a894 370 {
mbed_official 579:53297373a894 371 /* Sanity check arguments */
mbed_official 579:53297373a894 372 Assert(events);
mbed_official 579:53297373a894 373
mbed_official 579:53297373a894 374 /* Array of available EICs. */
mbed_official 579:53297373a894 375 Eic *const eics[EIC_INST_NUM] = EIC_INSTS;
mbed_official 579:53297373a894 376
mbed_official 579:53297373a894 377 /* Update the event control register for each physical EIC instance */
mbed_official 579:53297373a894 378 for (uint32_t i = 0; i < EIC_INST_NUM; i++) {
mbed_official 579:53297373a894 379 uint32_t event_mask = 0;
mbed_official 579:53297373a894 380
mbed_official 579:53297373a894 381 /* Create an enable mask for the current EIC module */
mbed_official 579:53297373a894 382 for (uint32_t j = 0; j < 32; j++) {
mbed_official 579:53297373a894 383 if (events->generate_event_on_detect[(32 * i) + j]) {
mbed_official 579:53297373a894 384 event_mask |= (1UL << j);
mbed_official 579:53297373a894 385 }
mbed_official 579:53297373a894 386 }
mbed_official 579:53297373a894 387
mbed_official 579:53297373a894 388 /* Enable the masked events */
mbed_official 579:53297373a894 389 eics[i]->EVCTRL.reg |= event_mask;
mbed_official 579:53297373a894 390 }
mbed_official 579:53297373a894 391 }
mbed_official 579:53297373a894 392
mbed_official 579:53297373a894 393 /**
mbed_official 579:53297373a894 394 * \brief Disables an External Interrupt event output.
mbed_official 579:53297373a894 395 *
mbed_official 579:53297373a894 396 * Disables one or more output events from the External Interrupt module. See
mbed_official 579:53297373a894 397 * \ref extint_events "here" for a list of events this module supports.
mbed_official 579:53297373a894 398 *
mbed_official 579:53297373a894 399 * \note Events cannot be altered while the module is enabled.
mbed_official 579:53297373a894 400 *
mbed_official 579:53297373a894 401 * \param[in] events Struct containing flags of events to disable
mbed_official 579:53297373a894 402 */
mbed_official 579:53297373a894 403 void extint_disable_events(
mbed_official 579:53297373a894 404 struct extint_events *const events)
mbed_official 579:53297373a894 405 {
mbed_official 579:53297373a894 406 /* Sanity check arguments */
mbed_official 579:53297373a894 407 Assert(events);
mbed_official 579:53297373a894 408
mbed_official 579:53297373a894 409 /* Array of available EICs. */
mbed_official 579:53297373a894 410 Eic *const eics[EIC_INST_NUM] = EIC_INSTS;
mbed_official 579:53297373a894 411
mbed_official 579:53297373a894 412 /* Update the event control register for each physical EIC instance */
mbed_official 579:53297373a894 413 for (uint32_t i = 0; i < EIC_INST_NUM; i++) {
mbed_official 579:53297373a894 414 uint32_t event_mask = 0;
mbed_official 579:53297373a894 415
mbed_official 579:53297373a894 416 /* Create a disable mask for the current EIC module */
mbed_official 579:53297373a894 417 for (uint32_t j = 0; j < 32; j++) {
mbed_official 579:53297373a894 418 if (events->generate_event_on_detect[(32 * i) + j]) {
mbed_official 579:53297373a894 419 event_mask |= (1UL << j);
mbed_official 579:53297373a894 420 }
mbed_official 579:53297373a894 421 }
mbed_official 579:53297373a894 422
mbed_official 579:53297373a894 423 /* Disable the masked events */
mbed_official 579:53297373a894 424 eics[i]->EVCTRL.reg &= ~event_mask;
mbed_official 579:53297373a894 425 }
mbed_official 579:53297373a894 426 }