mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Fri May 22 10:45:46 2015 +0100
Revision:
548:1abac31e188e
Parent:
527:74d34ce5a2b5
Synchronized with git revision 88d158e43b54f97c5e94da305ea9a096889cc81b

Full URL: https://github.com/mbedmicro/mbed/commit/88d158e43b54f97c5e94da305ea9a096889cc81b/

Silicon Labs - Cosmetic: apply mbed coding style to HAL

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 548:1abac31e188e 53 /* cmuClock_LFB (to date) only has LEUART peripherals.
mbed_official 548:1abac31e188e 54 * Do NOT set it up here, as LEUARTs might have been initialized
mbed_official 548:1abac31e188e 55 * before this code is called. (Limitation of the override mechanism of ARMCC)
mbed_official 548:1abac31e188e 56 */
mbed_official 548:1abac31e188e 57 //TODO: Look for a more elegant fix.
mbed_official 527:74d34ce5a2b5 58 //CMU_ClockSelectSet(cmuClock_LFB, LFXO);
mbed_official 525:c320967f86b9 59 #endif
mbed_official 525:c320967f86b9 60 #ifdef CMU_LFECLKSEL_REG
mbed_official 525:c320967f86b9 61 CMU_ClockSelectSet(cmuClock_LFE, LFXO);
mbed_official 525:c320967f86b9 62 #endif
mbed_official 525:c320967f86b9 63 SystemLFXOClockSet(LFXO_FREQUENCY);
mbed_official 525:c320967f86b9 64
mbed_official 525:c320967f86b9 65 #elif( LOW_ENERGY_CLOCK_SOURCE == LFRCO )
mbed_official 525:c320967f86b9 66 #ifdef CMU_LFACLKSEL_REG
mbed_official 525:c320967f86b9 67 CMU_ClockSelectSet(cmuClock_LFA, LFRCO);
mbed_official 525:c320967f86b9 68 #endif
mbed_official 525:c320967f86b9 69 #ifdef CMU_LFBCLKSEL_REG
mbed_official 525:c320967f86b9 70 //CMU_ClockSelectSet(cmuClock_LFB, LFRCO);
mbed_official 525:c320967f86b9 71 #endif
mbed_official 525:c320967f86b9 72 #ifdef CMU_LFECLKSEL_REG
mbed_official 525:c320967f86b9 73 CMU_ClockSelectSet(cmuClock_LFE, LFRCO);
mbed_official 525:c320967f86b9 74 #endif
mbed_official 525:c320967f86b9 75 CMU_HFRCOBandSet(HFRCO_FREQUENCY);
mbed_official 525:c320967f86b9 76
mbed_official 525:c320967f86b9 77 #elif( LOW_ENERGY_CLOCK_SOURCE == ULFRCO)
mbed_official 525:c320967f86b9 78 #ifdef CMU_LFACLKSEL_REG
mbed_official 525:c320967f86b9 79 CMU_ClockSelectSet(cmuClock_LFA, ULFRCO);
mbed_official 525:c320967f86b9 80 #endif
mbed_official 525:c320967f86b9 81 #ifdef CMU_LFBCLKSEL_REG
mbed_official 525:c320967f86b9 82 CMU_ClockSelectSet(cmuClock_LFB, ULFRCO);
mbed_official 525:c320967f86b9 83 #endif
mbed_official 525:c320967f86b9 84 #ifdef CMU_LFECLKSEL_REG
mbed_official 525:c320967f86b9 85 CMU_ClockSelectSet(cmuClock_LFE, ULFRCO);
mbed_official 525:c320967f86b9 86 #endif
mbed_official 525:c320967f86b9 87 #else
mbed_official 525:c320967f86b9 88 #error "Low energy clock selection not valid"
mbed_official 525:c320967f86b9 89 #endif
mbed_official 525:c320967f86b9 90
mbed_official 525:c320967f86b9 91 /* Enable BC line driver to avoid garbage on CDC port */
mbed_official 525:c320967f86b9 92 gpio_init_out_ex(&bc_enable, EFM_BC_EN, 1);
mbed_official 525:c320967f86b9 93 }
mbed_official 525:c320967f86b9 94
mbed_official 548:1abac31e188e 95 void check_usart_clock(USART_TypeDef* usart, uint32_t clockmask)
mbed_official 548:1abac31e188e 96 {
mbed_official 525:c320967f86b9 97 uint32_t freq = 14000000, baudrate;
mbed_official 525:c320967f86b9 98 USART_OVS_TypeDef ovs;
mbed_official 525:c320967f86b9 99
mbed_official 525:c320967f86b9 100 if(CMU->HFPERCLKEN0 & clockmask) {
mbed_official 525:c320967f86b9 101 /* Different methods for sync vs async */
mbed_official 525:c320967f86b9 102 if(usart->CTRL & USART_CTRL_SYNC) {
mbed_official 525:c320967f86b9 103 ovs = (USART_OVS_TypeDef) (usart->CTRL & _USART_CTRL_OVS_MASK);
mbed_official 525:c320967f86b9 104 baudrate = USART_BaudrateCalc(freq, usart->CLKDIV, true, ovs);
mbed_official 525:c320967f86b9 105 USART_BaudrateSyncSet(usart, 0, baudrate);
mbed_official 525:c320967f86b9 106 } else {
mbed_official 525:c320967f86b9 107 ovs = (USART_OVS_TypeDef) (usart->CTRL & _USART_CTRL_OVS_MASK);
mbed_official 525:c320967f86b9 108 baudrate = USART_BaudrateCalc(freq, usart->CLKDIV, false, ovs);
mbed_official 525:c320967f86b9 109 USART_BaudrateAsyncSet(usart, 0, baudrate, ovs);
mbed_official 525:c320967f86b9 110 }
mbed_official 525:c320967f86b9 111 }
mbed_official 525:c320967f86b9 112 }