Advertisement
Guest User

Boot

a guest
May 28th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. #include <inttypes.h>
  2. #include <avr/interrupt.h>
  3. #include <avr/pgmspace.h>
  4. void boot_program_page (uint32_t page, uint8_t *buf)
  5. {
  6.     uint16_t i;
  7.     uint8_t sreg;
  8.     // Disable interrupts.
  9.     sreg = SREG;
  10.     cli();
  11.     eeprom_busy_wait ();
  12.     boot_page_erase (page);
  13.     boot_spm_busy_wait ();      // Wait until the memory is erased.
  14.     for (i=0; i<SPM_PAGESIZE; i+=2)
  15.     {
  16.         // Set up little-endian word.
  17.         uint16_t w = *buf++;
  18.         w += (*buf++) << 8;
  19.    
  20.         boot_page_fill (page + i, w);
  21.     }
  22.     boot_page_write (page);     // Store buffer in flash page.
  23.     boot_spm_busy_wait();       // Wait until the memory is written.
  24.     // Reenable RWW-section again. We need this if we want to jump back
  25.     // to the application after bootloading.
  26.     boot_rww_enable ();
  27.     // Re-enable interrupts (if they were ever enabled).
  28.     SREG = sreg;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement