]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
new command: time
authorLeo C <erbl259-lmu@yahoo.de>
Mon, 1 Oct 2018 13:19:19 +0000 (15:19 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Mon, 1 Oct 2018 13:19:19 +0000 (15:19 +0200)
avr/cmd_misc.c
avr/command_tbl.c
include/cmd_misc.h

index 72102c66c46e82788cd314a9a85a18a4585e5904..ad913e83815d7938cafd09bcc3eacd2a93cae9b5 100644 (file)
@@ -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;
+}
index c526199ec889a10ebbb77f7fb42e480d268bbea7..5a63e7636b740806d382f8fa3e719d7db182646d 100644 (file)
@@ -33,6 +33,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",
@@ -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,
index f0f56a74aa7903d7b5760797ae4b8f3e8d9057dd..8dd7d568e91920104c004c6280482d51a2ba25dd 100644 (file)
@@ -11,5 +11,6 @@
 
 command_ret_t do_echo(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]);
 command_ret_t do_sleep(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]);
+command_ret_t do_time(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]);
 
 #endif /* CMD_MISC_H */