|
@@ -3,7 +3,6 @@
|
|
|
************************************************************************************************/
|
|
|
#include "dev_iap.h"
|
|
|
#include "dev_at24cxx.h"
|
|
|
-#include "hal_conf.h"
|
|
|
#include "hal_flash.h"
|
|
|
#include "queue.h"
|
|
|
#include <stdint.h>
|
|
@@ -78,6 +77,10 @@ void set_firmver(void)
|
|
|
fmc_read_n_half_word(UPGRADE_FLAG_START_ADDR, firm_ver_buff, UPGRADE_BUFF_DATA_SIZE);
|
|
|
fmc_erase_pages(UPGRADE_FLAG_START_ADDR, 1);
|
|
|
|
|
|
+ for (uint8_t i = 0; i < UPGRADE_APP_DATA_SIZE; i++)
|
|
|
+ {
|
|
|
+ firm_ver_buff[i + UPGRADE_FLAG_DATA_SIZE] = firm_ver[i];
|
|
|
+ }
|
|
|
fmc_write_n_half_word(UPGRADE_FLAG_START_ADDR, firm_ver_buff, UPGRADE_BUFF_DATA_SIZE);
|
|
|
fmc_clear_flag_end();
|
|
|
}
|
|
@@ -105,8 +108,8 @@ uint8_t erase_app_flash(uint32_t start_address, uint32_t end_addr)
|
|
|
{
|
|
|
uint8_t status = 0;
|
|
|
uint16_t page_len = 0;
|
|
|
- page_len = (end_addr - start_address) / FMC_PAGE_SIZE;
|
|
|
- status = fmc_erase_pages(start_address, page_len);
|
|
|
+ // page_len = (end_addr - start_address) / FMC_PAGE_SIZE;
|
|
|
+ status = fmc_erase_pages(start_address, page_len);
|
|
|
return status;
|
|
|
}
|
|
|
|
|
@@ -192,73 +195,75 @@ void iap_rec_handler(pdu_tag rec_msg)
|
|
|
send_buff[4] = g_iap.count_packages >> 8;
|
|
|
send_buff[5] = g_iap.count_packages & 0xFF;
|
|
|
}
|
|
|
- else
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ switch (rec_msg.data.u8_buf[0])
|
|
|
{
|
|
|
- switch (rec_msg.data.u8_buf[0])
|
|
|
+ case IAP_CMD_VERSION:
|
|
|
+ iap_param_init();
|
|
|
+ for (uint8_t i = 0; i < (UPGRADE_APP_DATA_SIZE * 2); i++)
|
|
|
{
|
|
|
- case IAP_CMD_VERSION:
|
|
|
- iap_param_init();
|
|
|
- for (uint8_t i = 0; i < (UPGRADE_APP_DATA_SIZE * 2); i++)
|
|
|
- {
|
|
|
- send_buff[i] = fmc_read_byte(UPGRADE_FLAG_START_ADDR + (UPGRADE_FLAG_START_ADDR * 2) + i);
|
|
|
- }
|
|
|
-
|
|
|
- send_buff[0] = IAP_CMD_VERSION;
|
|
|
- send_buff[1] = 0x01;
|
|
|
- break;
|
|
|
- case IAP_CMD_INFO:
|
|
|
- g_iap.total_bytes = (uint16_t)rec_msg.data.u8_buf[1] << 8 | rec_msg.data.u8_buf[2];
|
|
|
- g_iap.total_bytes <<= 16;
|
|
|
- g_iap.total_bytes |= (uint16_t)rec_msg.data.u8_buf[3] << 8 | rec_msg.data.u8_buf[4];
|
|
|
- g_iap.total_packages = (uint16_t)rec_msg.data.u8_buf[5] << 8 | rec_msg.data.u8_buf[6];
|
|
|
- send_buff[0] = IAP_CMD_INFO;
|
|
|
- send_buff[1] = 0x01;
|
|
|
- break;
|
|
|
- case IAP_CMD_ERASE:
|
|
|
- g_iap.firmware_crc16 = (uint16_t)rec_msg.data.u8_buf[2] << 8 | rec_msg.data.u8_buf[3];
|
|
|
- if (rec_msg.data.u8_buf[1])
|
|
|
- {
|
|
|
- // 喂狗
|
|
|
- fmc_clear_flag_star();
|
|
|
- erase_flag = erase_app_flash(DOWNLOAD_START_ADDR, DOWNLOAD_END_ADDR / 2);
|
|
|
- fmc_clear_flag_end();
|
|
|
- // 喂狗
|
|
|
- g_iap.count_bytes = 0;
|
|
|
- g_iap.count_packages = 0;
|
|
|
- }
|
|
|
- send_buff[0] = IAP_CMD_ERASE;
|
|
|
- send_buff[1] = !erase_flag;
|
|
|
- case IAP_CMD_CRC:
|
|
|
- send_buff[0] = IAP_CMD_CRC;
|
|
|
- send_buff[1] = (g_iap.crc16 == g_iap.firmware_crc16 ? 1 : 0);
|
|
|
- break;
|
|
|
- case IAP_CMD_JUMP:
|
|
|
- if (g_iap.crc16 != g_iap.firmware_crc16)
|
|
|
- {
|
|
|
- send_buff[1] = 0x00;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- fmc_clear_flag_star();
|
|
|
- fmc_erase_pages(UPGRADE_FLAG_START_ADDR, 1);
|
|
|
- upgrade.param.sign = UPGRADE_SIGN;
|
|
|
- upgrade.param.crc16 = g_iap.crc16;
|
|
|
- upgrade.param.moving_size = g_iap.total_bytes;
|
|
|
- fmc_write_n_half_word(UPGRADE_FLAG_START_ADDR, upgrade.infor_buf, UPGRADE_FLAG_DATA_SIZE);
|
|
|
- fmc_clear_flag_end();
|
|
|
- jump_boot_time = 10;
|
|
|
- send_buff[1] = 0x01;
|
|
|
- }
|
|
|
- break;
|
|
|
- case IAP_CMD_MODEL_TYPE:
|
|
|
- send_buff[0] = IAP_CMD_MODEL_TYPE;
|
|
|
- send_buff[1] = 0x01;
|
|
|
+ send_buff[i] = fmc_read_byte(UPGRADE_FLAG_START_ADDR + (UPGRADE_FLAG_DATA_SIZE * 2) + i);
|
|
|
+ }
|
|
|
|
|
|
- send_buff[2] = DEVICE_ID >> 8;
|
|
|
- send_buff[3] = DEVICE_ID & 0xFF;
|
|
|
+ send_buff[0] = IAP_CMD_VERSION;
|
|
|
+ send_buff[1] = 0x01;
|
|
|
+ break;
|
|
|
+ case IAP_CMD_INFO:
|
|
|
+ g_iap.total_bytes = (uint16_t)rec_msg.data.u8_buf[1] << 8 | rec_msg.data.u8_buf[2];
|
|
|
+ g_iap.total_bytes <<= 16;
|
|
|
+ g_iap.total_bytes |= (uint16_t)rec_msg.data.u8_buf[3] << 8 | rec_msg.data.u8_buf[4];
|
|
|
+ g_iap.total_packages = (uint16_t)rec_msg.data.u8_buf[5] << 8 | rec_msg.data.u8_buf[6];
|
|
|
+ send_buff[0] = IAP_CMD_INFO;
|
|
|
+ send_buff[1] = 0x01;
|
|
|
+ break;
|
|
|
+ case IAP_CMD_ERASE:
|
|
|
+ g_iap.firmware_crc16 = (uint16_t)rec_msg.data.u8_buf[2] << 8 | rec_msg.data.u8_buf[3];
|
|
|
+ if (rec_msg.data.u8_buf[1])
|
|
|
+ {
|
|
|
+ // 喂狗
|
|
|
+ fmc_clear_flag_star();
|
|
|
+ erase_flag = erase_app_flash(DOWNLOAD_START_ADDR, DOWNLOAD_MIDDLE_ADDR);
|
|
|
+ fmc_clear_flag_end();
|
|
|
+ // 喂狗
|
|
|
+ g_iap.count_bytes = 0;
|
|
|
+ g_iap.count_packages = 0;
|
|
|
}
|
|
|
- }
|
|
|
+ send_buff[0] = IAP_CMD_ERASE;
|
|
|
+ send_buff[1] = !erase_flag;
|
|
|
+ break;
|
|
|
+ case IAP_CMD_CRC:
|
|
|
+ send_buff[0] = IAP_CMD_CRC;
|
|
|
+ send_buff[1] = (g_iap.crc16 == g_iap.firmware_crc16 ? 1 : 0);
|
|
|
+ break;
|
|
|
+ case IAP_CMD_JUMP:
|
|
|
+ if (g_iap.crc16 != g_iap.firmware_crc16)
|
|
|
+ {
|
|
|
+ send_buff[1] = 0x00;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ fmc_clear_flag_star();
|
|
|
+ fmc_erase_pages(UPGRADE_FLAG_START_ADDR, 1);
|
|
|
+ upgrade.param.sign = UPGRADE_SIGN;
|
|
|
+ upgrade.param.crc16 = g_iap.crc16;
|
|
|
+ upgrade.param.moving_size = g_iap.total_bytes;
|
|
|
+ fmc_write_n_half_word(UPGRADE_FLAG_START_ADDR, upgrade.infor_buf, UPGRADE_FLAG_DATA_SIZE);
|
|
|
+ fmc_clear_flag_end();
|
|
|
+ jump_boot_time = 10;
|
|
|
+ send_buff[1] = 0x01;
|
|
|
+ }
|
|
|
+ send_buff[0] = IAP_CMD_JUMP;
|
|
|
+ break;
|
|
|
+ case IAP_CMD_MODEL_TYPE:
|
|
|
+ send_buff[0] = IAP_CMD_MODEL_TYPE;
|
|
|
+ send_buff[1] = 0x01;
|
|
|
|
|
|
- // push_can_message_to_queue(IAP, 8, send_buff);
|
|
|
+ send_buff[2] = DEVICE_ID >> 8;
|
|
|
+ send_buff[3] = DEVICE_ID & 0xFF;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ push_can_message_to_queue(0x18DFE1F4, 8, send_buff);
|
|
|
}
|