From 8bccd3ada575fbb243cbd82d0c0015caf39f4781 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Wed, 26 Feb 2014 20:30:55 +0100 Subject: [PATCH] Cleanup date and time handling --- kernel/include/rtc.hpp | 13 ++----------- kernel/src/fat32.cpp | 6 +++--- kernel/src/rtc.cpp | 2 +- kernel/src/shell.cpp | 10 +--------- programs/stat/src/main.cpp | 6 +++--- tlib/include/datetime.hpp | 5 +++-- 6 files changed, 13 insertions(+), 29 deletions(-) diff --git a/kernel/include/rtc.hpp b/kernel/include/rtc.hpp index 6dfc43d2..789741e6 100644 --- a/kernel/include/rtc.hpp +++ b/kernel/include/rtc.hpp @@ -8,20 +8,11 @@ #ifndef RTC_H #define RTC_H -#include +#include namespace rtc { -struct data { - uint8_t second; - uint8_t minute; - uint8_t hour; - uint8_t day; - uint8_t month; - uint16_t year; -}; - -data all_data(); +datetime all_data(); } //end of rtc namespace diff --git a/kernel/src/fat32.cpp b/kernel/src/fat32.cpp index f3c159db..0bdef5f6 100644 --- a/kernel/src/fat32.cpp +++ b/kernel/src/fat32.cpp @@ -362,7 +362,7 @@ std::vector files(fat32::dd disk, uint32_t cluster_number){ file.created.day = entry.creation_date & 0x1F; file.created.month = (entry.creation_date >> 5) & 0xF; - file.created.year = entry.creation_date >> 9; + file.created.year = (entry.creation_date >> 9) + 1980; file.created.seconds = entry.creation_time & 0x1F; file.created.minutes = (entry.creation_time >> 5) & 0x3F; @@ -735,8 +735,8 @@ cluster_entry* init_entry(cluster_entry* entry_ptr, const char* name, uint32_t c //Set the date and time of the entries entry.creation_time_seconds = 0; - entry.creation_time = datetime.second | datetime.minute << 5 | datetime.hour << 11; - entry.modification_time = datetime.second | datetime.minute << 5 | datetime.hour << 11; + entry.creation_time = datetime.seconds | datetime.minutes << 5 | datetime.hour << 11; + entry.modification_time = datetime.seconds | datetime.minutes << 5 | datetime.hour << 11; entry.creation_date = datetime.day | datetime.month << 5 | (datetime.year - 1980) << 9; entry.modification_date = datetime.day | datetime.month << 5 | (datetime.year - 1980) << 9; diff --git a/kernel/src/rtc.cpp b/kernel/src/rtc.cpp index 3528b34f..d4d53c8d 100644 --- a/kernel/src/rtc.cpp +++ b/kernel/src/rtc.cpp @@ -26,7 +26,7 @@ uint8_t get_RTC_register(int reg){ } //end of anonymous namespace -rtc::data rtc::all_data(){ +datetime rtc::all_data(){ uint8_t second; uint8_t minute; uint8_t hour; diff --git a/kernel/src/shell.cpp b/kernel/src/shell.cpp index 13183627..97a44a6f 100644 --- a/kernel/src/shell.cpp +++ b/kernel/src/shell.cpp @@ -50,7 +50,6 @@ bool shift = false; void help_command(const std::vector& params); void uptime_command(const std::vector& params); void clear_command(const std::vector& params); -void date_command(const std::vector& params); void echo_command(const std::vector& params); void mmap_command(const std::vector& params); void memory_command(const std::vector& params); @@ -70,11 +69,10 @@ struct command_definition { void (*function)(const std::vector&); }; -command_definition commands[18] = { +command_definition commands[17] = { {"help", help_command}, {"uptime", uptime_command}, {"clear", clear_command}, - {"date", date_command}, {"echo", echo_command}, {"mmap", mmap_command}, {"memory", memory_command}, @@ -218,12 +216,6 @@ void uptime_command(const std::vector&){ k_printf("Uptime: %us\n", timer::seconds()); } -void date_command(const std::vector&){ - auto data = rtc::all_data(); - - k_printf("%u.%u.%u %u:%.2d:%.2d\n", data.day, data.month, data.year, data.hour, data.minute, data.second); -} - void echo_command(const std::vector& params){ for(uint64_t i = 1; i < params.size(); ++i){ k_print(params[i]); diff --git a/programs/stat/src/main.cpp b/programs/stat/src/main.cpp index 525e9f93..a892317b 100644 --- a/programs/stat/src/main.cpp +++ b/programs/stat/src/main.cpp @@ -49,7 +49,7 @@ int main(int argc, char* argv[]){ print('.'); print(info->created.month); print('.'); - print(info->created.year + 1980); + print(info->created.year); print(' '); print(info->created.hour); @@ -63,7 +63,7 @@ int main(int argc, char* argv[]){ print('.'); print(info->modified.month); print('.'); - print(1980+info->modified.year); + print(info->modified.year); print(' '); print(info->modified.hour); @@ -77,7 +77,7 @@ int main(int argc, char* argv[]){ print('.'); print(info->accessed.month); print('.'); - print(1980+info->accessed.year); + print(info->accessed.year); print(' '); print(info->accessed.hour); diff --git a/tlib/include/datetime.hpp b/tlib/include/datetime.hpp index c589679d..cf57d7bf 100644 --- a/tlib/include/datetime.hpp +++ b/tlib/include/datetime.hpp @@ -11,13 +11,14 @@ #include struct datetime { - uint8_t year; + uint16_t year; uint8_t month; uint8_t day; uint8_t hour; uint8_t minutes; uint8_t seconds; - uint16_t precise; + uint8_t unused; + uint64_t precise; } __attribute__((packed)) ; #endif