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:
Wed Feb 20 20:53:29 2019 +0000
Revision:
172:65be27845400
Parent:
171:3a7713b1edbc
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Anna Bridge 142:4eea097334d6 1 /***************************************************************************//**
Anna Bridge 142:4eea097334d6 2 * @file clocking.h
Anna Bridge 142:4eea097334d6 3 * @brief Clock selection calculations
Anna Bridge 142:4eea097334d6 4 *******************************************************************************
Anna Bridge 142:4eea097334d6 5 * @section License
Anna Bridge 142:4eea097334d6 6 * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b>
Anna Bridge 142:4eea097334d6 7 *******************************************************************************
Anna Bridge 142:4eea097334d6 8 *
Anna Bridge 142:4eea097334d6 9 * SPDX-License-Identifier: Apache-2.0
Anna Bridge 142:4eea097334d6 10 *
Anna Bridge 142:4eea097334d6 11 * Licensed under the Apache License, Version 2.0 (the "License"); you may
Anna Bridge 142:4eea097334d6 12 * not use this file except in compliance with the License.
Anna Bridge 142:4eea097334d6 13 * You may obtain a copy of the License at
Anna Bridge 142:4eea097334d6 14 *
Anna Bridge 142:4eea097334d6 15 * http://www.apache.org/licenses/LICENSE-2.0
Anna Bridge 142:4eea097334d6 16 *
Anna Bridge 142:4eea097334d6 17 * Unless required by applicable law or agreed to in writing, software
Anna Bridge 142:4eea097334d6 18 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
Anna Bridge 142:4eea097334d6 19 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Anna Bridge 142:4eea097334d6 20 * See the License for the specific language governing permissions and
Anna Bridge 142:4eea097334d6 21 * limitations under the License.
Anna Bridge 142:4eea097334d6 22 *
Anna Bridge 142:4eea097334d6 23 ******************************************************************************/
Anna Bridge 142:4eea097334d6 24 #ifndef MBED_CLOCKING_H
Anna Bridge 142:4eea097334d6 25 #define MBED_CLOCKING_H
Anna Bridge 142:4eea097334d6 26
AnnaBridge 161:aa5281ff4a02 27 #include "em_cmu.h"
AnnaBridge 161:aa5281ff4a02 28
Anna Bridge 142:4eea097334d6 29 /* Clock definitions */
Anna Bridge 142:4eea097334d6 30 #define LFXO 0
Anna Bridge 142:4eea097334d6 31 #define HFXO 1
Anna Bridge 142:4eea097334d6 32 #define LFRCO 2
Anna Bridge 142:4eea097334d6 33 #define HFRCO 3
Anna Bridge 142:4eea097334d6 34 #if !defined(_EFM32_GECKO_FAMILY)
Anna Bridge 142:4eea097334d6 35 #define ULFRCO 4
Anna Bridge 142:4eea097334d6 36 #endif
Anna Bridge 142:4eea097334d6 37
Anna Bridge 142:4eea097334d6 38 /* Low Energy peripheral clock source.
Anna Bridge 142:4eea097334d6 39 * Options:
Anna Bridge 142:4eea097334d6 40 * * LFXO: external crystal, please define frequency.
Anna Bridge 142:4eea097334d6 41 * * LFRCO: internal RC oscillator (32.768kHz)
Anna Bridge 142:4eea097334d6 42 * * ULFRCO: internal ultra-low power RC oscillator (available down to EM3) (1kHz)
Anna Bridge 142:4eea097334d6 43 */
Anna Bridge 142:4eea097334d6 44 #ifndef LOW_ENERGY_CLOCK_SOURCE
Anna Bridge 142:4eea097334d6 45 #define LOW_ENERGY_CLOCK_SOURCE LFXO
Anna Bridge 142:4eea097334d6 46 #endif
Anna Bridge 142:4eea097334d6 47
Anna Bridge 142:4eea097334d6 48 /** Core clock source.
Anna Bridge 142:4eea097334d6 49 * Options:
Anna Bridge 142:4eea097334d6 50 * * HFXO: external crystal, please define frequency.
Anna Bridge 142:4eea097334d6 51 * * HFRCO: High-frequency internal RC oscillator. Please select band as well.
Anna Bridge 142:4eea097334d6 52 */
Anna Bridge 142:4eea097334d6 53 #ifndef CORE_CLOCK_SOURCE
Anna Bridge 142:4eea097334d6 54 #define CORE_CLOCK_SOURCE HFRCO
Anna Bridge 142:4eea097334d6 55 #if defined(_CMU_HFRCOCTRL_BAND_MASK)
AnnaBridge 161:aa5281ff4a02 56 #define HFRCO_FREQUENCY_ENUM _CMU_HFRCOCTRL_BAND_21MHZ
AnnaBridge 161:aa5281ff4a02 57 #define HFRCO_FREQUENCY 21000000
Anna Bridge 142:4eea097334d6 58 #elif defined(_CMU_HFRCOCTRL_FREQRANGE_MASK)
Anna Bridge 142:4eea097334d6 59 #define HFRCO_FREQUENCY_ENUM cmuHFRCOFreq_32M0Hz
Anna Bridge 142:4eea097334d6 60 #define HFRCO_FREQUENCY 32000000
Anna Bridge 142:4eea097334d6 61 #endif
Anna Bridge 142:4eea097334d6 62 #endif // CORE_CLOCK_SOURCE
Anna Bridge 142:4eea097334d6 63
Anna Bridge 142:4eea097334d6 64 #if !defined(LFXO_FREQUENCY) && (LOW_ENERGY_CLOCK_SOURCE == LFXO)
Anna Bridge 142:4eea097334d6 65 #error "LFXO frequency is undefined!"
Anna Bridge 142:4eea097334d6 66 #endif
Anna Bridge 142:4eea097334d6 67
Anna Bridge 142:4eea097334d6 68 #if !defined(HFXO_FREQUENCY) && (CORE_CLOCK_SOURCE == HFXO)
Anna Bridge 142:4eea097334d6 69 #error "HFXO frequency is undefined!"
Anna Bridge 142:4eea097334d6 70 #endif
Anna Bridge 142:4eea097334d6 71
Anna Bridge 142:4eea097334d6 72 #if (LOW_ENERGY_CLOCK_SOURCE == LFXO)
Anna Bridge 142:4eea097334d6 73 #define LOW_ENERGY_CLOCK_FREQUENCY LFXO_FREQUENCY
Anna Bridge 142:4eea097334d6 74 #elif (LOW_ENERGY_CLOCK_SOURCE == LFRCO)
Anna Bridge 142:4eea097334d6 75 #define LOW_ENERGY_CLOCK_FREQUENCY 32768
Anna Bridge 142:4eea097334d6 76 #elif (LOW_ENERGY_CLOCK_SOURCE == ULFRCO)
Anna Bridge 142:4eea097334d6 77 #define LOW_ENERGY_CLOCK_FREQUENCY 1000
Anna Bridge 142:4eea097334d6 78 #else
Anna Bridge 142:4eea097334d6 79 #error "Unknown Low Energy Clock selection"
Anna Bridge 142:4eea097334d6 80 #endif
Anna Bridge 142:4eea097334d6 81
Anna Bridge 142:4eea097334d6 82 #if( CORE_CLOCK_SOURCE == HFXO)
Anna Bridge 142:4eea097334d6 83 # define REFERENCE_FREQUENCY HFXO_FREQUENCY
Anna Bridge 142:4eea097334d6 84 #elif( CORE_CLOCK_SOURCE == HFRCO)
Anna Bridge 142:4eea097334d6 85 #if !defined(HFRCO_FREQUENCY)
Anna Bridge 142:4eea097334d6 86 # error "HFRCO frequency is not defined!"
Anna Bridge 142:4eea097334d6 87 #else
Anna Bridge 142:4eea097334d6 88 # define REFERENCE_FREQUENCY HFRCO_FREQUENCY
Anna Bridge 142:4eea097334d6 89 #endif
Anna Bridge 142:4eea097334d6 90 #endif
Anna Bridge 142:4eea097334d6 91
Anna Bridge 142:4eea097334d6 92 #if ( LOW_ENERGY_CLOCK_SOURCE == LFXO )
Anna Bridge 142:4eea097334d6 93 # define LEUART_USING_LFXO
Anna Bridge 142:4eea097334d6 94 # if ( (defined(CMU_CTRL_HFLE) || defined(CMU_CTRL_WSHFLE) ) && (REFERENCE_FREQUENCY > 24000000) )
Anna Bridge 142:4eea097334d6 95 # define LEUART_HF_REF_FREQ (REFERENCE_FREQUENCY / 4)
Anna Bridge 142:4eea097334d6 96 # else
Anna Bridge 142:4eea097334d6 97 # define LEUART_HF_REF_FREQ (REFERENCE_FREQUENCY / 2)
Anna Bridge 142:4eea097334d6 98 # endif
Anna Bridge 142:4eea097334d6 99 # define LEUART_LF_REF_FREQ LFXO_FREQUENCY
Anna Bridge 142:4eea097334d6 100 #else
Anna Bridge 142:4eea097334d6 101 # if ( (defined(CMU_CTRL_HFLE) || defined(CMU_CTRL_WSHFLE) ) && (REFERENCE_FREQUENCY > 24000000) )
Anna Bridge 142:4eea097334d6 102 # define LEUART_REF_FREQ (REFERENCE_FREQUENCY / 4)
Anna Bridge 142:4eea097334d6 103 # else
Anna Bridge 142:4eea097334d6 104 # define LEUART_REF_FREQ (REFERENCE_FREQUENCY / 2)
Anna Bridge 142:4eea097334d6 105 # endif
Anna Bridge 142:4eea097334d6 106 #endif
Anna Bridge 142:4eea097334d6 107
AnnaBridge 161:aa5281ff4a02 108 /* Adjust this to change speed of RTC and LP ticker ticks */
Anna Bridge 169:a7c7b631e539 109 #define RTC_CLOCKDIV cmuClkDiv_1
AnnaBridge 161:aa5281ff4a02 110 /* Adjust this to match RTC_CLOCKDIV as integer value */
Anna Bridge 169:a7c7b631e539 111 #define RTC_CLOCKDIV_INT 1U
AnnaBridge 161:aa5281ff4a02 112 /* Adjust this to match RTC_CLOCKDIV as shift for 1 second worth of ticks.
AnnaBridge 161:aa5281ff4a02 113 * E.g. with 32768 Hz crystal and CLOCKDIV of 8, 1 second is 4096 ticks.
AnnaBridge 161:aa5281ff4a02 114 * 4096 equals 1 << 12, so RTC_FREQ_SHIFT needs to be 12. */
Anna Bridge 169:a7c7b631e539 115 #define RTC_FREQ_SHIFT 15U
AnnaBridge 161:aa5281ff4a02 116
Anna Bridge 142:4eea097334d6 117 #endif