1.5wuling_zhuanjietou/UDS/uds_interface.h

217 lines
5.8 KiB
C
Raw Normal View History

2024-10-17 01:06:51 +00:00
/*!
* @file uds_interface.h
* @brief customized service sequence definition. Modify the file according to the requirements.
*
*/
#ifndef UDS_INTERFACE_H
#define UDS_INTERFACE_H
#include "uds_types.h"
#if BOOTLOADER_CODE_FLAG == 0
#define UDS_SERVICE_FOREACH(func)\
/*00*/ func(0x10,UDS_10_Service_Session_Control,0)\
/*01*/ func(0x11,UDS_11_Service_Ecu_Reset,0)\
/*02*/ func(0x14,UDS_14_Service_Clear_DTC,0)\
/*03*/ func(0x19,UDS_19_Service_Read_DTC,0) \
/*04*/ func(0x22,UDS_22_Service_Read_Data,0)\
/*05*/ func(0x2E,UDS_2E_Service_Write_Data,1) \
/*06*/ func(0x27,UDS_27_Service_Security_Access,0) \
/*07*/ func(0x3E,UDS_3E_Service_Tester_Present,0) \
/*08*/ func(0x31,UDS_31_Service_Routine_Ctrl,0) \
/*09*/ func(0x28,UDS_28_Service_Communication_Control,0) \
/*10*/ func(0x85,UDS_85_Service_Control_DTC,0) \
/*12*/ func(0x7F,UDS_Service_NRC,0)
#else
#define UDS_SERVICE_FOREACH(func)\
/*00*/ func(0x10,UDS_10_Service_Session_Control,0)\
/*01*/ func(0x11,UDS_11_Service_Ecu_Reset,0)\
/*02*/ func(0x22,UDS_22_Service_Read_Data,0)\
/*03*/ func(0x2E,UDS_2E_Service_Write_Data,1) \
/*04*/ func(0x27,UDS_27_Service_Security_Access,0) \
/*05*/ func(0x3E,UDS_3E_Service_Tester_Present,0) \
/*06*/ func(0x31,UDS_31_Service_Routine_Ctrl,0) \
/*07*/ func(0x28,UDS_28_Service_Communication_Control,0) \
/*08*/ func(0x85,UDS_85_Service_Control_DTC,0) \
/*09*/ func(0x34,UDS_34_Service_Request_Download,1) \
/*10*/ func(0x36,UDS_36_Service_Transfer_Data,1) \
/*11*/ func(0x37,UDS_37_Service_Transfer_Exit,0) \
/*12*/ func(0x7F,UDS_Service_NRC,0)
#endif
#define GENERATE_UDS_SERVICE_INDEX(sid,service,rx_end_flag) Index_Sid_##sid,
#define GENERATE_UDS_SERVICE_TABLE(sid,service,rx_end_flag) service,
#define GENERATE_UDS_SERVICE_ID(sid,name,rx_end_flag) sid ,
typedef enum _UDS_SERVICE_INDEX {
UDS_SERVICE_FOREACH(GENERATE_UDS_SERVICE_INDEX)
UDS_SERVICE_NUM,
}UDS_SERVICE_INDEX;
typedef enum{
_UDS_DEFAULT_SESSION=0x01,
_UDS_PROGRAM_SESSION=0x02,
_UDS_EXT_SESSION=0x03,
// _UDS_STD_DIAG_SESSION=0x81,
// _UDS_PRO_DIAG_SESSION=0x85,
// _UDS_EXT_DIAG_SESSION=0x90,
}UDS_SESSION;
typedef enum {
DOWNLOAD_SEQUENCE_IDLE,
DOWNLOAD_SEQUENCE_34,
DOWNLOAD_SEQUENCE_36,
DOWNLOAD_SEQUENCE_37,
}DownloadSequenceType;
#define UDS_UP_LEN (FMC_PAGE_SIZE)
typedef struct
{
bool start; /*!< Sequence start state */
uint8_t index; /*!< Sequence index to be serviced */
}UDS_Demo_Service_Ctrl_T;
typedef struct{
bool RxEraseFlg;
bool RxProgramFlag;
bool UpCompFlg;
bool UpChkProgIntegFlg;
bool UpModleFlg;
bool EraseMemoryFlg;
//bool SecureFlg;
//bool SecureSw;
uint8_t EraseMemorySts;
uint32_t OffSetAdd;
uint32_t EraseAddress;
uint32_t EraseLength;
uint16_t GetCrc;
uint16_t CalcCrc;
uint32_t dLen;
uint32_t StackTopAdr;
uint32_t checksum;
#if BOOTLOADER_CODE_FLAG
uint8_t Buf[UDS_UP_LEN];
#endif
bool RoutineEraseMemoryFlg;
bool RoutineChkProgIntegrityFlg;
bool RoutineChkProgIntegrityPass;
bool PrintFingerFlg;
bool RoutineEraseMemoryErr;
//uint16_t FlashDriverDlength;
uint8_t Sn;
uint32_t totalRecvLength;
DownloadSequenceType DownloadSeq;
}_UdsUpData;
typedef struct{
bool ResetMcuFlg;
bool UdsTxFlg;
bool UdsTxCompFlg;
bool KeyLockFlg;
bool PhyFlg;
bool TxCompFlg;
bool AlreadSendSeed;
bool StartFlg;
bool IsUdsFlg;
bool BattErrFlg;
bool HsCanErrFlg;
bool TypeVech;
bool UpDataFlg;
bool CanRxOkFlg;
bool BusOffNoSendFlg;
bool ChkProgPreconditionFlg;
bool Sid2FWaitResFlg;
uint8_t IOCP;
uint16_t IOCS;
uint8_t SwErrCnt;
uint8_t VersionMod;
uint8_t CheckDtc5S;
uint8_t DtcFlg;
uint8_t DtcErr;
uint8_t FrameType;
uint8_t RequestFlg;
uint8_t SessionDiagModel;
uint8_t RxSessionDiagModel;
uint8_t Id;
uint8_t RstTimer;
uint8_t MultFrameComp;
uint8_t SeedKeyIsOK;
uint8_t SeedKeyLevel;
uint8_t NcmDisRxAndTx;
uint8_t NmcmDisRxAndTx;
uint8_t EnRxAndTx0x29;
uint8_t DisDTCRecord;
uint8_t KeyErrCnt;
uint8_t KeyErrLockTimer;
uint8_t TxUdsChann;
uint8_t ReqCmdBuf[20];
uint16_t SessionTimer;//<2F><><EFBFBD><EFBFBD>Ĭ<EFBFBD>ϻỰ<CFBB><E1BBB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD><C2A3><EFBFBD>ʱ<EFBFBD><CAB1>תһ<D7AA><D2BB>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>Ĭ<EFBFBD>ϻỰ<CFBB><E1BBB0>
uint16_t RxDlc;
uint16_t RxMulDlc;
uint16_t TxTimerOut;
uint16_t RxBlockCnt;
uint16_t SwImageErrTimer;
uint16_t BusOffNoSendTimer;
uint16_t CanID;
uint16_t IoDid;
uint16_t Nrc78Timer;
}__UDSService;
extern uint8_t UDS_SeedKeyBuf[8];
extern __UDSService UdsService;
extern _UdsUpData UdsUpData;
extern const uint8_t UDSsid[];
extern UDS_Demo_Service_Ctrl_T Service_Ctrl;
void GotoDefaultSession(void);
bool CheckIsBeyonSession(INT8U CurSession,INT8U SelfSession,INT8U Type);
bool CheckUdsDlcIsOk(INT16U RxDlc,INT16U rDlc);
bool CheckSubSidNeedPosResp(INT8U SubSID);
bool CheckIsKeyOk(void);
bool CanRxConStatus(void);
bool CheckIsSupportBootloaderRead_Sid22(uint16_t did);
bool CheckIsSupportSubFunc_Sid19(uint8_t sub);
bool CheckIsSupportSubFunc_Sid11(uint8_t sub);
/*!
* @brief Demo Service Function to start service sequencce
* This function is used to start service sequencce
*/
void UDS_Demo_Services_Start(void);
/*!
* @brief Demo Service Function to call the services in sequencce
* This function is used to call the services in sequencce
*/
void UDS_Demo_Services_Sequence(void);
/*!
* @brief Demo service function to calculate key according to seed.
* The function is used to calculate key according to seed.
*
* @param rsp_buf Response buf pointer
*/
void UDS_Demo_Calculate_Key(uint8_t* rsp_buf);
/*!
* @brief Demo Service Function for positive response callback
* This function is used for positive response callback
*/
void UDS_Pos_Response_Callback(void);
/*!
* @brief Demo Service Function for negtive response callback
* This function is used for negtive response callback
*/
void UDS_Neg_Response_Callback(void);
#endif