Subversion Repositories HomeAutomation

Rev

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

Rev 278 Rev 279
Line 211... Line 211...
211
                        data = bios_msg.Data.words[i];
211
                        data = bios_msg.Data.words[i];
212
                        flash_write_word(addr, data);
212
                        flash_write_word(addr, data);
213
                        addr += 2;
213
                        addr += 2;
214
                    }
214
                    }
215
                    //update crc //cannot update crc here, data not written yet /arune
215
                    //update crc //cannot update crc here, data not written yet /arune
-
 
216
                    offset += bios_msg.DataLength - 2;  //let offset be last address to simplify crc calc later
216
                    //send CAN_NMT_PGM_ACK(offset)
217
                    //send CAN_NMT_PGM_ACK(offset)
217
                    tx_msg.Id = CAN_ID_NMT_PGM_ACK;
218
                    tx_msg.Id = CAN_ID_NMT_PGM_ACK;
218
                } else {
219
                } else {
219
                    //send CAN_NMT_PGM_NACK(offset)
220
                    //send CAN_NMT_PGM_NACK(offset)
220
                    tx_msg.Id = CAN_ID_NMT_PGM_NACK;
221
                    tx_msg.Id = CAN_ID_NMT_PGM_NACK;
Line 226... Line 227...
226
                data = bios_msg.Data.words[0];
227
                data = bios_msg.Data.words[0];
227
                uint16_t calccrc = 0;
228
                uint16_t calccrc = 0;
228
                for (i=0; i < offset; i++) {
229
                for (i=0; i < offset; i++) {
229
                    calccrc = _crc16_update(calccrc, pgm_read_byte(base_addr+i));
230
                    calccrc = _crc16_update(calccrc, pgm_read_byte(base_addr+i));
230
                }
231
                }
231
                //tx_msg.Data.words[0] = crc;
232
                tx_msg.Data.words[0] = calccrc;
232
                if (data == calccrc) { //crc ok
233
                if (data == calccrc) { //crc ok
233
                    //send CAN_NMT_PGM_ACK(crc)
234
                    //send CAN_NMT_PGM_ACK(crc)
234
                    tx_msg.Id = CAN_ID_NMT_PGM_ACK;
235
                    tx_msg.Id = CAN_ID_NMT_PGM_ACK;
235
                } else {
236
                } else {
236
                    //send CAN_NMT_PGM_NACK(crc)
237
                    //send CAN_NMT_PGM_NACK(crc)