#include "uds_config.h" #include "24cxx.h" extern DIDs gDIDCache; /* uds强制清除硬件自身DTC相关故障标志位 */ void UdsApi_HardwareFault_ForceClear(void) { //硬件强制清除自身DTC相关故障,请根据实际情况填入 } /* 硬件向UDS更新车身信号 */ void UdsApi_VehicleInfo2UdsProc(void) { /* 请根据实际情况填入 vehicleInfo2uds.IgnSts = ; vehicleInfo2uds.BattLow = ; vehicleInfo2uds.BattHigh = ; vehicleInfo2uds.InOverVoltFault = ; vehicleInfo2uds.InUnderVoltFault = ; vehicleInfo2uds.OutOverVoltFault = ; vehicleInfo2uds.OutUnderVoltFault = ; vehicleInfo2uds.InOverCurFault = ; vehicleInfo2uds.OutOverCurFault = ; vehicleInfo2uds.OverTemperture = ; vehicleInfo2uds.BusoffCnt = ; vehicleInfo2uds.Snapshot.PowerMode = ; vehicleInfo2uds.Snapshot.TolOdometerH = ; vehicleInfo2uds.Snapshot.TolOdometerM = ; vehicleInfo2uds.Snapshot.TolOdometerL = ; vehicleInfo2uds.Snapshot.DateSec = ; vehicleInfo2uds.Snapshot.DateMin = ; vehicleInfo2uds.Snapshot.DateHour = ; vehicleInfo2uds.Snapshot.DateDay = ; vehicleInfo2uds.Snapshot.DateMonth = ; vehicleInfo2uds.Snapshot.DateYear = ; vehicleInfo2uds.Snapshot.VehSpeedH = ; vehicleInfo2uds.Snapshot.VehSpeedL = ; vehicleInfo2uds.Snapshot.BatVolt = ; vehicleInfo2uds.Snapshot.SOC = ; */ } /* uds parameter init*/ void UdsApi_ParaInit(void) { #if BOOTLOADER_CODE_FLAG memcpy(gDIDCache.DID_BootSoftware, BOOTLOADER_SOFTWARE_VERSION, DIDSize[BootSoftware]); #else memcpy(gDIDCache.DID_BootSoftware, (uint8_t*)GetBootloaderSwVersionAddress(), DIDSize[BootSoftware]); memset(gDIDCache.DID_ProgrammingDate, 0x00, DIDSize[ProgrammingDate]); memset(gDIDCache.DID_TesterSerialNumber, 0x00, DIDSize[TesterSerialNumber]); memset(gDIDCache.DID_VehicleIdentificationNumber, 0x00, DIDSize[VehicleIdentificationNumber]); gDIDCache.DID_ActiveDiagnosticSession[0] = _UDS_DEFAULT_SESSION; //以下请根据实际填入数据 memcpy(gDIDCache.DID_ECUManufacturerSparePartNumber, "xxxxxxxxxxxxxxxxx", DIDSize[ECUManufacturerSparePartNumber]); memcpy(gDIDCache.DID_SystemSupplierIdentifierData, "xxxxxxxxxxxxxxx", DIDSize[SystemSupplierIdentifierData]); memcpy(gDIDCache.DID_VehicleManufacturerECUHardwareNumber, "xxxxxxxxxxxxxxx", DIDSize[VehicleManufacturerECUHardwareNumber]); memcpy(gDIDCache.DID_VehicleManufacturerECUSoftwareNumber, "B30C43 ", DIDSize[VehicleManufacturerECUSoftwareNumber]); memcpy(gDIDCache.DID_ECUSerialNumber, "xxxxxxxxxxxxxxx", DIDSize[ECUSerialNumber]); gDIDCache.DID_InputOvervoltageValue[0] = MSB(350); gDIDCache.DID_InputOvervoltageValue[1] = LSB(350); gDIDCache.DID_InputUndervoltageValue[0] = MSB(200); gDIDCache.DID_InputUndervoltageValue[1] = LSB(200); gDIDCache.DID_OutputOvervoltageValue[0] = MSB(130); gDIDCache.DID_OutputOvervoltageValue[1] = LSB(130); gDIDCache.DID_OutputUndervoltageValue[0] = MSB(60); gDIDCache.DID_OutputUndervoltageValue[1] = LSB(60); gDIDCache.DID_OutputOvercurrentFaultValue[0] = 120; gDIDCache.DID_InputOvercurrentFaultValue[0] = 40; gDIDCache.DID_OverTempertureProtectValue[0] = 95; #endif } /* uds 1ms task */ void UdsApi_1ms_task(void) { UdsProcTask(); } /* uds 10ms task */ void UdsApi_10ms_task(void) { UdsApi_VehicleInfo2UdsProc(); } /* uds can receive msg in */ void UdsApi_MsgQueueIn(CanRxMsg msg) { can_msg_t uds_msg; uds_msg.id = msg.StdId; uds_msg.dlc = msg.DLC; memcpy(uds_msg.data, msg.Data, uds_msg.dlc); UdsQueueCanIn(uds_msg); } /* uds transmit diag msg */ void UdsApi_MsgQueueOut(can_msg_t uds_msg) { CanTxMsg msg; msg.IDE = CAN_Id_Standard; msg.StdId = uds_msg.id; msg.DLC = uds_msg.dlc; msg.RTR = CAN_RTR_Data; memcpy(msg.Data, uds_msg.data, msg.DLC); // Can2_Send_Message(msg); can_write2(&msg); } /* uds 生成随机数 */ uint32_t UdsApi_GetRandom(void) { static uint32_t Seed=0; uint32_t Random; if(Seed == 0) { Seed = SysTick->VAL; Seed *= 91939597; } Random = Seed+SysTick->VAL; Seed += 13957; Random = (u32)( (u32)Random<<16)>>16; Random |= ((Seed*5)<<16); return Random; } /* eeprom write*/ uint8_t UdsApi_EE_WriteBytes(uint8_t *_pWriteBuf, uint16_t _usAddress, uint16_t _usSize) { return ee_WriteBytes(_pWriteBuf, _usAddress, _usSize); } /* eeprom read*/ uint8_t UdsApi_EE_ReadBytes(uint8_t *_pReadBuf, uint16_t _usAddress, uint16_t _usSize) { return ee_ReadBytes(_pReadBuf, _usAddress, _usSize); } /* NVM 初始化*/ void UdsApi_NVM_Init(void) { static uint8_t enter_flag = 0; // Delay_MS(50);//等待电源稳定 if (!enter_flag) { enter_flag = 1; NVM_Init(); DID_SignalInit(); DTC_SignalInit(); } } /* 查询UDS是否使能常规通信报文发送 */ bool UdsApi_Is_UdsEnableNCMTx(void) { bool bRst=false; if (udsInfo2Vehicle.NcmTxEnable) { bRst = true; } return bRst; } /* 查询UDS是否使能网络管理报文发送 */ bool UdsApi_Is_UdsEnableNWMCMTx(void) { bool bRst=false; if (udsInfo2Vehicle.NmcmTxEnable) { bRst = true; } return bRst; } /* 查询UDS是否使能常规通信报文接收 */ bool UdsApi_Is_UdsEnableNCMRx(void) { bool bRst=false; if (udsInfo2Vehicle.NcmRxEnable) { bRst = true; } return bRst; } /* 查询UDS是否使能网络管理报文接收 */ bool UdsApi_Is_UdsEnableNWMCMRx(void) { bool bRst=false; if (udsInfo2Vehicle.NmcmRxEnable) { bRst = true; } return bRst; } /* 查询UDS是否在线 */ bool UdsApi_Is_UdsOnline(void) { bool bRst=false; if (!udsInfo2Vehicle.UdsOffLine) { bRst = true; } return bRst; }