diff --git a/Makefile b/Makefile index 50a1d5f..837283a 100644 --- a/Makefile +++ b/Makefile @@ -44,6 +44,7 @@ obj-y += source/shell/cmd.o obj-y += source/shell/flash.o obj-y += source/shell/ftl.o obj-y += source/shell/mufs.o +obj-y += source/shell/rtc.o obj = $(addprefix $(BUILD)/, $(obj-y)) diff --git a/source/shell/rtc.c b/source/shell/rtc.c new file mode 100644 index 0000000..7a66af6 --- /dev/null +++ b/source/shell/rtc.c @@ -0,0 +1,56 @@ +#include +#include + +#include +#include + +#include + +void shell_date(struct console *con, const char **argv, size_t argc) +{ + struct tm now; + + (void)argv; + (void)argc; + + rtc_get_time(&now); + + fprintf(con->fp, "%02d:%02d:%02d %02d-%02d-%d\n", + now.tm_hour, now.tm_min, now.tm_sec, + now.tm_mday, now.tm_mon + 1, now.tm_year + 1900); +} + +void shell_time(struct console *con, const char **argv, size_t argc) +{ + struct tm now; + + (void)argv; + (void)argc; + + rtc_get_time(&now); + + fprintf(con->fp, "%ld\n", mktime(&now)); +} + +void shell_set_date(struct console *con, const char **argv, size_t argc) +{ + struct tm now; + + if (argc < 2) { + fprintf(con->fp, "usage: set-date \n"); + return; + } + + rtc_get_time(&now); + + if (!strptime(argv[1], argv[0], &now)) { + fprintf(con->fp, "error\n"); + return; + } + + rtc_init(&now); + + fprintf(con->fp, "%02d:%02d:%02d %02d-%02d-%d\n", + now.tm_hour, now.tm_min, now.tm_sec, + now.tm_mday, now.tm_mon + 1, now.tm_year + 1900); +}