-
Notifications
You must be signed in to change notification settings - Fork 7
/
boot.c
38 lines (30 loc) · 996 Bytes
/
boot.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <avr/boot.h>
#include <avr/interrupt.h>
/* This is called "boot_program_page" in the main code,
* but as that's a non-weak symbol this would clash.
*/
void _boot_program_page (uint32_t page, uint8_t *buf)
{
uint16_t i;
uint8_t sreg;
/* Disable interrupts.*/
sreg = SREG;
cli();
eeprom_busy_wait ();
boot_page_erase (page);
boot_spm_busy_wait (); /* Wait until the memory is erased. */
for (i=0; i<SPM_PAGESIZE; i+=2)
{
/* Set up little-endian word. */
uint16_t w = *buf++;
w += (*buf++) << 8;
boot_page_fill (page + i, w);
}
boot_page_write (page); /* Store buffer in flash page. */
boot_spm_busy_wait(); /* Wait until the memory is written.*/
/* Reenable RWW-section again. We need this if we want to jump back */
/* to the application after bootloading. */
boot_rww_enable ();
/* Re-enable interrupts (if they were ever enabled). */
SREG = sreg;
}