rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions
rtc_helper.h File Reference

Detailed Description

Real Time Clock helper.

Date
Feb 5, 2014
Author
Andrey Belomutskiy, (c) 2012-2020
Nathan Schulte, (c) 2022

Definition in file rtc_helper.h.

Functions

void initRtc ()
 
void printRtcDateTime ()
 
uint32_t getEpochTime ()
 
efidatetime_t getRtcDateTime ()
 
void setRtcDateTime (const efidatetime_t *const dateTime)
 
efidatetime_t convertRtcDateTimeToEfi (const RTCDateTime *const timespec)
 
RTCDateTime convertRtcDateTimeFromEfi (const efidatetime_t *const dateTime)
 
bool dateToStringShort (char *lcd_str)
 

Function Documentation

◆ convertRtcDateTimeFromEfi()

RTCDateTime convertRtcDateTimeFromEfi ( const efidatetime_t *const  dateTime)

Definition at line 100 of file rtc_helper.cpp.

100 {
101 RTCDateTime timespec;
102 timespec.year = dateTime->year - RTC_BASE_YEAR; // ChibiOS year origin is e.g. 1980
103 timespec.month = dateTime->month; // [1..12]
104 timespec.day = dateTime->day; // [1..31]
105 timespec.millisecond = (((dateTime->hour * 60) + dateTime->minute) * 60 + dateTime->second) * 1000; // ms since midnight
106 timespec.dayofweek = RTC_DAY_CATURDAY; // CATURDAY: 0 ... ?
107 timespec.dstflag = 0; // 0 ... ?
108 return timespec;
109}
uint32_t year

Referenced by setRtcDateTime().

Here is the caller graph for this function:

◆ convertRtcDateTimeToEfi()

efidatetime_t convertRtcDateTimeToEfi ( const RTCDateTime *const  timespec)

Definition at line 82 of file rtc_helper.cpp.

82 {
83 uint32_t second = timespec->millisecond / 1000;
84 uint16_t minute = second / 60;
85 second -= minute * 60;
86 uint8_t hour = minute / 60;
87 minute -= hour * 60;
88
89 efidatetime_t const dateTime = {
90 .year = timespec->year + RTC_BASE_YEAR,
91 .month = (uint8_t)timespec->month,
92 .day = (uint8_t)timespec->day,
93 .hour = hour,
94 .minute = (uint8_t)minute,
95 .second = (uint8_t)second,
96 };
97 return dateTime;
98}

Referenced by getRtcDateTime().

Here is the caller graph for this function:

◆ dateToStringShort()

bool dateToStringShort ( char destination)
Returns
true if we seem to know current date, false if no valid RTC state

Definition at line 131 of file rtc_helper.cpp.

131 {
132#if EFI_RTC
133 strcpy(destination, "000000_000000\0");
134 efidatetime_t dateTime = getRtcDateTime();
135 if (dateTime.year < 2016 || dateTime.year > 2030) {
136 // 2016 to 2030 is the valid range
137 destination[0] = 0;
138 return false;
139 }
140
141 putTwoSymbolDecimal(0, destination, dateTime.year % 100); // year, format as just the last two digits
142 putTwoSymbolDecimal(2, destination, dateTime.month); // month 1-12
143 putTwoSymbolDecimal(4, destination, dateTime.day); // day of the month 1-31
144
145 putTwoSymbolDecimal(7, destination, dateTime.hour); // hours since midnight 0-23
146 putTwoSymbolDecimal(9, destination, dateTime.minute); // minutes
147 putTwoSymbolDecimal(11, destination, dateTime.second); // seconds
148
149 return true;
150#else // EFI_RTC
151 destination[0] = 0;
152 return false;
153#endif // EFI_RTC
154}
static void putTwoSymbolDecimal(int offset, char *destination, int value)
efidatetime_t getRtcDateTime()

Referenced by prepareLogFileName().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getEpochTime()

uint32_t getEpochTime ( )

Definition at line 70 of file rtc_helper.cpp.

70 {
71 RTCDateTime timespec;
72 rtcGetTime(&RTCD1, &timespec);
73 return rtc_encode(&timespec);
74}
static time_t rtc_encode(const RTCDateTime *timespec)

Referenced by updateDevConsoleState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getRtcDateTime()

efidatetime_t getRtcDateTime ( )

Definition at line 76 of file rtc_helper.cpp.

76 {
77 RTCDateTime timespec;
78 rtcGetTime(&RTCD1, &timespec);
79 return convertRtcDateTimeToEfi(&timespec);
80}
efidatetime_t convertRtcDateTimeToEfi(RTCDateTime const *const timespec)

Referenced by canDashboardBmwE90(), dateToStringShort(), onGpsMessage(), and printRtcDateTime().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initRtc()

void initRtc ( )

Definition at line 35 of file rtc_helper.cpp.

35 {
36 efiPrintf("initRtc()");
38 printDateTime(); // this would test RTC, see #311
39}
void PUBLIC_API_WEAK hal_lld_rtc_fixup(void)
void printDateTime()
Definition settings.cpp:691

Referenced by initHardwareNoConfig().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ printRtcDateTime()

void printRtcDateTime ( )

Definition at line 48 of file rtc_helper.cpp.

48 {
49 efidatetime_t dateTime = getRtcDateTime();
50 // prints the date like: 19 sep 2022 21:19:55
51 efiPrintf("Current RTC time: %02u %s %04lu %02u:%02u:%02u",
52 dateTime.day, monthAbbrs[dateTime.month - 1], dateTime.year,
53 dateTime.hour, dateTime.minute, dateTime.second);
54}
static const char *const monthAbbrs[]

Referenced by printDateTime(), and setDateTime().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setRtcDateTime()

void setRtcDateTime ( const efidatetime_t *const  dateTime)

Definition at line 56 of file rtc_helper.cpp.

56 {
57 RTCDateTime timespec = convertRtcDateTimeFromEfi(dateTime);
58 rtcSetTime(&RTCD1, &timespec);
59}
RTCDateTime convertRtcDateTimeFromEfi(efidatetime_t const *const dateTime)

Referenced by onGpsMessage(), and setDateTime().

Here is the call graph for this function:
Here is the caller graph for this function:

Go to the source code of this file.