]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/cmd_cpu.c
env var fmon (F_CPU)
[z180-stamp.git] / avr / cmd_cpu.c
index f3438852afb6bae8707360206cf11eaf3c18d380..745c68a97dabe6368c596f9c2729715015ec9ffe 100644 (file)
 
 #include "z80-if.h"
 #include "con-utils.h"
-//#include "env.h"
+#include "env.h"
 #include "eval_arg.h"
 #include "timer.h"
 #include "getopt-min.h"
-//#include "debug.h"
+#include "debug.h"
 
 /* hack to get Z180 loadfile into flash memory */
 #define const const FLASH
@@ -114,7 +114,7 @@ static int32_t z80_measure_phi(uint8_t cycles, uint16_t wait_ms)
                uint32_t x_cnt = x_freq;
                x_freq *= cycles;
 
-               x_freq = ((uint64_t) x_freq * F_CPU + (ref_cnt / 2))/ ref_cnt;
+               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, cycles: %3u, xfreq: %9lu\n",
@@ -332,17 +332,18 @@ command_ret_t do_busack_test(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED,
 }
 
 static const FLASH uint8_t loop_code[] = {
-       /* 0000 */  0x01,0x36,0x00,             /* ld   bc,00*256+RCR                           */
+       /* 0000 */  0x01,0x36,0x00,             /* ld   bc,00*256+RCR ; no refresh cycles       */
        /* 0003 */  0xAF,                       /* xor  a                                       */
        /* 0004 */  0xED,0x79,          /* out  (c),a                                   */
-       /* 0006 */  0xD3,0x40,          /* out  (040H),a                                */
+       /* 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   */
+       /* 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[])
 {
@@ -416,7 +417,7 @@ command_ret_t do_cpu_freq(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int
 
        int32_t cpu_freq;
        if (!err)
-               cpu_freq = z80_measure_phi(lcycles, false, timeout);
+               cpu_freq = z80_measure_phi(lcycles, timeout);
 
        z80_bus_cmd(Reset);
        if (options & O_UNLOAD_LOOP) {