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

Detailed Description

Real Time Clock helper.

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

Definition in file rtc_helper.cpp.

Functions

int _gettimeofday (timeval *tv, void *tzvp)
 
void PUBLIC_API_WEAK hal_lld_rtc_fixup (void)
 
void initRtc ()
 
void printRtcDateTime ()
 
void setRtcDateTime (efidatetime_t const *const dateTime)
 
static time_t rtc_encode (const RTCDateTime *timespec)
 
uint32_t getEpochTime ()
 
efidatetime_t getRtcDateTime ()
 
efidatetime_t convertRtcDateTimeToEfi (RTCDateTime const *const timespec)
 
RTCDateTime convertRtcDateTimeFromEfi (efidatetime_t const *const dateTime)
 
static void putTwoSymbolDecimal (int offset, char *destination, int value)
 
bool dateToStringShort (char *destination)
 

Variables

static const char *const monthAbbrs []
 

Function Documentation

◆ _gettimeofday()

int _gettimeofday ( timeval *  tv,
void *  tzvp 
)

Definition at line 23 of file rtc_helper.cpp.

23 {
24 (void)tv; (void)tzvp;
25 return 0;
26}

◆ convertRtcDateTimeFromEfi()

RTCDateTime convertRtcDateTimeFromEfi ( efidatetime_t const *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}

Referenced by setRtcDateTime().

Here is the caller graph for this function:

◆ convertRtcDateTimeToEfi()

efidatetime_t convertRtcDateTimeToEfi ( RTCDateTime const *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}
uint32_t year

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:

◆ hal_lld_rtc_fixup()

void PUBLIC_API_WEAK hal_lld_rtc_fixup ( void  )

Definition at line 31 of file rtc_helper.cpp.

31 {
32 /* nop */
33}

Referenced by initRtc().

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:

◆ putTwoSymbolDecimal()

static void putTwoSymbolDecimal ( int  offset,
char destination,
int  value 
)
static

Definition at line 113 of file rtc_helper.cpp.

113 {
114 static char buff[_MAX_FILLER];
115 efiAssertVoid(ObdCode::CUSTOM_ERR_6666, value >=0 && value <100, "value");
116 itoa10(buff, value);
117 if (value < 10) {
118 destination[offset] = '0';
119 destination[offset + 1] = buff[0];
120 } else {
121 destination[offset] = buff[0];
122 destination[offset + 1] = buff[1];
123 }
124}
char * itoa10(char *p, int num)
Definition efilib.cpp:107
@ CUSTOM_ERR_6666
uint16_t offset
Definition tunerstudio.h:0

Referenced by dateToStringShort().

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

◆ rtc_encode()

static time_t rtc_encode ( const RTCDateTime *  timespec)
static

Definition at line 61 of file rtc_helper.cpp.

61 {
62 struct tm tim;
63
64 // todo: looks like this pulls a lot of library code? 4K+?
65 // todo: reimplement lighter? https://github.com/rusefi/rusefi/issues/6876
66 rtcConvertDateTimeToStructTm(timespec, &tim, NULL);
67 return mktime(&tim);
68}

Referenced by getEpochTime().

Here is the caller graph for this function:

◆ setRtcDateTime()

void setRtcDateTime ( efidatetime_t const *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:

Variable Documentation

◆ monthAbbrs

const char* const monthAbbrs[]
static
Initial value:
= {
"Jan", "Feb", "Mar",
"Apr", "May", "Jun",
"Jul", "Aug", "Sep",
"Oct", "Nov", "Dec"
}

Definition at line 41 of file rtc_helper.cpp.

41 {
42 "Jan", "Feb", "Mar",
43 "Apr", "May", "Jun",
44 "Jul", "Aug", "Sep",
45 "Oct", "Nov", "Dec"
46};

Referenced by printRtcDateTime().

Go to the source code of this file.