Subversion Repositories HomeAutomation

Rev

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

Rev 307 Rev 309
Line 94... Line 94...
94
 
94
 
95
#ifdef FLASH_COPY_DATA_NEW
95
#ifdef FLASH_COPY_DATA_NEW
96
extern uint16_t __flash_code_start;
96
extern uint16_t __flash_code_start;
97
 
97
 
98
void flash_copy_data(uint16_t src, uint16_t dst, uint16_t len) {
98
void flash_copy_data(uint16_t src, uint16_t dst, uint16_t len) {
-
 
99
#if 0
99
    uint16_t offset;
100
    uint16_t offset;
-
 
101
#endif
100
    uint16_t data;
102
    uint16_t data;
101
 
103
 
102
    eeprom_busy_wait();     // Make sure any current writes to eeprom
104
    eeprom_busy_wait();     // Make sure any current writes to eeprom
103
    boot_spm_busy_wait();   // or flash has completed before updating.
105
    //boot_spm_busy_wait(); // or flash has completed before updating.
104
 
106
 
105
    cli(); // From this point we're on our own
107
    cli(); // From this point we're on our own
106
   
108
   
-
 
109
#if 0
107
    for (offset = 0; offset < ((len | (SPM_PAGESIZE - 1)) + 1); offset += 2) {
110
    for (offset = 0; offset < ((len | (SPM_PAGESIZE - 1)) + 1); offset += 2) {
108
        if (dst + offset >= (uint16_t)&__flash_code_start) break;
111
        if (dst + offset >= (uint16_t)&__flash_code_start) break;
109
        data = pgm_read_word(src + offset);
112
        data = pgm_read_word(src + offset);
110
        boot_page_fill(dst + offset, data);
113
        boot_page_fill(dst + offset, data);
111
        if ((dst + offset + 2) % SPM_PAGESIZE == 0) {
114
        if ((dst + offset + 2) % SPM_PAGESIZE == 0) {
Line 116... Line 119...
116
            boot_spm_busy_wait();       // Wait until the memory is written.
119
            boot_spm_busy_wait();       // Wait until the memory is written.
117
        }
120
        }
118
           
121
           
119
        wdt_reset();
122
        wdt_reset();
120
    }
123
    }
-
 
124
#else
-
 
125
    len = (len | (SPM_PAGESIZE - 1)) + 3; // Round len up to a whole page + 2
-
 
126
   
-
 
127
    while (len -= 2) {
-
 
128
        wdt_reset();
-
 
129
 
-
 
130
        boot_spm_busy_wait();      // Wait until the memory is erased.
-
 
131
        data = pgm_read_word(src); // Read source word
-
 
132
        boot_spm_busy_wait();      // Wait until the memory is erased.
-
 
133
        boot_page_fill_safe(dst, data); // Write word to destination
-
 
134
       
-
 
135
        if ((dst + 2) % SPM_PAGESIZE == 0) { // If we just wrote the last word of a page
-
 
136
            boot_spm_busy_wait();      // Wait until the memory is erased.
-
 
137
            boot_page_erase(dst);
-
 
138
            boot_spm_busy_wait();       // Wait until the memory is written.
-
 
139
            boot_page_write(dst); // Store buffer in flash page.
-
 
140
        }
-
 
141
         
-
 
142
        src += 2;
-
 
143
        dst += 2;
-
 
144
    }
-
 
145
         
-
 
146
#endif
121
    while (1); // Nothing more we can do, hopefully there is a watchdog active
147
    while (1); // Nothing more we can do, hopefully there is a watchdog active
122
}
148
}
123
#endif
149
#endif