Rev 299 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 299 | Rev 307 | ||
|---|---|---|---|
| Line 96... | Line 96... | ||
| 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 | uint16_t offset; |
99 | uint16_t offset; |
| 100 | uint16_t data; |
100 | uint16_t data; |
| - | 101 | ||
| - | 102 | eeprom_busy_wait(); // Make sure any current writes to eeprom |
|
| - | 103 | boot_spm_busy_wait(); // or flash has completed before updating. |
|
| 101 | 104 | ||
| 102 | cli(); // From this point we're on our own |
105 | cli(); // From this point we're on our own |
| 103 | 106 | ||
| 104 | for (offset = 0; offset < len; offset += 2) { |
107 | for (offset = 0; offset < ((len | (SPM_PAGESIZE - 1)) + 1); offset += 2) { |
| 105 | if (dst + offset >= (uint16_t)&__flash_code_start) break; |
108 | if (dst + offset >= (uint16_t)&__flash_code_start) break; |
| 106 | data = pgm_read_word(src + offset); |
109 | data = pgm_read_word(src + offset); |
| 107 | boot_page_fill(dst + offset, data); |
110 | boot_page_fill(dst + offset, data); |
| 108 | if ((dst + offset + 2) % SPM_PAGESIZE == 0) { |
111 | if ((dst + offset + 2) % SPM_PAGESIZE == 0) { |
| 109 | boot_page_erase(dst + offset); |
112 | boot_page_erase(dst + offset); |
| 110 |
|
113 | boot_spm_busy_wait(); // Wait until the memory is erased. |
| 111 | 114 | ||
| 112 | boot_page_write(dst + offset); // Store buffer in flash page. |
115 | boot_page_write(dst + offset); // Store buffer in flash page. |
| 113 |
|
116 | boot_spm_busy_wait(); // Wait until the memory is written. |
| 114 | } |
117 | } |
| 115 | 118 | ||
| 116 | wdt_reset(); |
119 | wdt_reset(); |
| 117 | } |
120 | } |
| 118 | while (1); // Nothing more we can do, hopefully there is a watchdog active |
121 | while (1); // Nothing more we can do, hopefully there is a watchdog active |