diff --git a/source/shell/rtc.c b/source/shell/rtc.c index 20b3362..870513d 100644 --- a/source/shell/rtc.c +++ b/source/shell/rtc.c @@ -1,4 +1,5 @@ #include +#include #include #include @@ -36,6 +37,27 @@ int shell_time(struct console *con, size_t argc, const char **argv) return 0; } +int shell_set_time(struct console *con, size_t argc, const char **argv) +{ + struct tm now; + time_t time; + + if (argc < 1) { + fprintf(con->fp, "usage: set-time \n"); + return -1; + } + + time = (time_t)strtoul(argv[0], NULL, 0); + gmtime_r(&time, &now); + 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); + + return 0; +} + int shell_set_date(struct console *con, size_t argc, const char **argv) { struct tm now;