summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo C2015-04-23 02:28:53 +0200
committerLeo C2015-04-23 02:28:53 +0200
commitd264541a3e7fe756695f811136d7a89e8e7ec478 (patch)
tree8e5291b6578dc4b1d543210c6446d3e97c06f1e1
parent31033ab3f82c4d00e12fb72a65c2ba614da8ad2f (diff)
downloadz180-stamp-hexrel-5.zip
loadi seems to work now.hexrel-5
-rw-r--r--avr/cmd_loadihex.c95
-rw-r--r--include/common.h6
2 files changed, 13 insertions, 88 deletions
diff --git a/avr/cmd_loadihex.c b/avr/cmd_loadihex.c
index 01fb6b0..debccd7 100644
--- a/avr/cmd_loadihex.c
+++ b/avr/cmd_loadihex.c
@@ -12,7 +12,7 @@
#include "command.h"
#include "con-utils.h"
#include "z80-if.h"
-//#include "debug.h"
+#include "debug.h"
uint32_t detect_ramsize(void)
@@ -43,14 +43,6 @@ uint32_t detect_ramsize(void)
return addr;
}
-static uint32_t min(uint32_t a, uint32_t b)
-{
- if (a < b)
- return a;
- return b;
-}
-
-
typedef enum {
IHX_OK,
IHX_BROKEN,
@@ -93,74 +85,6 @@ int get_hexbyte(void) {
return -1;
}
-#if 0
-
-static
-ihex_t ihex_get_record() {
-
- int i;
- uint8_t sum, c;
- ihex_t rec = { IHX_BROKEN, 0, 0, 0, 0 };
-
-
- while ((c = my_getchar(0)) != ':')
- if (c == 0x03)
- return rec;
-
- if ((i = get_hexbyte()) < 0) /* Start code */
- return rec;
- sum = i;
- rec.len = i;
- if ((i = get_hexbyte()) < 0) /* Byte Count */
- return rec;
- sum += i;
- rec.address = i * 256;
- if ((i = get_hexbyte()) < 0) /* Address */
- return rec;
- sum += i;
- rec.address += i;
- if ((i = get_hexbyte()) < 0) /* Record type */
- return rec;
- sum += i;
- rec.type = i;
-
- if (rec.len) { /* Record Data */
- uint8_t *p; int k;
- if ((rec.data = malloc(rec.len)) == 0)
- return rec;
-
- for (p=rec.data, k=rec.len; k; k--) {
- if ((i = get_hexbyte()) < 0)
- break;
- sum += i;
- *p++ = i;
- }
-
- if (k) {
- free(rec.data); rec.data = 0;
- return rec;
- }
- }
-
- i = get_hexbyte(); /* Check sum */
-
- if (i >= 0) {
- sum += i;
- if (sum == 0)
- rec.status = IHX_OK;
- else
- rec.status = IHX_CHKSUMERR;
- }
-
- if (rec.status != IHX_OK) {
- free(rec.data);
- rec.data = 0;
- }
-
- return rec;
-}
-
-#else
static
int ihex_get_record(ihex_t *rec) {
@@ -220,7 +144,6 @@ int ihex_get_record(ihex_t *rec) {
return rec->len;
}
-#endif
command_ret_t do_loadihex(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
@@ -235,9 +158,6 @@ command_ret_t do_loadihex(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg
(void) cmdtp; (void) flag;
- printf_P(PSTR("RAM Size: 0x%.5lX\n"), address_max);
-
-
if (argc > 1)
offset = strtol(argv[1], NULL, 16);
@@ -254,9 +174,8 @@ command_ret_t do_loadihex(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg
if (addr+rec.len > address_high)
address_high = addr + rec.len;
-
-printf_P(PSTR("low: 0x%.5lX, high: 0x%.5lX, max: 0x%.5lX, addr: 0x%.5lX, len: %d\n"),
- address_low, address_high, address_max, addr, rec.len);
+// debug("low: 0x%.5lX, high: 0x%.5lX, max: 0x%.5lX, addr: 0x%.5lX, len: %d\n",
+// address_low, address_high, address_max, addr, rec.len);
if (addr < address_max) {
uint32_t tmplen = address_max - addr;
@@ -280,7 +199,7 @@ printf_P(PSTR("low: 0x%.5lX, high: 0x%.5lX, max: 0x%.5lX, addr: 0x%.5lX, len: %d
break;
#endif
case 2: /* Extended Segment Address Record */
- base_address = ((rec.data[0] << 8) + rec.data[1]) << 4;
+ base_address = (uint32_t)((rec.data[0] << 8) + rec.data[1]) << 4;
break;
case 4: /* Extended Linear Address Record */
@@ -306,15 +225,15 @@ printf_P(PSTR("low: 0x%.5lX, high: 0x%.5lX, max: 0x%.5lX, addr: 0x%.5lX, len: %d
}
printf_P(PSTR("Data loaded: "));
- if (address_low >= min(address_high, address_max))
+ if (address_low >= MIN(address_high, address_max))
printf_P(PSTR("None.\n"));
else
printf_P(PSTR("low: 0x%.5lX high: 0x%.5lX\n"), address_low,
- min(address_high, address_max) - 1);
+ MIN(address_high, address_max) - 1);
if (address_high > address_max)
printf_P(PSTR("Data above highest RAM address "
- "(Range 0x%.5lX...0x%.5lX) ignored!\n"), address_max, address_high - 1);
+ "(in range 0x%.5lX - 0x%.5lX) ignored!\n"), address_max, address_high - 1);
return rcode;
}
diff --git a/include/common.h b/include/common.h
index cfbbae5..10c4417 100644
--- a/include/common.h
+++ b/include/common.h
@@ -52,6 +52,12 @@ struct bits {
#define FSTR(X) ((const FLASH char[]) { X } )
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#define MIN(a,b) ({ typeof (a) _a = (a); \
+ typeof (b) _b = (b); \
+ _a < _b ? _a : _b; })
+#define MAX(a,b) ({ typeof (a) _a = (a); \
+ typeof (b) _b = (b); \
+ _a > _b ? _a : _b; })
#ifdef __AVR__
#define Stat GPIOR0