From 73bf3cdb517b55f662ed5fa513cdaaf55c1fd0c8 Mon Sep 17 00:00:00 2001 From: tao_z <tzj0429@163.com> Date: Wed, 01 Jun 2022 23:51:43 +0800 Subject: [PATCH] Bootloader调试完成,可以正常烧录程序 --- Application/source/uds_modules/did.c | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 40 insertions(+), 3 deletions(-) diff --git a/Application/source/uds_modules/did.c b/Application/source/uds_modules/did.c index 08a918f..e73fcce 100644 --- a/Application/source/uds_modules/did.c +++ b/Application/source/uds_modules/did.c @@ -44,16 +44,51 @@ uint16_t DIDTable_Entry_Count_u16 = 0; UDS_DIDtableEntry DIDtable[UDS_DID_TABLE_SIZE]; -static uint8_t DID_LoaderWaitTimer = 0; +// static uint8_t DID_LoaderWaitTimer = 0; +static uint8_t DID_NeedtoSaveFlag = 0; void did_init(void) { + DID_NeedtoSaveFlag = 0; UDS_InitDIDMapRW(DID_NS_ProgrammingCounter, VA_PROGRAM_DATA, &NVM_ProgramBLOCK.ProgrammingCounter, 1); UDS_InitDIDMapRW(DID_NS_ProAtpCounter, VA_PROGRAM_DATA, &NVM_ProgramBLOCK.ProgrammingAttempCounter, 1); UDS_InitDIDMapRW(DID_NS_ReadFingerPrint, VA_PROGRAM_DATA, &NVM_ProgramBLOCK.FingerPrint_W, 9); UDS_InitDIDMapRW(DID_NS_RepairShopCodeOrTester, VA_PROGRAM_DATA, &NVM_ProgramBLOCK.RepairShopCodeOrTesterSerialNumber, 16); UDS_InitDIDMapRW(DID_NS_ECUProgtammingDate, VA_PROGRAM_DATA, &NVM_ProgramBLOCK.UDS_NS_ProgrammingDate.ProgrammingDate_YY_H, 4); UDS_InitDIDMapRW(DID_NS_WriteFingerPrint, VA_PROGRAM_DATA, &NVM_ProgramBLOCK.FingerPrint_W, 10); + + FblReadProgramBlock(); // load program data.must after ee_init() +} + +extern void DID_SetWriteSaveFlag(void) +{ + DID_NeedtoSaveFlag = 1; +} + +extern int8_t DID_SaveProgamDataToNvm(void) +{ + int8_t rtn = OP_STATUS_FAIL; + + if (DID_NeedtoSaveFlag == 1) + { + rtn = FblWriteProgramBlock(); + } + else + { + rtn = OP_STATUS_OK; + } +} + +extern void DID_UpdateProgramCnt(void) +{ + NVM_ProgramBLOCK.ProgrammingCounter += 1; + DID_NeedtoSaveFlag = 1; +} + +extern void DID_UpdateAtpProgramCnt(void) +{ + NVM_ProgramBLOCK.ProgrammingAttempCounter += 1; + DID_NeedtoSaveFlag = 1; } extern int8_t FblReadProgramBlock(void) @@ -61,13 +96,14 @@ uint32_t *p_dest = (uint32_t *)(&NVM_ProgramBLOCK); uint8_t i = 0; - int8_t rtn = OP_STATUS_FAIL; + int8_t rtn = OP_STATUS_OK; EE_Status retValue1 = EE_WRITE_ERROR; for (i = 0; i < (ProgramBlockLenth >> 2); i++) { if (EE_OK != EE_ReadVariable32bits(VA_PROGRAM_DATA + i * 4, (p_dest + i))) { + rtn = OP_STATUS_FAIL; break; } } @@ -78,13 +114,14 @@ { uint32_t *p_dest = (uint32_t *)(&NVM_ProgramBLOCK); uint8_t i = 0; - int8_t rtn = OP_STATUS_FAIL; + int8_t rtn = OP_STATUS_OK; EE_Status retValue1 = EE_WRITE_ERROR; for (i = 0; i < (ProgramBlockLenth >> 2); i++) { if (EE_OK != EE_WriteVariable32bits(VA_PROGRAM_DATA + i * 4, *(p_dest + i))) { + rtn = OP_STATUS_FAIL; break; } } -- Gitblit v1.8.0