From c9f2308a1d4401ceefaac47b1ea851530d07e47d Mon Sep 17 00:00:00 2001 From: James Buren Date: Sat, 3 Jul 2021 00:19:58 +0000 Subject: fat: move fattime_mktime to timefuncs This moves the time conversion function to timefuncs since it has uses on ports that don't use the FAT driver. This function has no dependency on the FAT driver as it is so this should not cause any issues. To reflect this separation the function was renamed to dostime_mktime since it is really for DOS timestamps. The places where it was used have also been updated. Change-Id: Id98b1448d5c6fcda286846e1d2c736db682bfb52 --- firmware/common/timefuncs.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'firmware/common/timefuncs.c') diff --git a/firmware/common/timefuncs.c b/firmware/common/timefuncs.c index 108431753a..d87e6b67f2 100644 --- a/firmware/common/timefuncs.c +++ b/firmware/common/timefuncs.c @@ -32,6 +32,20 @@ static struct tm tm; +time_t dostime_mktime(uint16_t dosdate, uint16_t dostime) +{ + /* this knows our mktime() only uses these struct tm fields */ + struct tm tm; + tm.tm_sec = ((dostime ) & 0x1f) * 2; + tm.tm_min = ((dostime >> 5) & 0x3f); + tm.tm_hour = ((dostime >> 11) ); + tm.tm_mday = ((dosdate ) & 0x1f); + tm.tm_mon = ((dosdate >> 5) & 0x0f) - 1; + tm.tm_year = ((dosdate >> 9) ) + 80; + + return mktime(&tm); +} + #if !CONFIG_RTC static inline bool rtc_dirty(void) { -- cgit v1.2.3