Subversion Repositories HomeAutomation

Rev

Rev 254 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 254 Rev 283
Line 2... Line 2...
2
#include <avr/boot.h>
2
#include <avr/boot.h>
3
#include <avr/pgmspace.h>
3
#include <avr/pgmspace.h>
-
 
4
#include <avr/wdt.h>
4
#include "flash.h"
5
#include "flash.h"
5
 
6
 
6
static uint16_t flash_prev_addr;
7
static uint16_t flash_prev_addr;
7
static uint8_t flash_buffer_dirty = 0;
8
static uint8_t flash_buffer_dirty = 0;
8
 
9
 
Line 39... Line 40...
39
void flash_load_buffer(uint16_t addr) BOOTLOADER;
40
void flash_load_buffer(uint16_t addr) BOOTLOADER;
40
void flash_load_buffer(uint16_t addr) {
41
void flash_load_buffer(uint16_t addr) {
41
    //TODO: Load current flash page contents into temporary buffer to implement
42
    //TODO: Load current flash page contents into temporary buffer to implement
42
    // flash read-modify-writes with word granularity. (If possible, the data
43
    // flash read-modify-writes with word granularity. (If possible, the data
43
    // sheet is a little fuzzy about this.)
44
    // sheet is a little fuzzy about this.)
-
 
45
    // Update: It seems it isn't possible to write any location in the temporary
-
 
46
    // buffer more than once without destroying the buffer. To implement this
-
 
47
    // functionality, a sram based buffer is probably neccessary. Problem is, 
-
 
48
    // how should it be allocated? A global buffer uses valuable .bss space.
-
 
49
    // All functions should probably take a pointer to a buffer allocated by
-
 
50
    // main code.
44
    uint8_t i;
51
    uint8_t i;
45
    uint16_t data;
52
    uint16_t data;
46
    uint16_t page = (addr / SPM_PAGESIZE) * SPM_PAGESIZE;
53
    uint16_t page = (addr / SPM_PAGESIZE) * SPM_PAGESIZE;
47
   
54
   
48
    for (i = 0; i < SPM_PAGESIZE; i += 2) {
55
    for (i = 0; i < SPM_PAGESIZE; i += 2) {
Line 73... Line 80...
73
 
80
 
74
#ifdef FLASH_COPY_DATA
81
#ifdef FLASH_COPY_DATA
75
void flash_copy_data(uint16_t src, uint16_t dst, uint16_t len) {
82
void flash_copy_data(uint16_t src, uint16_t dst, uint16_t len) {
76
    uint16_t i;
83
    uint16_t i;
77
    flash_init();
84
    flash_init();
-
 
85
    cli(); // From this point we're on our own
78
    for (i = 0; i < len; i+=2) {
86
    for (i = 0; i < len; i+=2) {
79
        flash_write_word(dst + i, pgm_read_word(src + i));
87
        flash_write_word(dst + i, pgm_read_word(src + i));
-
 
88
        wdt_reset();
80
    }
89
    }
81
    flash_flush_buffer();
90
    flash_flush_buffer();
-
 
91
    while (1); // Nothing more we can do, hopefully there is a watchdog active
82
}
92
}
83
#endif
93
#endif