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;
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).
}
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 {