mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-12 22:17:11 -04:00
Cleanup date and time handling
This commit is contained in:
parent
f1804b6795
commit
8bccd3ada5
@ -8,20 +8,11 @@
|
|||||||
#ifndef RTC_H
|
#ifndef RTC_H
|
||||||
#define RTC_H
|
#define RTC_H
|
||||||
|
|
||||||
#include <types.hpp>
|
#include <datetime.hpp>
|
||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
|
|
||||||
struct data {
|
datetime all_data();
|
||||||
uint8_t second;
|
|
||||||
uint8_t minute;
|
|
||||||
uint8_t hour;
|
|
||||||
uint8_t day;
|
|
||||||
uint8_t month;
|
|
||||||
uint16_t year;
|
|
||||||
};
|
|
||||||
|
|
||||||
data all_data();
|
|
||||||
|
|
||||||
} //end of rtc namespace
|
} //end of rtc namespace
|
||||||
|
|
||||||
|
@ -362,7 +362,7 @@ std::vector<disks::file> files(fat32::dd disk, uint32_t cluster_number){
|
|||||||
|
|
||||||
file.created.day = entry.creation_date & 0x1F;
|
file.created.day = entry.creation_date & 0x1F;
|
||||||
file.created.month = (entry.creation_date >> 5) & 0xF;
|
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.seconds = entry.creation_time & 0x1F;
|
||||||
file.created.minutes = (entry.creation_time >> 5) & 0x3F;
|
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
|
//Set the date and time of the entries
|
||||||
entry.creation_time_seconds = 0;
|
entry.creation_time_seconds = 0;
|
||||||
|
|
||||||
entry.creation_time = datetime.second | datetime.minute << 5 | datetime.hour << 11;
|
entry.creation_time = datetime.seconds | datetime.minutes << 5 | datetime.hour << 11;
|
||||||
entry.modification_time = datetime.second | datetime.minute << 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.creation_date = datetime.day | datetime.month << 5 | (datetime.year - 1980) << 9;
|
||||||
entry.modification_date = datetime.day | datetime.month << 5 | (datetime.year - 1980) << 9;
|
entry.modification_date = datetime.day | datetime.month << 5 | (datetime.year - 1980) << 9;
|
||||||
|
@ -26,7 +26,7 @@ uint8_t get_RTC_register(int reg){
|
|||||||
|
|
||||||
} //end of anonymous namespace
|
} //end of anonymous namespace
|
||||||
|
|
||||||
rtc::data rtc::all_data(){
|
datetime rtc::all_data(){
|
||||||
uint8_t second;
|
uint8_t second;
|
||||||
uint8_t minute;
|
uint8_t minute;
|
||||||
uint8_t hour;
|
uint8_t hour;
|
||||||
|
@ -50,7 +50,6 @@ bool shift = false;
|
|||||||
void help_command(const std::vector<std::string>& params);
|
void help_command(const std::vector<std::string>& params);
|
||||||
void uptime_command(const std::vector<std::string>& params);
|
void uptime_command(const std::vector<std::string>& params);
|
||||||
void clear_command(const std::vector<std::string>& params);
|
void clear_command(const std::vector<std::string>& params);
|
||||||
void date_command(const std::vector<std::string>& params);
|
|
||||||
void echo_command(const std::vector<std::string>& params);
|
void echo_command(const std::vector<std::string>& params);
|
||||||
void mmap_command(const std::vector<std::string>& params);
|
void mmap_command(const std::vector<std::string>& params);
|
||||||
void memory_command(const std::vector<std::string>& params);
|
void memory_command(const std::vector<std::string>& params);
|
||||||
@ -70,11 +69,10 @@ struct command_definition {
|
|||||||
void (*function)(const std::vector<std::string>&);
|
void (*function)(const std::vector<std::string>&);
|
||||||
};
|
};
|
||||||
|
|
||||||
command_definition commands[18] = {
|
command_definition commands[17] = {
|
||||||
{"help", help_command},
|
{"help", help_command},
|
||||||
{"uptime", uptime_command},
|
{"uptime", uptime_command},
|
||||||
{"clear", clear_command},
|
{"clear", clear_command},
|
||||||
{"date", date_command},
|
|
||||||
{"echo", echo_command},
|
{"echo", echo_command},
|
||||||
{"mmap", mmap_command},
|
{"mmap", mmap_command},
|
||||||
{"memory", memory_command},
|
{"memory", memory_command},
|
||||||
@ -218,12 +216,6 @@ void uptime_command(const std::vector<std::string>&){
|
|||||||
k_printf("Uptime: %us\n", timer::seconds());
|
k_printf("Uptime: %us\n", timer::seconds());
|
||||||
}
|
}
|
||||||
|
|
||||||
void date_command(const std::vector<std::string>&){
|
|
||||||
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<std::string>& params){
|
void echo_command(const std::vector<std::string>& params){
|
||||||
for(uint64_t i = 1; i < params.size(); ++i){
|
for(uint64_t i = 1; i < params.size(); ++i){
|
||||||
k_print(params[i]);
|
k_print(params[i]);
|
||||||
|
@ -49,7 +49,7 @@ int main(int argc, char* argv[]){
|
|||||||
print('.');
|
print('.');
|
||||||
print(info->created.month);
|
print(info->created.month);
|
||||||
print('.');
|
print('.');
|
||||||
print(info->created.year + 1980);
|
print(info->created.year);
|
||||||
print(' ');
|
print(' ');
|
||||||
|
|
||||||
print(info->created.hour);
|
print(info->created.hour);
|
||||||
@ -63,7 +63,7 @@ int main(int argc, char* argv[]){
|
|||||||
print('.');
|
print('.');
|
||||||
print(info->modified.month);
|
print(info->modified.month);
|
||||||
print('.');
|
print('.');
|
||||||
print(1980+info->modified.year);
|
print(info->modified.year);
|
||||||
print(' ');
|
print(' ');
|
||||||
|
|
||||||
print(info->modified.hour);
|
print(info->modified.hour);
|
||||||
@ -77,7 +77,7 @@ int main(int argc, char* argv[]){
|
|||||||
print('.');
|
print('.');
|
||||||
print(info->accessed.month);
|
print(info->accessed.month);
|
||||||
print('.');
|
print('.');
|
||||||
print(1980+info->accessed.year);
|
print(info->accessed.year);
|
||||||
print(' ');
|
print(' ');
|
||||||
|
|
||||||
print(info->accessed.hour);
|
print(info->accessed.hour);
|
||||||
|
@ -11,13 +11,14 @@
|
|||||||
#include <types.hpp>
|
#include <types.hpp>
|
||||||
|
|
||||||
struct datetime {
|
struct datetime {
|
||||||
uint8_t year;
|
uint16_t year;
|
||||||
uint8_t month;
|
uint8_t month;
|
||||||
uint8_t day;
|
uint8_t day;
|
||||||
uint8_t hour;
|
uint8_t hour;
|
||||||
uint8_t minutes;
|
uint8_t minutes;
|
||||||
uint8_t seconds;
|
uint8_t seconds;
|
||||||
uint16_t precise;
|
uint8_t unused;
|
||||||
|
uint64_t precise;
|
||||||
} __attribute__((packed)) ;
|
} __attribute__((packed)) ;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user