b61c21c648
Signed-off-by: lidun <1084178170@qq.com>
405 lines
11 KiB
C
405 lines
11 KiB
C
|
||
#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; //电池状态标志
|
||
static const PWR_Volt_State_Config_Type pwr_volt_state_range_cfg[]= //10mv
|
||
{
|
||
{0, 650, 0x02, 0x02},
|
||
{630, 950, 0x02, 0x05},
|
||
{900, 1600, 0x02, 0x05},
|
||
{1550, 1850, 0x02, 0x05},
|
||
{1820, 2400, 0x02, 0x05},
|
||
};
|
||
|
||
|
||
/* uds强制清除硬件自身DTC相关故障标志位 */
|
||
void UdsApi_HardwareFault_ForceClear(void)
|
||
{
|
||
//硬件强制清除自身DTC相关故障,请根据实际情况填入
|
||
}
|
||
|
||
/* 硬件向UDS更新车身信号 */
|
||
void UdsApi_VehicleInfo2UdsProc(void)
|
||
{
|
||
vehicleInfo2uds.IgnSts = 1;
|
||
|
||
/********************请根据实际情况将值实时更新给UDS**************************/
|
||
vehicleInfo2uds.Snapshot.BatVolt = (uint8_t)(Volt_SamplData.KL30_Volt*10); //请传入实际的KL30电压值,单位为0.1V
|
||
// busoff计数器,进入busoff后每恢复一次就累加1。CAN总线正常后退出busoff就清零。
|
||
// vehicleInfo2uds.BusoffCnt = can_bus_off_recovery_times(1); // busoff计数器,进入busoff后每恢复一次就累加1。CAN总线正常后退出busoff就清零。
|
||
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;//无法检测
|
||
vehicleInfo2uds.ChargeTempDerateFault = 0;//没做逻辑
|
||
vehicleInfo2uds.InterTempDerateFault = 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 = 0;//无法检测
|
||
vehicleInfo2uds.CpCc1RelayCtrlInv = 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;//无
|
||
/********************end**************************/
|
||
|
||
if(battery_volt_state < NORM_VOLT)//供电电源低
|
||
vehicleInfo2uds.BattLow = 1;
|
||
else
|
||
vehicleInfo2uds.BattLow = 0;
|
||
|
||
if(battery_volt_state > NORM_VOLT)//供电电源高
|
||
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]);
|
||
//以下请根据实际填入默认数据 ,长度不足用空格代替
|
||
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:1.0.C", DIDSize[VehicleManufacturerECUHardwareNumber]);
|
||
memcpy(gDIDCache.DID_VehicleManufacturerECUSoftwareNumber, "SW:1.00.C_240204_8926_00", DIDSize[VehicleManufacturerECUSoftwareNumber]);
|
||
memcpy(gDIDCache.DID_SystemSupplierECUHardwareNumber, "xxxxxxxx", DIDSize[SystemSupplierECUHardwareNumber]);
|
||
memcpy(gDIDCache.DID_SystemSupplierECUSoftwareNumber, "xxxxxxxxxxxxxxxxxxxxx", 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 生成随机数 */
|
||
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;
|
||
}
|
||
|
||
/* 查询是否为UDS响应消息 */
|
||
bool UdsApi_Is_UdsResponeMsg(uint16_t msg_id)
|
||
{
|
||
bool bRst=false;
|
||
|
||
if (msg_id == UDS_PHY_RX_ID) {
|
||
bRst = true;
|
||
}
|
||
return bRst;
|
||
}
|
||
|
||
/* 取BootLoader软件版本地址 */
|
||
void UdsApi_BootSwAddr_Get(void)
|
||
{
|
||
bootSwAddr = BKP->DR42;
|
||
bootSwAddr = (bootSwAddr << 16) | BKP->DR41;
|
||
}
|
||
|
||
|
||
/**
|
||
* @breif: 监控B+电压
|
||
*
|
||
* @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
|
||
{
|
||
|
||
}
|
||
}
|