Enable radio stats in sensor cgi as default
[contiki-2.x.git] / cpu / avr / dev / flash.c
blobcb5699167c7bd243a0d4f375b8794265c22633bc
2 #include "dev/flash.h"
4 #include <avr/boot.h>
5 #include <inttypes.h>
6 #include <avr/interrupt.h>
7 #include <avr/pgmspace.h>
9 /*---------------------------------------------------------------------------*/
11 * The following code was taken from the avr-libc manual:
13 void
14 flash_write_page(uint32_t page, uint8_t *buf)
16 uint16_t i;
17 uint8_t sreg;
19 /* Disable interrupts. */
21 sreg = SREG;
22 cli();
24 eeprom_busy_wait();
26 boot_page_erase(page);
27 boot_spm_busy_wait(); /* Wait until the memory is erased. */
29 for(i = 0; i < SPM_PAGESIZE; i += 2) {
30 /* Set up little-endian word. */
32 uint16_t w = *buf++;
33 w += (*buf++) << 8;
35 boot_page_fill(page + i, w);
38 boot_page_write(page); /* Store buffer in flash page. */
39 boot_spm_busy_wait(); /* Wait until the memory is written. */
41 /* Reenable RWW-section again. We need this if we want to jump back
42 * to the application after bootloading. */
44 boot_rww_enable();
46 /* Re-enable interrupts (if they were ever enabled). */
48 SREG = sreg;
50 /*---------------------------------------------------------------------------*/