Bootloader.c


1
#include "Bootloader.h"
2
3
4
void init_bootloader(){    
5
    /*temp = MCUCR;
6
    MCUCR = temp | (1<<IVCE);
7
    MCUCR = temp | (1<<IVSEL);
8
  */
9
  
10
}
11
12
void program_page (uint32_t page, uint8_t *buf)
13
{
14
    uint16_t i;
15
    uint8_t sreg;
16
 
17
    /* Disable interrupts */
18
    //sreg = SREG;
19
    //cli();
20
 
21
    eeprom_busy_wait ();
22
 
23
    boot_page_erase (page);
24
    boot_spm_busy_wait ();      /* Wait until the memory is erased. */
25
 
26
    for (i=0; i<SPM_PAGESIZE; i+=2)
27
    {
28
        /* Set up little-endian word. */
29
        uint16_t w = *buf++;
30
        w += (*buf++) << 8;
31
    
32
        boot_page_fill (page + i, w);
33
    }
34
 
35
    boot_page_write (page);     /* Store buffer in flash page.    */
36
    boot_spm_busy_wait();       /* Wait until the memory is written.*/
37
 
38
    /* Reenable RWW-section again. We need this if we want to jump back */
39
    /* to the application after bootloading. */
40
    boot_rww_enable ();
41
 
42
    /* Re-enable interrupts (if they were ever enabled). */
43
    //SREG = sreg;
44
}