git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@14032 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
Giovanni Di Sirio 2021-02-07 10:14:23 +00:00
parent 1d3aae3b93
commit b9d081adeb
2 changed files with 18 additions and 2 deletions

View File

@ -46,7 +46,11 @@
* Lookup table with months' length * Lookup table with months' length
*/ */
static const uint8_t month_len[12] = { static const uint8_t month_len[12] = {
31, 30, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
static const uint16_t accu_month_len[12] = {
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
}; };
/*===========================================================================*/ /*===========================================================================*/
@ -220,7 +224,8 @@ void rtcSetCallback(RTCDriver *rtcp, rtccb_t callback) {
void rtcConvertDateTimeToStructTm(const RTCDateTime *timespec, void rtcConvertDateTimeToStructTm(const RTCDateTime *timespec,
struct tm *timp, struct tm *timp,
uint32_t *tv_msec) { uint32_t *tv_msec) {
int sec; int sec, year;
bool is_leap_year;
timp->tm_year = (int)timespec->year + (int)(RTC_BASE_YEAR - 1900U); timp->tm_year = (int)timespec->year + (int)(RTC_BASE_YEAR - 1900U);
timp->tm_mon = (int)timespec->month - 1; timp->tm_mon = (int)timespec->month - 1;
@ -237,6 +242,15 @@ void rtcConvertDateTimeToStructTm(const RTCDateTime *timespec,
if (NULL != tv_msec) { if (NULL != tv_msec) {
*tv_msec = (uint32_t)timespec->millisecond % 1000U; *tv_msec = (uint32_t)timespec->millisecond % 1000U;
} }
/* Day of the year calculation.*/
year = timp->tm_year + 1900;
timp->tm_yday = timp->tm_mday - 1;
timp->tm_yday += accu_month_len[timp->tm_mon];
is_leap_year = ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
if (is_leap_year && (timp->tm_mon > 1)) {
timp->tm_yday++;
}
} }
/** /**

View File

@ -128,6 +128,8 @@
MEMS Accelerometers. MEMS Accelerometers.
- NEW: Safer messages mechanism for sandboxes (to be backported to 20.3.1). - NEW: Safer messages mechanism for sandboxes (to be backported to 20.3.1).
- NEW: Added latency measurement test application. - NEW: Added latency measurement test application.
- FIX: Fixed FAT time problem in RTC driver (bug #1142)
(backported to 20.3.3)(backported to 19.1.5).
- FIX: Fixed Heap allocation of aligned FIFO objects in chFactory (bug #1141) - FIX: Fixed Heap allocation of aligned FIFO objects in chFactory (bug #1141)
(backported to 20.3.3)(backported to 19.1.5). (backported to 20.3.3)(backported to 19.1.5).
- FIX: Fixed chsnprintf() sign mode/filler mode conflict (bug #1140) - FIX: Fixed chsnprintf() sign mode/filler mode conflict (bug #1140)