Source code for the Trusted Boot Module.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
tbm-mcu/source/shell/rtc.c

84 lines
1.5 KiB

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <console.h>
#include <rtc.h>
#include <shell/rtc.h>
int shell_date(struct console *con, size_t argc, const char **argv)
{
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);
return 0;
}
int shell_time(struct console *con, size_t argc, const char **argv)
{
struct tm now;
(void)argv;
(void)argc;
rtc_get_time(&now);
fprintf(con->fp, "%ld\n", mktime(&now));
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 <seconds>\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;
if (argc < 2) {
fprintf(con->fp, "usage: set-date <format> <date>\n");
return -1;
}
rtc_get_time(&now);
if (!strptime(argv[1], argv[0], &now)) {
fprintf(con->fp, "error\n");
return -1;
}
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;
}