CELIS/UDS/uds_api.c

405 lines
11 KiB
C
Raw Normal View History

#include "uds_config.h"
#include "uds_nvm.h"
#include "24cxx.h"
#include "can.h"
#include "sys.h"
#include "dc300.h"
#include "adc.h"
#include "app_pwr_manage.h"
#include "CDZ_DATA.h"
#include "adc.h"
#include "CDZ_State.h"
#include "Sleep.h"
#include "Err_code.h"
static uint32_t bootSwAddr;
extern DIDs gDIDCache;
extern void DTC_SignalInit(void);
extern void DID_SignalInit(void);
extern int8_t can_write2( CanTxMsg *TxMessage);
extern void Pwr_BatVoltRangeMonitor(void);
PWR_BATT_VOLT_STATE_ENUM battery_volt_state = NORM_VOLT; //<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC>־
static const PWR_Volt_State_Config_Type pwr_volt_state_range_cfg[]= //10mv
{
{0, 650, 0x02, 0x02},
{630, 900, 0x02, 0x05},
{850, 1650, 0x02, 0x05},
{1600, 1850, 0x02, 0x05},
{1820, 2400, 0x02, 0x05},
};
/* 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)
{
vehicleInfo2uds.IgnSts = 1;
/********************<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵʵʱ<CAB5><CAB1><EFBFBD>¸<EFBFBD>UDS**************************/
vehicleInfo2uds.Snapshot.BatVolt = (uint8_t)(Volt_SamplData.KL30_Volt*10); //<2F><EFBFBD><EBB4AB>ʵ<EFBFBD>ʵ<EFBFBD>KL30<33><30>ѹֵ<D1B9><D6B5><EFBFBD><EFBFBD>λΪ0.1V
// busoff<66><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>busoff<66><66>ÿ<EFBFBD>ָ<EFBFBD>һ<EFBFBD>ξ<EFBFBD><CEBE>ۼ<EFBFBD>1<EFBFBD><31>CAN<41><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD>busoff<66><66><EFBFBD><EFBFBD><EFBFBD>
// vehicleInfo2uds.BusoffCnt = can_bus_off_recovery_times(1); // busoff<66><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>busoff<66><66>ÿ<EFBFBD>ָ<EFBFBD>һ<EFBFBD>ξ<EFBFBD><CEBE>ۼ<EFBFBD>1<EFBFBD><31>CAN<41><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD>busoff<66><66><EFBFBD><EFBFBD><EFBFBD>
vehicleInfo2uds.BusoffCnt = Sleep_Parame.BusoffCnt;
vehicleInfo2uds.Snapshot.SOCH = MSB(GetBCP_ChargeState());
vehicleInfo2uds.Snapshot.SOCL = LSB(GetBCP_ChargeState());
vehicleInfo2uds.Snapshot.DCInVolH = MSB((uint16_t)Volt_SamplData.BAT_B_Reverse_Voltage);
vehicleInfo2uds.Snapshot.DCInVolL = LSB((uint16_t)Volt_SamplData.BAT_B_Reverse_Voltage);
if(SysInfo.This_State == STATE_AC_Charge)
vehicleInfo2uds.Snapshot.GunSts = 1;
else if(Get_Sampl_Data.WorkMode() == DC_Charging)
vehicleInfo2uds.Snapshot.GunSts = 2;
else
vehicleInfo2uds.Snapshot.GunSts = 0;
if(DCU_SendState.AC_Relay_State_Filter == true)
{
vehicleInfo2uds.Snapshot.ACRealySts = 0;
}
else if(DCU_SendState.AC_Relay_State_Filter== false)
{
vehicleInfo2uds.Snapshot.ACRealySts = 1;
}
else if(Err_Read(4) == true)
{
vehicleInfo2uds.Snapshot.ACRealySts = 2;
}
if(DCU_SendState.DC_Relay_State_Filter == true)
{
vehicleInfo2uds.Snapshot.DCRealySts = 1;
}
else if(DCU_SendState.DC_Relay_State_Filter == false)
{
vehicleInfo2uds.Snapshot.DCRealySts = 0;
}
else if(Err_Read(3) == true)
{
vehicleInfo2uds.Snapshot.DCRealySts = 2;
}
vehicleInfo2uds.Snapshot.CC2ResistorH = MSB((uint16_t)(Get_Sampl_Data.Resistance_Value*10000));
vehicleInfo2uds.Snapshot.CC2ResistorL = LSB((uint16_t)(Get_Sampl_Data.Resistance_Value*10000));
vehicleInfo2uds.Snapshot.CommSts = Sleep_Parame.Bus_Packet_Free?0:1;
vehicleInfo2uds.InOverVoltFault = Err_Read(1)==true?1:0;
vehicleInfo2uds.InUnderVoltFault = 0;//<2F>޷<EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD>
vehicleInfo2uds.ChargeTempDerateFault = Err_Read(51)==true?1:0;
vehicleInfo2uds.InterTempDerateFault = Err_Read(52)==true?1:0;
vehicleInfo2uds.InterOverTempFault = Err_Read(48)==true?1:0;
vehicleInfo2uds.ChargeOverTempFault = Err_Read(49)==true?1:0;
vehicleInfo2uds.DcPosRelayAdhFault = Err_Read(3)==true?1:0;;
vehicleInfo2uds.DcNegRelayAdhFault = Err_Read(3)==true?1:0;;
vehicleInfo2uds.AcPosRelayAdhFault = Err_Read(4)==true?1:0;
vehicleInfo2uds.AcNegRelayAdhFault = Err_Read(4)==true?1:0;
vehicleInfo2uds.HvInterlockFault = DCU_SendState.HV_DSG_CHECJ_Signal_Filter || DCU_SendState.HV_DSG_CHECJ_2_Signal_Filter?1:0;
vehicleInfo2uds.CcCc2RelayCtrlInv = Err_Read(53)==true?1:0;
vehicleInfo2uds.CpCc1RelayCtrlInv = Err_Read(54)==true?1:0;
vehicleInfo2uds.CurrDcVolt = (uint16_t)Volt_SamplData.BAT_B_Reverse_Voltage;
vehicleInfo2uds.ChargeTemp = DCU_SendState.GUN_TEMP_Filter;
vehicleInfo2uds.BoardTemp = Get_Sampl_Data.TEMP1();
vehicleInfo2uds.OtaModeSts = 0;//<2F><>
/********************end**************************/
if(battery_volt_state < NORM_VOLT)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>
vehicleInfo2uds.BattLow = 1;
else
vehicleInfo2uds.BattLow = 0;
if(battery_volt_state > NORM_VOLT)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>
vehicleInfo2uds.BattHigh = 1;
else
vehicleInfo2uds.BattHigh = 0;
}
/* uds parameter init*/
void UdsApi_ParaInit(void)
{
#if BOOTLOADER_CODE_FLAG
memcpy(gDIDCache.DID_BootSoftware, BOOTLOADER_SOFTWARE_VERSION, DIDSize[BootSoftware]);
#else
memcpy(gDIDCache.DID_BootSoftwareNumber, (uint8_t *)bootSwAddr, DIDSize[BootSoftwareNumber]);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ,<2C><><EFBFBD>Ȳ<EFBFBD><C8B2><EFBFBD><EFBFBD>ÿո<C3BF><D5B8><EFBFBD><EFBFBD><EFBFBD>
memcpy(gDIDCache.DID_ECUManufacturerSparePartNumber, "2109140-SZ01", DIDSize[ECUManufacturerSparePartNumber]);
memcpy(gDIDCache.DID_SystemSupplierIdentifierData, "8926 ", DIDSize[SystemSupplierIdentifierData]);
memcpy(gDIDCache.DID_SystemName, "DCU ", DIDSize[SystemName]);
memcpy(gDIDCache.DID_VehicleManufacturerECUHardwareNumber, "HW:C.1.0", DIDSize[VehicleManufacturerECUHardwareNumber]);
memcpy(gDIDCache.DID_VehicleManufacturerECUSoftwareNumber, "SW:1.00.C_240312_8926_00", DIDSize[VehicleManufacturerECUSoftwareNumber]);
memcpy(gDIDCache.DID_SystemSupplierECUHardwareNumber, "HW:C.1.0", DIDSize[SystemSupplierECUHardwareNumber]);
memcpy(gDIDCache.DID_SystemSupplierECUSoftwareNumber, Version(), DIDSize[SystemSupplierECUSoftwareNumber]);
memcpy(gDIDCache.DID_ECUSerialNumber, "R2X00001", DIDSize[ECUSerialNumber]);
memset(gDIDCache.DID_VehicleIdentificationNumber, 0x00, DIDSize[VehicleIdentificationNumber]);
gDIDCache.DID_CurrentDCVolt[0] = MSB(0);
gDIDCache.DID_CurrentDCVolt[1] = LSB(0);
gDIDCache.DID_DCUVariousTempProtectVal[0] = 100 + 40;
gDIDCache.DID_DCUVariousTempProtectVal[1] = 120 + 40;
gDIDCache.DID_DCVoltProtectVal[0] = MSB(520*10);
gDIDCache.DID_DCVoltProtectVal[1] = LSB(520*10);
gDIDCache.DID_InsulationDectVolt[0] = MSB(500*10);
gDIDCache.DID_InsulationDectVolt[1] = LSB(500*10);
gDIDCache.DID_DCUVariousCurrentTempVal[0] = 25;
gDIDCache.DID_DCUVariousCurrentTempVal[1] = 25;
#endif
}
/* uds 1ms task */
void UdsApi_1ms_task(void)
{
UdsProcTask();
}
/* uds 10ms task */
void UdsApi_10ms_task(void)
{
UdsApi_VehicleInfo2UdsProc();
Pwr_BatVoltRangeMonitor();
}
/* 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;
}
/* <20><>ѯ<EFBFBD>Ƿ<EFBFBD>ΪUDS<44><53>Ӧ<EFBFBD><D3A6>Ϣ */
bool UdsApi_Is_UdsResponeMsg(uint16_t msg_id)
{
bool bRst=false;
if (msg_id == UDS_PHY_RX_ID) {
bRst = true;
}
return bRst;
}
/* ȡBootLoader<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E6B1BE>ַ */
void UdsApi_BootSwAddr_Get(void)
{
bootSwAddr = BKP->DR42;
bootSwAddr = (bootSwAddr << 16) | BKP->DR41;
}
/**
* @breif: <EFBFBD><EFBFBD><EFBFBD><EFBFBD>B+<EFBFBD><EFBFBD>ѹ
*
* @param void
*
* @return None
*/
static void Pwr_BatVoltRangeMonitor(void)
{
uint8_t i/*,sned_msg[10]*/;
uint16_t batt_mon_value,tempVolt;
PWR_BATT_VOLT_STATE_ENUM temp_volt_state;
static uint8_t up_chage_flag = FALSE,dn_chage_flag=FALSE;
static uint16_t wait_change_time = 0x00;
tempVolt = (uint16_t)(vehicleInfo2uds.Snapshot.BatVolt*10); //0.01v
if( tempVolt<350)return;
batt_mon_value=tempVolt;
temp_volt_state = battery_volt_state;
if(batt_mon_value > pwr_volt_state_range_cfg[temp_volt_state].VMax_Cfg)
{
for(i = temp_volt_state ;i<VOLT_STATE_NUM;i++)
{
if((batt_mon_value > pwr_volt_state_range_cfg[i].VMin_Cfg) &&
batt_mon_value < pwr_volt_state_range_cfg[i].VMax_Cfg)
{
break;
}
}
if(i>=VOLT_STATE_NUM)
{
i = VOLT_STATE_NUM-1;
}
dn_chage_flag = FALSE;
if(up_chage_flag == FALSE)
{
up_chage_flag = TRUE;
wait_change_time = pwr_volt_state_range_cfg[temp_volt_state].MaxTimeCfg;
}
temp_volt_state = (PWR_BATT_VOLT_STATE_ENUM)i;
}
else if(batt_mon_value < pwr_volt_state_range_cfg[temp_volt_state].VMin_Cfg)
{
for(i = temp_volt_state ;i>0;i--)
{
if((batt_mon_value > pwr_volt_state_range_cfg[i].VMin_Cfg) &&
batt_mon_value < pwr_volt_state_range_cfg[i].VMax_Cfg)
{
break;
}
}
up_chage_flag = FALSE;
if(dn_chage_flag == FALSE)
{
dn_chage_flag = TRUE;
wait_change_time = pwr_volt_state_range_cfg[temp_volt_state].MaxTimeCfg;
}
temp_volt_state = (PWR_BATT_VOLT_STATE_ENUM)i;
}
else
{
dn_chage_flag=FALSE;
up_chage_flag=FALSE;
}
if(0u != wait_change_time)
{
wait_change_time--;
}
else if((battery_volt_state != temp_volt_state)&&(batt_mon_value>50))
{
battery_volt_state = temp_volt_state;
}
else
{
}
}