RTC auf true
targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/rtc_api.c@0:38ceb79fef03, 2018-11-28 (annotated)
- Committer:
- kevman
- Date:
- Wed Nov 28 15:10:15 2018 +0000
- Revision:
- 0:38ceb79fef03
- Child:
- 2:7aab896b1a3b
RTC modified
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kevman | 0:38ceb79fef03 | 1 | /* mbed Microcontroller Library |
kevman | 0:38ceb79fef03 | 2 | * Copyright (c) 2006-2013 ARM Limited |
kevman | 0:38ceb79fef03 | 3 | * |
kevman | 0:38ceb79fef03 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kevman | 0:38ceb79fef03 | 5 | * you may not use this file except in compliance with the License. |
kevman | 0:38ceb79fef03 | 6 | * You may obtain a copy of the License at |
kevman | 0:38ceb79fef03 | 7 | * |
kevman | 0:38ceb79fef03 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kevman | 0:38ceb79fef03 | 9 | * |
kevman | 0:38ceb79fef03 | 10 | * Unless required by applicable law or agreed to in writing, software |
kevman | 0:38ceb79fef03 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kevman | 0:38ceb79fef03 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kevman | 0:38ceb79fef03 | 13 | * See the License for the specific language governing permissions and |
kevman | 0:38ceb79fef03 | 14 | * limitations under the License. |
kevman | 0:38ceb79fef03 | 15 | */ |
kevman | 0:38ceb79fef03 | 16 | #include "rtc_api.h" |
kevman | 0:38ceb79fef03 | 17 | |
kevman | 0:38ceb79fef03 | 18 | #if DEVICE_RTC || DEVICE_LPTICKER |
kevman | 0:38ceb79fef03 | 19 | |
kevman | 0:38ceb79fef03 | 20 | #include "pinmap.h" |
kevman | 0:38ceb79fef03 | 21 | #include "fsl_rtc.h" |
kevman | 0:38ceb79fef03 | 22 | #include "PeripheralPins.h" |
kevman | 0:38ceb79fef03 | 23 | |
kevman | 0:38ceb79fef03 | 24 | // changed PeterS |
kevman | 0:38ceb79fef03 | 25 | static bool rtc_time_set = true; |
kevman | 0:38ceb79fef03 | 26 | |
kevman | 0:38ceb79fef03 | 27 | void rtc_init(void) |
kevman | 0:38ceb79fef03 | 28 | { |
kevman | 0:38ceb79fef03 | 29 | rtc_config_t rtcConfig; |
kevman | 0:38ceb79fef03 | 30 | |
kevman | 0:38ceb79fef03 | 31 | RTC_GetDefaultConfig(&rtcConfig); |
kevman | 0:38ceb79fef03 | 32 | RTC_Init(RTC, &rtcConfig); |
kevman | 0:38ceb79fef03 | 33 | |
kevman | 0:38ceb79fef03 | 34 | RTC_StartTimer(RTC); |
kevman | 0:38ceb79fef03 | 35 | } |
kevman | 0:38ceb79fef03 | 36 | |
kevman | 0:38ceb79fef03 | 37 | void rtc_free(void) |
kevman | 0:38ceb79fef03 | 38 | { |
kevman | 0:38ceb79fef03 | 39 | #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) |
kevman | 0:38ceb79fef03 | 40 | /* Gate the module clock */ |
kevman | 0:38ceb79fef03 | 41 | CLOCK_DisableClock(kCLOCK_Rtc0); |
kevman | 0:38ceb79fef03 | 42 | #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */ |
kevman | 0:38ceb79fef03 | 43 | } |
kevman | 0:38ceb79fef03 | 44 | |
kevman | 0:38ceb79fef03 | 45 | /* |
kevman | 0:38ceb79fef03 | 46 | * Little check routine to see if the RTC has been initialized and time has been set |
kevman | 0:38ceb79fef03 | 47 | * 0 = Disabled, 1 = Enabled |
kevman | 0:38ceb79fef03 | 48 | */ |
kevman | 0:38ceb79fef03 | 49 | int rtc_isenabled(void) |
kevman | 0:38ceb79fef03 | 50 | { |
kevman | 0:38ceb79fef03 | 51 | #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) |
kevman | 0:38ceb79fef03 | 52 | CLOCK_EnableClock(kCLOCK_Rtc0); |
kevman | 0:38ceb79fef03 | 53 | #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */ |
kevman | 0:38ceb79fef03 | 54 | |
kevman | 0:38ceb79fef03 | 55 | const bool rtc_init_done = ((RTC->SR & RTC_SR_TCE_MASK) >> RTC_SR_TCE_SHIFT); |
kevman | 0:38ceb79fef03 | 56 | |
kevman | 0:38ceb79fef03 | 57 | /* If RTC is not initialized, then disable the clock gate on exit. */ |
kevman | 0:38ceb79fef03 | 58 | if(!rtc_init_done) { |
kevman | 0:38ceb79fef03 | 59 | rtc_free(); |
kevman | 0:38ceb79fef03 | 60 | } |
kevman | 0:38ceb79fef03 | 61 | |
kevman | 0:38ceb79fef03 | 62 | return (rtc_init_done & rtc_time_set); |
kevman | 0:38ceb79fef03 | 63 | } |
kevman | 0:38ceb79fef03 | 64 | |
kevman | 0:38ceb79fef03 | 65 | time_t rtc_read(void) |
kevman | 0:38ceb79fef03 | 66 | { |
kevman | 0:38ceb79fef03 | 67 | return (time_t)RTC->TSR; |
kevman | 0:38ceb79fef03 | 68 | } |
kevman | 0:38ceb79fef03 | 69 | |
kevman | 0:38ceb79fef03 | 70 | void rtc_write(time_t t) |
kevman | 0:38ceb79fef03 | 71 | { |
kevman | 0:38ceb79fef03 | 72 | RTC_StopTimer(RTC); |
kevman | 0:38ceb79fef03 | 73 | RTC->TSR = t; |
kevman | 0:38ceb79fef03 | 74 | RTC_StartTimer(RTC); |
kevman | 0:38ceb79fef03 | 75 | |
kevman | 0:38ceb79fef03 | 76 | rtc_time_set = true; |
kevman | 0:38ceb79fef03 | 77 | } |
kevman | 0:38ceb79fef03 | 78 | |
kevman | 0:38ceb79fef03 | 79 | #endif |