/*
* bootloader.c
*
* Created on: 2022-4-24
* Author: Administrator
*/
#include "bootloader.h"
#include "flash.h"
#include "instruments.h"
#include "stdio.h"
#include "watchdog.h"
#include "sev_usart.h"
#include "LCD.h"
static unsigned char head_buf[MSGLEN]={0};
unsigned char bin_buf[FRAME_SIZE]={0};
static unsigned char src_code[BIN_FILE_FRAME_SIZE]={0,0};
static unsigned char checkCnt = 0;
static unsigned char MsgCnt = 0;
static int infocrc_error = 0; // 信息段中92个有效字节的CRC校验出错
static int flashW_error = 0; //flash写入错误
static int boot_err_info = 0; //写flash过程中出现过错误
static int uart_Timeout_error = 0; //串口接收超时
static int Framecrc_error = 0; //帧尾CRC校验错误
static int uart_RecCnt_error = 0; //帧数接收错误
enum updata_flag updata_complete; //升级完成标志
uint32_t *const updataFlag = (uint32_t*)(0x10000000);
#pragma pack(push,1)
boot_shot_header head_info;
#pragma pack(pop)
extern struct rt_ringbuffer rb_usart2_rx;
//字符串常量的定义
unsigned char state_info[][20]=
{
{"state_null"},
{"State_Pre"} ,
{"State_Check"} ,
{"State_Erease_Write"} ,
{"State_Crc_Record"} ,
{"state_Done"} ,
{"State_none"},//不需要升级
};
unsigned char *boot_error[]={
"err_time_out",
"err_platform",
"err_3times",
"err_flash_write",
"err_crc",
"err_flash",
"err_flash_bad",
"err_not_first",
};
/*---------------------------------升级数据协议---------------------------------
7F 7E 00 CRC16 //MCU开机启动间隔一秒发送重启成功进入boot指令;
7F 7E 01 XX XX YY YY ... ... CRC16 //模块回复总包数 当前包数 数据,每包有效数据4096字节,每一包数据前面都有两个标签一个是总包数,一个是当前包序号
7F 7E 02 01 CRC16 //MCU接收成功
7F 7E 02 00 CRC16 //MCU接收失败
7F 7E 03 CRC16 //接收完成
*/
uint8_t com_string[4][14]={
{0x55,0xAA,0x01,0x00,0x0c,0x01,0x00,0x02,0x00,0x00,0x00,0,},
{0x55,0xAA,0x01,0x00,0x0d,0x01,0x00,0x02,0x01,0x02,0x01,0,0,},
{0x55,0xAA,0x01,0x00,0x0d,0x01,0x00,0x02,0x01,0x02,0x00,0,0,},
{0x55,0xAA,0x01,0x00,0x0c,0x01,0x00,0x02,0x00,0x03,0x00,0,},
};
//字符串常量的定义
static uint32_t CRCAll = 0;
unsigned char Date[10]=__TIME__;//记录升级日期
uint8
最新发布