From 52ef24e4020adcb773adcb0d82b1c2c385610461 Mon Sep 17 00:00:00 2001 From: Leo C Date: Mon, 1 Oct 2018 15:18:33 +0200 Subject: reset optind before executing command --- avr/cmd_attach.c | 3 --- avr/cmd_boot.c | 6 ------ avr/cmd_cpu.c | 8 -------- avr/cmd_gpio.c | 3 --- avr/cmd_mem.c | 4 ---- avr/cmd_misc.c | 3 --- avr/command.c | 6 ++---- avr/env.c | 3 --- avr/getopt-min.c | 2 +- 9 files changed, 3 insertions(+), 35 deletions(-) diff --git a/avr/cmd_attach.c b/avr/cmd_attach.c index 0949687..651404f 100644 --- a/avr/cmd_attach.c +++ b/avr/cmd_attach.c @@ -49,9 +49,6 @@ command_ret_t do_attach(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * co return CMD_RET_SUCCESS; } - /* reset getopt() */ - optind = 0; - int opt; while ((opt = getopt(argc, argv, PSTR("darwo:"))) != -1) { switch (opt) { diff --git a/avr/cmd_boot.c b/avr/cmd_boot.c index e26a8b1..dcf834d 100644 --- a/avr/cmd_boot.c +++ b/avr/cmd_boot.c @@ -106,9 +106,6 @@ command_ret_t do_bootcf(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int a memcpy_P(&boot_param, cfboot, sizeof boot_param); default_stages = boot_param.stages; - /* reset getopt() */ - optind = 0; - int opt; while ((opt = getopt(argc, argv, PSTR("vna:s:c:t:i:"))) != -1) { switch (opt) { @@ -256,9 +253,6 @@ command_ret_t do_go(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, uint32_t addr; bool hold = 0; - /* reset getopt() */ - optind = 0; - int opt; while ((opt = getopt(argc, argv, PSTR("h"))) != -1) { switch (opt) { diff --git a/avr/cmd_cpu.c b/avr/cmd_cpu.c index 6f50a2a..d692211 100644 --- a/avr/cmd_cpu.c +++ b/avr/cmd_cpu.c @@ -204,9 +204,6 @@ command_ret_t do_cpu_test(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int uint32_t pulsewidth = 10; /* ms */ - /* reset getopt() */ - optind = 0; - int opt; while ((opt = getopt(argc, argv, PSTR("t:"))) != -1) { switch (opt) { @@ -237,8 +234,6 @@ command_ret_t do_bus_test(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int char ch; #if 0 - /* reset getopt() */ - optind = 0; int opt; while ((opt = getopt(argc, argv, PSTR("t:"))) != -1) { switch (opt) { @@ -331,9 +326,6 @@ command_ret_t do_cpu_freq(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int uint8_t eimsk_save; uint8_t mem_save[cpuinfo_length]; - /* reset getopt() */ - optind = 0; - int opt; while ((opt = getopt(argc, argv, PSTR("swnuc:t:"))) != -1) { switch (opt) { diff --git a/avr/cmd_gpio.c b/avr/cmd_gpio.c index 65a71be..549654f 100644 --- a/avr/cmd_gpio.c +++ b/avr/cmd_gpio.c @@ -173,9 +173,6 @@ command_ret_t do_gpio(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int arg uint_fast8_t pinarg[GPIO_MAX]; uint_fast8_t pinargc; - /* reset getopt() */ - optind = 0; - int opt; while ((opt = getopt(argc, argv, PSTR("s"))) != -1) { switch (opt) { diff --git a/avr/cmd_mem.c b/avr/cmd_mem.c index d641410..3e18770 100644 --- a/avr/cmd_mem.c +++ b/avr/cmd_mem.c @@ -204,9 +204,6 @@ command_ret_t do_mem_mw(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * co (void) cmdtp; (void) flag; - /* reset getopt() */ - optind = 0; - int opt; while ((opt = getopt(argc, argv, PSTR("bwl"))) != -1) { switch (opt) { @@ -261,7 +258,6 @@ command_ret_t do_mem_mdc ( cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * (void) cmdtp; (void) flag; - optind = 0; if (argv[0][1] != 'd') { int opt; while ((opt = getopt(argc, argv, PSTR("bwl"))) != -1) diff --git a/avr/cmd_misc.c b/avr/cmd_misc.c index a88ba72..72102c6 100644 --- a/avr/cmd_misc.c +++ b/avr/cmd_misc.c @@ -22,9 +22,6 @@ command_ret_t do_echo(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * cons (void) cmdtp; (void) flag; - /* reset getopt() */ - optind = 0; - int opt; while ((opt = getopt(argc, argv, PSTR("n"))) != -1) { switch (opt) { diff --git a/avr/command.c b/avr/command.c index ff3a685..8eb5bb7 100644 --- a/avr/command.c +++ b/avr/command.c @@ -262,9 +262,6 @@ command_ret_t do_help(cmd_tbl_t *cmdtp, uint_fast8_t flag UNUSED, int argc, char #define OPT_USAGE 0x08 #define OPT_LONG 0x10 - /* reset getopt() */ - optind = 0; - int opt; while ((opt = getopt(argc, argv, PSTR("afk"))) != -1) { switch (opt) { @@ -708,7 +705,7 @@ static cmd_tbl_t *cmd_invocation_ptr; * @param argv Arguments * @return 0 if command succeeded, else non-zero (CMD_RET_...) */ -command_ret_t cmd_call(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]) +static command_ret_t cmd_call(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]) { command_ret_t result; @@ -770,6 +767,7 @@ command_ret_t cmd_process(uint_fast8_t flag, int argc, char * const argv[], /* If OK so far, then do the command */ if (!rc) { + optind = 0; /* reset getopt() */ cmd_invocation_ptr = cmdtp; rc = cmd_call(cmdtp, flag, argc, argv); *repeatable &= (cmdtp->flags & CTBL_RPT) != 0; diff --git a/avr/env.c b/avr/env.c index add281c..3bb04c2 100644 --- a/avr/env.c +++ b/avr/env.c @@ -693,9 +693,6 @@ command_ret_t do_env_print(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, bool mode = 0; command_ret_t rc = CMD_RET_SUCCESS; - /* reset getopt() */ - optind = 0; - int opt; while ((opt = getopt(argc, argv, PSTR("s"))) != -1) { switch (opt) { diff --git a/avr/getopt-min.c b/avr/getopt-min.c index 8508f40..401beed 100644 --- a/avr/getopt-min.c +++ b/avr/getopt-min.c @@ -13,7 +13,7 @@ #include "common.h" /* definition of FLASH */ #include -int optind = 0; /* next argv[] index */ +int optind; /* next argv[] index */ char *optarg; /* option parameter if any */ -- cgit v1.2.3 From eb49471efdeb6b317afeffa9bc05b25cb7d7a72c Mon Sep 17 00:00:00 2001 From: Leo C Date: Mon, 1 Oct 2018 15:19:19 +0200 Subject: new command: time --- avr/cmd_misc.c | 25 +++++++++++++++++++++++++ avr/command_tbl.c | 7 ++++++- include/cmd_misc.h | 1 + 3 files changed, 32 insertions(+), 1 deletion(-) 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 @@ -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, diff --git a/include/cmd_misc.h b/include/cmd_misc.h index f0f56a7..8dd7d56 100644 --- a/include/cmd_misc.h +++ b/include/cmd_misc.h @@ -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 */ -- cgit v1.2.3 From dd1cc6f0b4a9cc2b49afb86c768813c087e46b4b Mon Sep 17 00:00:00 2001 From: Leo C Date: Mon, 1 Oct 2018 15:20:11 +0200 Subject: bit operation optimizing --- avr/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/avr/main.c b/avr/main.c index 486e15c..486d992 100644 --- a/avr/main.c +++ b/avr/main.c @@ -84,7 +84,8 @@ void print_reset_reason(void) ISR(INT5_vect) { - Stat |= S_MSG_PENDING + S_IO_0X40; + Stat |= S_MSG_PENDING; + Stat |= S_IO_0X40; } ISR(INT6_vect) -- cgit v1.2.3