bootloader: Reimplement flash::run_command() in C.
[gps-watch.git] / src / bootloader / flash.rs
index f6c00d956622a9068216d87a128c89b858e0c78f..7d0d294f0d92b62c4d2c256873481366f173cf85 100644 (file)
@@ -41,7 +41,6 @@ const FTFA_FSTAT_MGSTAT0 : u8 = 1 << 0;
 const FTFA_FSTAT_FPVIOL  : u8 = 1 << 4;
 const FTFA_FSTAT_ACCERR  : u8 = 1 << 5;
 const FTFA_FSTAT_RDCOLERR: u8 = 1 << 6;
-const FTFA_FSTAT_CCIF    : u8 = 1 << 7;
 
 const FCMD_RD1SEC : u8 = 0x01;
 const FCMD_PGM4   : u8 = 0x06;
@@ -49,6 +48,10 @@ const FCMD_ERSSCR : u8 = 0x09;
 
 pub const SECTOR_SIZE : usize = 1024;
 
+extern {
+    fn flash_run_command() -> u8;
+}
+
 // The hardware refuses to run another command (or even take the new command's
 // parameters) until the errors reported by a previous command have been
 // acknowledged (see KL26P121M48SF4RM.pdf p. 445).
@@ -59,19 +62,7 @@ fn prepare_command() {
 }
 
 fn run_command() -> u8 {
-    let mut fstat = Reg8::new(FTFA_FSTAT);
-
-    // Start command.
-    fstat.write(FTFA_FSTAT_CCIF);
-
-    // Wait for it to finish.
-    loop {
-        let v = fstat.read();
-
-        if (v & FTFA_FSTAT_CCIF) != 0 {
-            return v;
-        }
-    }
+    unsafe { flash_run_command() }
 }
 
 fn erase_check(sector: u32) -> bool {