| | |
| | | #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" |
| | |
| | | /* 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); |
| | |
| | | {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}, |
| | |
| | | |
| | | 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 |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | 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); |
| | |
| | | /*****************************************************************************/ |
| | | 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]); |
| | |
| | | { |
| | | /**/ |
| | | 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*/ |
| | |
| | | } |
| | | 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: |
| | |
| | | /* response with the request data */ |
| | | UDS_RespTxMessage(); |
| | | } |
| | | #ifdef ENABLE_BOOTLOADER |
| | | if (UDS_L_Diag_session_e == PROGRAMMING) |
| | | { /*reset es*/ |
| | | CPU_HardReset(); |
| | | } |
| | | #endif |
| | | } |
| | | |
| | | /*****************************************************************************/ |
| | |
| | | { |
| | | } |
| | | } |
| | | DID_UpdateAtpProgramCnt(); |
| | | /*always from buff 0*/ |
| | | currentbuffId = 0; |
| | | UDS_L_TransferDataState_e = TRANFER_START; |
| | |
| | | /* Compose a response message and send a positive */ |
| | | /* response with the request data */ |
| | | UDS_RespTxMessage(); |
| | | DID_UpdateProgramCnt(); |
| | | } |
| | | |
| | | /*****************************************************************************/ |
| | |
| | | /* (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) |