1.5wuling_zhuanjietou/UDS/uds_api.c

215 lines
5.2 KiB
C
Raw Normal View History

2024-10-17 01:06:51 +00:00
#include "uds_config.h"
#include "24cxx.h"
extern DIDs gDIDCache;
/* udsǿ<73><C7BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DTC<54><43><EFBFBD>ع<EFBFBD><D8B9>ϱ<EFBFBD>־λ */
void UdsApi_HardwareFault_ForceClear(void)
{
//Ӳ<><D3B2>ǿ<EFBFBD><C7BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DTC<54><43><EFBFBD>ع<EFBFBD><D8B9><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
/* Ӳ<><D3B2><EFBFBD><EFBFBD>UDS<44><53><EFBFBD>³<EFBFBD><C2B3><EFBFBD><EFBFBD>ź<EFBFBD> */
void UdsApi_VehicleInfo2UdsProc(void)
{
/* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
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 <20><>ʼ<EFBFBD><CABC>*/
void UdsApi_NVM_Init(void)
{
static uint8_t enter_flag = 0;
// Delay_MS(50);//<2F>ȴ<EFBFBD><C8B4><EFBFBD>Դ<EFBFBD>ȶ<EFBFBD>
if (!enter_flag) {
enter_flag = 1;
NVM_Init();
DID_SignalInit();
DTC_SignalInit();
}
}
/* <20><>ѯUDS<44>Ƿ<EFBFBD>ʹ<EFBFBD>ܳ<EFBFBD><DCB3><EFBFBD>ͨ<EFBFBD>ű<EFBFBD><C5B1>ķ<EFBFBD><C4B7><EFBFBD> */
bool UdsApi_Is_UdsEnableNCMTx(void)
{
bool bRst=false;
if (udsInfo2Vehicle.NcmTxEnable) {
bRst = true;
}
return bRst;
}
/* <20><>ѯUDS<44>Ƿ<EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD> */
bool UdsApi_Is_UdsEnableNWMCMTx(void)
{
bool bRst=false;
if (udsInfo2Vehicle.NmcmTxEnable) {
bRst = true;
}
return bRst;
}
/* <20><>ѯUDS<44>Ƿ<EFBFBD>ʹ<EFBFBD>ܳ<EFBFBD><DCB3><EFBFBD>ͨ<EFBFBD>ű<EFBFBD><C5B1>Ľ<EFBFBD><C4BD><EFBFBD> */
bool UdsApi_Is_UdsEnableNCMRx(void)
{
bool bRst=false;
if (udsInfo2Vehicle.NcmRxEnable) {
bRst = true;
}
return bRst;
}
/* <20><>ѯUDS<44>Ƿ<EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD> */
bool UdsApi_Is_UdsEnableNWMCMRx(void)
{
bool bRst=false;
if (udsInfo2Vehicle.NmcmRxEnable) {
bRst = true;
}
return bRst;
}
/* <20><>ѯUDS<44>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD> */
bool UdsApi_Is_UdsOnline(void)
{
bool bRst=false;
if (!udsInfo2Vehicle.UdsOffLine) {
bRst = true;
}
return bRst;
}