Skip to content

Commit 1e46895

Browse files
mprsebulislaw
authored andcommitted
K64F: adapt RTC drivers to the new standards (is_enabled function)
Make rtc_isenabled() to return 1 if the RTC is initialized and the time has been set; 0 otherwise. Disable clock gate on exit from this function if RTC was initialized.
1 parent 377db73 commit 1e46895

File tree

1 file changed

+16
-2
lines changed
  • targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api

1 file changed

+16
-2
lines changed

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/rtc_api.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
extern void rtc_setup_oscillator(RTC_Type *base);
2525

26+
static bool rtc_time_set = false;
27+
2628
void rtc_init(void)
2729
{
2830
rtc_config_t rtcConfig;
@@ -44,13 +46,23 @@ void rtc_free(void)
4446
}
4547

4648
/*
47-
* Little check routine to see if the RTC has been enabled
49+
* Little check routine to see if the RTC has been initialized and time has been set
4850
* 0 = Disabled, 1 = Enabled
4951
*/
5052
int rtc_isenabled(void)
5153
{
54+
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
5255
CLOCK_EnableClock(kCLOCK_Rtc0);
53-
return (int)((RTC->SR & RTC_SR_TCE_MASK) >> RTC_SR_TCE_SHIFT);
56+
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
57+
58+
const bool rtc_init_done = ((RTC->SR & RTC_SR_TCE_MASK) >> RTC_SR_TCE_SHIFT);
59+
60+
/* If RTC is not initialized, then disable the clock gate on exit. */
61+
if(!rtc_init_done) {
62+
rtc_free();
63+
}
64+
65+
return (rtc_init_done & rtc_time_set);
5466
}
5567

5668
time_t rtc_read(void)
@@ -63,6 +75,8 @@ void rtc_write(time_t t)
6375
RTC_StopTimer(RTC);
6476
RTC->TSR = t;
6577
RTC_StartTimer(RTC);
78+
79+
rtc_time_set = true;
6680
}
6781

6882
#endif

0 commit comments

Comments
 (0)