Subversion Repositories HomeAutomation

Rev

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

Rev 292 Rev 294
Line 126... Line 126...
126
    uint16_t offset = 0;
126
    uint16_t offset = 0;
127
    uint16_t addr;
127
    uint16_t addr;
128
    uint8_t len;
128
    uint8_t len;
129
    uint16_t i;
129
    uint16_t i;
130
    uint16_t data;
130
    uint16_t data;
-
 
131
    uint8_t send_msg = 0;
131
    Can_Message_t tx_msg;
132
    Can_Message_t tx_msg;
132
    Can_Message_t bios_msg;
133
    Can_Message_t bios_msg;
133
    bios_msg_ptr = &bios_msg;
134
    bios_msg_ptr = &bios_msg;
134
   
135
   
135
#ifdef BIOS_UART
136
#ifdef BIOS_UART
Line 195... Line 196...
195
                base_addr = bios_msg.Data.words[0];
196
                base_addr = bios_msg.Data.words[0];
196
                flash_init();
197
                flash_init();
197
                //send CAN_NMT_PGM_ACK(offset)
198
                //send CAN_NMT_PGM_ACK(offset)
198
                tx_msg.Id = CAN_ID_NMT_PGM_ACK;
199
                tx_msg.Id = CAN_ID_NMT_PGM_ACK;
199
                tx_msg.Data.words[0] = base_addr;
200
                tx_msg.Data.words[0] = base_addr;
-
 
201
                send_msg = 1;
200
                bios_state = BIOS_PGM;
202
                bios_state = BIOS_PGM;
201
            }
203
            }
202
            if (nmt_type == CAN_NMT_PGM_COPY) {
204
            if (nmt_type == CAN_NMT_PGM_COPY) {
203
                // For BIOS updating over CAN. Upload bios to application area,
205
                // For BIOS updating over CAN. Upload bios to application area,
204
                // send this message with correct parameters to copy data from
206
                // send this message with correct parameters to copy data from
Line 233... Line 235...
233
                    tx_msg.Id = CAN_ID_NMT_PGM_ACK;
235
                    tx_msg.Id = CAN_ID_NMT_PGM_ACK;
234
                } else {
236
                } else {
235
                    //send CAN_NMT_PGM_NACK(offset)
237
                    //send CAN_NMT_PGM_NACK(offset)
236
                    tx_msg.Id = CAN_ID_NMT_PGM_NACK;
238
                    tx_msg.Id = CAN_ID_NMT_PGM_NACK;
237
                }
239
                }
-
 
240
                send_msg = 1;
238
            }
241
            }
239
            if (nmt_type == CAN_NMT_PGM_END) {
242
            if (nmt_type == CAN_NMT_PGM_END) {
240
                flash_flush_buffer();
243
                flash_flush_buffer();
241
                //check crc
244
                //check crc
242
                uint16_t calccrc = 0;
245
                uint16_t calccrc = 0;
243
                for (i=0; i < offset; i++) {
246
                for (i=0; i < offset; i++) {
244
                    calccrc = _crc16_update(calccrc, pgm_read_byte(base_addr+i));
247
                    calccrc = _crc16_update(calccrc, pgm_read_byte(base_addr+i));
245
                }
248
                }
246
                tx_msg.Data.words[0] = calccrc;
249
                tx_msg.Data.words[0] = calccrc;
247
                tx_msg.Id = CAN_ID_NMT_PGM_ACK;
250
                tx_msg.Id = CAN_ID_NMT_PGM_ACK;
-
 
251
                send_msg = 1;
248
                bios_state = BIOS_NOAPP;
252
                bios_state = BIOS_NOAPP;
249
            }
253
            }
250
        }
254
        }
-
 
255
       
-
 
256
        if (send_msg) {
251
        while (Can_Send(&tx_msg) != CAN_OK);
257
            while (Can_Send(&tx_msg) != CAN_OK);
-
 
258
            send_msg = 0;
-
 
259
        }
252
 
260
 
253
        bios_msg_full = 0; // We're done with this message, ready for the next.
261
        bios_msg_full = 0; // We're done with this message, ready for the next.
254
    }
262
    }
255
 
263
 
256
    return 0;
264
    return 0;