Example #1
0
void ws_flash_write_page(uint32_t address, uint8_t *buf)
{
  uint32_t i;
  uint8_t sreg;
  uint8_t *buffer;

  buffer = buf;

  // Disable interrupts
  sreg = SREG;
  cli();

  // Start by erasing the page at given address
  boot_page_erase_safe (address);
  boot_spm_busy_wait ();	// Wait until the memory is erased

  for(i=0; i<PAGESIZE; i+=2){
    uint16_t w = *buffer++;
    w += (*buffer++) << 8;
    boot_page_fill_safe(address+i, w);
  }
  boot_page_write_safe (address);
  boot_spm_busy_wait ();

  while(boot_rww_busy()){ boot_rww_enable_safe();}

  boot_rww_enable();
  SREG = sreg;
}
Example #2
0
void BOOTLOADER_SECTION bootloader(void)
{
  unsigned long address;
  unsigned short boot_word;
//  unsigned char buffer[8];

  cli();

  // Erase page.
  boot_page_erase((unsigned long)ADDRESS);
  while(boot_rww_busy())
  {
    boot_rww_enable();
  }

  // Write data to buffer a word at a time. Note incrementing address by 2.
  // SPM_PAGESIZE is defined in the microprocessor IO header file.
  for(address = ADDRESS; address < ADDRESS + SPM_PAGESIZE; address += 2)
  {
    boot_word=boot_word_read();
    boot_page_fill(address, boot_word);
  }

  // Write page.
  boot_page_write((unsigned long)ADDRESS);
  while(boot_rww_busy())
  {
    boot_rww_enable();
  }

  sei();

  // Read back the values and display.
  // (The show() function is undefined and is used here as an example only.)
  // for(unsigned long i = ADDRESS; i < ADDRESS + 256; i++)
  // {
  //   show(utoa(pgm_read_byte(i), buffer, 16));
  // }
}