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:
Tue Apr 28 11:45:12 2015 +0100
Revision:
525:c320967f86b9
Child:
527:74d34ce5a2b5
Synchronized with git revision 299385b8331142b9dc524da7a986536f60b14553

Full URL: https://github.com/mbedmicro/mbed/commit/299385b8331142b9dc524da7a986536f60b14553/

Add in Silicon Labs targets with asynchronous API support

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 525:c320967f86b9 1 /* mbed Microcontroller Library
mbed_official 525:c320967f86b9 2 * Copyright (c) 2006-2013 ARM Limited
mbed_official 525:c320967f86b9 3 *
mbed_official 525:c320967f86b9 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 525:c320967f86b9 5 * you may not use this file except in compliance with the License.
mbed_official 525:c320967f86b9 6 * You may obtain a copy of the License at
mbed_official 525:c320967f86b9 7 *
mbed_official 525:c320967f86b9 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 525:c320967f86b9 9 *
mbed_official 525:c320967f86b9 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 525:c320967f86b9 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 525:c320967f86b9 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 525:c320967f86b9 13 * See the License for the specific language governing permissions and
mbed_official 525:c320967f86b9 14 * limitations under the License.
mbed_official 525:c320967f86b9 15 */
mbed_official 525:c320967f86b9 16 #include "em_chip.h"
mbed_official 525:c320967f86b9 17 #include "em_device.h"
mbed_official 525:c320967f86b9 18 #include "em_cmu.h"
mbed_official 525:c320967f86b9 19 #include "em_emu.h"
mbed_official 525:c320967f86b9 20 #include "device_peripherals.h"
mbed_official 525:c320967f86b9 21 #include "device.h"
mbed_official 525:c320967f86b9 22 #include "em_usart.h"
mbed_official 525:c320967f86b9 23 #include "gpio_api.h"
mbed_official 525:c320967f86b9 24
mbed_official 525:c320967f86b9 25 gpio_t bc_enable;
mbed_official 525:c320967f86b9 26
mbed_official 525:c320967f86b9 27 void check_usart_clock(USART_TypeDef* usart, uint32_t clockmask);
mbed_official 525:c320967f86b9 28
mbed_official 525:c320967f86b9 29 /* Called before main - implement here if board needs it.
mbed_official 525:c320967f86b9 30 * Otherwise, let the application override this if necessary */
mbed_official 525:c320967f86b9 31 void mbed_sdk_init()
mbed_official 525:c320967f86b9 32 {
mbed_official 525:c320967f86b9 33 CHIP_Init();
mbed_official 525:c320967f86b9 34
mbed_official 525:c320967f86b9 35 /* Set up the clock sources for this chip */
mbed_official 525:c320967f86b9 36 #if( CORE_CLOCK_SOURCE == HFXO)
mbed_official 525:c320967f86b9 37 CMU_ClockSelectSet(cmuClock_HF, HFXO);
mbed_official 525:c320967f86b9 38 SystemHFXOClockSet(HFXO_FREQUENCY);
mbed_official 525:c320967f86b9 39 #elif( CORE_CLOCK_SOURCE == HFRCO)
mbed_official 525:c320967f86b9 40 CMU_ClockSelectSet(cmuClock_HF, HFRCO);
mbed_official 525:c320967f86b9 41 CMU_HFRCOBandSet(HFRCO_FREQUENCY);
mbed_official 525:c320967f86b9 42 #else
mbed_official 525:c320967f86b9 43 #error "Core clock selection not valid (mbed_overrides.c)"
mbed_official 525:c320967f86b9 44 #endif
mbed_official 525:c320967f86b9 45
mbed_official 525:c320967f86b9 46 CMU_ClockEnable(cmuClock_CORELE, true);
mbed_official 525:c320967f86b9 47
mbed_official 525:c320967f86b9 48 #if( LOW_ENERGY_CLOCK_SOURCE == LFXO )
mbed_official 525:c320967f86b9 49 #ifdef CMU_LFACLKSEL_REG
mbed_official 525:c320967f86b9 50 CMU_ClockSelectSet(cmuClock_LFA, LFXO);
mbed_official 525:c320967f86b9 51 #endif
mbed_official 525:c320967f86b9 52 #ifdef CMU_LFBCLKSEL_REG
mbed_official 525:c320967f86b9 53 CMU_ClockSelectSet(cmuClock_LFB, LFXO);
mbed_official 525:c320967f86b9 54 #endif
mbed_official 525:c320967f86b9 55 #ifdef CMU_LFECLKSEL_REG
mbed_official 525:c320967f86b9 56 CMU_ClockSelectSet(cmuClock_LFE, LFXO);
mbed_official 525:c320967f86b9 57 #endif
mbed_official 525:c320967f86b9 58 SystemLFXOClockSet(LFXO_FREQUENCY);
mbed_official 525:c320967f86b9 59
mbed_official 525:c320967f86b9 60 #elif( LOW_ENERGY_CLOCK_SOURCE == LFRCO )
mbed_official 525:c320967f86b9 61 #ifdef CMU_LFACLKSEL_REG
mbed_official 525:c320967f86b9 62 CMU_ClockSelectSet(cmuClock_LFA, LFRCO);
mbed_official 525:c320967f86b9 63 #endif
mbed_official 525:c320967f86b9 64 #ifdef CMU_LFBCLKSEL_REG
mbed_official 525:c320967f86b9 65 //CMU_ClockSelectSet(cmuClock_LFB, LFRCO);
mbed_official 525:c320967f86b9 66 #endif
mbed_official 525:c320967f86b9 67 #ifdef CMU_LFECLKSEL_REG
mbed_official 525:c320967f86b9 68 CMU_ClockSelectSet(cmuClock_LFE, LFRCO);
mbed_official 525:c320967f86b9 69 #endif
mbed_official 525:c320967f86b9 70 CMU_HFRCOBandSet(HFRCO_FREQUENCY);
mbed_official 525:c320967f86b9 71
mbed_official 525:c320967f86b9 72 #elif( LOW_ENERGY_CLOCK_SOURCE == ULFRCO)
mbed_official 525:c320967f86b9 73 #ifdef CMU_LFACLKSEL_REG
mbed_official 525:c320967f86b9 74 CMU_ClockSelectSet(cmuClock_LFA, ULFRCO);
mbed_official 525:c320967f86b9 75 #endif
mbed_official 525:c320967f86b9 76 #ifdef CMU_LFBCLKSEL_REG
mbed_official 525:c320967f86b9 77 CMU_ClockSelectSet(cmuClock_LFB, ULFRCO);
mbed_official 525:c320967f86b9 78 #endif
mbed_official 525:c320967f86b9 79 #ifdef CMU_LFECLKSEL_REG
mbed_official 525:c320967f86b9 80 CMU_ClockSelectSet(cmuClock_LFE, ULFRCO);
mbed_official 525:c320967f86b9 81 #endif
mbed_official 525:c320967f86b9 82 #else
mbed_official 525:c320967f86b9 83 #error "Low energy clock selection not valid"
mbed_official 525:c320967f86b9 84 #endif
mbed_official 525:c320967f86b9 85
mbed_official 525:c320967f86b9 86 /* Enable BC line driver to avoid garbage on CDC port */
mbed_official 525:c320967f86b9 87 gpio_init_out_ex(&bc_enable, EFM_BC_EN, 1);
mbed_official 525:c320967f86b9 88 }
mbed_official 525:c320967f86b9 89
mbed_official 525:c320967f86b9 90 void check_usart_clock(USART_TypeDef* usart, uint32_t clockmask) {
mbed_official 525:c320967f86b9 91 uint32_t freq = 14000000, baudrate;
mbed_official 525:c320967f86b9 92 USART_OVS_TypeDef ovs;
mbed_official 525:c320967f86b9 93
mbed_official 525:c320967f86b9 94 if(CMU->HFPERCLKEN0 & clockmask) {
mbed_official 525:c320967f86b9 95 /* Different methods for sync vs async */
mbed_official 525:c320967f86b9 96 if(usart->CTRL & USART_CTRL_SYNC) {
mbed_official 525:c320967f86b9 97 ovs = (USART_OVS_TypeDef) (usart->CTRL & _USART_CTRL_OVS_MASK);
mbed_official 525:c320967f86b9 98 baudrate = USART_BaudrateCalc(freq, usart->CLKDIV, true, ovs);
mbed_official 525:c320967f86b9 99 USART_BaudrateSyncSet(usart, 0, baudrate);
mbed_official 525:c320967f86b9 100 } else {
mbed_official 525:c320967f86b9 101 ovs = (USART_OVS_TypeDef) (usart->CTRL & _USART_CTRL_OVS_MASK);
mbed_official 525:c320967f86b9 102 baudrate = USART_BaudrateCalc(freq, usart->CLKDIV, false, ovs);
mbed_official 525:c320967f86b9 103 USART_BaudrateAsyncSet(usart, 0, baudrate, ovs);
mbed_official 525:c320967f86b9 104 }
mbed_official 525:c320967f86b9 105 }
mbed_official 525:c320967f86b9 106 }