From c9f2308a1d4401ceefaac47b1ea851530d07e47d Mon Sep 17 00:00:00 2001 From: James Buren Date: Sat, 3 Jul 2021 00:19:58 +0000 Subject: [PATCH] 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/dir.c | 3 ++- firmware/common/dircache.c | 2 +- firmware/common/timefuncs.c | 14 ++++++++++++++ firmware/drivers/fat.c | 14 -------------- firmware/export/fat.h | 1 - firmware/include/timefuncs.h | 2 ++ 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/firmware/common/dir.c b/firmware/common/dir.c index f89129ae34..245947b134 100644 --- a/firmware/common/dir.c +++ b/firmware/common/dir.c @@ -26,6 +26,7 @@ #include "debug.h" #include "dir.h" #include "pathfuncs.h" +#include "timefuncs.h" #include "fileobj_mgr.h" #include "dircache_redirect.h" @@ -406,7 +407,7 @@ struct dirinfo dir_get_info(DIR *dirp, struct dirent *entry) { .attribute = entry->info.attr, .size = entry->info.size, - .mtime = fattime_mktime(entry->info.wrtdate, entry->info.wrttime), + .mtime = dostime_mktime(entry->info.wrtdate, entry->info.wrttime), }; file_error: diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c index 589986911c..3b880d3382 100644 --- a/firmware/common/dircache.c +++ b/firmware/common/dircache.c @@ -2956,7 +2956,7 @@ void dircache_dump(void) FOR_EACH_CACHE_ENTRY(ce) { #ifdef DIRCACHE_NATIVE - time_t mtime = fattime_mktime(ce->wrtdate, ce->wrttime); + time_t mtime = dostime_mktime(ce->wrtdate, ce->wrttime); #else time_t mtime = ce->mtime; #endif 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) { diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index 337e29a1bc..cc9735d0f7 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c @@ -2954,20 +2954,6 @@ void fat_empty_fat_direntry(struct fat_direntry *entry) entry->firstcluster = 0; } -time_t fattime_mktime(uint16_t fatdate, uint16_t fattime) -{ - /* this knows our mktime() only uses these struct tm fields */ - struct tm tm; - tm.tm_sec = ((fattime ) & 0x1f) * 2; - tm.tm_min = ((fattime >> 5) & 0x3f); - tm.tm_hour = ((fattime >> 11) ); - tm.tm_mday = ((fatdate ) & 0x1f); - tm.tm_mon = ((fatdate >> 5) & 0x0f) - 1; - tm.tm_year = ((fatdate >> 9) ) + 80; - - return mktime(&tm); -} - void fat_init(void) { dc_lock_cache(); diff --git a/firmware/export/fat.h b/firmware/export/fat.h index b8092290e6..27c2a161f6 100644 --- a/firmware/export/fat.h +++ b/firmware/export/fat.h @@ -174,7 +174,6 @@ void fat_recalc_free(IF_MV_NONVOID(int volume)); bool fat_size(IF_MV(int volume,) unsigned long *size, unsigned long *free); /** Misc. **/ -time_t fattime_mktime(uint16_t fatdate, uint16_t fattime); void fat_empty_fat_direntry(struct fat_direntry *entry); void fat_init(void); diff --git a/firmware/include/timefuncs.h b/firmware/include/timefuncs.h index c72508e862..2e8ef01ca6 100644 --- a/firmware/include/timefuncs.h +++ b/firmware/include/timefuncs.h @@ -24,8 +24,10 @@ #include "config.h" #include +#include #include "time.h" +time_t dostime_mktime(uint16_t dosdate, uint16_t dostime); struct tm *get_time(void); int set_time(const struct tm *tm); #if CONFIG_RTC