123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- #include "board.h"
- #include "core_cmFunc.h"
- #include "dev_boot.h"
- #include "dev_iap.h"
- #include "drv_flash.h"
- #include "schedule.h"
- #include <stdint.h>
- #include <stm32f4xx.h>
- uint16_t cache_buf[1024] = {0};
- int main(void)
- {
- drv_board_init();
- dev_can_network_init();
- uint32_t w_size = 0;
- u16 cnt = 0;
- iap_param_init();
- fmc_read_n_half_word(UPGRADE_FLAG_START_ADDR, upgrade.infor_buf, 4);
- if (upgrade.param.sign == UPGRADE_SIGN)
- {
- if (check_addr_sp(DOWNLOAD_START_ADDR))
- {
- fmc_clear_flag_star();
- erase_app_flash(APP_START_ADDR, APP_END_ADDR);
- while (w_size < upgrade.param.moving_size)
- {
- if ((upgrade.param.moving_size - w_size) > FMC_PAGE_SIZE)
- {
- fmc_read_n_half_word(DOWNLOAD_START_ADDR + w_size, cache_buf, FMC_PAGE_SIZE_U16);
- fmc_write_n_half_word(APP_START_ADDR + w_size, cache_buf, FMC_PAGE_SIZE_U16);
- w_size += FMC_PAGE_SIZE;
- }
- else
- {
- if (((upgrade.param.moving_size - w_size) % 2) != 0)
- w_size--;
- fmc_read_n_half_word(DOWNLOAD_START_ADDR + w_size, cache_buf, (upgrade.param.moving_size - w_size) / 2);
- fmc_write_n_half_word(APP_START_ADDR + w_size, cache_buf, (upgrade.param.moving_size - w_size) / 2);
- w_size = upgrade.param.moving_size;
- }
- }
- fmc_clear_flag_end();
- if (check_addr_sp(APP_START_ADDR) && check_addr_pc(APP_START_ADDR + 4))
- {
- CAN_DeInit(CAN1);
- __set_PRIMASK(1);
- run_app();
- }
- else
- {
- iap_flag_release();
- }
- }
- else
- {
- iap_flag_release();
- CAN_DeInit(CAN1);
- __set_PRIMASK(1);
- run_app();
- }
- }
- if (INVALID == check_addr_sp(APP_START_ADDR))
- {
- if (check_addr_sp(DOWNLOAD_START_ADDR))
- {
- fmc_clear_flag_star();
- erase_app_flash(APP_START_ADDR, APP_END_ADDR);
- while (w_size < upgrade.param.moving_size)
- {
- if ((upgrade.param.moving_size - w_size) > FMC_PAGE_SIZE)
- {
- fmc_read_n_half_word(DOWNLOAD_START_ADDR + w_size, cache_buf, FMC_PAGE_SIZE_U16);
- fmc_write_n_half_word(APP_START_ADDR + w_size, cache_buf, FMC_PAGE_SIZE_U16);
- w_size += FMC_PAGE_SIZE;
- }
- else
- {
- if (((upgrade.param.moving_size - w_size) % 2) != 0)
- w_size--;
- fmc_read_n_half_word(DOWNLOAD_START_ADDR + w_size, cache_buf, (upgrade.param.moving_size - w_size) / 2);
- fmc_write_n_half_word(APP_START_ADDR + w_size, cache_buf, (upgrade.param.moving_size - w_size) / 2);
- w_size = upgrade.param.moving_size;
- }
- }
- fmc_clear_flag_end();
- if (check_addr_sp(APP_START_ADDR) && check_addr_pc(APP_START_ADDR))
- {
- CAN_DeInit(CAN1);
- __set_PRIMASK(1);
- run_app();
- }
- }
- }
- else
- {
- CAN_DeInit(CAN1);
- __set_PRIMASK(1);
- run_app();
- }
- schedule_init(TASK_PERIOD);
- while (1)
- {
- schedule();
- }
- }
|