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 Generic Clock 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 #ifndef SYSTEM_CLOCK_GCLK_H_INCLUDED
mbed_official 579:53297373a894 47 #define SYSTEM_CLOCK_GCLK_H_INCLUDED
mbed_official 579:53297373a894 48
mbed_official 579:53297373a894 49 /**
mbed_official 579:53297373a894 50 * \addtogroup asfdoc_sam0_system_clock_group
mbed_official 579:53297373a894 51 *
mbed_official 579:53297373a894 52 * @{
mbed_official 579:53297373a894 53 */
mbed_official 579:53297373a894 54
mbed_official 579:53297373a894 55 #include <compiler.h>
mbed_official 579:53297373a894 56
mbed_official 579:53297373a894 57 #ifdef __cplusplus
mbed_official 579:53297373a894 58 extern "C" {
mbed_official 579:53297373a894 59 #endif
mbed_official 579:53297373a894 60
mbed_official 579:53297373a894 61 /**
mbed_official 579:53297373a894 62 * \brief List of available GCLK generators.
mbed_official 579:53297373a894 63 *
mbed_official 579:53297373a894 64 * List of Available GCLK generators. This enum is used in the peripheral
mbed_official 579:53297373a894 65 * device drivers to select the GCLK generator to be used for its operation.
mbed_official 579:53297373a894 66 *
mbed_official 579:53297373a894 67 * The number of GCLK generators available is device dependent.
mbed_official 579:53297373a894 68 */
mbed_official 579:53297373a894 69 enum gclk_generator {
mbed_official 579:53297373a894 70 /** GCLK generator channel 0. */
mbed_official 579:53297373a894 71 GCLK_GENERATOR_0,
mbed_official 579:53297373a894 72 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 0)
mbed_official 579:53297373a894 73 /** GCLK generator channel 1. */
mbed_official 579:53297373a894 74 GCLK_GENERATOR_1,
mbed_official 579:53297373a894 75 #endif
mbed_official 579:53297373a894 76 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 1)
mbed_official 579:53297373a894 77 /** GCLK generator channel 2. */
mbed_official 579:53297373a894 78 GCLK_GENERATOR_2,
mbed_official 579:53297373a894 79 #endif
mbed_official 579:53297373a894 80 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 2)
mbed_official 579:53297373a894 81 /** GCLK generator channel 3. */
mbed_official 579:53297373a894 82 GCLK_GENERATOR_3,
mbed_official 579:53297373a894 83 #endif
mbed_official 579:53297373a894 84 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 3)
mbed_official 579:53297373a894 85 /** GCLK generator channel 4. */
mbed_official 579:53297373a894 86 GCLK_GENERATOR_4,
mbed_official 579:53297373a894 87 #endif
mbed_official 579:53297373a894 88 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 4)
mbed_official 579:53297373a894 89 /** GCLK generator channel 5. */
mbed_official 579:53297373a894 90 GCLK_GENERATOR_5,
mbed_official 579:53297373a894 91 #endif
mbed_official 579:53297373a894 92 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 5)
mbed_official 579:53297373a894 93 /** GCLK generator channel 6. */
mbed_official 579:53297373a894 94 GCLK_GENERATOR_6,
mbed_official 579:53297373a894 95 #endif
mbed_official 579:53297373a894 96 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 6)
mbed_official 579:53297373a894 97 /** GCLK generator channel 7. */
mbed_official 579:53297373a894 98 GCLK_GENERATOR_7,
mbed_official 579:53297373a894 99 #endif
mbed_official 579:53297373a894 100 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 7)
mbed_official 579:53297373a894 101 /** GCLK generator channel 8. */
mbed_official 579:53297373a894 102 GCLK_GENERATOR_8,
mbed_official 579:53297373a894 103 #endif
mbed_official 579:53297373a894 104 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 8)
mbed_official 579:53297373a894 105 /** GCLK generator channel 9. */
mbed_official 579:53297373a894 106 GCLK_GENERATOR_9,
mbed_official 579:53297373a894 107 #endif
mbed_official 579:53297373a894 108 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 9)
mbed_official 579:53297373a894 109 /** GCLK generator channel 10. */
mbed_official 579:53297373a894 110 GCLK_GENERATOR_10,
mbed_official 579:53297373a894 111 #endif
mbed_official 579:53297373a894 112 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 10)
mbed_official 579:53297373a894 113 /** GCLK generator channel 11. */
mbed_official 579:53297373a894 114 GCLK_GENERATOR_11,
mbed_official 579:53297373a894 115 #endif
mbed_official 579:53297373a894 116 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 11)
mbed_official 579:53297373a894 117 /** GCLK generator channel 12. */
mbed_official 579:53297373a894 118 GCLK_GENERATOR_12,
mbed_official 579:53297373a894 119 #endif
mbed_official 579:53297373a894 120 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 12)
mbed_official 579:53297373a894 121 /** GCLK generator channel 13. */
mbed_official 579:53297373a894 122 GCLK_GENERATOR_13,
mbed_official 579:53297373a894 123 #endif
mbed_official 579:53297373a894 124 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 13)
mbed_official 579:53297373a894 125 /** GCLK generator channel 14. */
mbed_official 579:53297373a894 126 GCLK_GENERATOR_14,
mbed_official 579:53297373a894 127 #endif
mbed_official 579:53297373a894 128 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 14)
mbed_official 579:53297373a894 129 /** GCLK generator channel 15. */
mbed_official 579:53297373a894 130 GCLK_GENERATOR_15,
mbed_official 579:53297373a894 131 #endif
mbed_official 579:53297373a894 132 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 15)
mbed_official 579:53297373a894 133 /** GCLK generator channel 16. */
mbed_official 579:53297373a894 134 GCLK_GENERATOR_16,
mbed_official 579:53297373a894 135 #endif
mbed_official 579:53297373a894 136 };
mbed_official 579:53297373a894 137
mbed_official 579:53297373a894 138 /**
mbed_official 579:53297373a894 139 * \brief Generic Clock Generator configuration structure.
mbed_official 579:53297373a894 140 *
mbed_official 579:53297373a894 141 * Configuration structure for a Generic Clock Generator channel. This
mbed_official 579:53297373a894 142 * structure should be initialized by the
mbed_official 579:53297373a894 143 * \ref system_gclk_gen_get_config_defaults() function before being modified by
mbed_official 579:53297373a894 144 * the user application.
mbed_official 579:53297373a894 145 */
mbed_official 579:53297373a894 146 struct system_gclk_gen_config {
mbed_official 579:53297373a894 147 /** Source clock input channel index, see the \ref system_clock_source. */
mbed_official 579:53297373a894 148 uint8_t source_clock;
mbed_official 579:53297373a894 149 /** If \c true, the generator output level is high when disabled. */
mbed_official 579:53297373a894 150 bool high_when_disabled;
mbed_official 579:53297373a894 151 /** Integer division factor of the clock output compared to the input. */
mbed_official 579:53297373a894 152 uint32_t division_factor;
mbed_official 579:53297373a894 153 /** If \c true, the clock is kept enabled during device standby mode. */
mbed_official 579:53297373a894 154 bool run_in_standby;
mbed_official 579:53297373a894 155 /** If \c true, enables GCLK generator clock output to a GPIO pin. */
mbed_official 579:53297373a894 156 bool output_enable;
mbed_official 579:53297373a894 157 };
mbed_official 579:53297373a894 158
mbed_official 579:53297373a894 159 /**
mbed_official 579:53297373a894 160 * \brief Generic Clock configuration structure.
mbed_official 579:53297373a894 161 *
mbed_official 579:53297373a894 162 * Configuration structure for a Generic Clock channel. This structure
mbed_official 579:53297373a894 163 * should be initialized by the \ref system_gclk_chan_get_config_defaults()
mbed_official 579:53297373a894 164 * function before being modified by the user application.
mbed_official 579:53297373a894 165 */
mbed_official 579:53297373a894 166 struct system_gclk_chan_config {
mbed_official 579:53297373a894 167 /** Generic Clock Generator source channel. */
mbed_official 579:53297373a894 168 enum gclk_generator source_generator;
mbed_official 579:53297373a894 169 };
mbed_official 579:53297373a894 170
mbed_official 579:53297373a894 171 /** \name Generic Clock Management
mbed_official 579:53297373a894 172 * @{
mbed_official 579:53297373a894 173 */
mbed_official 579:53297373a894 174 void system_gclk_init(void);
mbed_official 579:53297373a894 175
mbed_official 579:53297373a894 176 /** @} */
mbed_official 579:53297373a894 177
mbed_official 579:53297373a894 178
mbed_official 579:53297373a894 179 /**
mbed_official 579:53297373a894 180 * \name Generic Clock Management (Generators)
mbed_official 579:53297373a894 181 * @{
mbed_official 579:53297373a894 182 */
mbed_official 579:53297373a894 183
mbed_official 579:53297373a894 184 /**
mbed_official 579:53297373a894 185 * \brief Initializes a Generic Clock Generator configuration structure to defaults.
mbed_official 579:53297373a894 186 *
mbed_official 579:53297373a894 187 * Initializes a given Generic Clock Generator configuration structure to
mbed_official 579:53297373a894 188 * a set of known default values. This function should be called on all
mbed_official 579:53297373a894 189 * new instances of these configuration structures before being modified
mbed_official 579:53297373a894 190 * by the user application.
mbed_official 579:53297373a894 191 *
mbed_official 579:53297373a894 192 * The default configuration is as follows:
mbed_official 579:53297373a894 193 * \li Clock is generated undivided from the source frequency
mbed_official 579:53297373a894 194 * \li Clock generator output is low when the generator is disabled
mbed_official 579:53297373a894 195 * \li The input clock is sourced from input clock channel 0
mbed_official 579:53297373a894 196 * \li Clock will be disabled during sleep
mbed_official 579:53297373a894 197 * \li The clock output will not be routed to a physical GPIO pin
mbed_official 579:53297373a894 198 *
mbed_official 579:53297373a894 199 * \param[out] config Configuration structure to initialize to default values
mbed_official 579:53297373a894 200 */
mbed_official 579:53297373a894 201 static inline void system_gclk_gen_get_config_defaults(
mbed_official 579:53297373a894 202 struct system_gclk_gen_config *const config)
mbed_official 579:53297373a894 203 {
mbed_official 579:53297373a894 204 /* Sanity check arguments */
mbed_official 579:53297373a894 205 Assert(config);
mbed_official 579:53297373a894 206
mbed_official 579:53297373a894 207 /* Default configuration values */
mbed_official 579:53297373a894 208 config->division_factor = 1;
mbed_official 579:53297373a894 209 config->high_when_disabled = false;
mbed_official 579:53297373a894 210 #if SAML21
mbed_official 579:53297373a894 211 config->source_clock = GCLK_SOURCE_OSC16M;
mbed_official 579:53297373a894 212 #else
mbed_official 579:53297373a894 213 config->source_clock = GCLK_SOURCE_OSC8M;
mbed_official 579:53297373a894 214 #endif
mbed_official 579:53297373a894 215 config->run_in_standby = false;
mbed_official 579:53297373a894 216 config->output_enable = false;
mbed_official 579:53297373a894 217 }
mbed_official 579:53297373a894 218
mbed_official 579:53297373a894 219 void system_gclk_gen_set_config(
mbed_official 579:53297373a894 220 const uint8_t generator,
mbed_official 579:53297373a894 221 struct system_gclk_gen_config *const config);
mbed_official 579:53297373a894 222
mbed_official 579:53297373a894 223 void system_gclk_gen_enable(
mbed_official 579:53297373a894 224 const uint8_t generator);
mbed_official 579:53297373a894 225
mbed_official 579:53297373a894 226 void system_gclk_gen_disable(
mbed_official 579:53297373a894 227 const uint8_t generator);
mbed_official 579:53297373a894 228
mbed_official 579:53297373a894 229 bool system_gclk_gen_is_enabled(
mbed_official 579:53297373a894 230 const uint8_t generator);
mbed_official 579:53297373a894 231
mbed_official 579:53297373a894 232 /** @} */
mbed_official 579:53297373a894 233
mbed_official 579:53297373a894 234
mbed_official 579:53297373a894 235 /**
mbed_official 579:53297373a894 236 * \name Generic Clock Management (Channels)
mbed_official 579:53297373a894 237 * @{
mbed_official 579:53297373a894 238 */
mbed_official 579:53297373a894 239
mbed_official 579:53297373a894 240 /**
mbed_official 579:53297373a894 241 * \brief Initializes a Generic Clock configuration structure to defaults.
mbed_official 579:53297373a894 242 *
mbed_official 579:53297373a894 243 * Initializes a given Generic Clock configuration structure to a set of
mbed_official 579:53297373a894 244 * known default values. This function should be called on all new
mbed_official 579:53297373a894 245 * instances of these configuration structures before being modified by the
mbed_official 579:53297373a894 246 * user application.
mbed_official 579:53297373a894 247 *
mbed_official 579:53297373a894 248 * The default configuration is as follows:
mbed_official 579:53297373a894 249 * \li Clock is sourced from the Generic Clock Generator channel 0
mbed_official 579:53297373a894 250 * \li Clock configuration will not be write-locked when set
mbed_official 579:53297373a894 251 *
mbed_official 579:53297373a894 252 * \param[out] config Configuration structure to initialize to default values
mbed_official 579:53297373a894 253 */
mbed_official 579:53297373a894 254 static inline void system_gclk_chan_get_config_defaults(
mbed_official 579:53297373a894 255 struct system_gclk_chan_config *const config)
mbed_official 579:53297373a894 256 {
mbed_official 579:53297373a894 257 /* Sanity check arguments */
mbed_official 579:53297373a894 258 Assert(config);
mbed_official 579:53297373a894 259
mbed_official 579:53297373a894 260 /* Default configuration values */
mbed_official 579:53297373a894 261 config->source_generator = GCLK_GENERATOR_0;
mbed_official 579:53297373a894 262 }
mbed_official 579:53297373a894 263
mbed_official 579:53297373a894 264 void system_gclk_chan_set_config(
mbed_official 579:53297373a894 265 const uint8_t channel,
mbed_official 579:53297373a894 266 struct system_gclk_chan_config *const config);
mbed_official 579:53297373a894 267
mbed_official 579:53297373a894 268 void system_gclk_chan_enable(
mbed_official 579:53297373a894 269 const uint8_t channel);
mbed_official 579:53297373a894 270
mbed_official 579:53297373a894 271 void system_gclk_chan_disable(
mbed_official 579:53297373a894 272 const uint8_t channel);
mbed_official 579:53297373a894 273
mbed_official 579:53297373a894 274 bool system_gclk_chan_is_enabled(
mbed_official 579:53297373a894 275 const uint8_t channel);
mbed_official 579:53297373a894 276
mbed_official 579:53297373a894 277 void system_gclk_chan_lock(
mbed_official 579:53297373a894 278 const uint8_t channel);
mbed_official 579:53297373a894 279
mbed_official 579:53297373a894 280 bool system_gclk_chan_is_locked(
mbed_official 579:53297373a894 281 const uint8_t channel);
mbed_official 579:53297373a894 282
mbed_official 579:53297373a894 283 /** @} */
mbed_official 579:53297373a894 284
mbed_official 579:53297373a894 285
mbed_official 579:53297373a894 286 /**
mbed_official 579:53297373a894 287 * \name Generic Clock Frequency Retrieval
mbed_official 579:53297373a894 288 * @{
mbed_official 579:53297373a894 289 */
mbed_official 579:53297373a894 290
mbed_official 579:53297373a894 291 uint32_t system_gclk_gen_get_hz(
mbed_official 579:53297373a894 292 const uint8_t generator);
mbed_official 579:53297373a894 293
mbed_official 579:53297373a894 294 uint32_t system_gclk_chan_get_hz(
mbed_official 579:53297373a894 295 const uint8_t channel);
mbed_official 579:53297373a894 296
mbed_official 579:53297373a894 297 /** @} */
mbed_official 579:53297373a894 298
mbed_official 579:53297373a894 299 #ifdef __cplusplus
mbed_official 579:53297373a894 300 }
mbed_official 579:53297373a894 301 #endif
mbed_official 579:53297373a894 302
mbed_official 579:53297373a894 303 /** @} */
mbed_official 579:53297373a894 304
mbed_official 579:53297373a894 305 #endif