X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/d655d20a5d465471244a607fc7e18eef8623eab9..6dbf5891f52b1e06f8448e2b0526214bc882c6ec:/avr/cmd_cpu.c diff --git a/avr/cmd_cpu.c b/avr/cmd_cpu.c index 6e36b2b..2abf5db 100644 --- a/avr/cmd_cpu.c +++ b/avr/cmd_cpu.c @@ -5,7 +5,6 @@ */ #include "cmd_cpu.h" -//#include #include #include "z80-if.h" @@ -26,7 +25,7 @@ #define debug_cpu(fmt, args...) \ debug_cond(DEBUG_CPU, fmt, ##args) - +static char * ulltoa (uint64_t val, char *s) { char *p = s; @@ -61,21 +60,19 @@ static uint32_t z80_measure_phi(uint_fast8_t cycles) PRR1 &= ~_BV(PRTIM3); TCCR3A = 0; - TCCR3B = 0b000< 0 || x_tmp >= 100000) { - x_tmp = (x_tmp + 5)/10; - sc--; - } + for ( ; sc > 0 || x_tmp >= 100000; sc--) x_tmp = (x_tmp + 5)/10; x_freq = x_tmp; - while (sc < 0) { - x_freq *= 10; - sc++; - } - - /* Stop Timer */ - TCCR3B = 0; - PRR1 |= _BV(PRTIM3); + for ( ; sc < 0; sc++) x_freq *= 10; return x_freq; } @@ -159,7 +150,12 @@ static const FLASH char * const FLASH cpu_strings[] = { static const FLASH char * const FLASH opt_strings[] = { FSTR("swnu"), /* Options for chkcpu */ - FSTR("swnuc:t:"), /* Oprions for cpufreq */ + FSTR("swnuc:"), /* Oprions for cpufreq */ +}; + +static const FLASH char * const FLASH env_names[] = { + FSTR(ENV_CPU), /* Env var for chkcpu result */ + FSTR(ENV_CPU_FREQ), /* Env var for cpufreq result */ }; command_ret_t do_cpu_freq_chk(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[]) @@ -169,7 +165,7 @@ command_ret_t do_cpu_freq_chk(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, uint32_t cpu_freq = 0; uint_fast8_t lcycles = 0; uint_fast8_t freq_cmd = 0; - uint16_t timeout = 1000; +// uint16_t timeout = 1000; uint8_t eimsk_save; ERRNUM err = ESUCCESS; @@ -194,9 +190,9 @@ command_ret_t do_cpu_freq_chk(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, case 'c': lcycles = eval_arg(optarg, NULL); break; - case 't': - timeout = eval_arg(optarg, NULL); - break; +// case 't': +// timeout = eval_arg(optarg, NULL); +// break; default: /* '?' */ return CMD_RET_USAGE; } @@ -281,24 +277,27 @@ command_ret_t do_cpu_freq_chk(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, if (err) cmd_error(CMD_RET_FAILURE, err, NULL); + char result_str[11]; + if (freq_cmd) { + ultoa(cpu_freq, result_str, 10); + } else { + if (cputype >= ARRAY_SIZE(cpu_strings)) + cputype = 0; + strcpy_P(result_str, cpu_strings[cputype]); + } - if (!(options & O_SILENT)) - printf_P(PSTR("%lu\n"), cpu_freq); + if (!(options & O_SILENT)) + printf_P(PSTR("%s\n"), result_str); -#if 0 - if (options & O_WENV) { - if (setenv_ulong(PSTR(ENV_CPU_FREQ), cpu_freq)) { - if (!(options & O_SILENT)) - printf_P(PSTR("'SETENV (%S, %lu)' failed!\n"), PSTR(ENV_CPU_FREQ), cpu_freq); - return CMD_RET_FAILURE; + if (options & O_WENV) { + if (setenv(env_names[freq_cmd], result_str)) { + if (!(options & O_SILENT)) { + printf_P(PSTR("'setenv %S %s' failed!\n"), env_names[freq_cmd], result_str); + //cmd_error(CMD_RET_FAILURE, ENOMEM, PSTR("'setenv (%S, %s)' failed"), env_names[freq_cmd], result_str); } + return CMD_RET_FAILURE; } -#endif - } else { - if (cputype >= ARRAY_SIZE(cpu_strings)) - cputype = 0; - printf_P(PSTR("Detected CPU: %S\n"), cpu_strings[cputype]); } return CMD_RET_SUCCESS; @@ -419,19 +418,29 @@ command_ret_t do_busack_test(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, /* * command table for subcommands */ - cmd_tbl_t cmd_tbl_cpu[] = { CMD_TBL_ITEM( freq, CONFIG_SYS_MAXARGS, CTBL_RPT, do_cpu_freq_chk, "Measure cpu frequency", - "[-qwn] [-c loopcycles] [-t timeout]\n" - " -q Be quiet\n" -// " -w Write result to environment variable '"ENV_CPU_FREQ"'" +// "[-swnu] [-c loopcycles] [-t timeout]\n" + "[-swnu] [-c loopcycles]\n" + " -s Be silent\n" + " -w Write result to environment variable '"ENV_CPU_FREQ"'" + " -n Don't load code snippet. \n" + " -u Don't unload. Leave code snippet in ram.\n" + " -c Overwrite cycles per lopp for in \"l: a,(50h)/jp l\" loop." +// " -t Timeout (ms)\n" ), CMD_TBL_ITEM( chkcpu, CONFIG_SYS_MAXARGS, CTBL_RPT|CTBL_SUBCMDAUTO, do_cpu_freq_chk, "Check/Identify CPU", - "" +// "[-swnu] [-c loopcycles] [-t timeout]\n" + "[-swnu] [-c loopcycles]\n" + " -s Be silent\n" + " -w Write result to environment variable '"ENV_CPU"'" + " -n Don't load code snippet. \n" + " -u Don't unload. Leave code snippet in ram." +// " -t Timeout (ms)\n" ), CMD_TBL_ITEM( buscmd, CONFIG_SYS_MAXARGS, CTBL_RPT, do_bus_test,