test
Fork of mbed-dev by
targets/TARGET_Realtek/TARGET_AMEBA/rtc_api.c@168:e84263d55307, 2017-06-21 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Jun 21 17:46:44 2017 +0100
- Revision:
- 168:e84263d55307
This updates the lib to the mbed lib v 145
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 168:e84263d55307 | 1 | /* mbed Microcontroller Library |
AnnaBridge | 168:e84263d55307 | 2 | * Copyright (c) 2013-2016 Realtek Semiconductor Corp. |
AnnaBridge | 168:e84263d55307 | 3 | * |
AnnaBridge | 168:e84263d55307 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
AnnaBridge | 168:e84263d55307 | 5 | * you may not use this file except in compliance with the License. |
AnnaBridge | 168:e84263d55307 | 6 | * You may obtain a copy of the License at |
AnnaBridge | 168:e84263d55307 | 7 | * |
AnnaBridge | 168:e84263d55307 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
AnnaBridge | 168:e84263d55307 | 9 | * |
AnnaBridge | 168:e84263d55307 | 10 | * Unless required by applicable law or agreed to in writing, software |
AnnaBridge | 168:e84263d55307 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
AnnaBridge | 168:e84263d55307 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
AnnaBridge | 168:e84263d55307 | 13 | * See the License for the specific language governing permissions and |
AnnaBridge | 168:e84263d55307 | 14 | * limitations under the License. |
AnnaBridge | 168:e84263d55307 | 15 | */ |
AnnaBridge | 168:e84263d55307 | 16 | |
AnnaBridge | 168:e84263d55307 | 17 | #include "rtc_api.h" |
AnnaBridge | 168:e84263d55307 | 18 | |
AnnaBridge | 168:e84263d55307 | 19 | #if DEVICE_RTC |
AnnaBridge | 168:e84263d55307 | 20 | #include <time.h> |
AnnaBridge | 168:e84263d55307 | 21 | #include "timer_api.h" // software-RTC: use a g-timer for the tick of the RTC |
AnnaBridge | 168:e84263d55307 | 22 | #include "mbed_mktime.h" |
AnnaBridge | 168:e84263d55307 | 23 | |
AnnaBridge | 168:e84263d55307 | 24 | #define SW_RTC_TIMER_ID TIMER4 |
AnnaBridge | 168:e84263d55307 | 25 | |
AnnaBridge | 168:e84263d55307 | 26 | static gtimer_t sw_rtc; |
AnnaBridge | 168:e84263d55307 | 27 | static int sw_rtc_en=0; |
AnnaBridge | 168:e84263d55307 | 28 | static time_t rtc_time; |
AnnaBridge | 168:e84263d55307 | 29 | |
AnnaBridge | 168:e84263d55307 | 30 | void sw_rtc_tick_handler(uint32_t id) |
AnnaBridge | 168:e84263d55307 | 31 | { |
AnnaBridge | 168:e84263d55307 | 32 | rtc_time++; |
AnnaBridge | 168:e84263d55307 | 33 | } |
AnnaBridge | 168:e84263d55307 | 34 | |
AnnaBridge | 168:e84263d55307 | 35 | void rtc_init(void) |
AnnaBridge | 168:e84263d55307 | 36 | { |
AnnaBridge | 168:e84263d55307 | 37 | // Initial a periodical timer |
AnnaBridge | 168:e84263d55307 | 38 | gtimer_init(&sw_rtc, SW_RTC_TIMER_ID); |
AnnaBridge | 168:e84263d55307 | 39 | // Tick every 1 sec |
AnnaBridge | 168:e84263d55307 | 40 | gtimer_start_periodical(&sw_rtc, 1000000, (void*)sw_rtc_tick_handler, (uint32_t)&sw_rtc); |
AnnaBridge | 168:e84263d55307 | 41 | sw_rtc_en = 1; |
AnnaBridge | 168:e84263d55307 | 42 | } |
AnnaBridge | 168:e84263d55307 | 43 | |
AnnaBridge | 168:e84263d55307 | 44 | void rtc_free(void) |
AnnaBridge | 168:e84263d55307 | 45 | { |
AnnaBridge | 168:e84263d55307 | 46 | sw_rtc_en = 0; |
AnnaBridge | 168:e84263d55307 | 47 | gtimer_stop(&sw_rtc); |
AnnaBridge | 168:e84263d55307 | 48 | gtimer_deinit(&sw_rtc); |
AnnaBridge | 168:e84263d55307 | 49 | } |
AnnaBridge | 168:e84263d55307 | 50 | |
AnnaBridge | 168:e84263d55307 | 51 | int rtc_isenabled(void) |
AnnaBridge | 168:e84263d55307 | 52 | { |
AnnaBridge | 168:e84263d55307 | 53 | return(sw_rtc_en); |
AnnaBridge | 168:e84263d55307 | 54 | } |
AnnaBridge | 168:e84263d55307 | 55 | |
AnnaBridge | 168:e84263d55307 | 56 | time_t rtc_read(void) |
AnnaBridge | 168:e84263d55307 | 57 | { |
AnnaBridge | 168:e84263d55307 | 58 | return rtc_time; |
AnnaBridge | 168:e84263d55307 | 59 | } |
AnnaBridge | 168:e84263d55307 | 60 | |
AnnaBridge | 168:e84263d55307 | 61 | void rtc_write(time_t t) |
AnnaBridge | 168:e84263d55307 | 62 | { |
AnnaBridge | 168:e84263d55307 | 63 | gtimer_stop(&sw_rtc); |
AnnaBridge | 168:e84263d55307 | 64 | |
AnnaBridge | 168:e84263d55307 | 65 | // Set the RTC |
AnnaBridge | 168:e84263d55307 | 66 | rtc_time = t; |
AnnaBridge | 168:e84263d55307 | 67 | |
AnnaBridge | 168:e84263d55307 | 68 | gtimer_start(&sw_rtc); |
AnnaBridge | 168:e84263d55307 | 69 | } |
AnnaBridge | 168:e84263d55307 | 70 | |
AnnaBridge | 168:e84263d55307 | 71 | #endif // endof "#if DEVICE_RTC" |