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

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Thu Nov 08 11:45:42 2018 +0000
Revision:
171:3a7713b1edbc
Parent:
TARGET_SAMD21J18A/TARGET_Atmel/TARGET_SAM_CortexM0P/drivers/system/clock/gclk.h@111:4336505e4b1c
mbed library. Release version 164

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 111:4336505e4b1c 1 /**
Kojto 111:4336505e4b1c 2 * \file
Kojto 111:4336505e4b1c 3 *
Kojto 111:4336505e4b1c 4 * \brief SAM Generic Clock Driver
Kojto 111:4336505e4b1c 5 *
Kojto 111:4336505e4b1c 6 * Copyright (C) 2012-2015 Atmel Corporation. All rights reserved.
Kojto 111:4336505e4b1c 7 *
Kojto 111:4336505e4b1c 8 * \asf_license_start
Kojto 111:4336505e4b1c 9 *
Kojto 111:4336505e4b1c 10 * \page License
Kojto 111:4336505e4b1c 11 *
Kojto 111:4336505e4b1c 12 * Redistribution and use in source and binary forms, with or without
Kojto 111:4336505e4b1c 13 * modification, are permitted provided that the following conditions are met:
Kojto 111:4336505e4b1c 14 *
Kojto 111:4336505e4b1c 15 * 1. Redistributions of source code must retain the above copyright notice,
Kojto 111:4336505e4b1c 16 * this list of conditions and the following disclaimer.
Kojto 111:4336505e4b1c 17 *
Kojto 111:4336505e4b1c 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
Kojto 111:4336505e4b1c 19 * this list of conditions and the following disclaimer in the documentation
Kojto 111:4336505e4b1c 20 * and/or other materials provided with the distribution.
Kojto 111:4336505e4b1c 21 *
Kojto 111:4336505e4b1c 22 * 3. The name of Atmel may not be used to endorse or promote products derived
Kojto 111:4336505e4b1c 23 * from this software without specific prior written permission.
Kojto 111:4336505e4b1c 24 *
Kojto 111:4336505e4b1c 25 * 4. This software may only be redistributed and used in connection with an
Kojto 111:4336505e4b1c 26 * Atmel microcontroller product.
Kojto 111:4336505e4b1c 27 *
Kojto 111:4336505e4b1c 28 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
Kojto 111:4336505e4b1c 29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
Kojto 111:4336505e4b1c 30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
Kojto 111:4336505e4b1c 31 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
Kojto 111:4336505e4b1c 32 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Kojto 111:4336505e4b1c 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Kojto 111:4336505e4b1c 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Kojto 111:4336505e4b1c 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
Kojto 111:4336505e4b1c 36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
Kojto 111:4336505e4b1c 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Kojto 111:4336505e4b1c 38 * POSSIBILITY OF SUCH DAMAGE.
Kojto 111:4336505e4b1c 39 *
Kojto 111:4336505e4b1c 40 * \asf_license_stop
Kojto 111:4336505e4b1c 41 *
Kojto 111:4336505e4b1c 42 */
Kojto 111:4336505e4b1c 43 /*
Kojto 111:4336505e4b1c 44 * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
Kojto 111:4336505e4b1c 45 */
Kojto 111:4336505e4b1c 46 #ifndef SYSTEM_CLOCK_GCLK_H_INCLUDED
Kojto 111:4336505e4b1c 47 #define SYSTEM_CLOCK_GCLK_H_INCLUDED
Kojto 111:4336505e4b1c 48
Kojto 111:4336505e4b1c 49 /**
Kojto 111:4336505e4b1c 50 * \addtogroup asfdoc_sam0_system_clock_group
Kojto 111:4336505e4b1c 51 *
Kojto 111:4336505e4b1c 52 * @{
Kojto 111:4336505e4b1c 53 */
Kojto 111:4336505e4b1c 54
Kojto 111:4336505e4b1c 55 #include <compiler.h>
Kojto 111:4336505e4b1c 56
Kojto 111:4336505e4b1c 57 #ifdef __cplusplus
Kojto 111:4336505e4b1c 58 extern "C" {
Kojto 111:4336505e4b1c 59 #endif
Kojto 111:4336505e4b1c 60
Kojto 111:4336505e4b1c 61 /**
Kojto 111:4336505e4b1c 62 * \brief List of available GCLK generators.
Kojto 111:4336505e4b1c 63 *
Kojto 111:4336505e4b1c 64 * List of Available GCLK generators. This enum is used in the peripheral
Kojto 111:4336505e4b1c 65 * device drivers to select the GCLK generator to be used for its operation.
Kojto 111:4336505e4b1c 66 *
Kojto 111:4336505e4b1c 67 * The number of GCLK generators available is device dependent.
Kojto 111:4336505e4b1c 68 */
Kojto 111:4336505e4b1c 69 enum gclk_generator {
Kojto 111:4336505e4b1c 70 /** GCLK generator channel 0 */
Kojto 111:4336505e4b1c 71 GCLK_GENERATOR_0,
Kojto 111:4336505e4b1c 72 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 0)
Kojto 111:4336505e4b1c 73 /** GCLK generator channel 1 */
Kojto 111:4336505e4b1c 74 GCLK_GENERATOR_1,
Kojto 111:4336505e4b1c 75 #endif
Kojto 111:4336505e4b1c 76 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 1)
Kojto 111:4336505e4b1c 77 /** GCLK generator channel 2 */
Kojto 111:4336505e4b1c 78 GCLK_GENERATOR_2,
Kojto 111:4336505e4b1c 79 #endif
Kojto 111:4336505e4b1c 80 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 2)
Kojto 111:4336505e4b1c 81 /** GCLK generator channel 3 */
Kojto 111:4336505e4b1c 82 GCLK_GENERATOR_3,
Kojto 111:4336505e4b1c 83 #endif
Kojto 111:4336505e4b1c 84 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 3)
Kojto 111:4336505e4b1c 85 /** GCLK generator channel 4 */
Kojto 111:4336505e4b1c 86 GCLK_GENERATOR_4,
Kojto 111:4336505e4b1c 87 #endif
Kojto 111:4336505e4b1c 88 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 4)
Kojto 111:4336505e4b1c 89 /** GCLK generator channel 5 */
Kojto 111:4336505e4b1c 90 GCLK_GENERATOR_5,
Kojto 111:4336505e4b1c 91 #endif
Kojto 111:4336505e4b1c 92 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 5)
Kojto 111:4336505e4b1c 93 /** GCLK generator channel 6 */
Kojto 111:4336505e4b1c 94 GCLK_GENERATOR_6,
Kojto 111:4336505e4b1c 95 #endif
Kojto 111:4336505e4b1c 96 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 6)
Kojto 111:4336505e4b1c 97 /** GCLK generator channel 7 */
Kojto 111:4336505e4b1c 98 GCLK_GENERATOR_7,
Kojto 111:4336505e4b1c 99 #endif
Kojto 111:4336505e4b1c 100 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 7)
Kojto 111:4336505e4b1c 101 /** GCLK generator channel 8 */
Kojto 111:4336505e4b1c 102 GCLK_GENERATOR_8,
Kojto 111:4336505e4b1c 103 #endif
Kojto 111:4336505e4b1c 104 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 8)
Kojto 111:4336505e4b1c 105 /** GCLK generator channel 9 */
Kojto 111:4336505e4b1c 106 GCLK_GENERATOR_9,
Kojto 111:4336505e4b1c 107 #endif
Kojto 111:4336505e4b1c 108 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 9)
Kojto 111:4336505e4b1c 109 /** GCLK generator channel 10 */
Kojto 111:4336505e4b1c 110 GCLK_GENERATOR_10,
Kojto 111:4336505e4b1c 111 #endif
Kojto 111:4336505e4b1c 112 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 10)
Kojto 111:4336505e4b1c 113 /** GCLK generator channel 11 */
Kojto 111:4336505e4b1c 114 GCLK_GENERATOR_11,
Kojto 111:4336505e4b1c 115 #endif
Kojto 111:4336505e4b1c 116 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 11)
Kojto 111:4336505e4b1c 117 /** GCLK generator channel 12 */
Kojto 111:4336505e4b1c 118 GCLK_GENERATOR_12,
Kojto 111:4336505e4b1c 119 #endif
Kojto 111:4336505e4b1c 120 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 12)
Kojto 111:4336505e4b1c 121 /** GCLK generator channel 13 */
Kojto 111:4336505e4b1c 122 GCLK_GENERATOR_13,
Kojto 111:4336505e4b1c 123 #endif
Kojto 111:4336505e4b1c 124 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 13)
Kojto 111:4336505e4b1c 125 /** GCLK generator channel 14 */
Kojto 111:4336505e4b1c 126 GCLK_GENERATOR_14,
Kojto 111:4336505e4b1c 127 #endif
Kojto 111:4336505e4b1c 128 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 14)
Kojto 111:4336505e4b1c 129 /** GCLK generator channel 15 */
Kojto 111:4336505e4b1c 130 GCLK_GENERATOR_15,
Kojto 111:4336505e4b1c 131 #endif
Kojto 111:4336505e4b1c 132 #if defined(__DOXYGEN__) || (GCLK_GEN_NUM_MSB > 15)
Kojto 111:4336505e4b1c 133 /** GCLK generator channel 16 */
Kojto 111:4336505e4b1c 134 GCLK_GENERATOR_16,
Kojto 111:4336505e4b1c 135 #endif
Kojto 111:4336505e4b1c 136 };
Kojto 111:4336505e4b1c 137
Kojto 111:4336505e4b1c 138 /**
Kojto 111:4336505e4b1c 139 * \brief Generic Clock Generator configuration structure.
Kojto 111:4336505e4b1c 140 *
Kojto 111:4336505e4b1c 141 * Configuration structure for a Generic Clock Generator channel. This
Kojto 111:4336505e4b1c 142 * structure should be initialized by the
Kojto 111:4336505e4b1c 143 * \ref system_gclk_gen_get_config_defaults() function before being modified by
Kojto 111:4336505e4b1c 144 * the user application.
Kojto 111:4336505e4b1c 145 */
Kojto 111:4336505e4b1c 146 struct system_gclk_gen_config {
Kojto 111:4336505e4b1c 147 /** Source clock input channel index, see the \ref system_clock_source */
Kojto 111:4336505e4b1c 148 uint8_t source_clock;
Kojto 111:4336505e4b1c 149 /** If \c true, the generator output level is high when disabled */
Kojto 111:4336505e4b1c 150 bool high_when_disabled;
Kojto 111:4336505e4b1c 151 /** Integer division factor of the clock output compared to the input */
Kojto 111:4336505e4b1c 152 uint32_t division_factor;
Kojto 111:4336505e4b1c 153 /** If \c true, the clock is kept enabled during device standby mode */
Kojto 111:4336505e4b1c 154 bool run_in_standby;
Kojto 111:4336505e4b1c 155 /** If \c true, enables GCLK generator clock output to a GPIO pin */
Kojto 111:4336505e4b1c 156 bool output_enable;
Kojto 111:4336505e4b1c 157 };
Kojto 111:4336505e4b1c 158
Kojto 111:4336505e4b1c 159 /**
Kojto 111:4336505e4b1c 160 * \brief Generic Clock configuration structure.
Kojto 111:4336505e4b1c 161 *
Kojto 111:4336505e4b1c 162 * Configuration structure for a Generic Clock channel. This structure
Kojto 111:4336505e4b1c 163 * should be initialized by the \ref system_gclk_chan_get_config_defaults()
Kojto 111:4336505e4b1c 164 * function before being modified by the user application.
Kojto 111:4336505e4b1c 165 */
Kojto 111:4336505e4b1c 166 struct system_gclk_chan_config {
Kojto 111:4336505e4b1c 167 /** Generic Clock Generator source channel */
Kojto 111:4336505e4b1c 168 enum gclk_generator source_generator;
Kojto 111:4336505e4b1c 169 };
Kojto 111:4336505e4b1c 170
Kojto 111:4336505e4b1c 171 /** \name Generic Clock Management
Kojto 111:4336505e4b1c 172 * @{
Kojto 111:4336505e4b1c 173 */
Kojto 111:4336505e4b1c 174 void system_gclk_init(void);
Kojto 111:4336505e4b1c 175
Kojto 111:4336505e4b1c 176 /** @} */
Kojto 111:4336505e4b1c 177
Kojto 111:4336505e4b1c 178
Kojto 111:4336505e4b1c 179 /**
Kojto 111:4336505e4b1c 180 * \name Generic Clock Management (Generators)
Kojto 111:4336505e4b1c 181 * @{
Kojto 111:4336505e4b1c 182 */
Kojto 111:4336505e4b1c 183
Kojto 111:4336505e4b1c 184 /**
Kojto 111:4336505e4b1c 185 * \brief Initializes a Generic Clock Generator configuration structure to defaults.
Kojto 111:4336505e4b1c 186 *
Kojto 111:4336505e4b1c 187 * Initializes a given Generic Clock Generator configuration structure to
Kojto 111:4336505e4b1c 188 * a set of known default values. This function should be called on all
Kojto 111:4336505e4b1c 189 * new instances of these configuration structures before being modified
Kojto 111:4336505e4b1c 190 * by the user application.
Kojto 111:4336505e4b1c 191 *
Kojto 111:4336505e4b1c 192 * The default configuration is:
Kojto 111:4336505e4b1c 193 * \li Clock is generated undivided from the source frequency
Kojto 111:4336505e4b1c 194 * \li Clock generator output is low when the generator is disabled
Kojto 111:4336505e4b1c 195 * \li The input clock is sourced from input clock channel 0
Kojto 111:4336505e4b1c 196 * \li Clock will be disabled during sleep
Kojto 111:4336505e4b1c 197 * \li The clock output will not be routed to a physical GPIO pin
Kojto 111:4336505e4b1c 198 *
Kojto 111:4336505e4b1c 199 * \param[out] config Configuration structure to initialize to default values
Kojto 111:4336505e4b1c 200 */
Kojto 111:4336505e4b1c 201 static inline void system_gclk_gen_get_config_defaults(
Kojto 111:4336505e4b1c 202 struct system_gclk_gen_config *const config)
Kojto 111:4336505e4b1c 203 {
Kojto 111:4336505e4b1c 204 /* Sanity check arguments */
Kojto 111:4336505e4b1c 205 Assert(config);
Kojto 111:4336505e4b1c 206
Kojto 111:4336505e4b1c 207 /* Default configuration values */
Kojto 111:4336505e4b1c 208 config->division_factor = 1;
Kojto 111:4336505e4b1c 209 config->high_when_disabled = false;
Kojto 111:4336505e4b1c 210 #if SAML21
Kojto 111:4336505e4b1c 211 config->source_clock = GCLK_SOURCE_OSC16M;
Kojto 111:4336505e4b1c 212 #elif (SAMC20) || (SAMC21)
Kojto 111:4336505e4b1c 213 config->source_clock = GCLK_SOURCE_OSC48M;
Kojto 111:4336505e4b1c 214 #else
Kojto 111:4336505e4b1c 215 config->source_clock = GCLK_SOURCE_OSC8M;
Kojto 111:4336505e4b1c 216 #endif
Kojto 111:4336505e4b1c 217 config->run_in_standby = false;
Kojto 111:4336505e4b1c 218 config->output_enable = false;
Kojto 111:4336505e4b1c 219 }
Kojto 111:4336505e4b1c 220
Kojto 111:4336505e4b1c 221 void system_gclk_gen_set_config(
Kojto 111:4336505e4b1c 222 const uint8_t generator,
Kojto 111:4336505e4b1c 223 struct system_gclk_gen_config *const config);
Kojto 111:4336505e4b1c 224
Kojto 111:4336505e4b1c 225 void system_gclk_gen_enable(
Kojto 111:4336505e4b1c 226 const uint8_t generator);
Kojto 111:4336505e4b1c 227
Kojto 111:4336505e4b1c 228 void system_gclk_gen_disable(
Kojto 111:4336505e4b1c 229 const uint8_t generator);
Kojto 111:4336505e4b1c 230
Kojto 111:4336505e4b1c 231 bool system_gclk_gen_is_enabled(
Kojto 111:4336505e4b1c 232 const uint8_t generator);
Kojto 111:4336505e4b1c 233
Kojto 111:4336505e4b1c 234 /** @} */
Kojto 111:4336505e4b1c 235
Kojto 111:4336505e4b1c 236
Kojto 111:4336505e4b1c 237 /**
Kojto 111:4336505e4b1c 238 * \name Generic Clock Management (Channels)
Kojto 111:4336505e4b1c 239 * @{
Kojto 111:4336505e4b1c 240 */
Kojto 111:4336505e4b1c 241
Kojto 111:4336505e4b1c 242 /**
Kojto 111:4336505e4b1c 243 * \brief Initializes a Generic Clock configuration structure to defaults.
Kojto 111:4336505e4b1c 244 *
Kojto 111:4336505e4b1c 245 * Initializes a given Generic Clock configuration structure to a set of
Kojto 111:4336505e4b1c 246 * known default values. This function should be called on all new
Kojto 111:4336505e4b1c 247 * instances of these configuration structures before being modified by the
Kojto 111:4336505e4b1c 248 * user application.
Kojto 111:4336505e4b1c 249 *
Kojto 111:4336505e4b1c 250 * The default configuration is as follows:
Kojto 111:4336505e4b1c 251 * \li Clock is sourced from the Generic Clock Generator channel 0
Kojto 111:4336505e4b1c 252 * \li Clock configuration will not be write-locked when set
Kojto 111:4336505e4b1c 253 *
Kojto 111:4336505e4b1c 254 * \param[out] config Configuration structure to initialize to default values
Kojto 111:4336505e4b1c 255 */
Kojto 111:4336505e4b1c 256 static inline void system_gclk_chan_get_config_defaults(
Kojto 111:4336505e4b1c 257 struct system_gclk_chan_config *const config)
Kojto 111:4336505e4b1c 258 {
Kojto 111:4336505e4b1c 259 /* Sanity check arguments */
Kojto 111:4336505e4b1c 260 Assert(config);
Kojto 111:4336505e4b1c 261
Kojto 111:4336505e4b1c 262 /* Default configuration values */
Kojto 111:4336505e4b1c 263 config->source_generator = GCLK_GENERATOR_0;
Kojto 111:4336505e4b1c 264 }
Kojto 111:4336505e4b1c 265
Kojto 111:4336505e4b1c 266 void system_gclk_chan_set_config(
Kojto 111:4336505e4b1c 267 const uint8_t channel,
Kojto 111:4336505e4b1c 268 struct system_gclk_chan_config *const config);
Kojto 111:4336505e4b1c 269
Kojto 111:4336505e4b1c 270 void system_gclk_chan_enable(
Kojto 111:4336505e4b1c 271 const uint8_t channel);
Kojto 111:4336505e4b1c 272
Kojto 111:4336505e4b1c 273 void system_gclk_chan_disable(
Kojto 111:4336505e4b1c 274 const uint8_t channel);
Kojto 111:4336505e4b1c 275
Kojto 111:4336505e4b1c 276 bool system_gclk_chan_is_enabled(
Kojto 111:4336505e4b1c 277 const uint8_t channel);
Kojto 111:4336505e4b1c 278
Kojto 111:4336505e4b1c 279 void system_gclk_chan_lock(
Kojto 111:4336505e4b1c 280 const uint8_t channel);
Kojto 111:4336505e4b1c 281
Kojto 111:4336505e4b1c 282 bool system_gclk_chan_is_locked(
Kojto 111:4336505e4b1c 283 const uint8_t channel);
Kojto 111:4336505e4b1c 284
Kojto 111:4336505e4b1c 285 /** @} */
Kojto 111:4336505e4b1c 286
Kojto 111:4336505e4b1c 287
Kojto 111:4336505e4b1c 288 /**
Kojto 111:4336505e4b1c 289 * \name Generic Clock Frequency Retrieval
Kojto 111:4336505e4b1c 290 * @{
Kojto 111:4336505e4b1c 291 */
Kojto 111:4336505e4b1c 292
Kojto 111:4336505e4b1c 293 uint32_t system_gclk_gen_get_hz(
Kojto 111:4336505e4b1c 294 const uint8_t generator);
Kojto 111:4336505e4b1c 295
Kojto 111:4336505e4b1c 296 uint32_t system_gclk_chan_get_hz(
Kojto 111:4336505e4b1c 297 const uint8_t channel);
Kojto 111:4336505e4b1c 298
Kojto 111:4336505e4b1c 299 /** @} */
Kojto 111:4336505e4b1c 300
Kojto 111:4336505e4b1c 301 #ifdef __cplusplus
Kojto 111:4336505e4b1c 302 }
Kojto 111:4336505e4b1c 303 #endif
Kojto 111:4336505e4b1c 304
Kojto 111:4336505e4b1c 305 /** @} */
Kojto 111:4336505e4b1c 306
Kojto 111:4336505e4b1c 307 #endif