From 1633073f77aa4f9c90a8f1d7f317e4c4d7187921 Mon Sep 17 00:00:00 2001 From: Leo C Date: Tue, 4 Sep 2018 21:28:42 +0200 Subject: cmd_loadihex.c: use cmd_error() --- avr/cmd_loadihex.c | 52 ++++++++++++++++++---------------------------------- 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/avr/cmd_loadihex.c b/avr/cmd_loadihex.c index 2c0fa9e..f8044d5 100644 --- a/avr/cmd_loadihex.c +++ b/avr/cmd_loadihex.c @@ -55,9 +55,8 @@ typedef struct { } ihex_t; -static -int get_hexdigit(void) { - +static int get_hexdigit(void) +{ int c; c = toupper(my_getchar(1)); if (isxdigit(c)) { @@ -69,9 +68,8 @@ int get_hexdigit(void) { return -1; } -static -int get_hexbyte(void) { - +static int get_hexbyte(void) +{ uint8_t i,j; if ((i = (uint8_t) get_hexdigit()) < 0x10) @@ -83,9 +81,8 @@ int get_hexbyte(void) { } -static -int ihex_get_record(ihex_t *rec) { - +static int ihex_get_record(ihex_t *rec) +{ int c; uint8_t sum; @@ -148,24 +145,20 @@ int ihex_get_record(ihex_t *rec) { } -command_ret_t do_loadihex(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]) +command_ret_t do_loadihex(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[]) { long offset = 0; uint32_t base_address = 0; uint32_t address_max = detect_ramsize(); uint32_t address_high = 0; uint32_t address_low = address_max; - command_ret_t rcode = CMD_RET_FAILURE; - ihex_t rec; bool firstrec = true; - - (void) cmdtp; (void) flag; - + ihex_t rec; if (argc > 1) offset = strtol(argv[1], NULL, 16); - printf_P(PSTR("Waiting for Intel Hex Records...\n")); + my_puts_P(PSTR("Waiting for Intel Hex Records...\n")); while (ihex_get_record(&rec) > 0 && rec.status == IHX_OK && @@ -174,7 +167,7 @@ command_ret_t do_loadihex(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * switch (rec.type) { case 0: /* Data record */ if (firstrec) { - printf_P(PSTR("Loading: 0x.....")); + my_puts_P(PSTR("Loading: 0x.....")); firstrec = false; } if (rec.len) { @@ -193,8 +186,9 @@ command_ret_t do_loadihex(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * rec.len = tmplen; if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { - my_puts_P(PSTR("Bus timeout\n")); - return CMD_RET_FAILURE; + cmd_error(CMD_RET_FAILURE, EBUSTO, NULL); + //my_puts_P(PSTR("Bus timeout\n")); + //return CMD_RET_FAILURE; } z80_write_block(rec.data, /* src */ addr, /* dest */ @@ -223,17 +217,8 @@ command_ret_t do_loadihex(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * } } - switch (rec.status) { - case IHX_OK: - rcode = CMD_RET_SUCCESS; - break; - - case IHX_BROKEN: - case IHX_CHKSUMERR: - printf_P(PSTR("Broken Hex Record or loading interrupted!\n")); - break; - } - + if (rec.status != IHX_OK) + my_puts_P(PSTR("Broken Hex Record or loading interrupted!\n")); for (uint_fast8_t i=0; i<100; ++i) { /* flush input buffer */ @@ -242,10 +227,9 @@ command_ret_t do_loadihex(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * udelay(1000); } - - printf_P(PSTR("\nData loaded: ")); + my_puts_P(PSTR("\nData loaded: ")); if (address_low >= MIN(address_high, address_max)) - printf_P(PSTR("None.\n")); + my_puts_P(PSTR("None.\n")); else printf_P(PSTR("low: 0x%.5lX high: 0x%.5lX\n"), address_low, MIN(address_high, address_max) - 1); @@ -254,5 +238,5 @@ command_ret_t do_loadihex(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * printf_P(PSTR("Data above highest RAM address " "(in range 0x%.5lX - 0x%.5lX) ignored!\n"), address_max, address_high - 1); - return rcode; + return rec.status == IHX_OK ? CMD_RET_SUCCESS : CMD_RET_FAILURE; } -- cgit v1.2.3