Rev 310 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 310 | Rev 311 | ||
|---|---|---|---|
| Line 99... | Line 99... | ||
| 99 | #if 0 |
99 | #if 0 |
| 100 | uint16_t offset; |
100 | uint16_t offset; |
| 101 | #endif |
101 | #endif |
| 102 | uint16_t data; |
102 | uint16_t data; |
| 103 | 103 | ||
| 104 | eeprom_busy_wait |
104 | //eeprom_busy_wait(); // Make sure any current writes to eeprom |
| 105 | boot_spm_busy_wait |
105 | //boot_spm_busy_wait(); // or flash has completed before updating. |
| 106 | 106 | ||
| 107 | cli(); // From this point we're on our own |
107 | cli(); // From this point we're on our own |
| 108 | 108 | ||
| 109 | #if 0 |
109 | #if 0 |
| 110 | for (offset = 0; offset < ((len | (SPM_PAGESIZE - 1)) + 1); offset += 2) { |
110 | for (offset = 0; offset < ((len | (SPM_PAGESIZE - 1)) + 1); offset += 2) { |
| Line 115... | Line 115... | ||
| 115 | boot_page_erase(dst + offset); |
115 | boot_page_erase(dst + offset); |
| 116 | boot_spm_busy_wait(); // Wait until the memory is erased. |
116 | boot_spm_busy_wait(); // Wait until the memory is erased. |
| 117 | 117 | ||
| 118 | boot_page_write(dst + offset); // Store buffer in flash page. |
118 | boot_page_write(dst + offset); // Store buffer in flash page. |
| 119 | boot_spm_busy_wait(); // Wait until the memory is written. |
119 | boot_spm_busy_wait(); // Wait until the memory is written. |
| - | 120 | boot_rww_enable(); |
|
| 120 | } |
121 | } |
| 121 | 122 | ||
| 122 | wdt_reset(); |
123 | wdt_reset(); |
| 123 | } |
124 | } |
| 124 | #else |
125 | #else |
| 125 | len = (len | (SPM_PAGESIZE - 1)) + 3; // Round len up to a whole page + 2 |
126 | len = (len | (SPM_PAGESIZE - 1)) + 3; // Round len up to a whole page + 2 |
| 126 | 127 | ||
| 127 | while (len -= 2) { |
128 | while (len -= 2) { |
| 128 | wdt_reset(); |
129 | wdt_reset(); |
| 129 | 130 | ||
| 130 | data = pgm_read_word(src); // Read source word |
131 | data = pgm_read_word(src); // Read source word |
| 131 | boot_page_fill_safe(dst, data); // Write word to destination |
132 | boot_page_fill_safe(dst, data); // Write word to destination |
| 132 | boot_spm_busy_wait(); // Make sure spm is ready. |
- | |
| 133 | 133 | ||
| 134 | if (((uint8_t)dst + 2) % SPM_PAGESIZE == 0) { // If we just wrote the last word of a page |
134 | if (((uint8_t)dst + 2) % SPM_PAGESIZE == 0) { // If we just wrote the last word of a page |
| 135 | boot_page_erase(dst); |
135 | boot_page_erase(dst); |
| 136 | boot_spm_busy_wait(); // Wait until the memory is erased. |
136 | boot_spm_busy_wait(); // Wait until the memory is erased. |
| 137 | boot_page_write(dst); // Store buffer in flash page. |
137 | boot_page_write(dst); // Store buffer in flash page. |
| 138 | boot_spm_busy_wait(); // Wait until the memory is written. |
138 | boot_spm_busy_wait(); // Wait until the memory is written. |
| 139 | boot_rww_enable(); |
139 | boot_rww_enable(); |
| 140 | } |
140 | } |
| 141 | 141 | ||
| 142 | src += 2; |
142 | src += 2; |
| 143 | dst += 2; |
143 | dst += 2; |
| - | 144 | ||
| - | 145 | if (dst >= (uint16_t)&__flash_code_start) break; |
|
| 144 | } |
146 | } |
| 145 | 147 | ||
| 146 | #endif |
148 | #endif |
| 147 | while (1); // Nothing more we can do, hopefully there is a watchdog active |
149 | while (1); // Nothing more we can do, hopefully there is a watchdog active |
| 148 | } |
150 | } |