summaryrefslogtreecommitdiff
path: root/avr
diff options
context:
space:
mode:
authorLeo C2018-09-06 15:39:49 +0200
committerLeo C2018-09-06 15:39:49 +0200
commit1e5609bf0dfb390b0d62651cbd979e0ee21184fe (patch)
treea50d1a2123f6de6d02b937d2e2577dc99d922ff7 /avr
parente9d96859cfcfe170c0025e427fd9934728395dc2 (diff)
downloadz180-stamp-1e5609bf0dfb390b0d62651cbd979e0ee21184fe.zip
new command: memsize. new function z80_memsize_detect().
Diffstat (limited to 'avr')
-rw-r--r--avr/cmd_loadihex.c39
-rw-r--r--avr/cmd_mem.c17
-rw-r--r--avr/command_tbl.c5
-rw-r--r--avr/z80-if.c33
4 files changed, 61 insertions, 33 deletions
diff --git a/avr/cmd_loadihex.c b/avr/cmd_loadihex.c
index d55a63a..a7c9238 100644
--- a/avr/cmd_loadihex.c
+++ b/avr/cmd_loadihex.c
@@ -12,34 +12,6 @@
#include "debug.h"
-static uint32_t detect_ramsize(void)
-{
- uint32_t addr;
- uint8_t save_addr, save_0;
- const uint8_t PATTERN_1 = 0x55;
- const uint8_t PATTERN_2 = ~PATTERN_1;
-
- if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
- my_puts_P(PSTR("Bus timeout\n"));
- return 0;
- }
-
- save_0 = z80_read(0);
- z80_write(0, PATTERN_1);
-
- for (addr=1; addr < CONFIG_SYS_RAMSIZE_MAX; addr <<= 1) {
- save_addr = z80_read(addr);
- z80_write(addr, PATTERN_2);
- if (z80_read(0) != PATTERN_1 || z80_read(addr) != PATTERN_2)
- break;
- z80_write(addr, save_addr);
- }
- z80_write(0, save_0);
- z80_bus_cmd(Release);
-
- return addr;
-}
-
typedef enum {
IHX_OK,
IHX_BROKEN,
@@ -149,15 +121,22 @@ command_ret_t do_loadihex(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int
{
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;
+ uint32_t address_max;
+ uint32_t address_low;
bool firstrec = true;
ihex_t rec;
if (argc > 1)
offset = strtol(argv[1], NULL, 16);
+ int32_t ram = z80_memsize_detect();
+ if (ram < 0)
+ cmd_error(CMD_RET_FAILURE, (ERRNUM) -ram, NULL);
+
+ address_max = ram;
+ address_low = address_max;
+
my_puts_P(PSTR("Waiting for Intel Hex Records...\n"));
while (ihex_get_record(&rec) > 0 &&
diff --git a/avr/cmd_mem.c b/avr/cmd_mem.c
index 7a8781c..d641410 100644
--- a/avr/cmd_mem.c
+++ b/avr/cmd_mem.c
@@ -13,11 +13,9 @@
* Copied from FADS ROM, Dan Malek (dmalek@jlc.net)
*/
-#include "common.h"
-#include <ctype.h>
+#include "cmd_mem.h"
#include <avr/interrupt.h>
-#include "command.h"
#include "cli_readline.h"
#include "print-utils.h"
#include "con-utils.h"
@@ -55,6 +53,19 @@ static ERRNUM z180_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
/*--------------------------------------------------------------------------*/
+command_ret_t do_mem_size(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc UNUSED, char * const argv[] UNUSED)
+{
+ int32_t ramsize = z80_memsize_detect();
+
+ if (ramsize < 0)
+ cmd_error(CMD_RET_FAILURE, (ERRNUM) -ramsize, PSTR("Couldn't access RAM"));
+
+ printf_P(PSTR("Detected RAM: Start %.5lx, End: %.5lx, Size: %.5lx (%ld dec)\n"),
+ 0l, ramsize ? ramsize-1 : 0l, ramsize, ramsize);
+
+ return CMD_RET_SUCCESS;
+}
+
/* Memory Display
*
* Syntax:
diff --git a/avr/command_tbl.c b/avr/command_tbl.c
index 232d718..5d185ba 100644
--- a/avr/command_tbl.c
+++ b/avr/command_tbl.c
@@ -75,6 +75,11 @@ CMD_TBL_ITEM(
),
#endif
CMD_TBL_ITEM(
+ msize, 1, 1, do_mem_size,
+ "Detect memory size",
+ ""
+),
+CMD_TBL_ITEM(
mstep, 2, 1, do_busreq_pulse,
"execute one M cycle",
"[count]\n"
diff --git a/avr/z80-if.c b/avr/z80-if.c
index 6183849..6d83172 100644
--- a/avr/z80-if.c
+++ b/avr/z80-if.c
@@ -463,6 +463,39 @@ void z80_setaddress(uint32_t addr)
PIN_ADB = (((addr >> 16) << ADB_SHIFT) ^ P_ADB) & MASK(ADB_WIDTH) << ADB_SHIFT;
}
+int32_t z80_memsize_detect(void)
+{
+ const uint8_t PATTERN_1 = 0x55;
+ const uint8_t PATTERN_2 = ~PATTERN_1;
+ uint32_t addr;
+
+ if (!(z80_bus_cmd(Request) & ZST_ACQUIRED))
+ return -EBUSTO;
+
+ uint8_t ram_0 = z80_read(0);
+ uint8_t ram_1 = z80_read(1);
+
+ z80_write(0, ram_0 ^ 0xff);
+ z80_write(1, ram_1);
+ if ((z80_read(0) ^ ram_0) != 0xff) {
+ addr = 0;
+ } else {
+ z80_write(0, PATTERN_1);
+ for (addr=1; addr < CONFIG_SYS_RAMSIZE_MAX; addr <<= 1) {
+ uint8_t ram_i = z80_read(addr);
+ z80_write(addr, PATTERN_2);
+ if (z80_read(0) != PATTERN_1 || z80_read(addr) != PATTERN_2)
+ break;
+ z80_write(addr, ram_i);
+ }
+ }
+
+ z80_write(0, ram_0);
+ z80_bus_cmd(Release);
+
+ return addr;
+}
+
void z80_write(uint32_t addr, uint8_t data)
{
z80_setaddress(addr);