]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
Handle bus errors in md command
authorLeo C <erbl259-lmu@yahoo.de>
Wed, 23 Mar 2016 09:31:37 +0000 (10:31 +0100)
committerLeo C <erbl259-lmu@yahoo.de>
Wed, 23 Mar 2016 09:31:37 +0000 (10:31 +0100)
avr/cmd_mem.c
avr/debug.c
avr/print-utils.c
include/print-utils.h

index 101b91210d84e1f0b2ae13a263ec7b1f86a78fa2..effa416d86315c99a3d83d180117e970cec81724 100644 (file)
@@ -42,13 +42,14 @@ static      uint32_t        base_address = 0;
 
 /*--------------------------------------------------------------------------*/
 
-
-void z180_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
+int z180_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
 {
-               if (z80_bus_cmd(Request) & ZST_ACQUIRED) {
-                       z80_read_block (buf, addr, count);
-                       z80_bus_cmd(Release);
-               }
+       if (!(z80_bus_cmd(Request) & ZST_ACQUIRED))
+               return -1;
+
+       z80_read_block (buf, addr, count);
+       z80_bus_cmd(Release);
+       return 0;
 }
 
 /*--------------------------------------------------------------------------*/
@@ -92,10 +93,16 @@ command_ret_t do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
        }
 
        /* Print the lines. */
-       dump_mem(addr, addr, length, z180_read_buf, NULL);
+       int ret = dump_mem(addr, addr, length, z180_read_buf, NULL);
+       if (ret == -2)  { /* TODO: Error codes */
+               my_puts_P(PSTR("Bus timeout\n"));
+               return  CMD_RET_FAILURE;
+       }
 
-       dp_last_addr = addr + length;
-       dp_last_length = length;
+       if (ret >= 0) {
+               dp_last_addr = addr + length;
+               dp_last_length = length;
+       }
        return CMD_RET_SUCCESS;
 }
 
index f3632c288018c14ca31476ae4263f5393f5e8d75..e29a0858b91dd41004fe9f7aabd8aae123c5773e 100644 (file)
@@ -40,7 +40,7 @@ void dump_heap(void)
  */
 command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-       void (*readwhat)(uint8_t *buf, uint32_t addr, uint8_t count);
+       int (*readwhat)(uint8_t *buf, uint32_t addr, uint8_t count);
 
        (void) cmdtp; (void) flag;
 
index 9ce3e5044f9547e71ef131fe2bf8ad9cbe5f7733..83f86a91fe36cf5c4c0ce3030d20932bc28141a2 100644 (file)
@@ -18,25 +18,28 @@ void print_blanks(uint_fast8_t count)
 }
 
 
-void eeprom_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
+int eeprom_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
 {
        eeprom_read_block((void *) buf, (const void *) (size_t) addr, count);
+       return 0;
 }
 
-void ram_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
+int ram_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
 {
-               while (count--)
-                       *buf++ = *(uint8_t *) (size_t) addr++;
+       while (count--)
+               *buf++ = *(uint8_t *) (size_t) addr++;
+       return 0;
 }
 
-void flash_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
+int flash_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
 {
-               while (count--)
-                       *buf++ = *(const __memx uint8_t *) (__uint24) addr++;
+       while (count--)
+               *buf++ = *(const __memx uint8_t *) (__uint24) addr++;
+       return 0;
 }
 
 int dump_mem(uint32_t address, uint32_t offset, uint32_t len,
-               void (*readfkt)(uint8_t *, uint32_t, uint8_t), char *title)
+               int (*readfkt)(uint8_t *, uint32_t, uint8_t), char *title)
 {
        uint8_t buf[16];
        char *indent = NULL;
@@ -54,7 +57,8 @@ int dump_mem(uint32_t address, uint32_t offset, uint32_t len,
        while (len) {
                if (len < 16)
                        llen = len;
-               readfkt(buf, address, llen - pre);
+               if (readfkt(buf, address, llen - pre) != 0)
+                       return -2; /* TODO: Error codes */
 
                printf_P(PSTR("%s%.5lx:"),indent, offset);
                for (i = 0; i < llen; i++) {
index 7d48287c4dbc6f2c5a64f9d771ad392f31d4ee2f..ffff039944b6c294557cb82f27ed67f8b6385bbe 100644 (file)
 
 void print_blanks(uint_fast8_t count);
 int dump_mem(uint32_t address, uint32_t offset, uint32_t len,
-               void (*readfkt)(uint8_t *, uint32_t, uint8_t), char *title);
+               int (*readfkt)(uint8_t *, uint32_t, uint8_t), char *title);
 
 void dump_eep(uint32_t addr, unsigned int len, char *title);
 void dump_ram(uint8_t *addr, size_t offset, unsigned int len, char *title);
 
-void eeprom_read_buf(uint8_t *buf, uint32_t addr, uint8_t count);
-void ram_read_buf(uint8_t *buf, uint32_t addr, uint8_t count);
-void flash_read_buf(uint8_t *buf, uint32_t addr, uint8_t count);
+int eeprom_read_buf(uint8_t *buf, uint32_t addr, uint8_t count);
+int ram_read_buf(uint8_t *buf, uint32_t addr, uint8_t count);
+int flash_read_buf(uint8_t *buf, uint32_t addr, uint8_t count);
 
 #endif /* PRINT_UTILS_H */