1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include "fsl_rtc_hal.h"
22 #include "fsl_clock_manager.h"
23 #include "PeripheralPins.h"
26 SIM_HAL_EnableRtcClock(SIM_BASE, 0U);
28 RTC_HAL_Init(RTC_BASE);
29 RTC_HAL_Enable(RTC_BASE);
31 RTC_HAL_EnableCounter(RTC_BASE, true);
39 * Little check routine to see if the RTC has been enabled
40 * 0 = Disabled, 1 = Enabled
42 int rtc_isenabled(void) {
43 SIM_HAL_EnableRtcClock(SIM_BASE, 0U);
44 return (int)RTC_HAL_IsCounterEnabled(RTC_BASE);
47 time_t rtc_read(void) {
48 return (time_t)RTC_HAL_GetSecsReg(RTC_BASE);
51 void rtc_write(time_t t) {
55 RTC_HAL_EnableCounter(RTC_BASE, false);
56 RTC_HAL_SetSecsReg(RTC_BASE, t);
57 RTC_HAL_EnableCounter(RTC_BASE, true);