firmware: RTC setting via CLI
This commit is contained in:
parent
72b9444861
commit
0fae66fac2
40
src/cli.c
40
src/cli.c
@ -46,6 +46,7 @@
|
|||||||
#include "fpga_spi.h"
|
#include "fpga_spi.h"
|
||||||
#include "cic.h"
|
#include "cic.h"
|
||||||
#include "xmodem.h"
|
#include "xmodem.h"
|
||||||
|
#include "rtc.h"
|
||||||
|
|
||||||
#include "cli.h"
|
#include "cli.h"
|
||||||
|
|
||||||
@ -57,8 +58,8 @@ static char *curchar;
|
|||||||
|
|
||||||
/* Word lists */
|
/* Word lists */
|
||||||
static char command_words[] =
|
static char command_words[] =
|
||||||
"cd\0reset\0dir\0ls\0test\0resume\0loadrom\0loadraw\0saveraw\0put\0d4\0vmode\0mapper\0";
|
"cd\0reset\0dir\0ls\0test\0resume\0loadrom\0loadraw\0saveraw\0put\0d4\0vmode\0mapper\0settime\0time\0";
|
||||||
enum { CMD_CD = 0, CMD_RESET, CMD_DIR, CMD_LS, CMD_TEST, CMD_RESUME, CMD_LOADROM, CMD_LOADRAW, CMD_SAVERAW, CMD_PUT, CMD_D4, CMD_VMODE, CMD_MAPPER };
|
enum { CMD_CD = 0, CMD_RESET, CMD_DIR, CMD_LS, CMD_TEST, CMD_RESUME, CMD_LOADROM, CMD_LOADRAW, CMD_SAVERAW, CMD_PUT, CMD_D4, CMD_VMODE, CMD_MAPPER, CMD_SETTIME, CMD_TIME };
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
/* Parse functions */
|
/* Parse functions */
|
||||||
@ -372,6 +373,33 @@ void cmd_mapper(void) {
|
|||||||
printf("mapper set to %ld\n", mapper);
|
printf("mapper set to %ld\n", mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmd_settime(void) {
|
||||||
|
struct tm time;
|
||||||
|
if(strlen(curchar) != 4+2+2 + 2+2+2) {
|
||||||
|
printf("invalid time format (need YYYYMMDDhhmmss)\n");
|
||||||
|
} else {
|
||||||
|
time.tm_sec = atoi(curchar+4+2+2+2+2);
|
||||||
|
curchar[4+2+2+2+2] = 0;
|
||||||
|
time.tm_min = atoi(curchar+4+2+2+2);
|
||||||
|
curchar[4+2+2+2] = 0;
|
||||||
|
time.tm_hour = atoi(curchar+4+2+2);
|
||||||
|
curchar[4+2+2] = 0;
|
||||||
|
time.tm_mday = atoi(curchar+4+2);
|
||||||
|
curchar[4+2] = 0;
|
||||||
|
time.tm_mon = atoi(curchar+4);
|
||||||
|
curchar[4] = 0;
|
||||||
|
time.tm_year = atoi(curchar) - 1900;
|
||||||
|
set_rtc(&time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmd_time(void) {
|
||||||
|
struct tm time;
|
||||||
|
read_rtc(&time);
|
||||||
|
printf("%04d-%02d-%02d %02d:%02d:%02d\n", time.tm_year+1900, time.tm_mon,
|
||||||
|
time.tm_mday, time.tm_hour, time.tm_min, time.tm_sec);
|
||||||
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
/* CLI interface functions */
|
/* CLI interface functions */
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
@ -477,6 +505,14 @@ void cli_loop(void) {
|
|||||||
case CMD_MAPPER:
|
case CMD_MAPPER:
|
||||||
cmd_mapper();
|
cmd_mapper();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case CMD_SETTIME:
|
||||||
|
cmd_settime();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CMD_TIME:
|
||||||
|
cmd_time();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,7 +46,7 @@ uint32_t get_fattime(void) {
|
|||||||
|
|
||||||
read_rtc(&time);
|
read_rtc(&time);
|
||||||
return ((uint32_t)time.tm_year-80) << 25 |
|
return ((uint32_t)time.tm_year-80) << 25 |
|
||||||
((uint32_t)time.tm_mon+1) << 21 |
|
((uint32_t)time.tm_mon) << 21 |
|
||||||
((uint32_t)time.tm_mday) << 16 |
|
((uint32_t)time.tm_mday) << 16 |
|
||||||
((uint32_t)time.tm_hour) << 11 |
|
((uint32_t)time.tm_hour) << 11 |
|
||||||
((uint32_t)time.tm_min) << 5 |
|
((uint32_t)time.tm_min) << 5 |
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user