1.5wuling_zhuanjietou/UDS/uds_manage.c
2024-10-17 09:06:51 +08:00

313 lines
7.1 KiB
C

/*!
* @file uds_manage.c
* @brief interaction layer between UDS service and TP layer.
*
*/
#include "uds_config.h"
static uint8_t HAL_UDS_Rx_Buffer[8]; /*!< UDS Receive Buffer */
bool HAL_Response_Pocessing; /*!< UDS Response Processing */
static uint8_t HAL_UDS_RECEIVE_LENGTH; /*!< UDS Receive Length */
static uint8_t HAL_UDS_TRANSMIT_LENGTH; /*!< UDS Transmit Length */
static uint32_t HAL_UDS_TRANSMIT_ID; /*!< UDS Transmit ID */
//extern flexcan_state_t canCom0_State[3];
//flexcan_msgbuff_t recvBuff;
/*!
* @brief HAL_UDS_CallBack
* UDS Transmit and Receive interrupt callback
*
* @param instance instance
* @param eventType interrupt event type
* @param state flexCAN state
*/
/*!
* @brief HAL_UDS_Init
* Initialize function for CAN UDS
*
*/
/*!
* @brief HAL_UDS_Rx_DLC
* Return the DLC of the Rx Msg
*
* @return the DLC of the Rx Msg
*/
uint8_t HAL_UDS_Rx_DLC(void)
{
return HAL_UDS_RECEIVE_LENGTH;
}
/*!
* @brief HAL_UDS_Get_Buf
* Copy the rx msg data from the temp buffer to appl_data_ptr
*
* @param appl_data_ptr pointer to the destination buffer
*/
void HAL_UDS_Get_Buf(uint8_t* appl_data_ptr)
{
uint8_t index;
for(index = 0;index<HAL_UDS_RECEIVE_LENGTH;index++)
{
appl_data_ptr[index] = HAL_UDS_Rx_Buffer[index];
}
}
/*!
* @brief HAL_UDS_PHY_Rx_Callback
* The physical message rx callback function
*
* @param p_l_can_data_ptr the can message source buffer address
* @param p_l_can_msg_dlc the can data length of the can message
*
*/
void HAL_UDS_PHY_Rx_Callback(U8 *p_l_can_data_ptr, U8 p_l_can_msg_dlc)
{
uint8_t index;
HAL_UDS_RECEIVE_LENGTH = p_l_can_msg_dlc;
for(index = 0;index<HAL_UDS_RECEIVE_LENGTH;index++)
{
HAL_UDS_Rx_Buffer[index] = p_l_can_data_ptr[index];
}
TP_D_UUData_Indication_Physical();
}
/*!
* @brief HAL_UDS_FUN_Rx_Callback
* The functional message rx callback function
*
* @param p_l_can_data_ptr the can message source buffer address
* @param p_l_can_msg_dlc the can data length of the can message
*
*/
void HAL_UDS_FUN_Rx_Callback(U8 *p_l_can_data_ptr, U8 p_l_can_msg_dlc)
{
uint8_t index;
HAL_UDS_RECEIVE_LENGTH = p_l_can_msg_dlc;
for(index = 0;index<HAL_UDS_RECEIVE_LENGTH;index++)
{
HAL_UDS_Rx_Buffer[index] = p_l_can_data_ptr[index];
}
TP_D_UUData_Indication_Functional();
}
/*!
* @brief HAL_UDS_Tx_Callback
* The UDS message transmit interrupt callback function
*
*/
void HAL_UDS_Tx_Callback(void)
{
TP_D_UUData_Confirm();
}
/*!
* @brief HAL_UDS_Set_Tx_DLC
* Set the data length of the tx message
*
* @param in_dlc the data lenght of the tx message
*/
void HAL_UDS_Set_Tx_DLC(uint8_t in_dlc)
{
HAL_UDS_TRANSMIT_LENGTH = in_dlc;
}
/*!
* @brief HAL_UDS_Set_Tx_ID
* Set the transmit ID
*
* @param id 0 for physical ID; 1 for functional ID;
*/
void HAL_UDS_Set_Tx_ID(uint8_t id)
{
if(id == 0)
{
HAL_UDS_TRANSMIT_ID = UDS_PHY_RX_ID;
}
else
{
HAL_UDS_TRANSMIT_ID = UDS_PHY_RX_ID;
}
}
/*!
* @brief HAL_UDS_Set_Tx_Buf
* Set the data length of the tx message
*
* @param in_buf the data lenght of the tx message
*/
void HAL_UDS_Set_Tx_Buf(uint8_t* in_buf)
{
uint8_t index;
can_msg_t TxData;
TxData.id = HAL_UDS_TRANSMIT_ID;
TxData.dlc= HAL_UDS_TRANSMIT_LENGTH;
for(index =0;index<HAL_UDS_TRANSMIT_LENGTH;index++)
{
TxData.data[index] = in_buf[index];
}
TxData.flag = 1;
UdsService.UdsTxFlg=true;
TxQueueCan0In(TxData);
}
/*!
* @brief HAL_UDS_Transmit_Buffer_Empty
* The callback function for transmit buffer empty
*
*/
void HAL_UDS_Transmit_Buffer_Empty(void)
{
}
/*!
* @brief HAL_UDS_FF_Indication
* The receive callback function for first frame
*
* @param TPReceivexMessageLength Receive message length
*/
void HAL_UDS_FF_Indication(uint16_t TPReceivexMessageLength)
{
(void)TPReceivexMessageLength;
}
/*!
* @brief HAL_UDS_Change_Parameter_Confirm
* The callback funtion for parameter change
*
* @param Parameter Parameter
* @param ParameterChangeResult Parameter Changed result
*/
void HAL_UDS_Change_Parameter_Confirm(uint8_t Parameter,
uint8_t ParameterChangeResult)
{
(void)Parameter;
(void)ParameterChangeResult;
}
/*!
* @brief HAL_UDS_FF_Confirmation
* the tx callback function for first frame
*
*/
void HAL_UDS_FF_Confirmation(void)
{
}
/*!
* @brief HAL_UDS_Response_Confirm
* the tx callback function for response
*
* @param N_Result Result
*/
void HAL_UDS_Response_Confirm(uint8_t N_Result)
{
(void)N_Result;
UDS_Service_Transmit_Confirmed();
HAL_Response_Pocessing = false;
}
/*!
* @brief HAL_UDS_Indication
* the rx callback function for response
*
* @param TPReceivexMessageLength Receive Message Length
* @param N_Result Result
*/
void HAL_UDS_Indication(uint16_t TPReceivexMessageLength,
uint8_t N_Result)
{
uint8_t* tp_buf = TP_Get_Message_Buffer_Pointer();
UDS_Service_Response_Handler(TPReceivexMessageLength,N_Result,tp_buf);
}
/*!
* @brief HAL_UDS_Transmit_Pending_Response
* the transmit pending response for UDS
*
* @param SericeID Service ID
*/
void HAL_UDS_Transmit_Pending_Response(uint8_t SericeID,uint8_t ErrCode)//THT
{
uint8_t* tp_buf = TP_Get_Message_Buffer_Pointer();
uint8_t tp_dlc;
if(false == HAL_Response_Pocessing)
{
tp_buf[0] = 0x7F;
tp_buf[1] = SericeID;
tp_buf[2] = ErrCode;
tp_dlc = 3;
HAL_UDS_Set_Tx_ID(0);
TP_Transmit_Buffer_Filled();
TP_N_USData_Request((uint16_t)tp_dlc);
HAL_Response_Pocessing = true;
}
}
/*!
* @brief HAL_UDS_Transmit_Physical_Request
* the transmit physical request
*
* @param in_dlc DLC of the request message
* @param in_buf Data buffer pointer
*/
void HAL_UDS_Transmit_Physical_Request(uint16_t in_dlc, uint8_t* in_buf)
{
//TP_Get_Tx_Message_Buffer_Pointer();
uint8_t* tp_buf = TP_Get_Message_Buffer_Pointer();//TP_Get_Message_Buffer_Pointer();
uint16_t index;
uint16_t tp_dlc;
if(false == HAL_Response_Pocessing)
{
if(in_dlc != 0)
{
for(index=0;index<in_dlc;index++)
{
tp_buf[index] = in_buf[index];
}
tp_dlc = in_dlc;
HAL_UDS_Set_Tx_ID(0);
TP_Transmit_Buffer_Filled();
TP_N_USData_Request((uint16_t)tp_dlc);
HAL_Response_Pocessing = true;
}
}
}
/*!
* @brief HAL_UDS_Transmit_Functional_Request
* the transmit functional request
*
* @param in_dlc DLC of the request message
* @param in_buf Data buffer pointer
*/
void HAL_UDS_Transmit_Functional_Request(uint8_t in_dlc, uint8_t* in_buf)
{
uint8_t* tp_buf = TP_Get_Message_Buffer_Pointer();
uint8_t index;
uint8_t tp_dlc;
if(false == HAL_Response_Pocessing)
{
if(in_dlc != 0)
{
for(index=0;index<in_dlc;index++)
{
tp_buf[index] = in_buf[index];
}
tp_dlc = in_dlc;
HAL_UDS_Set_Tx_ID(1);
TP_Transmit_Buffer_Filled();
TP_N_USData_Request((uint16_t)tp_dlc);
HAL_Response_Pocessing = true;
}
}
}
/*
* @brief HAL_UDS_Periodic_Task
* the periodic tasks for UDS
*
*/
void HAL_UDS_Periodic_Task(void)
{
TP_Periodic_Task();
}