X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=ao-tools%2Faltosui%2FAltosFlash.java;h=25b4a06efedadfb5c4a3bcb7926d28b8a606e243;hb=8463ffcaca6bcd31e645aba71c171f548dce96d8;hp=b70185558f974a6fe9fb94b7ebf10db4c1dd5258;hpb=c443f43f8dee6e0fcbcecf9d09e948fd928b7af4;p=fw%2Faltos diff --git a/ao-tools/altosui/AltosFlash.java b/ao-tools/altosui/AltosFlash.java index b7018555..25b4a06e 100644 --- a/ao-tools/altosui/AltosFlash.java +++ b/ao-tools/altosui/AltosFlash.java @@ -28,8 +28,6 @@ import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; -import altosui.AltosHexfile; - public class AltosFlash { File file; FileInputStream input; @@ -202,9 +200,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 +223,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 +282,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++)