summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--avr/cli.c1
-rw-r--r--avr/cli_readline.c4
-rw-r--r--avr/cmd_boot.c1
-rw-r--r--avr/cmd_cpu.c97
-rw-r--r--avr/cmd_fat.c1
-rw-r--r--avr/cmd_gpio.c2
-rw-r--r--avr/cmd_loadcpm3.c2
-rw-r--r--avr/cmd_loadihex.c1
-rw-r--r--avr/command.c1
-rw-r--r--avr/con-utils.c1
-rw-r--r--avr/debug.c3
-rw-r--r--avr/eval_arg.c1
-rw-r--r--avr/getopt-min.c1
-rw-r--r--avr/i2c.c1
-rw-r--r--avr/mmc.c1
-rw-r--r--avr/print-utils.c2
-rw-r--r--avr/z180-serv.c3
-rw-r--r--include/common.h1
18 files changed, 54 insertions, 70 deletions
diff --git a/avr/cli.c b/avr/cli.c
index 7c45251..3e711b3 100644
--- a/avr/cli.c
+++ b/avr/cli.c
@@ -13,7 +13,6 @@
#include "cli.h"
#include "command.h"
-#include <ctype.h>
#include "config.h"
#include "debug.h"
diff --git a/avr/cli_readline.c b/avr/cli_readline.c
index 0ed8f67..81f68df 100644
--- a/avr/cli_readline.c
+++ b/avr/cli_readline.c
@@ -13,10 +13,6 @@
#include "cli_readline.h"
#include "common.h"
-#include <string.h>
-#include <stdio.h>
-#include <stdbool.h>
-#include <ctype.h>
#include "config.h"
#include "con-utils.h"
diff --git a/avr/cmd_boot.c b/avr/cmd_boot.c
index bba510f..6b98496 100644
--- a/avr/cmd_boot.c
+++ b/avr/cmd_boot.c
@@ -11,7 +11,6 @@
* Misc boot support
*/
#include "cmd_boot.h"
-#include <ctype.h>
#include <util/atomic.h>
#include "cli_readline.h" /* console_buffer[] */
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 <ctype.h>
#include <util/atomic.h>
#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<<CS30; /* stop counter */
+ TCCR3B = 0b000<<CS30; /* stop counter */
TCNT3 = 0;
x_ovfl = 0;
TIFR3 = _BV(TOV3);
ref_ovfl = 0;
ATOMIC_BLOCK(ATOMIC_FORCEON) {
- /* Reset pending int */
- EIFR = _BV(INTF6);
- /* Wait for falling edge */
- while ((EIFR & _BV(INTF6)) == 0)
+ EIFR = _BV(INTF6); /* Reset pending int */
+ while ((EIFR & _BV(INTF6)) == 0) /* Wait for falling edge */
;
OCR4B = TCNT4;
- TCCR3B = 0b110<<CS30; /* Count falling edges on T3 (==INT6) */
- TIFR4 = _BV(OCF4B); /* clear compare match flag */
+ TCCR3B = 0b110<<CS30; /* Count falling edges on T3 (==INT6) */
+ TIFR4 = _BV(OCF4B); /* clear compare match flag */
while (ref_ovfl < 60) {
if ((TIFR4 & _BV(OCF4B)) != 0) {
@@ -111,6 +108,10 @@ static uint32_t z80_measure_phi(uint_fast8_t cycles)
uint32_t x_cnt = TCNT3 + ((uint32_t) x_ovfl << 16);
uint64_t x_tmp = (uint64_t) 100000 * (x_cnt * cycles);
+ /* Stop Timer */
+ TCCR3B = 0;
+ PRR1 |= _BV(PRTIM3);
+
// char x_tmp_str[21];
//
// debug_cpu("TCNT3: %6u, ref_cnt: %9lu\n", TCNT3, ref_cnt);
@@ -124,19 +125,9 @@ static uint32_t z80_measure_phi(uint_fast8_t cycles)
/* round to 5 decimal digits */
int_fast8_t sc = 5;
- while (sc > 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,
diff --git a/avr/cmd_fat.c b/avr/cmd_fat.c
index fdd05b4..8477fc2 100644
--- a/avr/cmd_fat.c
+++ b/avr/cmd_fat.c
@@ -9,7 +9,6 @@
*/
#include "cmd_fat.h"
-#include <ctype.h>
#include <time.h>
uint32_t fat_time(const struct tm * timeptr);
diff --git a/avr/cmd_gpio.c b/avr/cmd_gpio.c
index 32bd53a..16c2202 100644
--- a/avr/cmd_gpio.c
+++ b/avr/cmd_gpio.c
@@ -5,8 +5,6 @@
*/
#include "cmd_gpio.h"
-#include <ctype.h>
-
#include "print-utils.h"
#include "getopt-min.h"
#include "env.h"
diff --git a/avr/cmd_loadcpm3.c b/avr/cmd_loadcpm3.c
index ee336da..425d1fd 100644
--- a/avr/cmd_loadcpm3.c
+++ b/avr/cmd_loadcpm3.c
@@ -9,7 +9,6 @@
*/
#include "cmd_loadcpm3.h"
-#include <ctype.h>
#include "env.h"
#include "ff.h"
@@ -17,7 +16,6 @@
#include "con-utils.h"
#include "z80-if.h"
#include "debug.h"
-#include "errnum.h"
#define RS 128 /* CP/M record size */
diff --git a/avr/cmd_loadihex.c b/avr/cmd_loadihex.c
index a7c9238..19cd29b 100644
--- a/avr/cmd_loadihex.c
+++ b/avr/cmd_loadihex.c
@@ -5,7 +5,6 @@
*/
#include "cmd_loadihex.h"
-#include <ctype.h>
#include "con-utils.h"
#include "z80-if.h"
diff --git a/avr/command.c b/avr/command.c
index 8eb5bb7..8a4ca02 100644
--- a/avr/command.c
+++ b/avr/command.c
@@ -13,7 +13,6 @@
#include "command.h"
#include "common.h"
-#include <ctype.h>
#include <setjmp.h>
#include "config.h"
diff --git a/avr/con-utils.c b/avr/con-utils.c
index 4a96771..5ea19fd 100644
--- a/avr/con-utils.c
+++ b/avr/con-utils.c
@@ -5,7 +5,6 @@
*/
#include "common.h"
-#include <string.h>
#include <avr/wdt.h>
#include "config.h"
diff --git a/avr/debug.c b/avr/debug.c
index 89ef4b1..ea21583 100644
--- a/avr/debug.c
+++ b/avr/debug.c
@@ -6,9 +6,6 @@
#include "debug.h"
#include "common.h"
-#include <stdlib.h> /* __malloc_margin */
-#include <string.h>
-#include <ctype.h>
#include <avr/eeprom.h>
#include "command.h"
diff --git a/avr/eval_arg.c b/avr/eval_arg.c
index fd8b067..deb601f 100644
--- a/avr/eval_arg.c
+++ b/avr/eval_arg.c
@@ -6,7 +6,6 @@
#include "eval_arg.h"
#include "command.h" /* jump_buf */
-#include <ctype.h>
#include <setjmp.h>
#include "print-utils.h"
diff --git a/avr/getopt-min.c b/avr/getopt-min.c
index 401beed..4e67a9b 100644
--- a/avr/getopt-min.c
+++ b/avr/getopt-min.c
@@ -11,7 +11,6 @@
/* $Id: getopt.c,v 1.2 1992/12/07 11:12:52 nickc Exp $ */
#include "common.h" /* definition of FLASH */
-#include <string.h>
int optind; /* next argv[] index */
char *optarg; /* option parameter if any */
diff --git a/avr/i2c.c b/avr/i2c.c
index ae2f8da..a0a12c8 100644
--- a/avr/i2c.c
+++ b/avr/i2c.c
@@ -10,7 +10,6 @@
#include "common.h"
#include <avr/interrupt.h>
-#include <string.h>
#include "config.h"
#include "timer.h"
diff --git a/avr/mmc.c b/avr/mmc.c
index d45cdf5..a40dc31 100644
--- a/avr/mmc.c
+++ b/avr/mmc.c
@@ -6,7 +6,6 @@
/*-----------------------------------------------------------------------*/
#include "common.h"
-#include <stdbool.h>
#include <util/atomic.h>
#include "timer.h"
#include "spi.h"
diff --git a/avr/print-utils.c b/avr/print-utils.c
index 15f69f8..ea3b5cf 100644
--- a/avr/print-utils.c
+++ b/avr/print-utils.c
@@ -6,8 +6,6 @@
#include "common.h"
#include <stdint.h>
-#include <stdio.h>
-#include <ctype.h>
#include "con-utils.h"
#include "print-utils.h"
diff --git a/avr/z180-serv.c b/avr/z180-serv.c
index f99a11e..ec3db7d 100644
--- a/avr/z180-serv.c
+++ b/avr/z180-serv.c
@@ -6,9 +6,6 @@
#include "z180-serv.h"
#include "common.h"
-#include <stdlib.h>
-#include <string.h>
-#include <stdbool.h>
#include <util/atomic.h>
#include "config.h"
diff --git a/include/common.h b/include/common.h
index 16f96bb..e89b91f 100644
--- a/include/common.h
+++ b/include/common.h
@@ -10,6 +10,7 @@
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
+#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include "errnum.h"