]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11U6X/rtc_api.c
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / hal / TARGET_NXP / TARGET_LPC11U6X / 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 void rtc_init(void)
21 {
22     // Enables clock for RTC
23     LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 30);
24
25     // Software reset
26     LPC_RTC->CTRL |= 1;
27
28     LPC_RTC->COUNT = 0;
29
30     // Enabled RTC
31     LPC_RTC->CTRL |= (1 << 7);
32     // clear reset
33     LPC_RTC->CTRL &= ~1;
34 }
35
36 void rtc_free(void)
37 {
38     LPC_SYSCON->SYSAHBCLKCTRL &= ~(1 << 30);
39     LPC_RTC->CTRL &= ~(1 << 7);
40 }
41
42 int rtc_isenabled(void)
43 {
44     return (((LPC_RTC->CTRL) & 0x80) != 0);
45 }
46
47 time_t rtc_read(void)
48 {
49     return (time_t)LPC_RTC->COUNT;
50 }
51
52 void rtc_write(time_t t)
53 {
54     // Disabled RTC
55     LPC_RTC->CTRL &= ~(1 << 7);
56
57     // Set count
58     LPC_RTC->COUNT = t;
59
60     //Enabled RTC
61     LPC_RTC->CTRL |= (1 << 7);
62 }
63
64 #endif