summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2010-09-01 22:43:22 -0700
committerKeith Packard <keithp@keithp.com>2010-09-03 07:04:28 -0700
commit2f07ad14a16dbf1b75c71784ceae303825c90ade (patch)
tree33bdf0156856796175ea7ffe9e165a3f6d2e42c6
parentcf30343aadd5039627a85319872685f743e64b16 (diff)
altosui: Abort flashing if debug port isn't working
Check each command going over the debug port and make sure it works as expected. This commit adds checks for initializing the clock, selecting the desired program counter and running the flash program. Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--ao-tools/altosui/AltosFlash.java35
1 files changed, 23 insertions, 12 deletions
diff --git a/ao-tools/altosui/AltosFlash.java b/ao-tools/altosui/AltosFlash.java
index b7018555..a3e431cd 100644
--- a/ao-tools/altosui/AltosFlash.java
+++ b/ao-tools/altosui/AltosFlash.java
@@ -202,9 +202,13 @@ public class AltosFlash {
debug.debug_instr(set_clkcon_fast);
byte status;
- do {
+ for (int times = 0; times < 20; times++) {
+ Thread.sleep(1);
status = debug.debug_instr(get_sleep);
- } while ((status & SLEEP_XOSC_STB) == 0);
+ if ((status & SLEEP_XOSC_STB) != 0)
+ return;
+ }
+ throw new IOException("Failed to initialize target clock");
}
void action(String s, int percent) {
@@ -221,6 +225,22 @@ public class AltosFlash {
percent);
}
+ void run(int pc) throws IOException, InterruptedException {
+ debug.set_pc(pc);
+ int set_pc = debug.get_pc();
+ if (pc != set_pc)
+ throw new IOException("Failed to set target program counter");
+ debug.resume();
+
+ for (int times = 0; times < 20; times++) {
+ byte status = debug.read_status();
+ if ((status & AltosDebug.STATUS_CPU_HALTED) != 0)
+ return;
+ }
+
+ throw new IOException("Failed to execute program on target");
+ }
+
public void flash() throws IOException, FileNotFoundException, InterruptedException {
if (!check_rom_config())
throw new IOException("Invalid rom config settings");
@@ -264,16 +284,7 @@ public class AltosFlash {
this_time);
debug.write_memory(flash_prog, flash_page);
- debug.set_pc(flash_prog);
- int pc = debug.get_pc();
- debug.resume();
- Thread.sleep(100);
- for (int times = 0; times < 10; times++) {
- byte status = debug.read_status();
- if ((status & AltosDebug.STATUS_CPU_HALTED) != 0)
- break;
- Thread.sleep(100);
- }
+ run(flash_prog);
byte[] check = debug.read_memory(flash_addr, this_time);
for (int i = 0; i < this_time; i++)