From a7c0d42a6590c26d37c17b082aef52925b466569 Mon Sep 17 00:00:00 2001 From: tao_z <tzj0429@163.com> Date: Sun, 29 May 2022 10:03:04 +0800 Subject: [PATCH] bootloader运行,烧录流程尚未测试 --- Application/source/uds_modules/uds.c | 84 +++++++++++++++++++++++------------------ 1 files changed, 47 insertions(+), 37 deletions(-) diff --git a/Application/source/uds_modules/uds.c b/Application/source/uds_modules/uds.c index 904fbc6..7f1040c 100644 --- a/Application/source/uds_modules/uds.c +++ b/Application/source/uds_modules/uds.c @@ -9,6 +9,7 @@ #include "cantp_user.h" #include "xl_mcan.h" #include "uds.h" +#include "did.h" #include "fbl_ap.h" #include "fbl_def.h" #include "nvm.h" @@ -308,7 +309,7 @@ /* Build DID data set */ static bool UDS_BuildDidSet(uint8_t *payload); /* Switch to default session */ -static void UDS_SwitchtoDefaultSession(void); +static void UDS_SwitchtoDefaultSession(uint8_t resetcmd); /*Security access*/ static void UDS_ControlDTCSetting(uint8_t *payload); @@ -376,7 +377,7 @@ {ECU_RESET, UDS_ECURest, false, true, false, true, SECURITY_ACCESS_LOCKED}, {READ_DATA_BY_IDENTIFIER, UDS_ReadData, true, true, false, false, SECURITY_ACCESS_LOCKED}, {SECURITY_ACCESS, UDS_SecurityAccess, false, true, false, false, SECURITY_ACCESS_LOCKED}, - {COMMUNICATION_CONTROL, UDS_CommunicationControl, false, true, true, true, SECURITY_ACCESS_LOCKED}, + // {COMMUNICATION_CONTROL, UDS_CommunicationControl, false, true, true, true, SECURITY_ACCESS_LOCKED}, {WRITE_DATA_BY_IDENTIFIER, UDS_WriteDataByIdentifier, false, true, false, false, SECURITY_ACCESS_UNLOCK_LEVEL_1}, {ROUTINE_CONTROL, UDS_RoutineControl, false, true, false, false, SECURITY_ACCESS_UNLOCK_LEVEL_2}, {TESTER_PRESENT, UDS_TesterPresent, true, true, true, true, SECURITY_ACCESS_LOCKED}, @@ -1030,23 +1031,17 @@ if (CDT_HASEXPIRED(TesterPresentTimer_u16) != false) { - UDS_SwitchtoDefaultSession(); + UDS_SwitchtoDefaultSession(true); } } else { - UDS_SwitchtoDefaultSession(); + UDS_SwitchtoDefaultSession(true); } } else { CDT_RESET(TesterPresentTimer_u16, 0); -#if 0 - if(CDT_EXPIRED(EntrySleepModeTimer_u16)==true) - { - //SBC_shutdown(); - } -#endif } } @@ -1204,29 +1199,14 @@ } else { - if ((DID_u16 & 0xff00u) == 0xF100u) - { - /* UDS_WriteF1DIDdata(&payload[3], Index_to_be_written); */ - memcpy(DIDtable[Index_to_be_written].address, &payload[3], - DIDtable[Index_to_be_written].size); - } - else - { - /* Flip the data contents in rx buffer */ - UDS_FlipEndian(&payload[3], DIDtable[Index_to_be_written].size); - - /* not sure this should be done... */ - /* memory copy the data into DID data location */ - memcpy(DIDtable[Index_to_be_written].address, &payload[3], - DIDtable[Index_to_be_written].size); - } + /* UDS_WriteF1DIDdata(&payload[3], Index_to_be_written); */ + memcpy(DIDtable[Index_to_be_written].address, &payload[3], + DIDtable[Index_to_be_written].size); /* Write the change to NVM */ if (DIDtable[Index_to_be_written].nvBlockID != 0xFF) { - // todo - // CAL_Save_Calibration_Block( - // DIDtable[Index_to_be_written].nvBlockID); + DID_SetWriteSaveFlag(); } UDS_L_tx_msg_buffer[0] = GET_RESPONSE_SERVICE_ID(WRITE_DATA_BY_IDENTIFIER); @@ -1446,6 +1426,7 @@ /*****************************************************************************/ static void UDS_SessionControl(uint8_t *payload) { + uint16_t cnt = 5000u; /* Change session based on CAN message request */ bool UDS_SessionSetOk_b = false; uint8_t sub_func = UDS_GET_SUB_FUNCTION(payload[UDS_RQ_BYTE1]); @@ -1473,6 +1454,7 @@ { /**/ UDS_L_Diag_session_e = PROGRAMMING; + UDS_SessionSetOk_b = true; FblSetFblProgramRequestFlag(); } else if ((UDS_L_Diag_session_e == DEFAULT) || (UDS_L_ProgrammingPreconditionCheckOK_b == false)) /*DEFAULT session can not trans to PROGRAMMING*/ @@ -1484,7 +1466,35 @@ } break; case DEFAULT: - UDS_SwitchtoDefaultSession(); + if (UDS_L_Diag_session_e == PROGRAMMING) + { + UDS_L_tx_msg_buffer[0] = GET_RESPONSE_SERVICE_ID(SESSION_CONTROL); + UDS_L_tx_msg_buffer[1] = UDS_L_Diag_session_e; + UDS_L_tx_msg_buffer[2] = 0; + UDS_L_tx_msg_buffer[3] = 0; + UDS_L_tx_msg_buffer[4] = 0; + UDS_L_tx_msg_buffer[5] = 0; + + /* Specify the send payload size */ + UDS_L_tx_msg_size = 0x06; + + /* Compose a response message and send a positive */ + /* response with the request data */ + UDS_RespTxMessage(); + while (cnt--) + { + ; /// wait send command send out and then reset + } + + UDS_SwitchtoDefaultSession(true); + while (1) + ; + } + else + { + UDS_SwitchtoDefaultSession(false); + } + TesterPresentTimer_u16 = 0; break; default: @@ -1508,12 +1518,6 @@ /* response with the request data */ UDS_RespTxMessage(); } -#ifdef ENABLE_BOOTLOADER - if (UDS_L_Diag_session_e == PROGRAMMING) - { /*reset es*/ - CPU_HardReset(); - } -#endif } /*****************************************************************************/ @@ -2076,6 +2080,7 @@ { } } + DID_UpdateAtpProgramCnt(); /*always from buff 0*/ currentbuffId = 0; UDS_L_TransferDataState_e = TRANFER_START; @@ -2245,6 +2250,7 @@ /* Compose a response message and send a positive */ /* response with the request data */ UDS_RespTxMessage(); + DID_UpdateProgramCnt(); } /*****************************************************************************/ @@ -2404,10 +2410,14 @@ /* (1) Date: 10/30/2014 Fogbugz: case#: 2283 */ /* Initial release by Tom Tao */ /*****************************************************************************/ -static void UDS_SwitchtoDefaultSession(void) +static void UDS_SwitchtoDefaultSession(uint8_t restcmd) { UDS_L_Diag_session_e = DEFAULT; UDS_L_ProgrammingPreconditionCheckOK_b = false; + if (restcmd == true) + { + CPU_HardReset(); + } } static void UDS_StringCopy(char *p_src, char *p_dest, uint8_t max_size) -- Gitblit v1.8.0