public static async Task UnlockAllRegionsAsync(this Samba nxt) { for (var i = 0; i < 16; i++) { await nxt.UnlockRegion(i); } }
static async Task LockAllRegionsAsync(this Samba nxt) { for (var i = 0; i < 16; i++) { await nxt.LockRegionAsync(i); } }
public static async Task FlashPrepareAsync(this Samba nxt) { // Put the clock in PLL/2 mode await nxt.WriteWordAsync(0xFFFFFC30, 0x7); // Unlock the flash chip await nxt.UnlockAllRegionsAsync(); // Send the flash writing routine await nxt.SendFileAsync(0x202000, Nxt.Flash.Bin); }
static async Task FlashBlockAsync(this Samba nxt, uint blockNum, byte[] buf) { // Set the target block number await nxt.WriteWordAsync(0x202300, blockNum); // Send the block to flash await nxt.SendFileAsync(0x202100, buf); // Jump into the flash writing routine await nxt.GoAsync(0x202000); }
public static async Task WaitReadyAsync(this Samba nxt) { uint status; do { status = await nxt.ReadWordAsync(0xFFFFFF68); /* Bit 0 is the FRDY field. Set to 1 if the flash controller is * ready to run a new command. */ } while ((status & 0x1) != 0x1); }
static async Task AlterLockAsync(this Samba nxt, int regionNum, Commands cmd) { var w = 0x5A000000 | (uint)((64 * regionNum) << 8); w += (uint)cmd; await nxt.WaitReadyAsync(); /* Flash mode register: FCMN 0x5, FWS 0x1 * Flash command register: KEY 0x5A, FCMD = clear-lock-bit (0x4) * Flash mode register: FCMN 0x34, FWS 0x1 */ await nxt.WriteWordAsync(0xFFFFFF60, 0x00050100); await nxt.WriteWordAsync(0xFFFFFF64, w); await nxt.WriteWordAsync(0xFFFFFF60, 0x00340100); }
public static async Task FlashAsync(this Samba nxt, byte[] data, IProgress <int> progress) { using (var f = new MemoryStream(data)) { Validate(data); await nxt.FlashPrepareAsync(); var buf = new byte[256]; for (var i = 0u; i < 1024; i++) { progress?.Report((int)i); var ret = f.Read(buf, 0, buf.Length); await nxt.FlashBlockAsync(i, buf); if (ret < 256) { await nxt.FlashFinishAsync(); return; } } } await nxt.FlashFinishAsync(); }
static Task FlashFinishAsync(this Samba nxt) { return(nxt.WaitReadyAsync()); }
static Task UnlockRegion(this Samba nxt, int regionNum) { return(nxt.AlterLockAsync(regionNum, Commands.Unlock)); }