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 "extint.h"
mbed_official 579:53297373a894 47 #include "extint_callback.h"
mbed_official 579:53297373a894 48
mbed_official 579:53297373a894 49 /**
mbed_official 579:53297373a894 50 * \internal
mbed_official 579:53297373a894 51 * Internal driver device instance struct, declared in the main module driver.
mbed_official 579:53297373a894 52 */
mbed_official 579:53297373a894 53 extern struct _extint_module _extint_dev;
mbed_official 579:53297373a894 54
mbed_official 579:53297373a894 55 /**
mbed_official 579:53297373a894 56 * \internal
mbed_official 579:53297373a894 57 * This is the number of the channel whose callback is currently running
mbed_official 579:53297373a894 58 */
mbed_official 579:53297373a894 59 uint8_t _current_channel;
mbed_official 579:53297373a894 60
mbed_official 579:53297373a894 61 /**
mbed_official 579:53297373a894 62 * \brief Registers an asynchronous callback function with the driver.
mbed_official 579:53297373a894 63 *
mbed_official 579:53297373a894 64 * Registers an asynchronous callback with the EXTINT driver, fired when a
mbed_official 579:53297373a894 65 * channel detects the configured channel detection criteria
mbed_official 579:53297373a894 66 * (e.g. edge or level). Callbacks are fired once for each detected channel.
mbed_official 579:53297373a894 67 *
mbed_official 579:53297373a894 68 * \note NMI channel callbacks cannot be registered via this function; the
mbed_official 579:53297373a894 69 * device's NMI interrupt should be hooked directly in the user
mbed_official 579:53297373a894 70 * application and the NMI flags manually cleared via
mbed_official 579:53297373a894 71 * \ref extint_nmi_clear_detected().
mbed_official 579:53297373a894 72 *
mbed_official 579:53297373a894 73 * \param[in] callback Pointer to the callback function to register
mbed_official 579:53297373a894 74 * \param[in] channel Logical channel to register callback for
mbed_official 579:53297373a894 75 * \param[in] type Type of callback function to register
mbed_official 579:53297373a894 76 *
mbed_official 579:53297373a894 77 * \return Status of the registration operation.
mbed_official 579:53297373a894 78 * \retval STATUS_OK The callback was registered successfully
mbed_official 579:53297373a894 79 * \retval STATUS_ERR_INVALID_ARG If an invalid callback type was supplied
mbed_official 579:53297373a894 80 * \retval STATUS_ERR_ALREADY_INITIALIZED Callback function has been
mbed_official 579:53297373a894 81 * registered, need unregister first
mbed_official 579:53297373a894 82 */
mbed_official 579:53297373a894 83 enum status_code extint_register_callback(
mbed_official 579:53297373a894 84 const extint_callback_t callback,
mbed_official 579:53297373a894 85 const uint8_t channel,
mbed_official 579:53297373a894 86 const enum extint_callback_type type)
mbed_official 579:53297373a894 87 {
mbed_official 579:53297373a894 88 /* Sanity check arguments */
mbed_official 579:53297373a894 89 Assert(callback);
mbed_official 579:53297373a894 90
mbed_official 579:53297373a894 91 if (type != EXTINT_CALLBACK_TYPE_DETECT) {
mbed_official 579:53297373a894 92 Assert(false);
mbed_official 579:53297373a894 93 return STATUS_ERR_INVALID_ARG;
mbed_official 579:53297373a894 94 }
mbed_official 579:53297373a894 95
mbed_official 579:53297373a894 96 if (_extint_dev.callbacks[channel] == NULL) {
mbed_official 579:53297373a894 97 _extint_dev.callbacks[channel] = callback;
mbed_official 579:53297373a894 98 return STATUS_OK;
mbed_official 579:53297373a894 99 } else if (_extint_dev.callbacks[channel] == callback) {
mbed_official 579:53297373a894 100 return STATUS_OK;
mbed_official 579:53297373a894 101 }
mbed_official 579:53297373a894 102
mbed_official 579:53297373a894 103 return STATUS_ERR_ALREADY_INITIALIZED;
mbed_official 579:53297373a894 104 }
mbed_official 579:53297373a894 105
mbed_official 579:53297373a894 106 /**
mbed_official 579:53297373a894 107 * \brief Unregisters an asynchronous callback function with the driver.
mbed_official 579:53297373a894 108 *
mbed_official 579:53297373a894 109 * Unregisters an asynchronous callback with the EXTINT driver, removing it
mbed_official 579:53297373a894 110 * from the internal callback registration table.
mbed_official 579:53297373a894 111 *
mbed_official 579:53297373a894 112 * \param[in] callback Pointer to the callback function to unregister
mbed_official 579:53297373a894 113 * \param[in] channel Logical channel to unregister callback for
mbed_official 579:53297373a894 114 * \param[in] type Type of callback function to unregister
mbed_official 579:53297373a894 115 *
mbed_official 579:53297373a894 116 * \return Status of the de-registration operation.
mbed_official 579:53297373a894 117 * \retval STATUS_OK The callback was Unregistered successfully
mbed_official 579:53297373a894 118 * \retval STATUS_ERR_INVALID_ARG If an invalid callback type was supplied
mbed_official 579:53297373a894 119 * \retval STATUS_ERR_BAD_ADDRESS No matching entry was found in the
mbed_official 579:53297373a894 120 * registration table
mbed_official 579:53297373a894 121 */
mbed_official 579:53297373a894 122 enum status_code extint_unregister_callback(
mbed_official 579:53297373a894 123 const extint_callback_t callback,
mbed_official 579:53297373a894 124 const uint8_t channel,
mbed_official 579:53297373a894 125 const enum extint_callback_type type)
mbed_official 579:53297373a894 126 {
mbed_official 579:53297373a894 127 /* Sanity check arguments */
mbed_official 579:53297373a894 128 Assert(callback);
mbed_official 579:53297373a894 129
mbed_official 579:53297373a894 130 if (type != EXTINT_CALLBACK_TYPE_DETECT) {
mbed_official 579:53297373a894 131 Assert(false);
mbed_official 579:53297373a894 132 return STATUS_ERR_INVALID_ARG;
mbed_official 579:53297373a894 133 }
mbed_official 579:53297373a894 134
mbed_official 579:53297373a894 135 if (_extint_dev.callbacks[channel] == callback) {
mbed_official 579:53297373a894 136 _extint_dev.callbacks[channel] = NULL;
mbed_official 579:53297373a894 137 return STATUS_OK;
mbed_official 579:53297373a894 138 }
mbed_official 579:53297373a894 139
mbed_official 579:53297373a894 140 return STATUS_ERR_BAD_ADDRESS;
mbed_official 579:53297373a894 141 }
mbed_official 579:53297373a894 142
mbed_official 579:53297373a894 143 /**
mbed_official 579:53297373a894 144 * \brief Enables asynchronous callback generation for a given channel and type.
mbed_official 579:53297373a894 145 *
mbed_official 579:53297373a894 146 * Enables asynchronous callbacks for a given logical external interrupt channel
mbed_official 579:53297373a894 147 * and type. This must be called before an external interrupt channel will
mbed_official 579:53297373a894 148 * generate callback events.
mbed_official 579:53297373a894 149 *
mbed_official 579:53297373a894 150 * \param[in] channel Logical channel to enable callback generation for
mbed_official 579:53297373a894 151 * \param[in] type Type of callback function callbacks to enable
mbed_official 579:53297373a894 152 *
mbed_official 579:53297373a894 153 * \return Status of the callback enable operation.
mbed_official 579:53297373a894 154 * \retval STATUS_OK The callback was enabled successfully
mbed_official 579:53297373a894 155 * \retval STATUS_ERR_INVALID_ARG If an invalid callback type was supplied
mbed_official 579:53297373a894 156 */
mbed_official 579:53297373a894 157 enum status_code extint_chan_enable_callback(
mbed_official 579:53297373a894 158 const uint8_t channel,
mbed_official 579:53297373a894 159 const enum extint_callback_type type)
mbed_official 579:53297373a894 160 {
mbed_official 579:53297373a894 161 if (type == EXTINT_CALLBACK_TYPE_DETECT) {
mbed_official 579:53297373a894 162 Eic *const eic = _extint_get_eic_from_channel(channel);
mbed_official 579:53297373a894 163
mbed_official 579:53297373a894 164 eic->INTENSET.reg = (1UL << channel);
mbed_official 579:53297373a894 165 } else {
mbed_official 579:53297373a894 166 Assert(false);
mbed_official 579:53297373a894 167 return STATUS_ERR_INVALID_ARG;
mbed_official 579:53297373a894 168 }
mbed_official 579:53297373a894 169
mbed_official 579:53297373a894 170 return STATUS_OK;
mbed_official 579:53297373a894 171 }
mbed_official 579:53297373a894 172
mbed_official 579:53297373a894 173 /**
mbed_official 579:53297373a894 174 * \brief Disables asynchronous callback generation for a given channel and type.
mbed_official 579:53297373a894 175 *
mbed_official 579:53297373a894 176 * Disables asynchronous callbacks for a given logical external interrupt
mbed_official 579:53297373a894 177 * channel and type.
mbed_official 579:53297373a894 178 *
mbed_official 579:53297373a894 179 * \param[in] channel Logical channel to disable callback generation for
mbed_official 579:53297373a894 180 * \param[in] type Type of callback function callbacks to disable
mbed_official 579:53297373a894 181 *
mbed_official 579:53297373a894 182 * \return Status of the callback disable operation.
mbed_official 579:53297373a894 183 * \retval STATUS_OK The callback was disabled successfully
mbed_official 579:53297373a894 184 * \retval STATUS_ERR_INVALID_ARG If an invalid callback type was supplied
mbed_official 579:53297373a894 185 */
mbed_official 579:53297373a894 186 enum status_code extint_chan_disable_callback(
mbed_official 579:53297373a894 187 const uint8_t channel,
mbed_official 579:53297373a894 188 const enum extint_callback_type type)
mbed_official 579:53297373a894 189 {
mbed_official 579:53297373a894 190 if (type == EXTINT_CALLBACK_TYPE_DETECT) {
mbed_official 579:53297373a894 191 Eic *const eic = _extint_get_eic_from_channel(channel);
mbed_official 579:53297373a894 192
mbed_official 579:53297373a894 193 eic->INTENCLR.reg = (1UL << channel);
mbed_official 579:53297373a894 194 } else {
mbed_official 579:53297373a894 195 Assert(false);
mbed_official 579:53297373a894 196 return STATUS_ERR_INVALID_ARG;
mbed_official 579:53297373a894 197 }
mbed_official 579:53297373a894 198
mbed_official 579:53297373a894 199 return STATUS_OK;
mbed_official 579:53297373a894 200 }
mbed_official 579:53297373a894 201
mbed_official 579:53297373a894 202 /**
mbed_official 579:53297373a894 203 * \brief Find what channel caused the callback.
mbed_official 579:53297373a894 204 *
mbed_official 579:53297373a894 205 * Can be used in an EXTINT callback function to find what channel caused
mbed_official 579:53297373a894 206 * the callback in case same callback is used by multiple channels.
mbed_official 579:53297373a894 207 *
mbed_official 579:53297373a894 208 * \return Channel number.
mbed_official 579:53297373a894 209 */
mbed_official 579:53297373a894 210 uint8_t extint_get_current_channel(void)
mbed_official 579:53297373a894 211 {
mbed_official 579:53297373a894 212 return _current_channel;
mbed_official 579:53297373a894 213 }
mbed_official 579:53297373a894 214
mbed_official 579:53297373a894 215 /** Handler for the EXTINT hardware module interrupt. */
mbed_official 579:53297373a894 216 void EIC_Handler(void)
mbed_official 579:53297373a894 217 {
mbed_official 579:53297373a894 218 /* Find any triggered channels, run associated callback handlers */
mbed_official 579:53297373a894 219 for (_current_channel = 0; _current_channel < EIC_NUMBER_OF_INTERRUPTS ; _current_channel++) {
mbed_official 579:53297373a894 220 if (extint_chan_is_detected(_current_channel)) {
mbed_official 579:53297373a894 221 /* Clear flag */
mbed_official 579:53297373a894 222 extint_chan_clear_detected(_current_channel);
mbed_official 579:53297373a894 223 /* Find any associated callback entries in the callback table */
mbed_official 579:53297373a894 224 if (_extint_dev.callbacks[_current_channel] != NULL) {
mbed_official 579:53297373a894 225 /* Run the registered callback */
mbed_official 579:53297373a894 226 _extint_dev.callbacks[_current_channel]();
mbed_official 579:53297373a894 227 }
mbed_official 579:53297373a894 228 }
mbed_official 579:53297373a894 229 }
mbed_official 579:53297373a894 230 }