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