Rev 279 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 279 | Rev 283 | ||
|---|---|---|---|
| Line 119... | Line 119... | ||
| 119 | 119 | ||
| 120 | int main() { |
120 | int main() { |
| 121 | void (*app_reset)(void) = 0; |
121 | void (*app_reset)(void) = 0; |
| 122 | uint8_t bios_state; |
122 | uint8_t bios_state; |
| 123 | uint8_t nmt_type; |
123 | uint8_t nmt_type; |
| - | 124 | // This unneccessary initialization uses 8 bytes flash, just to make the compiler happy! |
|
| 124 | uint16_t base_addr = 0; |
125 | uint16_t base_addr = 0; |
| 125 | uint16_t offset; |
126 | uint16_t offset = 0; |
| 126 | uint16_t addr; |
127 | uint16_t addr; |
| 127 | uint8_t len; |
128 | uint8_t len; |
| 128 | uint8_t i; |
129 | uint8_t i; |
| 129 | uint16_t data; |
130 | uint16_t data; |
| 130 | Can_Message_t tx_msg; |
131 | Can_Message_t tx_msg; |
| Line 155... | Line 156... | ||
| 155 | tx_msg.RemoteFlag = 0; |
156 | tx_msg.RemoteFlag = 0; |
| 156 | tx_msg.ExtendedFlag = 1; |
157 | tx_msg.ExtendedFlag = 1; |
| 157 | tx_msg.Id = CAN_ID_NMT_BIOS_START; |
158 | tx_msg.Id = CAN_ID_NMT_BIOS_START; |
| 158 | tx_msg.DataLength = 3; |
159 | tx_msg.DataLength = 3; |
| 159 | tx_msg.Data.words[0] = BIOS_VERSION; |
160 | tx_msg.Data.words[0] = BIOS_VERSION; |
| - | 161 | #ifdef BIOS_UART |
|
| 160 | printf(" |
162 | printf("BIOS start\n"); |
| - | 163 | #endif |
|
| 161 | if (pgm_read_word(0) == 0xffff) { |
164 | if (pgm_read_word(0) == 0xffff) { |
| 162 | // No application in flash |
165 | // No application in flash |
| 163 | //send CAN_NMT_BIOS_START(BIOS_VERSION, 0) |
166 | //send CAN_NMT_BIOS_START(BIOS_VERSION, 0) |
| 164 | tx_msg.Data.bytes[2] = 0; |
167 | tx_msg.Data.bytes[2] = 0; |
| 165 | bios_state = BIOS_NOAPP; |
168 | bios_state = BIOS_NOAPP; |
| Line 169... | Line 172... | ||
| 169 | tx_msg.Data.bytes[2] = 1; |
172 | tx_msg.Data.bytes[2] = 1; |
| 170 | bios_state = BIOS_APP; |
173 | bios_state = BIOS_APP; |
| 171 | } |
174 | } |
| 172 | 175 | ||
| 173 | while (Can_Send(&tx_msg) != CAN_OK); |
176 | while (Can_Send(&tx_msg) != CAN_OK); |
| 174 | 177 | ||
| 175 | tx_msg.DataLength = 2; |
178 | tx_msg.DataLength = 2; |
| 176 | 179 | ||
| 177 | // main loop |
180 | // main loop |
| 178 | while (1) { |
181 | while (1) { |
| 179 | // Wait for message |
182 | // Wait for message |
| Line 193... | Line 196... | ||
| 193 | flash_init(); |
196 | flash_init(); |
| 194 | //send CAN_NMT_PGM_ACK(offset) |
197 | //send CAN_NMT_PGM_ACK(offset) |
| 195 | tx_msg.Id = CAN_ID_NMT_PGM_ACK; |
198 | tx_msg.Id = CAN_ID_NMT_PGM_ACK; |
| 196 | tx_msg.Data.words[0] = base_addr; |
199 | tx_msg.Data.words[0] = base_addr; |
| 197 | bios_state = BIOS_PGM; |
200 | bios_state = BIOS_PGM; |
| - | 201 | } |
|
| - | 202 | if (nmt_type == CAN_NMT_PGM_COPY) { |
|
| - | 203 | // For BIOS updating over CAN. Upload bios to application area, |
|
| - | 204 | // send this message with correct parameters to copy data from |
|
| - | 205 | // application to bios area and pray it will come alive again. |
|
| - | 206 | // Make extra really super sure that the .bootloader section is |
|
| - | 207 | // EXACTLY the same, except for the vector table (which MUST be |
|
| - | 208 | // updated) or go get your ISP. |
|
| - | 209 | flash_copy_data(bios_msg.Data.words[0], |
|
| - | 210 | bios_msg.Data.words[1], |
|
| - | 211 | bios_msg.Data.words[2]); |
|
| - | 212 | // flash_copy_data will never return. |
|
| 198 | } |
213 | } |
| 199 | break; |
214 | break; |
| 200 | case BIOS_PGM: |
215 | case BIOS_PGM: |
| 201 | if (nmt_type == CAN_NMT_PGM_DATA) { |
216 | if (nmt_type == CAN_NMT_PGM_DATA) { |
| 202 | // Set address = base address + offset |
217 | // Set address = base address + offset |