Kernel/BAN: Add weekday to Time structure and get it with RTC

This commit is contained in:
Bananymous 2022-12-13 14:34:24 +02:00
parent 00f230fcb2
commit 171a33bbcd
2 changed files with 18 additions and 13 deletions

View File

@ -12,6 +12,7 @@ namespace BAN
uint8_t second;
uint8_t minute;
uint8_t hour;
uint8_t week_day;
uint8_t day;
uint8_t month;
int year;
@ -24,7 +25,9 @@ namespace BAN::Formatter
template<void(*PUTC_LIKE)(char)> void print_argument_impl(const Time& time, const ValueFormat&)
{
print<PUTC_LIKE>("{2}:{2}:{2} {2}.{2}.{4}", time.hour, time.minute, time.second, time.day, time.month, time.year);
constexpr const char* week_days[] { "", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
constexpr const char* months[] { "", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
print<PUTC_LIKE>("{} {} {} {}:{}:{} GMT+0 {}", week_days[time.week_day], months[time.month], time.day, time.hour, time.minute, time.second, time.year);
}
}

View File

@ -35,12 +35,13 @@ namespace RTC
static void get_time(BAN::Time& out)
{
out.second = get_rtc_register(CMOS_REGISTER_SECOND);
out.minute = get_rtc_register(CMOS_REGISTER_MINUTE);
out.hour = get_rtc_register(CMOS_REGISTER_HOUR);
out.day = get_rtc_register(CMOS_REGISTER_DAY);
out.month = get_rtc_register(CMOS_REGISTER_MONTH);
out.year = get_rtc_register(CMOS_REGISTER_YEAR);
out.second = get_rtc_register(CMOS_REGISTER_SECOND);
out.minute = get_rtc_register(CMOS_REGISTER_MINUTE);
out.hour = get_rtc_register(CMOS_REGISTER_HOUR);
out.week_day = get_rtc_register(CMOS_REGISTER_WEEK_DAY);
out.day = get_rtc_register(CMOS_REGISTER_DAY);
out.month = get_rtc_register(CMOS_REGISTER_MONTH);
out.year = get_rtc_register(CMOS_REGISTER_YEAR);
}
BAN::Time GetCurrentTime()
@ -65,12 +66,13 @@ namespace RTC
// Convert BCD to binary values if necessary
if (!(regB & 0x04))
{
time.second = (time.second & 0x0F) + ((time.second / 16) * 10);
time.minute = (time.minute & 0x0F) + ((time.minute / 16) * 10);
time.hour = ((time.hour & 0x0F) + (((time.hour & 0x70) / 16) * 10) ) | (time.hour & 0x80);
time.day = (time.day & 0x0F) + ((time.day / 16) * 10);
time.month = (time.month & 0x0F) + ((time.month / 16) * 10);
time.year = (time.year & 0x0F) + ((time.year / 16) * 10);
time.second = (time.second & 0x0F) + ((time.second / 16) * 10);
time.minute = (time.minute & 0x0F) + ((time.minute / 16) * 10);
time.hour = ((time.hour & 0x0F) + (((time.hour & 0x70) / 16) * 10) ) | (time.hour & 0x80);
time.week_day = (time.week_day & 0x0F) + ((time.week_day / 16) * 10);
time.day = (time.day & 0x0F) + ((time.day / 16) * 10);
time.month = (time.month & 0x0F) + ((time.month / 16) * 10);
time.year = (time.year & 0x0F) + ((time.year / 16) * 10);
}
// Convert 12 hour clock to 24 hour clock if necessary