]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
ew debug command: xx busack: Measure time RESET to BUSACK
authorLeo C <erbl259-lmu@yahoo.de>
Mon, 10 Sep 2018 18:54:33 +0000 (20:54 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Mon, 10 Sep 2018 18:54:33 +0000 (20:54 +0200)
avr/cmd_cpu.c
avr/strerror.c
avr/z80-if.c
include/z80-if.h

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,
index a4d2a67340c76c35dc022ba14d3a6452413635fc..199504a7ad5bf59b5c59974cc9e1dbb48bfe2bfa 100644 (file)
 
 static const FLASH char * const FLASH error_strings[] = {
        FSTR("Unknown error"),
-       FSTR("Not enough memory"),
-       FSTR("Interrupt"),
-       FSTR("Bus timeout"),
-       FSTR("Unexpected argument"),
-       FSTR("Invalid disk number"),
-       FSTR("Disk already attached"),
-       FSTR("Disk not attached"),
-       FSTR("Error opening file"),
-       FSTR("File already attached to other drive"),
-       FSTR("CPU is running"),
-       FSTR("Invalid argument"),
-       FSTR("Unexpected EOF"),
+       FSTR("Not enough memory"),                                              /* 101 */
+       FSTR("Interrupt"),                              /* 102 */
+       FSTR("Bus timeout"),                            /* 103 */
+       FSTR("Unexpected argument"),                    /* 104 */
+       FSTR("Invalid disk number"),                    /* 105 */
+       FSTR("Disk already attached"),                  /* 106 */
+       FSTR("Disk not attached"),                      /* 107 */
+       FSTR("Error opening file"),                     /* 108 */
+       FSTR("File already attached to other drive"),   /* 109 */
+       FSTR("CPU is running"),                         /* 110 */
+       FSTR("Invalid argument"),                       /* 111 */
+       FSTR("Unexpected EOF"),                         /* 112 */
 
 };
 
index 5d888420ed0d282242d1e2e6aeec3771c9a8586c..62199bb448258b881eb853526cffea5dbd983ada 100644 (file)
@@ -145,14 +145,15 @@ void z80_bus_request_or_exit(void)
 static zstate_t zstate;
 static volatile uint8_t timer;         /* used for bus timeout */
 
-#if 0
-static volatile uint16_t req_cycles_ovl;
+
+static volatile uint16_t busack_cycles_ovl;
+
+static uint32_t busack_cycles;
 
 ISR(TIMER4_COMPB_vect)
 {
-       req_cycles_ovl++;
+       busack_cycles_ovl++;
 }
-#endif
 
 /*---------------------------------------------------------*/
 /* 10Hz timer interrupt generated by OC5A                  */
@@ -282,6 +283,11 @@ void z80_setup_bus(void)
 }
 
 
+uint32_t z80_get_busreq_cycles(void)
+{
+       return busack_cycles;
+}
+
 zstate_t z80_bus_state(void)
 {
        return zstate;
@@ -373,13 +379,38 @@ zstate_t z80_bus_cmd(bus_cmd_t cmd)
                switch (zstate) {
                case RESET:
                        Z80_O_BUSREQ = 0;
-                       z80_reset_inactive();
-                       timer = BUS_TO;
+                       timer = 255; //BUS_TO;
+
+                       uint16_t tcnt;
+                       uint16_t ovl_cnt;
+                       uint8_t ifr;
+                       busack_cycles = 0;
+                       busack_cycles_ovl = 0;
+                       ATOMIC_BLOCK(ATOMIC_FORCEON) {
+                               //z80_reset_inactive();
+                               Z80_I_RST = 1;                                  /* Toggle RESET  --> inactive */
+                               OCR4B = TCNT4;
+                               TIFR4 = _BV(OCF4B);                             /* Clear compare match flag */
+                       }
+                       TIMSK4 |= _BV(OCIE4B);                          /* Enable compare match interrupt */
+
                        while (Z80_I_BUSACK == 1 && timer)
                                ;
+
+                       ATOMIC_BLOCK(ATOMIC_FORCEON) {
+                               tcnt = TCNT4 - OCR4B;
+                               ovl_cnt = busack_cycles_ovl;
+                               ifr = TIFR4;
+                               TIMSK4 &= ~_BV(OCIE4B);                 /* Disable compare match interrupt */
+                       }
                        if (Z80_I_BUSACK == 0) {
+                               if ((ifr & _BV(OCF4B)) && !(tcnt & (1<<15)))
+                                       ovl_cnt++;
+                               busack_cycles = tcnt + ((uint32_t) ovl_cnt << 16);
                                z80_addrbus_set_out();
                                zstate = RESET_AQRD;
+//                             debug("### ovl: %u, ifr: %u, beg: %u, end: %u\n", ovl_cnt,
+//                                                             (ifr & _BV(OCF4B)) != 0,        OCR4B, tcnt);
                        } else {
                                z80_reset_active();
                                Z80_O_BUSREQ = 1;
index 7225cf47c8a450f74e98d9e0b5eacfa30a86d0a1..a431500b85e1d7636881c06b25ecb82b75df5176 100644 (file)
@@ -29,6 +29,7 @@ typedef enum {LOW, HIGH} level_t;
 
 void z80_bus_request_or_exit(void);
 
+uint32_t z80_get_busreq_cycles(void);
 zstate_t z80_bus_state(void);
 zstate_t z80_bus_cmd(bus_cmd_t cmd);
 void z80_setup_bus(void);