mbed library sources for GR-PEACH rev.B.

Fork of mbed-src by mbed official

Committer:
RyoheiHagimoto
Date:
Wed Apr 15 01:34:29 2015 +0000
Revision:
514:cf59050bad8e
Parent:
348:3dfac0d3ce7b
mbed library sources for GR-PEACH rev.B.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 348:3dfac0d3ce7b 1 /* mbed Microcontroller Library
mbed_official 348:3dfac0d3ce7b 2 * Copyright (c) 2006-2013 ARM Limited
mbed_official 348:3dfac0d3ce7b 3 *
mbed_official 348:3dfac0d3ce7b 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 348:3dfac0d3ce7b 5 * you may not use this file except in compliance with the License.
mbed_official 348:3dfac0d3ce7b 6 * You may obtain a copy of the License at
mbed_official 348:3dfac0d3ce7b 7 *
mbed_official 348:3dfac0d3ce7b 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 348:3dfac0d3ce7b 9 *
mbed_official 348:3dfac0d3ce7b 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 348:3dfac0d3ce7b 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 348:3dfac0d3ce7b 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 348:3dfac0d3ce7b 13 * See the License for the specific language governing permissions and
mbed_official 348:3dfac0d3ce7b 14 * limitations under the License.
mbed_official 348:3dfac0d3ce7b 15 */
mbed_official 348:3dfac0d3ce7b 16 #include "rtc_api.h"
mbed_official 348:3dfac0d3ce7b 17
mbed_official 348:3dfac0d3ce7b 18 #if DEVICE_RTC
mbed_official 348:3dfac0d3ce7b 19
mbed_official 348:3dfac0d3ce7b 20 void rtc_init(void)
mbed_official 348:3dfac0d3ce7b 21 {
mbed_official 348:3dfac0d3ce7b 22 // Enables clock for RTC
mbed_official 348:3dfac0d3ce7b 23 LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 30);
mbed_official 348:3dfac0d3ce7b 24
mbed_official 348:3dfac0d3ce7b 25 // Software reset
mbed_official 348:3dfac0d3ce7b 26 LPC_RTC->CTRL |= 1;
mbed_official 348:3dfac0d3ce7b 27
mbed_official 348:3dfac0d3ce7b 28 LPC_RTC->COUNT = 0;
mbed_official 348:3dfac0d3ce7b 29
mbed_official 348:3dfac0d3ce7b 30 // Enabled RTC
mbed_official 348:3dfac0d3ce7b 31 LPC_RTC->CTRL |= (1 << 7);
mbed_official 348:3dfac0d3ce7b 32 // clear reset
mbed_official 348:3dfac0d3ce7b 33 LPC_RTC->CTRL &= ~1;
mbed_official 348:3dfac0d3ce7b 34 }
mbed_official 348:3dfac0d3ce7b 35
mbed_official 348:3dfac0d3ce7b 36 void rtc_free(void)
mbed_official 348:3dfac0d3ce7b 37 {
mbed_official 348:3dfac0d3ce7b 38 LPC_SYSCON->SYSAHBCLKCTRL &= ~(1 << 30);
mbed_official 348:3dfac0d3ce7b 39 LPC_RTC->CTRL &= ~(1 << 7);
mbed_official 348:3dfac0d3ce7b 40 }
mbed_official 348:3dfac0d3ce7b 41
mbed_official 348:3dfac0d3ce7b 42 int rtc_isenabled(void)
mbed_official 348:3dfac0d3ce7b 43 {
mbed_official 348:3dfac0d3ce7b 44 return (((LPC_RTC->CTRL) & 0x80) != 0);
mbed_official 348:3dfac0d3ce7b 45 }
mbed_official 348:3dfac0d3ce7b 46
mbed_official 348:3dfac0d3ce7b 47 time_t rtc_read(void)
mbed_official 348:3dfac0d3ce7b 48 {
mbed_official 348:3dfac0d3ce7b 49 return (time_t)LPC_RTC->COUNT;
mbed_official 348:3dfac0d3ce7b 50 }
mbed_official 348:3dfac0d3ce7b 51
mbed_official 348:3dfac0d3ce7b 52 void rtc_write(time_t t)
mbed_official 348:3dfac0d3ce7b 53 {
mbed_official 348:3dfac0d3ce7b 54 // Disabled RTC
mbed_official 348:3dfac0d3ce7b 55 LPC_RTC->CTRL &= ~(1 << 7);
mbed_official 348:3dfac0d3ce7b 56
mbed_official 348:3dfac0d3ce7b 57 // Set count
mbed_official 348:3dfac0d3ce7b 58 LPC_RTC->COUNT = t;
mbed_official 348:3dfac0d3ce7b 59
mbed_official 348:3dfac0d3ce7b 60 //Enabled RTC
mbed_official 348:3dfac0d3ce7b 61 LPC_RTC->CTRL |= (1 << 7);
mbed_official 348:3dfac0d3ce7b 62 }
mbed_official 348:3dfac0d3ce7b 63
mbed_official 348:3dfac0d3ce7b 64 #endif