mbed library sources. Supersedes mbed-src. Edited target satm32f446 for user USART3 pins

Dependents:   IGLOO_board

Fork of mbed-dev by mbed official

Committer:
ua1arn
Date:
Mon Jul 30 12:31:10 2018 +0000
Revision:
188:3f10722804f9
Parent:
186:707f6e361f3e
before add multi-configuration USB descriptors

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Anna Bridge 186:707f6e361f3e 1 /***************************************************************************//**
Anna Bridge 186:707f6e361f3e 2 * @file rtc_burtc.c
Anna Bridge 186:707f6e361f3e 3 *******************************************************************************
Anna Bridge 186:707f6e361f3e 4 * @section License
Anna Bridge 186:707f6e361f3e 5 * <b>(C) Copyright 2018 Silicon Labs, http://www.silabs.com</b>
Anna Bridge 186:707f6e361f3e 6 *******************************************************************************
Anna Bridge 186:707f6e361f3e 7 *
Anna Bridge 186:707f6e361f3e 8 * SPDX-License-Identifier: Apache-2.0
Anna Bridge 186:707f6e361f3e 9 *
Anna Bridge 186:707f6e361f3e 10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
Anna Bridge 186:707f6e361f3e 11 * not use this file except in compliance with the License.
Anna Bridge 186:707f6e361f3e 12 * You may obtain a copy of the License at
Anna Bridge 186:707f6e361f3e 13 *
Anna Bridge 186:707f6e361f3e 14 * http://www.apache.org/licenses/LICENSE-2.0
Anna Bridge 186:707f6e361f3e 15 *
Anna Bridge 186:707f6e361f3e 16 * Unless required by applicable law or agreed to in writing, software
Anna Bridge 186:707f6e361f3e 17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
Anna Bridge 186:707f6e361f3e 18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Anna Bridge 186:707f6e361f3e 19 * See the License for the specific language governing permissions and
Anna Bridge 186:707f6e361f3e 20 * limitations under the License.
Anna Bridge 186:707f6e361f3e 21 *
Anna Bridge 186:707f6e361f3e 22 ******************************************************************************/
Anna Bridge 186:707f6e361f3e 23
Anna Bridge 186:707f6e361f3e 24 #include "device.h"
Anna Bridge 186:707f6e361f3e 25 #if DEVICE_RTC
Anna Bridge 186:707f6e361f3e 26
Anna Bridge 186:707f6e361f3e 27 /* Use BURTC on devices that have it, and don't use the RTCC abstraction */
Anna Bridge 186:707f6e361f3e 28 #if defined(BURTC_PRESENT) && !defined(RTCC_PRESENT)
Anna Bridge 186:707f6e361f3e 29
Anna Bridge 186:707f6e361f3e 30 #include "clocking.h"
Anna Bridge 186:707f6e361f3e 31 #include "em_cmu.h"
Anna Bridge 186:707f6e361f3e 32 #include "em_emu.h"
Anna Bridge 186:707f6e361f3e 33 #include "em_burtc.h"
Anna Bridge 186:707f6e361f3e 34 #include "rtc_api.h"
Anna Bridge 186:707f6e361f3e 35
Anna Bridge 186:707f6e361f3e 36 void rtc_init(void)
Anna Bridge 186:707f6e361f3e 37 {
Anna Bridge 186:707f6e361f3e 38 /* Only reset & configure the RTC if it has never run before */
Anna Bridge 186:707f6e361f3e 39 if(BUS_RegBitRead(&BURTC->CTRL, _BURTC_CTRL_RSTEN_SHIFT)) {
Anna Bridge 186:707f6e361f3e 40 EMU_EM4Init_TypeDef em4_init = EMU_EM4INIT_DEFAULT;
Anna Bridge 186:707f6e361f3e 41 #if (LOW_ENERGY_CLOCK_SOURCE == LFXO)
Anna Bridge 186:707f6e361f3e 42 em4_init.osc = emuEM4Osc_LFXO;
Anna Bridge 186:707f6e361f3e 43 #elif (LOW_ENERGY_CLOCK_SOURCE == LFRCO)
Anna Bridge 186:707f6e361f3e 44 em4_init.osc = emuEM4Osc_LFRCO;
Anna Bridge 186:707f6e361f3e 45 #else
Anna Bridge 186:707f6e361f3e 46 #error "Can't use BURTC on mbed with ULFRCO"
Anna Bridge 186:707f6e361f3e 47 #endif
Anna Bridge 186:707f6e361f3e 48 EMU_EM4Init(&em4_init);
Anna Bridge 186:707f6e361f3e 49
Anna Bridge 186:707f6e361f3e 50 BURTC_Init_TypeDef burtc_init = BURTC_INIT_DEFAULT;
Anna Bridge 186:707f6e361f3e 51 burtc_init.mode = burtcModeEM4;
Anna Bridge 186:707f6e361f3e 52 #if (LOW_ENERGY_CLOCK_SOURCE == LFXO)
Anna Bridge 186:707f6e361f3e 53 burtc_init.clkSel = burtcClkSelLFXO;
Anna Bridge 186:707f6e361f3e 54 #elif (LOW_ENERGY_CLOCK_SOURCE == LFRCO)
Anna Bridge 186:707f6e361f3e 55 burtc_init.clkSel = burtcClkSelLFRCO;
Anna Bridge 186:707f6e361f3e 56 #else
Anna Bridge 186:707f6e361f3e 57 #error "Can't use BURTC on mbed with ULFRCO"
Anna Bridge 186:707f6e361f3e 58 #endif
Anna Bridge 186:707f6e361f3e 59 burtc_init.clkDiv = burtcClkDiv_128;
Anna Bridge 186:707f6e361f3e 60 burtc_init.lowPowerMode = burtcLPEnable;
Anna Bridge 186:707f6e361f3e 61
Anna Bridge 186:707f6e361f3e 62 BURTC_Reset();
Anna Bridge 186:707f6e361f3e 63 BUS_RegBitWrite(&RMU->CTRL, _RMU_CTRL_BURSTEN_SHIFT, 0);
Anna Bridge 186:707f6e361f3e 64 BURTC_Init(&burtc_init);
Anna Bridge 186:707f6e361f3e 65 BURTC_RetRegSet(0, 0);
Anna Bridge 186:707f6e361f3e 66 BURTC_RetRegSet(1, 0);
Anna Bridge 186:707f6e361f3e 67 }
Anna Bridge 186:707f6e361f3e 68 }
Anna Bridge 186:707f6e361f3e 69
Anna Bridge 186:707f6e361f3e 70 void rtc_free(void)
Anna Bridge 186:707f6e361f3e 71 {
Anna Bridge 186:707f6e361f3e 72 /* Nothing to release here */
Anna Bridge 186:707f6e361f3e 73 }
Anna Bridge 186:707f6e361f3e 74
Anna Bridge 186:707f6e361f3e 75 int rtc_isenabled(void)
Anna Bridge 186:707f6e361f3e 76 {
Anna Bridge 186:707f6e361f3e 77 return (BUS_RegBitRead(&BURTC->CTRL, _BURTC_CTRL_RSTEN_SHIFT) == 0);
Anna Bridge 186:707f6e361f3e 78 }
Anna Bridge 186:707f6e361f3e 79
Anna Bridge 186:707f6e361f3e 80 time_t rtc_read(void)
Anna Bridge 186:707f6e361f3e 81 {
Anna Bridge 186:707f6e361f3e 82 uint32_t ts = 0;
Anna Bridge 186:707f6e361f3e 83 uint32_t ts2 = 1;
Anna Bridge 186:707f6e361f3e 84 do {
Anna Bridge 186:707f6e361f3e 85 if (BURTC->IF & BURTC_IF_OF) {
Anna Bridge 186:707f6e361f3e 86 BURTC_RetRegSet(1, BURTC_RetRegGet(1)+1);
Anna Bridge 186:707f6e361f3e 87 BURTC->IFC = BURTC_IFC_OF;
Anna Bridge 186:707f6e361f3e 88 }
Anna Bridge 186:707f6e361f3e 89
Anna Bridge 186:707f6e361f3e 90 ts = ts2;
Anna Bridge 186:707f6e361f3e 91 ts2 = (BURTC_CounterGet() >> 8) + BURTC_RetRegGet(0) + (BURTC_RetRegGet(1) << 16);
Anna Bridge 186:707f6e361f3e 92 } while (ts != ts2);
Anna Bridge 186:707f6e361f3e 93 return ts2;
Anna Bridge 186:707f6e361f3e 94 }
Anna Bridge 186:707f6e361f3e 95
Anna Bridge 186:707f6e361f3e 96 void rtc_write(time_t t)
Anna Bridge 186:707f6e361f3e 97 {
Anna Bridge 186:707f6e361f3e 98 BURTC_RetRegSet(0, t - (BURTC_CounterGet() >> 8));
Anna Bridge 186:707f6e361f3e 99 BURTC_RetRegSet(1, 0);
Anna Bridge 186:707f6e361f3e 100 if (BURTC->IF & BURTC_IF_OF) {
Anna Bridge 186:707f6e361f3e 101 BURTC->IFC = BURTC_IFC_OF;
Anna Bridge 186:707f6e361f3e 102 }
Anna Bridge 186:707f6e361f3e 103 }
Anna Bridge 186:707f6e361f3e 104
Anna Bridge 186:707f6e361f3e 105 #endif /* BURTC_PRESENT && !RTCC_PRESENT */
Anna Bridge 186:707f6e361f3e 106 #endif /* DEVICE_RTC */