diff options
author | Zach Eveland <zeveland@blacklabel-development.com> | 2011-10-21 17:51:04 -0400 |
---|---|---|
committer | Zach Eveland <zeveland@blacklabel-development.com> | 2011-10-21 17:51:04 -0400 |
commit | 146922e21147baef802aba5cd3eb5ae0f75b545e (patch) | |
tree | fbce59a2fb56b902266a3626c4d5b029b7a0ebf1 /bootloaders/nuevo_diskloader/src/DiskLoader.cpp | |
parent | 629788e47c757432178f8a1b6855d10d665e6550 (diff) |
added and modified Program() routine
Diffstat (limited to 'bootloaders/nuevo_diskloader/src/DiskLoader.cpp')
-rw-r--r-- | bootloaders/nuevo_diskloader/src/DiskLoader.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/bootloaders/nuevo_diskloader/src/DiskLoader.cpp b/bootloaders/nuevo_diskloader/src/DiskLoader.cpp index 83ffc1b..efd386f 100644 --- a/bootloaders/nuevo_diskloader/src/DiskLoader.cpp +++ b/bootloaders/nuevo_diskloader/src/DiskLoader.cpp @@ -19,6 +19,32 @@ void entrypoint(void) ::); } +u8 _flashbuf[128]; + +void Program(u8 ep, u16 page, u8 count) +{ + u8 write = page < 30*1024; // Don't write over firmware please + if (write) + boot_page_erase(page); + + USB_Recv(ep,_flashbuf,count); // Read while page is erasing + + if (!write) + return; + + boot_spm_busy_wait(); // Wait until the memory is erased. + + count >>= 1; + u16* p = (u16*)page; + u16* b = (u16*)_flashbuf; + for (u8 i = 0; i < count; i++) + boot_page_fill(p++, b[i]); + + boot_page_write(page); + boot_spm_busy_wait(); + boot_rww_enable (); +} + int main(void) __attribute__ ((naked)); int main() { |