]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
rewrite of cmd_cpu/do_cpu_freq
authorLeo C. <erbl259-lmu@yahoo.de>
Sat, 22 Jun 2024 08:22:12 +0000 (10:22 +0200)
committerLeo C. <erbl259-lmu@yahoo.de>
Sat, 22 Jun 2024 08:22:12 +0000 (10:22 +0200)
Makefile [new file with mode: 0644]
avr/cmd_boot.c
avr/cmd_cpu.c
avr/cmd_misc.c
avr/main.c
avr/z80-if.c
include/common.h
z180/cpuinfo.180

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..a05b308
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,15 @@
+SUBDIRS = avr z180
+
+.PHONY: subdirs $(SUBDIRS) clean
+
+subdirs: $(SUBDIRS)
+
+$(SUBDIRS):
+       $(MAKE) -C $@
+
+clean:
+       $(MAKE) -C avr $@
+       $(MAKE) -C z180 $@
+
+
+avr: z180
index 036a041bd07a3d4c70c5fe3f73dedb69532396a9..fb533c73a3ca9ea8e977a76ea1decf5054d25456 100644 (file)
@@ -275,28 +275,24 @@ command_ret_t do_go(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc,
        }
 
        if (z80_bus_state() & ZST_RUNNING) {
-               printf_P(PSTR("CPU already running!\n"));
-               return CMD_RET_FAILURE;
+               cmd_error(CMD_RET_FAILURE, ERUNNING, NULL);
        }
 
        printf_P(PSTR("Starting application at 0x%04lx ...\n"), addr);
 
        if (addr != 0) {
-               uint8_t tmp[3];
+//             uint8_t tmp[3];
 
-               z80_bus_cmd(Request);
-               z80_read_block (tmp, 0, 3);
+               z80_bus_request_or_exit();
+//             z80_read_block (tmp, 0, 3);
                z80_write(0, 0xc3);
                z80_write(1, addr);
                z80_write(2, (addr >> 8));
 
+               z80_bus_cmd(Release);
+               _delay_ms(100);
                z80_bus_cmd(Run);
-               _delay_us(10);
-               z80_bus_cmd(M_Cycle);
-               _delay_us(10);
-               z80_bus_cmd(M_Cycle);
-               _delay_us(10);
-               z80_write_block(tmp, 0, 3);
+//             z80_write_block(tmp, 0, 3);
        } else {
                if (!hold)
                        z80_bus_cmd(Request);
index e5158fd705c11a2bc7a5ade6674f782552aca8a6..64dd7219e71cd2b4a2b359cc58e6ac120c9cd5af 100644 (file)
 #include "../z180/cpuinfo.h"
 #undef const
 
+#define DEBUG_CPU      1       /* set to 1 to debug */
+
+#define debug_cpu(fmt, args...)                                                              \
+       debug_cond(DEBUG_CPU, fmt, ##args)
+
 
 /*
  * delay for <count> ms...
@@ -32,24 +37,14 @@ static void test_delay(uint32_t count)
        while (get_timer(ts) <= count);
 }
 
-uint32_t z80_measure_phi(uint_fast8_t cycles)
+static uint32_t z80_measure_phi(uint_fast8_t cycles)
 {
        uint16_t ref_stop;
        uint16_t ref_ovfl;
        uint8_t x_ovfl;
-       uint8_t eimsk_save,eicrb_save;
        uint32_t x_freq;
 
 
-       ATOMIC_BLOCK(ATOMIC_FORCEON) {
-               /* Save state and disable INT6 */
-               eimsk_save = EIMSK;
-               EIMSK &= ~_BV(INT6);
-               /* Save state and set INT6 for falling edge */
-               eicrb_save = EICRB;
-               EICRB = (eicrb_save & ~(0b11 << ISC60)) | (0b10 << ISC60);
-       }
-
        PRR1 &= ~_BV(PRTIM3);
        TCCR3A = 0;
        TCCR3B = 0b000<<CS30;   /* stop counter */
@@ -101,29 +96,20 @@ uint32_t z80_measure_phi(uint_fast8_t cycles)
                x_ovfl++;
        }
 
-       ATOMIC_BLOCK(ATOMIC_FORCEON) {
-               /* Restore INT6 */
-               EICRB = eicrb_save;
-               if ((eimsk_save & _BV(INT6)) != 0)
-                       EIMSK |= _BV(INT6);
-               /* Reset pending int */
-               EIFR = _BV(INTF6);
-       }
-
        uint32_t ref_cnt = (ref_stop - OCR4B) + ((uint32_t)ref_ovfl << 16);
        uint32_t x_cnt = TCNT3 + ((uint32_t) x_ovfl << 16);
        uint64_t x_tmp = (uint64_t) 100000 * (x_cnt * cycles);
 
-       debug("TCNT3: %6u, ref_cnt: %9lu\n", TCNT3, ref_cnt);
-       debug("x_tmp: %lu %lu\n", (uint32_t) (x_tmp >> 32), (uint32_t) (x_tmp & 0xffffffff));
+       debug_cpu("TCNT3: %6u, ref_cnt: %9lu\n", TCNT3, ref_cnt);
+       debug_cpu("x_tmp: %lu %lu\n", (uint32_t) (x_tmp >> 32), (uint32_t) (x_tmp & 0xffffffff));
 
        x_tmp = (x_tmp * getenv_ulong(PSTR(ENV_FMON), 10, F_CPU) + (ref_cnt / 2)) / ref_cnt;
 
-       debug("x_tmp: %lu %lu\n", (uint32_t) (x_tmp >> 32), (uint32_t) (x_tmp & 0xffffffff));
+       debug_cpu("x_tmp: %lu %lu\n", (uint32_t) (x_tmp >> 32), (uint32_t) (x_tmp & 0xffffffff));
 
        /* round to 5 decimal digits */
        int_fast8_t sc = 5;
-       while (x_tmp >= 100000) {
+       while (sc > 0 || x_tmp >= 100000) {
                x_tmp = (x_tmp + 5)/10;
            sc--;
        }
@@ -132,8 +118,6 @@ uint32_t z80_measure_phi(uint_fast8_t cycles)
                x_freq *= 10;
            sc++;
        }
-       x_freq += (uint32_t) sc << 28;
-
 
        /* Stop Timer */
        TCCR3B = 0;
@@ -142,258 +126,144 @@ uint32_t z80_measure_phi(uint_fast8_t cycles)
        return x_freq;
 }
 
-#if 0
-float z80_measure_phi(uint_fast8_t cycles, uint16_t wait_ms)
-{
-       uint16_t ref_stop;
-       uint16_t ref_ovfl;
-       uint8_t x_ovfl;
-       uint8_t eimsk_save,eicrb_save;
-       float x_freq;
+static const FLASH uint8_t loop_code[] = {
+/* 0000 */  0x00,             /* nop                                        */
+/* 0001 */  0xAF,             /* xor  a                                     */
+/* 0005 */  0xD3,0x32,        /* out  (032h),a  ;DCNTL                      */
+/* 0002 */  0xD3,0x36,        /* out  (036h),a  ;RCR                        */
+/*      */                    /*                                            */
+/* 0006 */  0xD3,0x40,        /* out  (040H),a  ;Ready                      */
+/*      */                    /*                                            */
+/*      */                    /*                ;Z80    Z180(0W) Z180(MaxW) */
+/* 0008 */                    /* loop:          ;-------------------------- */
+/* 0008 */  0xDB,0x50,        /* in   a,(050h)  ;11       10     +3*3  19   */
+/* 000A */  0xC3,0x08,0x00    /* jp   loop      ;10        9     +3*3  18   */
+                              /*                ;-------------------------- */
+                              /*                ;21       19           37   */
+};
 
+command_ret_t do_cpu_freq(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[])
+{
 
-       ATOMIC_BLOCK(ATOMIC_FORCEON) {
-               /* Save state and disable INT6 */
-               eimsk_save = EIMSK;
-               EIMSK &= ~_BV(INT6);
-               /* Save state and set INT6 for falling edge */
-               eicrb_save = EICRB;
-               EICRB = (eicrb_save & ~(0b11 << ISC60)) | (0b10 << ISC60);
-       }
+#define O_SILENT               (1<<0)
+#define O_WENV                 (1<<1)
+#define O_LOAD_LOOP     (1<<2)
+#define O_UNLOAD_LOOP   (1<<3)
 
-       PRR1 &= ~_BV(PRTIM3);
-       TCCR3A = 0;
-       TCCR3B = 0b000<<CS30;   /* stop counter */
-       TCNT3 = 0;
-       x_ovfl = 0;
-       TIFR3 = _BV(TOV3);
-       ref_ovfl = 0;
+       uint_fast8_t options = O_LOAD_LOOP | O_UNLOAD_LOOP;
+       uint_fast8_t lcycles = 19;
+       uint16_t timeout = 1000;
+       uint8_t eimsk_save;
 
-       ATOMIC_BLOCK(ATOMIC_FORCEON) {
-               /* Reset pending int */
-               EIFR = _BV(INTF6);
-               /* Wait for falling edge */
-               while ((EIFR & _BV(INTF6)) == 0)
-                       ;
-               TCCR3B = 0b110<<CS30;   /* Count falling edges on T3 (==INT6) */
-               OCR4B = TCNT4;
-               TIFR4 = _BV(OCF4B);             /* clear compare match flag */
-       }
-       while (ref_ovfl < 60) {
-               ATOMIC_BLOCK(ATOMIC_FORCEON) {
-                       if ((TIFR4 & _BV(OCF4B)) != 0) {
-                               TIFR4 = _BV(OCF4B);
-                               ref_ovfl++;
-                       }
-                       if ((TIFR3 & _BV(TOV3)) != 0) {
-                               TIFR3 = _BV(TOV3);
-                               x_ovfl++;
-                       }
-               }
-       }
+       uint8_t mem_save[ARRAY_SIZE(loop_code)];
 
-       ATOMIC_BLOCK(ATOMIC_FORCEON) {
-               EIFR = _BV(INTF6);
-               for (;;) {
-                       if (EIFR & _BV(INTF6)) {
-                               TCCR3B = 0b000<<CS30;   /* stop counter */
-                               ref_stop = TCNT4;
-                               break;
-                       }
-                       if ((TIFR4 & _BV(OCF4B)) != 0) {
-                               TIFR4 = _BV(OCF4B);
-                               ref_ovfl++;
-                       }
+       int opt;
+       while ((opt = getopt(argc, argv, PSTR("swnuc:t:"))) != -1) {
+               switch (opt) {
+               case 's':
+                       options |= O_SILENT;
+                       break;
+               case 'w':
+                       options |= O_WENV;
+                       break;
+               case 'n':
+                       options &= ~O_LOAD_LOOP;
+                       break;
+               case 'u':
+                       options &= ~O_UNLOAD_LOOP;
+                       break;
+               case 'c':
+                       lcycles = eval_arg(optarg, NULL);
+                       break;
+               case 't':
+                       timeout = eval_arg(optarg, NULL);
+                       break;
+               default: /* '?' */
+                       return CMD_RET_USAGE;
                }
        }
+       if (argc - optind != 0)
+               return CMD_RET_USAGE;
 
-       if ((TIFR3 & _BV(TOV3)) != 0) {
-               TIFR3 = _BV(TOV3);
-               x_ovfl++;
+       if (z80_bus_state() & ZST_RUNNING) {
+               if (!(options & O_SILENT))
+                       printf_P(PSTR("Frequency measuring failed. CPU allready running!\n"));
+               return CMD_RET_FAILURE;
        }
 
        ATOMIC_BLOCK(ATOMIC_FORCEON) {
-               /* Restore INT6 */
-               EICRB = eicrb_save;
-               if ((eimsk_save & _BV(INT6)) != 0)
-                       EIMSK |= _BV(INT6);
-               /* Reset pending int */
-               EIFR = _BV(INTF6);
-       }
-
-       uint32_t ref_cnt = (ref_stop - OCR4B) + ((uint32_t)ref_ovfl << 16);
-
-       uint32_t x_cnt = TCNT3 + ((uint32_t) x_ovfl << 16);
-       x_freq = x_cnt * cycles;
-
-       x_freq = (x_freq * getenv_ulong(PSTR(ENV_FMON), 10, F_CPU)) / ref_cnt;
-
-       debug("TCNT3: %6u, ref_cnt: %9lu\n", TCNT3, ref_cnt);
-#if 0
-       debug("ref_start: %6u, ref_stop: %6u, ref_ovfl: %4u, ref_cnt: %9lu\n"
-                                 "    TCNT3: %6u, x_cnt: %6lu, xfreq: %f\n",
-                               OCR4B, ref_stop, ref_ovfl, ref_cnt,
-                               TCNT3, x_cnt, x_freq);
-#endif
-
-
-       /* Stop Timer */
-       TCCR3B = 0;
-       PRR1 |= _BV(PRTIM3);
-
-       return x_freq;
-}
-#endif
-
-#if 0
-int32_t z80_measure_phi(uint_fast8_t cycles, uint16_t wait_ms)
-{
-       uint16_t ref_stop;
-       uint16_t ref_ovfl;
-       uint8_t x_ovfl;
-       uint32_t x_freq;
-       uint8_t eimsk_save,eicrb_save;
-
-
-       ATOMIC_BLOCK(ATOMIC_FORCEON) {
-               /* Save state and disable INT6 */
+               /* Save state and disable INT5/INT6 */
                eimsk_save = EIMSK;
                EIMSK &= ~_BV(INT6);
-               /* Save state and set INT6 for falling edge */
-               eicrb_save = EICRB;
-               EICRB = (eicrb_save & ~(0b11 << ISC60)) | (0b10 << ISC60);
+               EIMSK &= ~_BV(INT5);
        }
 
-       PRR1 &= ~_BV(PRTIM3);
-       TCCR3A = 0;
-       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)
-                       ;
-               OCR4B = TCNT4;
-               TCCR3B = 0b110<<CS30;   /* Count falling edges on T3 (==INT6) */
-               TIFR4 = _BV(OCF4B);             /* clear compare match flag */
-       }
-       while (ref_ovfl < 60) {
-               ATOMIC_BLOCK(ATOMIC_FORCEON) {
-                       if ((TIFR4 & _BV(OCF4B)) != 0) {
-                               TIFR4 = _BV(OCF4B);
-                               ref_ovfl++;
-                       }
-                       if ((TIFR3 & _BV(TOV3)) != 0) {
-                               TIFR3 = _BV(TOV3);
-                               x_ovfl++;
-                       }
-               }
+       z80_bus_cmd(Request);
+       if (options & O_LOAD_LOOP) {
+               z80_read_block(mem_save, 0, ARRAY_SIZE(loop_code));
+               z80_write_block_P(loop_code, 0, ARRAY_SIZE(loop_code));
        }
+       EIFR = _BV(INTF5);                              /* Reset pending int */
+       z80_bus_cmd(Release);
+       z80_bus_cmd(Run);
 
-       ATOMIC_BLOCK(ATOMIC_FORCEON) {
-               EIFR = _BV(INTF6);
-               for (;;) {
-                       if (EIFR & _BV(INTF6)) {
-                               ref_stop = TCNT4;
-                               TCCR3B = 0b000<<CS30;   /* stop counter */
-                               break;
-                       }
-                       if ((TIFR4 & _BV(OCF4B)) != 0) {
-                               TIFR4 = _BV(OCF4B);
-                               if (ref_ovfl)
-                                       ref_ovfl++;
-                       }
-               }
-       }
+       clear_ctrlc();                                  /* forget any previous Control C */
+       ERRNUM err = 0;
 
-#if 0
-       ATOMIC_BLOCK(ATOMIC_FORCEON) {
-               EIFR = _BV(INTF6);
-               for (;;) {
-                       if (EIFR & _BV(INTF6))
-                               break;
-                       if (TIFR4 & _BV(OCF4B)) {
-                               if (EIFR & _BV(INTF6))
-                                       break;
-                               TIFR4 = _BV(OCF4B);
-                               if (EIFR & _BV(INTF6))
-                                       break;
-                               ref_ovfl++;
-                               if (EIFR & _BV(INTF6))
-                                       break;
-                               if (ref_ovfl == 0)
-                                       break;
-                       }
-               }
-               ref_stop = TCNT4;
-               TCCR3B = 0b000<<CS30;   /* stop counter */
-               if ((TIFR4 & _BV(OCF4B)) != 0) {
-                       TIFR4 = _BV(OCF4B);
-                       if (ref_ovfl)
-                               ref_ovfl++;
+       /* Wait for falling edge */
+       do {
+               /* check for ctrl-c to abort... */
+               if (had_ctrlc() || ctrlc()) {
+                       err = EINTR;
+                       break;
                }
-       }
-#endif
-       if ((TIFR3 & _BV(TOV3)) != 0) {
-               TIFR3 = _BV(TOV3);
-               x_ovfl++;
-       }
+       } while ((EIFR & _BV(INTF5)) == 0);
 
-       if (ref_ovfl == 0)
-               x_freq = 0xFFFFFFFE;
-       else
-       {
-               uint32_t ref_cnt = (ref_stop - OCR4B) + ((uint32_t)ref_ovfl << 16);
-
-               x_freq = TCNT3 + ((uint32_t) x_ovfl << 16);
-               uint32_t x_cnt = x_freq;
-               x_freq *= cycles;
-
-               x_freq = ((uint64_t) x_freq * getenv_ulong(PSTR(ENV_FMON), 10, F_CPU) + (ref_cnt / 2))/ ref_cnt;
-
-               debug("ref_start: %6u, ref_stop: %6u, ref_ovfl: %4u, ref_cnt: %9lu\n"
-                                         "    TCNT3: %6u, x_cnt: %6lu, xfreq: %9lu\n",
-                                       OCR4B, ref_stop, ref_ovfl, ref_cnt,
-                                       TCNT3, x_cnt, x_freq);
+       uint32_t cpu_freq = 0;
+       if (!err)
+               cpu_freq = z80_measure_phi(lcycles);
 
-               /* round to 5 decimal digits */
-               uint_fast8_t sc = 0;
-               while (x_freq >= 100000UL) {
-                       x_freq = (x_freq + 5)/10;
-                       ++sc;
-               }
-               while (sc--)
-                       x_freq *= 10;
+       z80_bus_cmd(Reset);
+       if (options & O_UNLOAD_LOOP) {
+               z80_bus_cmd(Request);
+               z80_write_block(mem_save, 0, ARRAY_SIZE(loop_code));
+               z80_bus_cmd(Release);
        }
-
-       /* Stop Timer */
-       TCCR3B = 0;
-       PRR1 |= _BV(PRTIM3);
-
        ATOMIC_BLOCK(ATOMIC_FORCEON) {
-               /* Restore INT6 */
-#if 0 /* wtf? */
-               eicrb_save = EICRB;
-               EICRB = (EICRB & ~(0b11 << ISC60)) | (eicrb_save & (0b11 << ISC60));
-#endif
-               EICRB = eicrb_save;
+               /* Restore INT5/INT6 */
+               if ((eimsk_save & _BV(INT5)) != 0)
+                       EIMSK |= _BV(INT5);
                if ((eimsk_save & _BV(INT6)) != 0)
                        EIMSK |= _BV(INT6);
                /* Reset pending int */
+               EIFR = _BV(INTF5);
                EIFR = _BV(INTF6);
        }
 
-       return (int32_t) x_freq;
-}
+       Stat &= ~S_MSG_PENDING;
+       Stat &= ~S_CON_PENDING;
+
+       if (err)
+               cmd_error(CMD_RET_FAILURE, err, NULL);
+
+       if (!(options & O_SILENT)) {
+               uint8_t sc = cpu_freq >> 28;
+               printf_P(PSTR("%lu %3u\n"), cpu_freq & 0x0fffffff, sc);
+       }
+#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;
+               }
+       }
 #endif
+       return CMD_RET_SUCCESS;
+}
 
 static const FLASH char * const FLASH cpu_strings[] = {
-       FSTR("Unknown CPU"),
+       FSTR("Unknown"),
        FSTR("8080"),
        FSTR("8085"),
        FSTR("Z80"),
@@ -407,6 +277,7 @@ command_ret_t do_cpuchk(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int a
 {
        uint_fast8_t cputype = 0;
        ERRNUM err = ESUCCESS;
+       uint8_t eimsk_save;
        uint8_t ram_save[cpuinfo_length];
 
        if (z80_bus_state() & ZST_RUNNING) {
@@ -423,26 +294,41 @@ command_ret_t do_cpuchk(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int a
                if (argv[1] && (argv[1][0] == 'n'))
                        goto donot;
 
+               ATOMIC_BLOCK(ATOMIC_FORCEON) {
+                       /* Save state and disable INT5/INT6 */
+                       eimsk_save = EIMSK;
+                       EIMSK &= ~_BV(INT6);
+                       EIMSK &= ~_BV(INT5);
+               }
+               EIFR = _BV(INTF5);                              /* Reset pending int */
                z80_bus_cmd(Run);
 
                clear_ctrlc();          /* forget any previous Control C */
-               uint_fast8_t done = 0;
-               while (done != 0xFF) {
-                       _delay_ms(8);
+               do {
                        /* check for ctrl-c to abort... */
                        if (had_ctrlc() || ctrlc()) {
                                err = EINTR;
                                break;
                        }
-                       z80_bus_cmd(Request);
-                       done = z80_read(3);
-                       if (done == 0xFF)
-                               cputype = z80_read(4);
-                       z80_bus_cmd(Release);
-               }
+               } while ((EIFR & _BV(INTF5)) == 0);
                z80_bus_cmd(Reset);
+               ATOMIC_BLOCK(ATOMIC_FORCEON) {
+                       /* Restore INT5/INT6 */
+                       if ((eimsk_save & _BV(INT5)) != 0)
+                               EIMSK |= _BV(INT5);
+                       if ((eimsk_save & _BV(INT6)) != 0)
+                               EIMSK |= _BV(INT6);
+                       /* Reset pending int */
+                       EIFR = _BV(INTF5);
+                       EIFR = _BV(INTF6);
+               }
+               Stat &= ~S_MSG_PENDING;
+               Stat &= ~S_CON_PENDING;
                z80_bus_cmd(Request);
-//             z80_write_block(ram_save, 0, cpuinfo_length);
+               if (z80_read(3) == 0xFF) {
+                       cputype = z80_read(4);
+               }
+               z80_write_block(ram_save, 0, cpuinfo_length);
                z80_bus_cmd(Release);
        }
 
@@ -569,134 +455,15 @@ command_ret_t do_busack_test(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED,
        return CMD_RET_SUCCESS;
 }
 
-static const FLASH uint8_t loop_code[] = {
-/* 0000 */  0x00,             /* nop                                        */
-/* 0001 */  0xAF,             /* xor  a                                     */
-/* 0005 */  0xD3,0x32,        /* out  (032h),a  ;DCNTL                      */
-/* 0002 */  0xD3,0x36,        /* out  (036h),a  ;RCR                        */
-/*      */                    /*                                            */
-/* 0006 */  0xD3,0x40,        /* out  (040H),a  ;Ready                      */
-/*      */                    /*                                            */
-/*      */                    /*                ;Z80    Z180(0W) Z180(MaxW) */
-/* 0008 */                    /* loop:          ;-------------------------- */
-/* 0008 */  0xDB,0x50,        /* in   a,(050h)  ;11       10     +3*3  19   */
-/* 000A */  0xC3,0x08,0x00    /* jp   loop      ;10        9     +3*3  18   */
-                              /*                ;-------------------------- */
-                              /*                ;21       19           37   */
-};
-
-command_ret_t do_cpu_freq(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[])
-{
-
-#define O_SILENT               (1<<0)
-#define O_WENV                 (1<<1)
-#define O_LOAD_LOOP     (1<<2)
-#define O_UNLOAD_LOOP   (1<<3)
-
-       uint_fast8_t options = O_LOAD_LOOP | O_UNLOAD_LOOP;
-       uint_fast8_t lcycles = 19;
-       uint16_t timeout = 1000;
-
-       uint8_t mem_save[ARRAY_SIZE(loop_code)];
-
-       int opt;
-       while ((opt = getopt(argc, argv, PSTR("swnuc:t:"))) != -1) {
-               switch (opt) {
-               case 's':
-                       options |= O_SILENT;
-                       break;
-               case 'w':
-                       options |= O_WENV;
-                       break;
-               case 'n':
-                       options &= ~O_LOAD_LOOP;
-                       break;
-               case 'u':
-                       options &= ~O_UNLOAD_LOOP;
-                       break;
-               case 'c':
-                       lcycles = eval_arg(optarg, NULL);
-                       break;
-               case 't':
-                       timeout = eval_arg(optarg, NULL);
-                       break;
-               default: /* '?' */
-                       return CMD_RET_USAGE;
-               }
-       }
-       if (argc - optind != 0)
-               return CMD_RET_USAGE;
-
-       if (z80_bus_state() & ZST_RUNNING) {
-               if (!(options & O_SILENT))
-                       printf_P(PSTR("Frequency measuring failed. CPU allready running!\n"));
-               return CMD_RET_FAILURE;
-       }
-
-
-       z80_bus_cmd(Request);
-       if (options & O_LOAD_LOOP) {
-               z80_read_block(mem_save, 0, ARRAY_SIZE(loop_code));
-               z80_write_block_P(loop_code, 0, ARRAY_SIZE(loop_code));
-       }
-       Stat &= ~S_IO_0X40;                             /* Reset pending int */
-       z80_bus_cmd(Release);
-       z80_bus_cmd(Run);
-
-       clear_ctrlc();                                  /* forget any previous Control C */
-       ERRNUM err = 0;
-
-       /* Wait for falling edge */
-       do {
-               /* check for ctrl-c to abort... */
-               if (had_ctrlc() || ctrlc()) {
-                       err = EINTR;
-                       break;
-               }
-       } while ((Stat & S_IO_0X40) == 0);
-
-       uint32_t cpu_freq = 0;
-       if (!err)
-               cpu_freq = z80_measure_phi(lcycles);
-
-       z80_bus_cmd(Reset);
-       if (options & O_UNLOAD_LOOP) {
-               z80_bus_cmd(Request);
-               z80_write_block(mem_save, 0, ARRAY_SIZE(loop_code));
-               z80_bus_cmd(Release);
-       }
-       if (err)
-               cmd_error(CMD_RET_FAILURE, err, NULL);
-
-       if (!(options & O_SILENT)) {
-               printf_P(PSTR("%lu %3u\n"), cpu_freq & 0x0fffffff, cpu_freq >> 28);
-
-//             printf_P(PSTR("%f%S\n"), cpu_freq, cpu_freq < 0 ? PSTR("") : PSTR("Hz"));
-//             if (cpu_freq != 0)
-//             else
-//                     printf_P(PSTR("No CPU clock or input frequency to low!\n"));
-       }
-#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;
-               }
-       }
-#endif
-       return CMD_RET_SUCCESS;
-}
-
 
 /*
- * command table for fat subcommands
+ * command table for subcommands
  */
 
 cmd_tbl_t cmd_tbl_cpu[] = {
 CMD_TBL_ITEM(
-       chkcpu, CONFIG_SYS_MAXARGS,     CTBL_RPT,       do_cpuchk,
-       "Check CPU",
+       chkcpu, CONFIG_SYS_MAXARGS,     CTBL_RPT|CTBL_SUBCMDAUTO, do_cpuchk,
+       "Check/Identify CPU",
        ""
 ),
 CMD_TBL_ITEM(
index ad913e83815d7938cafd09bcc3eacd2a93cae9b5..63a510cb9d8553eb43439f9966ac57cb7554196a 100644 (file)
@@ -104,7 +104,7 @@ command_ret_t do_time(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int arg
        sec = (elapsed_ms / 1000) % 60;
        ms = elapsed_ms % 1000;
 
-       printf_P(PSTR("\ntime: %lum%u.%03us\n"), min, sec, ms);
+       printf_P(PSTR("\ntime: %lum %u.%03us\n"), min, sec, ms);
 
        return retval;
 }
index 6fd29a87d3d0b0acb2714edee598d99fbafaebd3..09df64b1583073dc583339e62a6c68841e08543d 100644 (file)
@@ -85,7 +85,6 @@ void print_reset_reason(void)
 ISR(INT5_vect)
 {
        Stat |= S_MSG_PENDING;
-       Stat |= S_IO_0X40;
 }
 
 ISR(INT6_vect)
index 9865208b7f0d9f3fcdf4119afb7efb1a780d925b..5a4104dfadea5dd34e2932d1542aeac920a93834 100644 (file)
@@ -402,7 +402,7 @@ zstate_t z80_bus_cmd(bus_cmd_t cmd)
                                Z80_I_RST = 1;                                  /* Toggle RESET  --> inactive */
                                OCR4B = TCNT4;
                                TIFR4 = _BV(OCF4B);                             /* Clear compare match flag */
-/*test*/               TIMSK4 &= ~_BV(OCIE4A);         /* Disable Output Compare A interrupt */
+//                             TIMSK4 &= ~_BV(OCIE4A);         /* Disable Output Compare A interrupt */
                        }
                        TIMSK4 |= _BV(OCIE4B);                          /* Enable compare match interrupt */
 
@@ -414,7 +414,7 @@ zstate_t z80_bus_cmd(bus_cmd_t cmd)
                                ovl_cnt = busack_cycles_ovl;
                                ifr = TIFR4;
                                TIMSK4 &= ~_BV(OCIE4B);                 /* Disable compare match interrupt */
-/*test*/               TIMSK4 |= _BV(OCIE4A);          /* Enable Output Compare A interrupt */
+//                             TIMSK4 |= _BV(OCIE4A);          /* Enable Output Compare A interrupt */
                        }
                        if (Z80_I_BUSACK == 0) {
                                if ((ifr & _BV(OCF4B)) && !(tcnt & (1<<15)))
index 4037ac85658ee7f15aa5268e5494422580c5f65d..16f96bb0e944bfbffc403979d49e3f16a493a1b2 100644 (file)
@@ -82,7 +82,6 @@ extern volatile uint_least8_t Stat;
 
 #define S_10MS_TO                      (1<<0)
 #define S_MSG_PENDING          (1<<1)
-#define S_IO_0X40                      (1<<2)
 #define S_CON_PENDING          (1<<3)
 #define S_RESET_POLARITY       (1<<4)
 
index 7d25dc276f7ec437a06cc365db843c3223c5ea4a..0ea3e8e17b8dfc41af7567b1722716a2b6c97868 100644 (file)
@@ -30,52 +30,20 @@ base                equ     0
 done:  db      0\r
 result:        db      0\r
 \r
-;-------------------------------------------------------------------------------\r
-; Read internal register at address in L and IOBASE in H.\r
-;\r
-\r
-reg_in:\r
-       ld      a,h\r
-       add     a,l\r
-       ld      c,a\r
-       ld      b,0\r
-       in      a,(c)\r
-       ret\r
-\r
-;-------------------------------------------------------------------------------\r
-; Write internal register at address in L and IOBASE in H.\r
-;\r
-\r
-reg_out:\r
-       ld      b,a\r
-       ld      a,h\r
-       add     a,l\r
-       ld      c,a\r
-       ld      a,b\r
-       ld      b,0\r
-       out     (c),a\r
-       ret\r
-\r
 ;-------------------------------------------------------------------------------\r
 ; Check if register C exists. D holds mask of bit to test.\r
-;      return nz, if register exists\r
+;      return z, if register exists\r
 \r
 chk_reg:\r
-       call    reg_in\r
-       cp      0ffh\r
-       ret     nz              ;\r
-\r
+       in      a,(c)\r
+       ld      l,a\r
        ; check, if register is changeable\r
-\r
-       xor     d               ; set bit(s) in register to 0\r
-       call    reg_out\r
-       call    reg_in          ; get it back\r
-       ex      af,af'\r
-       ld      a,0ffh          ; set to register original state\r
-       call    reg_out\r
-       ex      af,af'\r
-       cpl\r
-       and     d\r
+       xor     d               ;\r
+       out     (c),a\r
+       in      a,(c)           ; get it back\r
+       xor     d\r
+       out     (c),l           ; set register to original state\r
+       cp      l\r
        ret\r
 \r
 ;-------------------------------------------------------------------------------\r
@@ -142,56 +110,47 @@ chk_z80:
        ; At least Hitachi HD64180\r
        ; Test differences in certain internal registers\r
        ; to determine the 180 variant.\r
-       ; First, search the internal register bank.\r
-\r
-       ld      h,00H           ; I/O Base\r
-find_base_loop:\r
-       ld      l,icr\r
-       call    reg_in\r
-       and     11011111b       ; mask I/O Stop bit\r
-       xor     h\r
+\r
+       ld      b,0\r
+       ld      c,icr\r
+       in      a,(c)\r
        cp      01FH\r
-       jr      nz,nxt_base\r
+       jr      z,icr_ok\r
 \r
        ;TODO: additional plausibility checks\r
 \r
-       jr      z,base_found\r
-nxt_base:\r
-       ld      a,h\r
-       add     a,040H\r
-       ld      h,a\r
-       jr      nc,find_base_loop\r
-       ret                     ;I/O registers not found\r
+       ret                     ; I/O registers not found\r
 \r
        ; Register (base) found.\r
 \r
-base_found:\r
+icr_ok:\r
        inc     e               ; HD64180\r
-       ld      l,RCR           ; Disable Refresh Controller\r
-       xor     a               ;\r
-       call    reg_out         ;\r
-       ld      l,omcr          ; Check, if CPU has OMCR register\r
+       out0    (RCR),b         ;\r
+       ld      c,omcr          ; Check, if CPU has OMCR register\r
        ld      d,M_IOC         ;\r
        call    chk_reg         ;\r
-       ret                   ; Register does not exist. It's a HD64180\r
+       ret     nz              ; Register does not exist. It's a HD64180\r
 \r
        inc     e               ; Z80180\r
-       ld      l,cmr           ; Check, if CPU has CMR register\r
+       ld      c,cmr           ; Check, if CPU has CMR register\r
        ld      d,M_LNC         ;\r
        call    chk_reg         ;\r
-       ret                   ; register does not exist. It's a Z80180\r
+       ret     nz              ; register does not exist. It's a Z80180\r
 \r
        inc     e               ; S180/L180 (class) detected.\r
-\r
        ret\r
 \r
 ;-------------------------------------------------------------------------------\r
 \r
 start:\r
        ld      sp,stack\r
+       ld      hl,done\r
+       ld      (hl),0\r
+       inc     hl\r
+       ld      (hl),0\r
+       push    hl\r
        call    check\r
-\r
-       ld      hl,result\r
+       pop     hl\r
        ld      (hl),e\r
        dec     hl\r
        ld      (hl),0ffH\r