]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
clean up includes
authorLeo C. <erbl259-lmu@yahoo.de>
Fri, 28 Jun 2024 20:35:29 +0000 (22:35 +0200)
committerLeo C. <erbl259-lmu@yahoo.de>
Fri, 28 Jun 2024 20:35:29 +0000 (22:35 +0200)
18 files changed:
avr/cli.c
avr/cli_readline.c
avr/cmd_boot.c
avr/cmd_cpu.c
avr/cmd_fat.c
avr/cmd_gpio.c
avr/cmd_loadcpm3.c
avr/cmd_loadihex.c
avr/command.c
avr/con-utils.c
avr/debug.c
avr/eval_arg.c
avr/getopt-min.c
avr/i2c.c
avr/mmc.c
avr/print-utils.c
avr/z180-serv.c
include/common.h

index 7c452511d0642b732c94befd0c0f61a1cbaf11d8..3e711b386e8c208dc33edb6dc86d412ae260aaa1 100644 (file)
--- 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"
index 0ed8f678e146982accb232fdb496c212ef9cdf56..81f68dff9d181f88f6124f4b309d145f6b5f3adf 100644 (file)
 
 #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"
index bba510f54c7d685c7bb91c48cd6c3355c7476b95..6b984966ae92e6e3396c0aa5ae7afb21b0d0b785 100644 (file)
@@ -11,7 +11,6 @@
  * Misc boot support
  */
 #include "cmd_boot.h"
-#include <ctype.h>
 #include <util/atomic.h>
 
 #include "cli_readline.h"      /* console_buffer[] */
index 6e36b2b64f5c622cabe1cc352387777307c5364d..2abf5db150d602c0d6498f0d486f40dfdb77fc2a 100644 (file)
@@ -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,
index fdd05b447dd6c0a2a721208870ff6e5dfe117f1a..8477fc2d4af5701c3d36645538e48c64483ff854 100644 (file)
@@ -9,7 +9,6 @@
  */
 
 #include "cmd_fat.h"
-#include <ctype.h>
 #include <time.h>
 uint32_t fat_time(const struct tm * timeptr);
 
index 32bd53ad8f9d95d50b33a2c42d05909278faeecd..16c22025be09221a99471858ebcccc249bcf7a99 100644 (file)
@@ -5,8 +5,6 @@
  */
 
 #include "cmd_gpio.h"
-#include <ctype.h>
-
 #include "print-utils.h"
 #include "getopt-min.h"
 #include "env.h"
index ee336dabd365752346c1ebc42554b7796d43da2f..425d1fdf3742133ec305590732cac4677dcb39c3 100644 (file)
@@ -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 */
index a7c9238d675f69913631e1466de7ad24fc79f992..19cd29b1fa589f798df7299a4f0c0badaf56c1cd 100644 (file)
@@ -5,7 +5,6 @@
  */
 
 #include "cmd_loadihex.h"
-#include <ctype.h>
 
 #include "con-utils.h"
 #include "z80-if.h"
index 8eb5bb74f91cf40cf68753717f30c9e5faf77d90..8a4ca02886706005b3aa8b672cb402c7a16d597f 100644 (file)
@@ -13,7 +13,6 @@
 
 #include "command.h"
 #include "common.h"
-#include <ctype.h>
 #include <setjmp.h>
 
 #include "config.h"
index 4a96771040c536123388f92657a0d1e6fe54c982..5ea19fdafdbe4573c7a0f1edfb0a528ab06e813a 100644 (file)
@@ -5,7 +5,6 @@
  */
 
 #include "common.h"
-#include <string.h>
 #include <avr/wdt.h>
 
 #include "config.h"
index 89ef4b131a0757e5dedf45f6773abe733c581bcd..ea21583fea9706ef1b0ad4e87169d18a66849338 100644 (file)
@@ -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"
index fd8b067acf53bed4339feed7a82045cec96db2c2..deb601fd6ff1f5a1311af94004782094a2150987 100644 (file)
@@ -6,7 +6,6 @@
 
 #include "eval_arg.h"
 #include "command.h"   /* jump_buf */
-#include <ctype.h>
 #include <setjmp.h>
 #include "print-utils.h"
 
index 401beedfc1b40333494ef213fc338bd96cba726f..4e67a9b4d0712a4c5e5a1d1a03318cc5ad65bf3b 100644 (file)
@@ -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 */
index ae2f8da46d3410df36cf2f35f1dc7cdfa4ac79eb..a0a12c8aaa21fa160411b0ae85b9006b56a5af2b 100644 (file)
--- 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"
index d45cdf540dba8c76ebe99010fdf48365476f84ff..a40dc31fdb2b789b8b747f11f3a917777064c1d3 100644 (file)
--- 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"
index 15f69f8c475c6b5b7bc92f6301124d316cb41d88..ea3b5cf333ea8eca483cb7137cec8268a1f92e35 100644 (file)
@@ -6,8 +6,6 @@
 
 #include "common.h"
 #include <stdint.h>
-#include <stdio.h>
-#include <ctype.h>
 #include "con-utils.h"
 #include "print-utils.h"
 
index f99a11efc095b812be258f56ad0238e5d5a400cb..ec3db7ddd4d578df64a37b447e472a39960c2cfa 100644 (file)
@@ -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"
index 16f96bb0e944bfbffc403979d49e3f16a493a1b2..e89b91f733b207b71c94198359630e40e72278c5 100644 (file)
@@ -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"