Supawat Yangdiew / rtc_api_11U6x
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers rtc_api_11U6x.c Source File

rtc_api_11U6x.c

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #include "rtc_api_11U6x.h"
00017 
00018 void rtc_init(void)
00019 {
00020     // Enables clock for RTC
00021     LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 30);
00022 
00023     // Software reset
00024     LPC_RTC->CTRL |= 1;
00025 
00026     LPC_RTC->COUNT = 0;
00027 
00028     // Enabled RTC
00029     LPC_RTC->CTRL |= (1 << 7);
00030     // clear reset
00031     LPC_RTC->CTRL &= ~1;
00032 }
00033 
00034 void rtc_free(void)
00035 {
00036     LPC_SYSCON->SYSAHBCLKCTRL &= ~(1 << 30);
00037     LPC_RTC->CTRL &= ~(1 << 7);
00038 }
00039 
00040 int rtc_isenabled(void)
00041 {
00042     return (((LPC_RTC->CTRL) & 0x80) != 0);
00043 }
00044 
00045 time_t rtc_read(void)
00046 {
00047     return (time_t)LPC_RTC->COUNT;
00048 }
00049 
00050 void rtc_write(time_t t)
00051 {
00052     // Disabled RTC
00053     LPC_RTC->CTRL &= ~(1 << 7);
00054 
00055     // Set count
00056     LPC_RTC->COUNT = t;
00057 
00058     //Enabled RTC
00059     LPC_RTC->CTRL |= (1 << 7);
00060 }