summaryrefslogtreecommitdiff
path: root/avr
diff options
context:
space:
mode:
authorLeo C2018-10-01 15:19:19 +0200
committerLeo C2018-10-01 15:19:19 +0200
commiteb49471efdeb6b317afeffa9bc05b25cb7d7a72c (patch)
treeec5f772097522fa3b6be1446e5f050d7f59f363c /avr
parent52ef24e4020adcb773adcb0d82b1c2c385610461 (diff)
downloadz180-stamp-eb49471efdeb6b317afeffa9bc05b25cb7d7a72c.zip
new command: time
Diffstat (limited to 'avr')
-rw-r--r--avr/cmd_misc.c25
-rw-r--r--avr/command_tbl.c7
2 files changed, 31 insertions, 1 deletions
diff --git a/avr/cmd_misc.c b/avr/cmd_misc.c
index 72102c6..ad913e8 100644
--- a/avr/cmd_misc.c
+++ b/avr/cmd_misc.c
@@ -83,3 +83,28 @@ command_ret_t do_sleep(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * con
return CMD_RET_SUCCESS;
}
+
+command_ret_t do_time(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[])
+{
+ uint32_t elapsed_ms = 0;
+ command_ret_t retval;
+ uint_fast8_t repeatable;
+
+ if (argc == 1)
+ return CMD_RET_USAGE;
+
+ elapsed_ms = get_timer(0);
+ retval = cmd_process(0, argc - 1, argv + 1, &repeatable);
+ elapsed_ms = get_timer(elapsed_ms);
+
+ uint32_t min;
+ uint16_t sec, ms;
+
+ min = elapsed_ms / 1000 / 60;
+ sec = (elapsed_ms / 1000) % 60;
+ ms = elapsed_ms % 1000;
+
+ printf_P(PSTR("\ntime: %lum%u.%03us\n"), min, sec, ms);
+
+ return retval;
+}
diff --git a/avr/command_tbl.c b/avr/command_tbl.c
index c526199..5a63e76 100644
--- a/avr/command_tbl.c
+++ b/avr/command_tbl.c
@@ -34,6 +34,11 @@ CMD_TBL_ITEM_TOP(
CMD_TBL_ITEM(
+ time, CONFIG_SYS_MAXARGS, 0, do_time,
+ "run command and print execution time",
+ "command [args...]\n"
+),
+CMD_TBL_ITEM(
date, 2, 1, do_date,
"get/set date & time",
"[MMDDhhmm[[CC]YY][.ss]]\n"
@@ -106,7 +111,7 @@ CMD_TBL_ITEM(
sleep , 2, 1, do_sleep,
"delay execution for some time",
"N[m][s]\n"
- " - delay execution for decimal N (milli) seconds"
+ " - delay execution for hexadecimal N (milli) seconds"
),
CMD_TBL_ITEM_COMPLETE(
run, CONFIG_SYS_MAXARGS, 1, do_run,