]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/cmd_cpu.c
ew debug command: xx busack: Measure time RESET to BUSACK
[z180-stamp.git] / avr / cmd_cpu.c
index 1b1982c3346eb838b01974528606df5fda894042..1627d9f6886e8f057ca059f46b297dd40e56c45f 100644 (file)
@@ -97,7 +97,7 @@ static void   test_delay(uint32_t count)
 {
        uint32_t ts = get_timer(0);
 
-       while (get_timer(ts) < count);
+       while (get_timer(ts) <= count);
 }
 
 command_ret_t do_cpu_test(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[])
@@ -133,6 +133,31 @@ command_ret_t do_cpu_test(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int
        return CMD_RET_SUCCESS;
 }
 
+command_ret_t do_busack_test(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc UNUSED, char * const argv[] UNUSED)
+{
+
+       if ((z80_bus_state() & ZST_ACQUIRED) != RESET)
+               cmd_error(CMD_RET_FAILURE, ERUNNING, NULL);
+
+       z80_bus_cmd(Request);
+       uint32_t result = z80_get_busreq_cycles();
+       test_delay(20);
+       z80_bus_cmd(Release);
+
+#if 0
+       long div;
+
+       pinconf = gpio_config_get(pin);
+       if (pinconf == OUTPUT_TIMER) {
+               div = gpio_clockdiv_get(pin);
+#endif
+
+
+       printf_P(PSTR("cycles: %lu, time: %luus\n"), result, (uint32_t) (result * 1000000LL / F_CPU));
+
+       return CMD_RET_SUCCESS;
+}
+
 #if 0
 command_ret_t do_cpu_freq(cmd_tbl_t *cmdtp UNUSED, int flag UNUSED, int argc, char * const argv[])
 {
@@ -250,6 +275,11 @@ CMD_TBL_ITEM(
        "Do bus request/release cycles",
        "[-t pulsewidth]"
 ),
+CMD_TBL_ITEM(
+       busack, 2,      1,      do_busack_test,
+       "Get time from /Reset high to /BUSACK low",
+       ""
+),
 #if 0
 CMD_TBL_ITEM(
        freq,   CONFIG_SYS_MAXARGS,     1,      do_cpu_freq,