|
@@ -2,14 +2,12 @@
|
|
|
#include "app/iap.h"
|
|
#include "app/iap.h"
|
|
|
#include "bsp/fmc_flash.h"
|
|
#include "bsp/fmc_flash.h"
|
|
|
|
|
|
|
|
-#define QWS_IAP_MAGIC_SUCCESS 0x11223344
|
|
|
|
|
-#define QWS_IAP_MAGIC_FLASH 0xAABBCCDD
|
|
|
|
|
-
|
|
|
|
|
static int iap_write_image(uint8_t *data, int len);
|
|
static int iap_write_image(uint8_t *data, int len);
|
|
|
static int iap_check_image(uint8_t *data, int len);
|
|
static int iap_check_image(uint8_t *data, int len);
|
|
|
-static void _reboot_timer_handler(shark_timer_t *t);
|
|
|
|
|
|
|
+void _reboot_timer_handler(shark_timer_t *t);
|
|
|
void iap_read_string(can_frame_t *frame);
|
|
void iap_read_string(can_frame_t *frame);
|
|
|
|
|
|
|
|
|
|
+static u8 _write_success = 0;
|
|
|
static int _write_position = 0;
|
|
static int _write_position = 0;
|
|
|
static shark_timer_t _reboot_timer = {.handler = _reboot_timer_handler,};
|
|
static shark_timer_t _reboot_timer = {.handler = _reboot_timer_handler,};
|
|
|
|
|
|
|
@@ -23,9 +21,11 @@ void process_iap_message(can_frame_t *frame, int len){
|
|
|
case CAN_KEY_IAP_BEGIN:
|
|
case CAN_KEY_IAP_BEGIN:
|
|
|
fmc_erase_image();
|
|
fmc_erase_image();
|
|
|
_write_position = 0;
|
|
_write_position = 0;
|
|
|
|
|
+ _write_success = 0;
|
|
|
protocol_send_ack(frame->head.can_addr, frame->key, 0);
|
|
protocol_send_ack(frame->head.can_addr, frame->key, 0);
|
|
|
break;
|
|
break;
|
|
|
case CAN_KEY_IAP_WRITE:
|
|
case CAN_KEY_IAP_WRITE:
|
|
|
|
|
+ _write_success = 0;
|
|
|
data_len = iap_write_image(frame->data, len);
|
|
data_len = iap_write_image(frame->data, len);
|
|
|
data = frame->data;
|
|
data = frame->data;
|
|
|
break;
|
|
break;
|
|
@@ -34,8 +34,11 @@ void process_iap_message(can_frame_t *frame, int len){
|
|
|
data = frame->data;
|
|
data = frame->data;
|
|
|
break;
|
|
break;
|
|
|
case CAN_KEY_IAP_BOOT:
|
|
case CAN_KEY_IAP_BOOT:
|
|
|
- protocol_send_ack(frame->head.can_addr, frame->key, 0);
|
|
|
|
|
- shark_timer_post(&_reboot_timer,1000);
|
|
|
|
|
|
|
+ if (_write_success) {
|
|
|
|
|
+ shark_timer_post(&_reboot_timer, 100);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ protocol_send_ack(frame->head.can_addr, frame->key, 0);
|
|
|
|
|
+ }
|
|
|
break;
|
|
break;
|
|
|
case CAN_EEY_IAP_READ_STRING:
|
|
case CAN_EEY_IAP_READ_STRING:
|
|
|
iap_read_string(frame);
|
|
iap_read_string(frame);
|
|
@@ -46,7 +49,7 @@ void process_iap_message(can_frame_t *frame, int len){
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static void _reboot_timer_handler(shark_timer_t *t){
|
|
|
|
|
|
|
+void _reboot_timer_handler(shark_timer_t *t){
|
|
|
NVIC_SystemReset();
|
|
NVIC_SystemReset();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -54,10 +57,10 @@ static int iap_write_image(uint8_t *data, int len){
|
|
|
int w_pos = shark_decode_u24(data);
|
|
int w_pos = shark_decode_u24(data);
|
|
|
if (w_pos == _write_position) {
|
|
if (w_pos == _write_position) {
|
|
|
fmc_write_image(data + 3, len - 3);
|
|
fmc_write_image(data + 3, len - 3);
|
|
|
- _write_position += w_pos;
|
|
|
|
|
|
|
+ _write_position += len - 3;
|
|
|
}
|
|
}
|
|
|
data[0] = 0;
|
|
data[0] = 0;
|
|
|
- shark_encode_u24(data+1, w_pos);
|
|
|
|
|
|
|
+ shark_encode_u24(data+1, _write_position);
|
|
|
return 4;
|
|
return 4;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -95,7 +98,8 @@ static int iap_check_image(uint8_t *data, int len) {
|
|
|
data[0] = 1;
|
|
data[0] = 1;
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
- fmc_write_magic(size, checksum, QWS_IAP_MAGIC_FLASH);
|
|
|
|
|
|
|
+ fmc_write_magic(size, checksum, SHARK_IAP_MAGIC_FLASH);
|
|
|
|
|
+ _write_success = 1;
|
|
|
data[0] = 0;
|
|
data[0] = 0;
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|