added prescaler for 16 bit pwm in LPC1347 target

Fork of mbed-dev by mbed official

Committer:
bogdanm
Date:
Thu Oct 01 15:25:22 2015 +0300
Revision:
0:9b334a45a8ff
Child:
50:a417edff4437
Initial commit on mbed-dev

Replaces mbed-src (now inactive)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bogdanm 0:9b334a45a8ff 1 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 2 * @file mbed_overrides.c
bogdanm 0:9b334a45a8ff 3 *******************************************************************************
bogdanm 0:9b334a45a8ff 4 * @section License
bogdanm 0:9b334a45a8ff 5 * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b>
bogdanm 0:9b334a45a8ff 6 *******************************************************************************
bogdanm 0:9b334a45a8ff 7 *
bogdanm 0:9b334a45a8ff 8 * Permission is granted to anyone to use this software for any purpose,
bogdanm 0:9b334a45a8ff 9 * including commercial applications, and to alter it and redistribute it
bogdanm 0:9b334a45a8ff 10 * freely, subject to the following restrictions:
bogdanm 0:9b334a45a8ff 11 *
bogdanm 0:9b334a45a8ff 12 * 1. The origin of this software must not be misrepresented; you must not
bogdanm 0:9b334a45a8ff 13 * claim that you wrote the original software.
bogdanm 0:9b334a45a8ff 14 * 2. Altered source versions must be plainly marked as such, and must not be
bogdanm 0:9b334a45a8ff 15 * misrepresented as being the original software.
bogdanm 0:9b334a45a8ff 16 * 3. This notice may not be removed or altered from any source distribution.
bogdanm 0:9b334a45a8ff 17 *
bogdanm 0:9b334a45a8ff 18 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no
bogdanm 0:9b334a45a8ff 19 * obligation to support this Software. Silicon Labs is providing the
bogdanm 0:9b334a45a8ff 20 * Software "AS IS", with no express or implied warranties of any kind,
bogdanm 0:9b334a45a8ff 21 * including, but not limited to, any implied warranties of merchantability
bogdanm 0:9b334a45a8ff 22 * or fitness for any particular purpose or warranties against infringement
bogdanm 0:9b334a45a8ff 23 * of any proprietary rights of a third party.
bogdanm 0:9b334a45a8ff 24 *
bogdanm 0:9b334a45a8ff 25 * Silicon Labs will not be liable for any consequential, incidental, or
bogdanm 0:9b334a45a8ff 26 * special damages, or any other relief, or for any claim by any third party,
bogdanm 0:9b334a45a8ff 27 * arising from your use of this Software.
bogdanm 0:9b334a45a8ff 28 *
bogdanm 0:9b334a45a8ff 29 ******************************************************************************/
bogdanm 0:9b334a45a8ff 30
bogdanm 0:9b334a45a8ff 31 #include "em_chip.h"
bogdanm 0:9b334a45a8ff 32 #include "em_device.h"
bogdanm 0:9b334a45a8ff 33 #include "em_cmu.h"
bogdanm 0:9b334a45a8ff 34 #include "em_emu.h"
bogdanm 0:9b334a45a8ff 35 #include "device_peripherals.h"
bogdanm 0:9b334a45a8ff 36 #include "device.h"
bogdanm 0:9b334a45a8ff 37 #include "em_usart.h"
bogdanm 0:9b334a45a8ff 38 #include "gpio_api.h"
bogdanm 0:9b334a45a8ff 39
bogdanm 0:9b334a45a8ff 40 gpio_t bc_enable;
bogdanm 0:9b334a45a8ff 41
bogdanm 0:9b334a45a8ff 42 void check_usart_clock(USART_TypeDef* usart, uint32_t clockmask);
bogdanm 0:9b334a45a8ff 43
bogdanm 0:9b334a45a8ff 44 /* Called before main - implement here if board needs it.
bogdanm 0:9b334a45a8ff 45 * Otherwise, let the application override this if necessary */
bogdanm 0:9b334a45a8ff 46 void mbed_sdk_init()
bogdanm 0:9b334a45a8ff 47 {
bogdanm 0:9b334a45a8ff 48 CHIP_Init();
bogdanm 0:9b334a45a8ff 49
bogdanm 0:9b334a45a8ff 50 /* Set up the clock sources for this chip */
bogdanm 0:9b334a45a8ff 51 #if( CORE_CLOCK_SOURCE == HFXO)
bogdanm 0:9b334a45a8ff 52 CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);
bogdanm 0:9b334a45a8ff 53 SystemHFXOClockSet(HFXO_FREQUENCY);
bogdanm 0:9b334a45a8ff 54 #elif( CORE_CLOCK_SOURCE == HFRCO)
bogdanm 0:9b334a45a8ff 55 CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFRCO);
bogdanm 0:9b334a45a8ff 56 CMU_HFRCOBandSet(HFRCO_FREQUENCY);
bogdanm 0:9b334a45a8ff 57 #else
bogdanm 0:9b334a45a8ff 58 #error "Core clock selection not valid (mbed_overrides.c)"
bogdanm 0:9b334a45a8ff 59 #endif
bogdanm 0:9b334a45a8ff 60
bogdanm 0:9b334a45a8ff 61 CMU_ClockEnable(cmuClock_CORELE, true);
bogdanm 0:9b334a45a8ff 62
bogdanm 0:9b334a45a8ff 63 #if( LOW_ENERGY_CLOCK_SOURCE == LFXO )
bogdanm 0:9b334a45a8ff 64 #ifdef CMU_LFACLKSEL_REG
bogdanm 0:9b334a45a8ff 65 CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFXO);
bogdanm 0:9b334a45a8ff 66 #endif
bogdanm 0:9b334a45a8ff 67 #ifdef CMU_LFBCLKSEL_REG
bogdanm 0:9b334a45a8ff 68 /* cmuClock_LFB (to date) only has LEUART peripherals.
bogdanm 0:9b334a45a8ff 69 * This gets set automatically whenever you create serial objects using LEUART
bogdanm 0:9b334a45a8ff 70 */
bogdanm 0:9b334a45a8ff 71 #endif
bogdanm 0:9b334a45a8ff 72 #ifdef CMU_LFECLKSEL_REG
bogdanm 0:9b334a45a8ff 73 CMU_ClockSelectSet(cmuClock_LFE, cmuSelect_LFXO);
bogdanm 0:9b334a45a8ff 74 #endif
bogdanm 0:9b334a45a8ff 75 SystemLFXOClockSet(LFXO_FREQUENCY);
bogdanm 0:9b334a45a8ff 76
bogdanm 0:9b334a45a8ff 77 #elif( LOW_ENERGY_CLOCK_SOURCE == LFRCO )
bogdanm 0:9b334a45a8ff 78 #ifdef CMU_LFACLKSEL_REG
bogdanm 0:9b334a45a8ff 79 CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFRCO);
bogdanm 0:9b334a45a8ff 80 #endif
bogdanm 0:9b334a45a8ff 81 #ifdef CMU_LFBCLKSEL_REG
bogdanm 0:9b334a45a8ff 82 //CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_LFRCO);
bogdanm 0:9b334a45a8ff 83 #endif
bogdanm 0:9b334a45a8ff 84 #ifdef CMU_LFECLKSEL_REG
bogdanm 0:9b334a45a8ff 85 CMU_ClockSelectSet(cmuClock_LFE, cmuSelect_LFRCO);
bogdanm 0:9b334a45a8ff 86 #endif
bogdanm 0:9b334a45a8ff 87 CMU_HFRCOBandSet(HFRCO_FREQUENCY);
bogdanm 0:9b334a45a8ff 88
bogdanm 0:9b334a45a8ff 89 #elif( LOW_ENERGY_CLOCK_SOURCE == ULFRCO)
bogdanm 0:9b334a45a8ff 90 #ifdef CMU_LFACLKSEL_REG
bogdanm 0:9b334a45a8ff 91 CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_ULFRCO);
bogdanm 0:9b334a45a8ff 92 #endif
bogdanm 0:9b334a45a8ff 93 #ifdef CMU_LFBCLKSEL_REG
bogdanm 0:9b334a45a8ff 94 CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_ULFRCO);
bogdanm 0:9b334a45a8ff 95 #endif
bogdanm 0:9b334a45a8ff 96 #ifdef CMU_LFECLKSEL_REG
bogdanm 0:9b334a45a8ff 97 CMU_ClockSelectSet(cmuClock_LFE, cmuSelect_ULFRCO);
bogdanm 0:9b334a45a8ff 98 #endif
bogdanm 0:9b334a45a8ff 99 #else
bogdanm 0:9b334a45a8ff 100 #error "Low energy clock selection not valid"
bogdanm 0:9b334a45a8ff 101 #endif
bogdanm 0:9b334a45a8ff 102
bogdanm 0:9b334a45a8ff 103 /* Enable BC line driver to avoid garbage on CDC port */
bogdanm 0:9b334a45a8ff 104 gpio_init_out_ex(&bc_enable, EFM_BC_EN, 1);
bogdanm 0:9b334a45a8ff 105 }
bogdanm 0:9b334a45a8ff 106
bogdanm 0:9b334a45a8ff 107 void check_usart_clock(USART_TypeDef* usart, uint32_t clockmask)
bogdanm 0:9b334a45a8ff 108 {
bogdanm 0:9b334a45a8ff 109 uint32_t freq = 14000000, baudrate;
bogdanm 0:9b334a45a8ff 110 USART_OVS_TypeDef ovs;
bogdanm 0:9b334a45a8ff 111
bogdanm 0:9b334a45a8ff 112 if(CMU->HFPERCLKEN0 & clockmask) {
bogdanm 0:9b334a45a8ff 113 /* Different methods for sync vs async */
bogdanm 0:9b334a45a8ff 114 if(usart->CTRL & USART_CTRL_SYNC) {
bogdanm 0:9b334a45a8ff 115 ovs = (USART_OVS_TypeDef) (usart->CTRL & _USART_CTRL_OVS_MASK);
bogdanm 0:9b334a45a8ff 116 baudrate = USART_BaudrateCalc(freq, usart->CLKDIV, true, ovs);
bogdanm 0:9b334a45a8ff 117 USART_BaudrateSyncSet(usart, 0, baudrate);
bogdanm 0:9b334a45a8ff 118 } else {
bogdanm 0:9b334a45a8ff 119 ovs = (USART_OVS_TypeDef) (usart->CTRL & _USART_CTRL_OVS_MASK);
bogdanm 0:9b334a45a8ff 120 baudrate = USART_BaudrateCalc(freq, usart->CLKDIV, false, ovs);
bogdanm 0:9b334a45a8ff 121 USART_BaudrateAsyncSet(usart, 0, baudrate, ovs);
bogdanm 0:9b334a45a8ff 122 }
bogdanm 0:9b334a45a8ff 123 }
bogdanm 0:9b334a45a8ff 124 }