summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo C2018-09-10 20:54:33 +0200
committerLeo C2018-09-10 20:54:33 +0200
commitd66348b4fb147eb01c30aa9b3a8904ce6c59a4c1 (patch)
tree528825bbd00bb36bfbae201aa7b3b4eac40813c4
parentdf728b3578bfba42632b2a3bd7250fba70776b22 (diff)
downloadz180-stamp-d66348b4fb147eb01c30aa9b3a8904ce6c59a4c1.zip
ew debug command: xx busack: Measure time RESET to BUSACK
-rw-r--r--avr/cmd_cpu.c32
-rw-r--r--avr/strerror.c24
-rw-r--r--avr/z80-if.c43
-rw-r--r--include/z80-if.h1
4 files changed, 81 insertions, 19 deletions
diff --git a/avr/cmd_cpu.c b/avr/cmd_cpu.c
index 1b1982c..1627d9f 100644
--- a/avr/cmd_cpu.c
+++ b/avr/cmd_cpu.c
@@ -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,
diff --git a/avr/strerror.c b/avr/strerror.c
index a4d2a67..199504a 100644
--- a/avr/strerror.c
+++ b/avr/strerror.c
@@ -10,18 +10,18 @@
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 */
};
diff --git a/avr/z80-if.c b/avr/z80-if.c
index 5d88842..62199bb 100644
--- a/avr/z80-if.c
+++ b/avr/z80-if.c
@@ -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;
diff --git a/include/z80-if.h b/include/z80-if.h
index 7225cf4..a431500 100644
--- a/include/z80-if.h
+++ b/include/z80-if.h
@@ -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);