]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/rtc_api.c
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / hal / TARGET_Freescale / TARGET_KPSDK_MCUS / rtc_api.c
1 /* mbed Microcontroller Library
2  * Copyright (c) 2006-2013 ARM Limited
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 #include "rtc_api.h"
17
18 #if DEVICE_RTC
19
20 #include "pinmap.h"
21 #include "fsl_rtc_hal.h"
22 #include "fsl_clock_manager.h"
23 #include "PeripheralPins.h"
24
25 void rtc_init(void) {
26     SIM_HAL_EnableRtcClock(SIM_BASE, 0U);
27
28     RTC_HAL_Init(RTC_BASE);
29     RTC_HAL_Enable(RTC_BASE);
30
31     RTC_HAL_EnableCounter(RTC_BASE, true);
32 }
33
34 void rtc_free(void) {
35     // [TODO]
36 }
37
38 /*
39  * Little check routine to see if the RTC has been enabled
40  * 0 = Disabled, 1 = Enabled
41  */
42 int rtc_isenabled(void) {
43     SIM_HAL_EnableRtcClock(SIM_BASE, 0U);
44     return (int)RTC_HAL_IsCounterEnabled(RTC_BASE);
45 }
46
47 time_t rtc_read(void) {
48     return (time_t)RTC_HAL_GetSecsReg(RTC_BASE);
49 }
50
51 void rtc_write(time_t t) {
52     if (t == 0) {
53         t = 1;
54     }
55     RTC_HAL_EnableCounter(RTC_BASE, false);
56     RTC_HAL_SetSecsReg(RTC_BASE, t);
57     RTC_HAL_EnableCounter(RTC_BASE, true);
58 }
59
60 #endif