Commit f958e54b authored by 李延凯's avatar 李延凯

feat: 添加周期检测Flash中的MCU信息, 删除不使用的诊断服务

parent 74f41343
......@@ -27,4 +27,4 @@ void BackLight_Process(void);
#endif
\ No newline at end of file
#endif
......@@ -39,4 +39,4 @@ void AMT630H_Main(void);
unsigned char AMT630H_isInitFinish(void);
extern uint32_t Amt630hInitTimerCnts ;
#endif
\ No newline at end of file
#endif
#include "UartProtocol.h"
#include "PicBin.h"
#include <stdint.h>
#include "UDS_ISO14229_Services.h"
#define NULL 0
#define READ_MCU_DATA_MAX 0x400
extern uint8_t UartRevBuff[0x1000];
extern uint32_t UartRevCnts;
uint8_t ReadDataBuf[READ_MCU_DATA_MAX]; /* 读取缓存 */
uint32_t NeedWriteSize; /* 需要写入文件的长度 */
uint32_t FactOffset; /* 绝对地址 */
uint32_t ReadOffset; /* 630中读取偏移量 */
uint32_t AppOffset;
uint32_t Check_Upgrade_Cnt;
uint8_t *GetUartRecvData(uint32_t *UartRecvBufLen, uint32_t *UartRecvPos)
{
*UartRecvBufLen = 0x1000;
......@@ -345,3 +355,110 @@ void TestWrite630Backup(void)
}
}
/* Test end */
void GetReadInfo(READ_ARK630_CMD type)
{
static uint8_t readSt = 0;
static uint16_t getStRetryCnts = 0;
uint32_t tmpRet;
if (NeedWriteSize == 0)
{
if (readSt == 0)
{
readSt = 1;
ProcMcuOrBackupData(type, 0, 0, 0); /* 获取偏移地址 */
getStRetryCnts = 500;
}
else
{
tmpRet = ProcMcuOrBackupData(GET_STATUS, 0, 0, 0);
if ((tmpRet != 2) || (--getStRetryCnts == 0)) /* 非零值为获得的程序地址 */
{
if (tmpRet != 2)
{
NeedWriteSize = 32; /* 此时的NeedWriteSize不重要, 只要跳出循环就行 */
if (type == GET_APP_DATA_OFFSET)
{
FactOffset = 0; /* USB按相对地址获取数据 */
}
else
{
FactOffset = tmpRet; /* 备份程序按绝对地址获取数据 */
}
AppOffset = 0x00;
}
readSt = 0;
}
}
}
}
/**
* @brief 检查Flash中的MCU程序信息, 是否与当前运行的MCU_APP信息相同, 若不同, 则进入升级模式
*/
void Check_MCU_in_Flash(READ_ARK630_CMD type)
{
static uint8_t readSt = 0;
static uint16_t getStRetryCnts = 0;
uint32_t tmpLen;
uint32_t writeLen;
uint8_t saveVersion[16];
uint8_t readVersion[16];
if (NeedWriteSize != 0)
{
if (readSt == 0)
{
readSt = 1;
(void)memset(ReadDataBuf, 0xFFU, sizeof(ReadDataBuf)); /* 初始化buffer */
ProcMcuOrBackupData(REQ_DATA, FactOffset + ReadOffset, READ_MCU_DATA_MAX, ReadDataBuf); // 按地址获取程序数据
getStRetryCnts = 500;
ReadOffset += READ_MCU_DATA_MAX;
}
else
{
tmpLen = ProcMcuOrBackupData(GET_STATUS, 0, 0, 0); /* 获取读取状态 */
if (FactOffset + ReadOffset == tmpLen) /* 当返回值为目标位置时为数据获取成功 */
{
if (AppOffset == 0) /* 首个数据块内解析文件信息 */
{
if (type == GET_APP_DATA_OFFSET) /* 从 MCU_APP 升级文件 */
{
flash_read(FLASH_630H_UPDATE_INFO, sizeof(saveVersion), saveVersion); /* 读取630H升级记录 */
memcpy(readVersion, &ReadDataBuf[16], 16); /* 630中读出的版本信息 */
if (memcmp(&ReadDataBuf[16], saveVersion, 16) != 0) /* 对比版本不同才更新 */
{
Get_Into_630H_Update_MCU_Mode();
}
else
{
/* 信息相同, 重置状态 */
NeedWriteSize = 0;
readSt = 0;
}
}
}
}
if (--getStRetryCnts == 0)
{
/* 读信息超时, 重置状态 */
ReadOffset -= READ_MCU_DATA_MAX;
readSt = 0;
}
}
}
}
void Check_MCU_Info_in_630H(void)
{
Check_Upgrade_Cnt += 100U;
if(Check_Upgrade_Cnt >= 5000U) /* 每5秒检查一次Flash中的MCU程序信息 */
{
Check_Upgrade_Cnt = 0U;
GetReadInfo(GET_APP_DATA_OFFSET);
Check_MCU_in_Flash(GET_APP_DATA_OFFSET);
}
}
......@@ -426,4 +426,4 @@ void Menu_User_WAKEUP(void);
/*-----------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------*/
#endif
\ No newline at end of file
#endif
......@@ -15,10 +15,10 @@ typedef enum
extern uint32_t flash_protect_flag;
int EraseChip (uint32_t adr);
int EraseSector (uint32_t adr);
int ProgramPage (uint32_t adr, uint32_t sz, uint8_t *buf);
FLASH_STATUS flash_write(uint32_t adr, uint32_t sz, uint8_t *buf);
void flashRead(uint8_t *read_address, uint16_t size, uint8_t *readbuf);
extern int EraseChip (uint32_t adr);
extern int EraseSector (uint32_t adr);
extern int ProgramPage (uint32_t adr, uint32_t sz, uint8_t *buf);
extern FLASH_STATUS flash_write(uint32_t adr, uint32_t sz, uint8_t *buf);
extern void flash_read(uint32_t read_address, uint16_t size, uint8_t *readbuf);
#endif
......@@ -255,16 +255,15 @@ FLASH_STATUS flash_write(uint32_t adr, uint32_t sz, uint8_t *buf)
return (status);
}
void flashRead(uint8_t *read_address, uint16_t size, uint8_t *readbuf)
void flash_read(uint32_t read_address, uint16_t size, uint8_t *readbuf)
{
uint8_t *w_ptr;
uint32_t i;
w_ptr = (uint8_t *)read_address;
for (i = 0; i < size; i++)
{
*readbuf = *w_ptr++;
readbuf++;
readbuf++;
}
}
......
......@@ -77,6 +77,7 @@ void Sys_100ms_Tasks(void)
ODOtest = Data_ODO_Read();
Triptest = Data_Read_Trip(0);
S3_ServerCNTT();
Check_MCU_Info_in_630H();
Get_DisTime_Service();
Fuel_Cal_Sevice(100u);
Coolant_Cal_Sevice(100u);
......
This diff is collapsed.
......@@ -41,10 +41,11 @@
*/
#define NoNeedWait 0x00u
#define NeedWait 0x01u
#define APP_STATUS_ADDR (0x501000)
#define APP_DATA_INFO (0x501400)
#define APP_DATA_WRITE (0x501800)
#define FLASH_APP_STATUS_INFO (0x00501000UL) /* APP 程序有效性标识地址 */
#define FLASH_SECOND_BOOT_INFO (0x00501400UL) /* 二级Boot程序状态地址 */
#define FLASH_630H_UPDATE_INFO (0x00501800UL) /* 630H升级信息 */
#define FLASH_APP_RODATA_INFO (0x00501C00UL) /* 存储只读DID信息 */
#define FLASH_APP_RWDATA_INFO (0x00502000UL) /* 存储可写的DID信息 */
#define Data_Flash_Addr_BootValid_OFFSET 0x00000000
#define Data_Flash_Addr_DiagReceive_OFFSET 0x00002000
......@@ -323,35 +324,6 @@
#define CheckSumErr 7 // Checksum Error
#define UnknownPartID 8 // Unknown Part ID
typedef struct
{
uint32_t Flag;
uint8_t Attemptcnt;
uint8_t RequestSeedCnt;
uint8_t AttemptIIcnt;
uint8_t RequestSeedIICnt;
} Ser27_FlowCtrlCntUnion;
typedef struct
{
uint32_t Flag;
uint8_t DID_F180[6];
uint8_t DID_F187[16];
uint8_t DID_F193[6];
uint8_t DID_F195[6];
uint8_t Filldata[2];
}DiagDFlashData;
extern DiagDFlashData DiagDataForDFlash;
typedef struct
{
uint32_t Flag;
uint8_t DID_F184[32];
} Ser2EDFlashData;
extern Ser2EDFlashData Ser2EDataForDFlash;
typedef struct
{
uint32_t Flag;
......@@ -369,19 +341,10 @@ typedef struct
void UDS_Service_10_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A_Data);
void UDS_Service_11_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A_Data);
void UDS_Service_22_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A_Data);
void UDS_Service_2E_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A_Data);
void UDS_Service_27_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A_Data);
void UDS_Service_28_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A_Data);
void UDS_Service_3E_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A_Data);
void UDS_Service_85_Indication(uint16_t A_TA_type, uint16_t A_Length, uint8_t *A_Data);
void S3_ServerCNTT(void);
void Randomcnt(void);
extern void DIAG_InitParameter(void);
void GetSeed(void);
void CalculateKey(void);
void CalculateKeyLv11(void);
typedef void (*InitFunction)(void);
/***********Local Functin*************/
......@@ -390,15 +353,11 @@ uint8_t SerXXNRC12Filter(uint8_t insub, const uint8_t *supportsub, uint8_t size,
uint8_t SerXXNRC13Filter(uint8_t type, uint8_t serlength, const uint8_t *length, uint8_t index);
uint8_t SerXXNRC22Filter(void);
uint8_t SerXXNRC31DIDFilter(uint16_t inDID, const uint16_t *DIDList, uint8_t size, uint8_t *index);
uint8_t SerXXNRC33Filter(const uint8_t *levelList, uint8_t index);
uint8_t SerXXNRC7EFilter(const uint8_t *SubSupportSession, uint8_t index);
uint8_t SerXXNRC7FFilter(uint8_t SupportSession);
extern void Data_Set_DiagPara(void);
void Write_App_InValid(uint32_t m32);
void Data_Read_DiagPara(void);
void DFlash_init(void);
void Data_Read_DiagPara(void);
extern void Get_Into_630H_Update_MCU_Mode(void);
extern void Check_MCU_Info_in_630H(void);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment