Morpheus / target-freescale-ksdk

Fork of target-freescale-ksdk by -deleted-

Committer:
screamer
Date:
Wed Mar 23 21:26:50 2016 +0000
Revision:
0:e4d670b91a9a
Initial revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
screamer 0:e4d670b91a9a 1 /* mbed Microcontroller Library
screamer 0:e4d670b91a9a 2 * Copyright (c) 2006-2013 ARM Limited
screamer 0:e4d670b91a9a 3 *
screamer 0:e4d670b91a9a 4 * Licensed under the Apache License, Version 2.0 (the "License");
screamer 0:e4d670b91a9a 5 * you may not use this file except in compliance with the License.
screamer 0:e4d670b91a9a 6 * You may obtain a copy of the License at
screamer 0:e4d670b91a9a 7 *
screamer 0:e4d670b91a9a 8 * http://www.apache.org/licenses/LICENSE-2.0
screamer 0:e4d670b91a9a 9 *
screamer 0:e4d670b91a9a 10 * Unless required by applicable law or agreed to in writing, software
screamer 0:e4d670b91a9a 11 * distributed under the License is distributed on an "AS IS" BASIS,
screamer 0:e4d670b91a9a 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
screamer 0:e4d670b91a9a 13 * See the License for the specific language governing permissions and
screamer 0:e4d670b91a9a 14 * limitations under the License.
screamer 0:e4d670b91a9a 15 */
screamer 0:e4d670b91a9a 16 #include "rtc_api.h"
screamer 0:e4d670b91a9a 17
screamer 0:e4d670b91a9a 18 #if DEVICE_RTC
screamer 0:e4d670b91a9a 19
screamer 0:e4d670b91a9a 20 #include "pinmap.h"
screamer 0:e4d670b91a9a 21 #include "fsl_rtc_hal.h"
screamer 0:e4d670b91a9a 22 #include "fsl_clock_manager.h"
screamer 0:e4d670b91a9a 23 #include "PeripheralPins.h"
screamer 0:e4d670b91a9a 24
screamer 0:e4d670b91a9a 25 void rtc_init(void) {
screamer 0:e4d670b91a9a 26 SIM_HAL_EnableRtcClock(SIM_BASE, 0U);
screamer 0:e4d670b91a9a 27
screamer 0:e4d670b91a9a 28 RTC_HAL_Init(RTC_BASE);
screamer 0:e4d670b91a9a 29 RTC_HAL_Enable(RTC_BASE);
screamer 0:e4d670b91a9a 30
screamer 0:e4d670b91a9a 31 RTC_HAL_EnableCounter(RTC_BASE, true);
screamer 0:e4d670b91a9a 32 }
screamer 0:e4d670b91a9a 33
screamer 0:e4d670b91a9a 34 void rtc_free(void) {
screamer 0:e4d670b91a9a 35 // [TODO]
screamer 0:e4d670b91a9a 36 }
screamer 0:e4d670b91a9a 37
screamer 0:e4d670b91a9a 38 /*
screamer 0:e4d670b91a9a 39 * Little check routine to see if the RTC has been enabled
screamer 0:e4d670b91a9a 40 * 0 = Disabled, 1 = Enabled
screamer 0:e4d670b91a9a 41 */
screamer 0:e4d670b91a9a 42 int rtc_isenabled(void) {
screamer 0:e4d670b91a9a 43 SIM_HAL_EnableRtcClock(SIM_BASE, 0U);
screamer 0:e4d670b91a9a 44 return (int)RTC_HAL_IsCounterEnabled(RTC_BASE);
screamer 0:e4d670b91a9a 45 }
screamer 0:e4d670b91a9a 46
screamer 0:e4d670b91a9a 47 time_t rtc_read(void) {
screamer 0:e4d670b91a9a 48 return (time_t)RTC_HAL_GetSecsReg(RTC_BASE);
screamer 0:e4d670b91a9a 49 }
screamer 0:e4d670b91a9a 50
screamer 0:e4d670b91a9a 51 void rtc_write(time_t t) {
screamer 0:e4d670b91a9a 52 if (t == 0) {
screamer 0:e4d670b91a9a 53 t = 1;
screamer 0:e4d670b91a9a 54 }
screamer 0:e4d670b91a9a 55 RTC_HAL_EnableCounter(RTC_BASE, false);
screamer 0:e4d670b91a9a 56 RTC_HAL_SetSecsReg(RTC_BASE, t);
screamer 0:e4d670b91a9a 57 RTC_HAL_EnableCounter(RTC_BASE, true);
screamer 0:e4d670b91a9a 58 }
screamer 0:e4d670b91a9a 59
screamer 0:e4d670b91a9a 60 #endif