2024-05-26 08:08:32 +08:00

593 lines
18 KiB
C

/**------------------历史版本信息-------------------------------------------------------
** 修 改 人:
** 版 本: V1.0
** 日 期:
** 描 述: 初始版本
**-------------------------------------------------------------------------------------*/
#include "CanIf.h"
//#include "CanNM.h"
/***************************************************************************************/
static CanIf_ControllerModeType TeCanIf_e_ControllerMode;
static CanTrcv_WorkModeType TeCanTrcv_e_WorkMode;
static ComUint8 SeCanIf_u_IsInit;
static ComUint8 SeCanIf_u_WakeEvent;
static ComUint32 SeCanIf_u_TxQueueCounter;
static CanIf_TxQueueType TsCanIf_h_TxQueue[CANIF_CFG_MAX_TX_HANDLE];
extern unsigned char TransmitCAN_Message(unsigned int ID,unsigned char Dlc,unsigned char *Data);
/****************************************************************************************
@函数名称 : void ClearCanIf_Queue(void)
@参数 : void
@返回值 : void
@描述 :
@最后编辑时间 : 2015/04/08
@版本 : V1.0
@备注 :
*****************************************************************************************/
void ClearCanIf_Queue(void)
{
ComUint8 LeCanIf_u_Index;
SeCanIf_u_TxQueueCounter = 0;
for(LeCanIf_u_Index = 0; LeCanIf_u_Index < CANIF_CFG_MAX_TX_HANDLE; LeCanIf_u_Index++)
{
TsCanIf_h_TxQueue[LeCanIf_u_Index].eCanIf_CanId = 0x00;
TsCanIf_h_TxQueue[LeCanIf_u_Index].eCanIf_CanDlc = 0x00;
TsCanIf_h_TxQueue[LeCanIf_u_Index].eQueued = 0x00;
TsCanIf_h_TxQueue[LeCanIf_u_Index].eCanIf_Txdata[0] = 0x00;
TsCanIf_h_TxQueue[LeCanIf_u_Index].eCanIf_Txdata[1] = 0x00;
TsCanIf_h_TxQueue[LeCanIf_u_Index].eCanIf_Txdata[2] = 0x00;
TsCanIf_h_TxQueue[LeCanIf_u_Index].eCanIf_Txdata[3] = 0x00;
TsCanIf_h_TxQueue[LeCanIf_u_Index].eCanIf_Txdata[4] = 0x00;
TsCanIf_h_TxQueue[LeCanIf_u_Index].eCanIf_Txdata[5] = 0x00;
TsCanIf_h_TxQueue[LeCanIf_u_Index].eCanIf_Txdata[6] = 0x00;
TsCanIf_h_TxQueue[LeCanIf_u_Index].eCanIf_Txdata[7] = 0x00;
}
}
/****************************************************************************************
@函数名称 : void DeInitCanIf_Parameter(void)
@参数 : void
@返回值 : void
@描述 :
@最后编辑时间 : 2015/03/14
@版本 : V1.0
@备注 :
*****************************************************************************************/
void DeInitCanIf_Parameter(void)
{
SeCanIf_u_IsInit = COM_FALSE;
}
/****************************************************************************************
@函数名称 : void ReInitCanIf_Parameter(void)
@参数 : void
@返回值 : void
@描述 :
@最后编辑时间 : 2015/05/7
@版本 : V1.0
@备注 :
*****************************************************************************************/
void ReInitCanIf_Parameter(void)
{
SeCanIf_u_IsInit = COM_TRUE;
}
/****************************************************************************************
@函数名称 : void InitCanIf_Parameter(void)
@参数 : void
@返回值 : void
@描述 :
@最后编辑时间 : 2015/03/14
@版本 : V1.0
@备注 : called by main
*****************************************************************************************/
void InitCanIf_Parameter(void)
{
TeCanIf_e_ControllerMode = CANIF_CS_STOP;
TeCanTrcv_e_WorkMode = CANTRCV_STANDBY;
ClearCanIf_Queue();
SeCanIf_u_IsInit = COM_TRUE;
}
/****************************************************************************************
@函数名称 : ComStd_ReturnType SetCanIf_BusoffEvent(void)
@参数 : void
@返回值 : ComStd_ReturnType
@描述 :
@最后编辑时间 : 2015/03/14
@版本 : V1.0
@备注 : called by can module to indicator busoff event has happened
*****************************************************************************************/
#if 0
ComStd_ReturnType SetCanIf_BusoffEvent(CanIf_ControllerErrorType LeCanIf_u_BusoffEvent)
{
(void)LeCanIf_u_BusoffEvent;
SetCanSM_BusoffEvent(LeCanIf_u_BusoffEvent);
return COM_E_OK;
}
#endif
/****************************************************************************************
@函数名称 : ComStd_ReturnType ResetCanIf_Controller(ComUint8 LeCanIf_u_Channel)
@参数 : LeCanIf_u_Channel
@返回值 : ComStd_ReturnType
@描述 :
@最后编辑时间 : 2015/04/13
@版本 : V1.0
@备注 : called by can module to indicator busoff event has happened
*****************************************************************************************/
ComStd_ReturnType ResetCanIf_Controller(ComUint8 LeCanIf_u_Channel)
{
(void)LeCanIf_u_Channel;
#if 0
ResetCan_Controller();
#endif
return COM_E_OK;
}
/****************************************************************************************
@函数名称 : ComStd_ReturnType SetCanIf_WakeUpEvent(CanIf_WakeUpSourceType LeCanIf_u_WakeUpSource)
@参数 : CanIf_WakeUpSourceType LeCanIf_e_WakeUpSource
@返回值 : ComStd_ReturnType
@描述 :
@最后编辑时间 : 2015/03/14
@版本 : V1.0
@备注 : called by can/cantrcv/ICU module to indicator wakeup event has happened
*****************************************************************************************/
ComStd_ReturnType SetCanIf_WakeUpEvent(CanIf_WakeUpSourceType LeCanIf_e_WakeUpSource)
{
SeCanIf_u_WakeEvent |= LeCanIf_e_WakeUpSource;
//SetCanNM_NmMode(NMStatus_WAITCHECK,NoActiveLoad);
return COM_E_OK;
}
ComStd_ReturnType ClrCanIf_WakeUpEvent(CanIf_WakeUpSourceType LeCanIf_e_WakeUpSource)
{
SeCanIf_u_WakeEvent &= ~LeCanIf_e_WakeUpSource;
return COM_E_OK;
}
ComStd_ReturnType GetCanIf_WakeUpEvent(CanIf_WakeUpSourceType *LeCanIf_e_WakeUpSource)
{
*LeCanIf_e_WakeUpSource = SeCanIf_u_WakeEvent;
return COM_E_OK;
}
/****************************************************************************************
@函数名称 : ComStd_ReturnType SetCanIf_ControllerMode(CanIf_ControllerModeType LeCanIf_e_RequestedMode)
@参数 : CanIf_ControllerModeType LeCanIf_e_RequestedMode
@返回值 : ComStd_ReturnType
@描述 : Call by CanSM
@最后编辑时间 : 2015/03/14
@版本 : V1.0
@备注 : CanIf Layer Set Controller RequestMode
*****************************************************************************************/
ComStd_ReturnType SetCanIf_ControllerMode(CanIf_ControllerModeType LeCanIf_e_RequestedMode)
{
#if 0
SetCan_ControllerMode(LeCanIf_e_RequestedMode);
TeCanIf_e_ControllerMode = LeCanIf_e_RequestedMode;
#endif
return COM_E_OK;
}
/****************************************************************************************
@函数名称 : ComStd_ReturnType GetCanIf_ControllerMode(CanIf_ControllerModeType *LeCanIf_e_ControllerModePtr)
@参数 : CanIf_ControllerModeType *LeCanIf_e_ControllerModePtr
@返回值 : ComStd_ReturnType
@描述 :
@最后编辑时间 : 2015/03/14
@版本 : V1.0
@备注 : Upper Layer Get Controller Mode
*****************************************************************************************/
ComStd_ReturnType GetCanIf_ControllerMode(CanIf_ControllerModeType *LeCanIf_e_ControllerModePtr)
{
*LeCanIf_e_ControllerModePtr = TeCanIf_e_ControllerMode;
return COM_E_OK;
}
/****************************************************************************************
@函数名称 : ComStd_ReturnType GetCanIf_TransceiverMode(CanTrcv_WorkModeType *LeCanIf_e_WorkModePtr)
@参数 : CanTrcv_WorkModeType *LeCanIf_e_WorkModePtr
@返回值 : ComStd_ReturnType
@描述 :
@最后编辑时间 : 2015/03/14
@版本 : V1.0
@备注 : Upper Layer Get Transceive Mode
*****************************************************************************************/
ComStd_ReturnType GetCanIf_TransceiverMode(CanTrcv_WorkModeType *LeCanIf_e_WorkModePtr)
{
*LeCanIf_e_WorkModePtr = TeCanTrcv_e_WorkMode;
return COM_E_OK;
}
/****************************************************************************************
@函数名称 : ComStd_ReturnType SetCanIf_TransceiverMode(CanTrcv_WorkModeType LeCanIf_e_WorkMode)
@参数 : CanTrcv_WorkModeType LeCanIf_e_WorkMode
@返回值 : ComStd_ReturnType
@描述 :
@最后编辑时间 : 2015/03/14
@版本 : V1.0
@备注 :
*****************************************************************************************/
ComStd_ReturnType SetCanIf_TransceiverMode(CanTrcv_WorkModeType LeCanIf_e_WorkMode)
{
SetCanTrcv_WorkMode(LeCanIf_e_WorkMode);
TeCanTrcv_e_WorkMode = LeCanIf_e_WorkMode;
return COM_E_OK;
}
/****************************************************************************************
@函数名称 : void RxIndicationCanIf_Messages(CanIf_HwHandleType LeCanIf_e_Hrh, CanIf_CanIdType LeCanIf_e_CanId, CanIf_CanDlcType LeCanIf_e_CanDlc, const CanIf_CanDataType* LeCanIf_e_CanSduPtr)
@参数 : CanIf_HwHandleType LeCanIf_e_Hrh, CanIf_CanIdType LeCanIf_e_CanId, CanIf_CanDlcType LeCanIf_e_CanDlc, const CanIf_CanDataType* LeCanIf_e_CanSduPtr
@返回值 : void
@描述 :
@最后编辑时间 : 2015/03/16
@版本 : V1.0
@备注 :
*****************************************************************************************/
void RxIndicationCanIf_Messages(CanIf_HwHandleType LeCanIf_e_Hrh, CanIf_CanIdType LeCanIf_e_CanId, CanIf_CanDlcType LeCanIf_e_CanDlc, CanIf_CanDataType* LeCanIf_e_CanSduPtr)
{
CanIf_PduIdType LeCanIf_e_RxPduId = 0;
uint16_t temp;
(void)LeCanIf_e_Hrh;
/* No Rx-Pdus or Ranges configured. Nothing to search. */
if (0 != CANIF_CFG_GENERIC(eMaxRxPDUHandle))
{
/* Checked for invalid RxPduId earlier */
for(LeCanIf_e_RxPduId = 0;LeCanIf_e_RxPduId < CANIF_CFG_GENERIC(eMaxRxPDUHandle);LeCanIf_e_RxPduId++)
{
temp = CANIF_CFG_GENERIC(eMaxRxPDUHandle);
temp = CANIF_CFG_CANRX_TABLE(LeCanIf_e_RxPduId,eRxCanId);
if( CANIF_CFG_CANRX_TABLE(LeCanIf_e_RxPduId,eRxCanId) == LeCanIf_e_CanId )
{
/* ID matches - Pdu identified */
/* DLC check - if configured DLC == 0 the following condition is always false and DLC check is deactivated */
CanIf_RxIndicationType rxIndicationFct;
if (LeCanIf_e_CanDlc != CANIF_CFG_CANRX_TABLE(LeCanIf_e_RxPduId, eRxCanDlc) )
{
/*DLC Error*/
rxIndicationFct = CANIF_CFG_CANRX_TABLE(LeCanIf_e_RxPduId,eCanIf_RxErrorFct);
if(COM_NULL_PTR != rxIndicationFct)
{
rxIndicationFct(LeCanIf_e_Hrh,LeCanIf_e_CanId,LeCanIf_e_CanDlc,LeCanIf_e_CanSduPtr);
}
else
{
/*Avoid Warning*/
}
}
else
{
rxIndicationFct = CANIF_CFG_CANRX_TABLE(LeCanIf_e_RxPduId,eCanIf_RxIndicationFct);
if(COM_NULL_PTR != rxIndicationFct)
{
rxIndicationFct(LeCanIf_e_Hrh,LeCanIf_e_CanId,LeCanIf_e_CanDlc,LeCanIf_e_CanSduPtr);
}
else
{
/*Avoid Warning*/
}
}
break;
}
else
{
/*Avoid Warning*/
}
}
}
else
{
/*Avoid Warning*/
}
}
/****************************************************************************************
@函数名称 : ComStd_ReturnType TransmitCanIf_Buffer(CanIf_CanIdType LeCanIf_t_TxCanID,CanIf_CanDlcType LeCanIf_t_TxCanDlc,CanIf_CanDataType *LeCanIf_t_TxCanDataPtr)
@参数 : CanIf_CanIdType LeCanIf_t_TxCanID,CanIf_CanDlcType LeCanIf_t_TxCanDlc,CanIf_CanDataType *LeCanIf_t_TxCanDataPtr
@返回值 : ComStd_ReturnType
@描述 :
@最后编辑时间 : 2015/03/14
@版本 : V1.0
@备注 :
*****************************************************************************************/
ComStd_ReturnType TransmitCanIf_Buffer(CanIf_CanIdType LeCanIf_t_TxCanID,CanIf_CanDlcType LeCanIf_t_TxCanDlc,CanIf_CanDataType *LeCanIf_t_TxCanDataPtr)
{
Can_ReturnType txResult = CAN_OK; /*or CAN_OK*/
#if 0
AC_DiagResp.RcvId = LeCanIf_t_TxCanID;
AC_DiagResp.RcvDLC = LeCanIf_t_TxCanDlc;
AC_DiagResp.Data[0] = *LeCanIf_t_TxCanDataPtr++;
AC_DiagResp.Data[1] = *LeCanIf_t_TxCanDataPtr++;
AC_DiagResp.Data[2] = *LeCanIf_t_TxCanDataPtr++;
AC_DiagResp.Data[3] = *LeCanIf_t_TxCanDataPtr++;
AC_DiagResp.Data[4] = *LeCanIf_t_TxCanDataPtr++;
AC_DiagResp.Data[5] = *LeCanIf_t_TxCanDataPtr++;
AC_DiagResp.Data[6] = *LeCanIf_t_TxCanDataPtr++;
AC_DiagResp.Data[7] = *LeCanIf_t_TxCanDataPtr;
#endif
CanIf_EnterCritical();
#if 0
txResult = CanSnd(CanBufDsc[9]);//TransmitCAN_Message(LeCanIf_t_TxCanID,LeCanIf_t_TxCanDlc,LeCanIf_t_TxCanDataPtr);
#endif
txResult = TransmitCAN_Message(LeCanIf_t_TxCanID,LeCanIf_t_TxCanDlc,LeCanIf_t_TxCanDataPtr);
CanIf_LeaveCritical();
/*发送失败*/
if(CAN_NOT_OK == txResult)
{
CanIf_uint8Type LeCanIf_e_TxPduId;
for(LeCanIf_e_TxPduId = 0;LeCanIf_e_TxPduId < CANIF_CFG_GENERIC(eMaxTxPDUHandle);LeCanIf_e_TxPduId++)
{
if( CANIF_CFG_CANTX_TABLE(LeCanIf_e_TxPduId,eTxCanId) == LeCanIf_t_TxCanID )
{
CanIf_uint8Type LeCanIf_e_TxDataCycle;
TsCanIf_h_TxQueue[CANIF_CFG_CANTX_TABLE(LeCanIf_e_TxPduId,eQueuedIndex)].eCanIf_CanId = LeCanIf_t_TxCanID;
TsCanIf_h_TxQueue[CANIF_CFG_CANTX_TABLE(LeCanIf_e_TxPduId,eQueuedIndex)].eCanIf_CanDlc = LeCanIf_t_TxCanDlc;
for(LeCanIf_e_TxDataCycle = 0;LeCanIf_e_TxDataCycle < LeCanIf_t_TxCanDlc;LeCanIf_e_TxDataCycle++)
{
TsCanIf_h_TxQueue[CANIF_CFG_CANTX_TABLE(LeCanIf_e_TxPduId,eQueuedIndex)].eCanIf_Txdata[LeCanIf_e_TxDataCycle] = LeCanIf_t_TxCanDataPtr[LeCanIf_e_TxDataCycle];
}
TsCanIf_h_TxQueue[CANIF_CFG_CANTX_TABLE(LeCanIf_e_TxPduId,eQueuedIndex)].eQueued = 1;
SeCanIf_u_TxQueueCounter |= ( 1 << (CANIF_CFG_CANTX_TABLE(LeCanIf_e_TxPduId,eQueuedIndex)) );
break;
}
else
{
}
}
}
else
{
/*Tx OK == do nothing */
}
return (ComStd_ReturnType)txResult;
}
/****************************************************************************************
@函数名称 : void TreatCanIf_TxQueue(void)
@参数 : void
@返回值 : void
@描述 :
@最后编辑时间 : 2015/04/08
@版本 : V1.0
@备注 :
*****************************************************************************************/
#if 0
void TreatCanIf_TxQueue(void)
{
if(0 != SeCanIf_u_TxQueueCounter)
{
Can_ReturnType txResult = CAN_NOT_OK;
CanIf_uint8Type LeCanIf_e_Index = 0;
for(LeCanIf_e_Index = 0;LeCanIf_e_Index < CANIF_CFG_MAX_TX_HANDLE;LeCanIf_e_Index++)
{
if(0 != TsCanIf_h_TxQueue[LeCanIf_e_Index].eQueued)
{
txResult = TransmitCAN_Message(TsCanIf_h_TxQueue[LeCanIf_e_Index].eCanIf_CanId,TsCanIf_h_TxQueue[LeCanIf_e_Index].eCanIf_CanDlc,TsCanIf_h_TxQueue[LeCanIf_e_Index].eCanIf_Txdata);
if(CAN_OK == txResult)
{
TsCanIf_h_TxQueue[LeCanIf_e_Index].eQueued = 0;
SeCanIf_u_TxQueueCounter &= ~( 1 << LeCanIf_e_Index );
}
else
{
}
break;
}
else
{
}
}
}
else
{
}
}
#endif
/****************************************************************************************
@函数名称 : void ConfirmCanIf_TxOK(CanIf_CanIdType LeCanIf_t_TxCanID)
@参数 : LeCanIf_t_TxCanID
@返回值 : void
@描述 :
@最后编辑时间 : 2015/04/08
@版本 : V1.0
@备注 :
*****************************************************************************************/
#if 0
void ConfirmCanIf_TxOK(ComUint8 LeCanIf_e_Hrh,CanIf_CanIdType LeCanIf_t_TxCanID)
{
CanIf_PduIdType LeCanIf_e_TxPduId = 0;
if(0 != CANIF_CFG_MAX_TX_HANDLE)
{
/* Checked for invalid RxPduId earlier */
for(LeCanIf_e_TxPduId = 0;LeCanIf_e_TxPduId < CANIF_CFG_GENERIC(eMaxTxPDUHandle);LeCanIf_e_TxPduId++)
{
if( CANIF_CFG_CANTX_TABLE(LeCanIf_e_TxPduId,eTxCanId) == LeCanIf_t_TxCanID )
{
CanIf_TxConfirmationType TxConfirmationFct;
TxConfirmationFct = CANIF_CFG_CANTX_TABLE(LeCanIf_e_TxPduId,eCanIf_TxConfirmationFct);
if(COM_NULL_PTR != TxConfirmationFct)
{
TxConfirmationFct(LeCanIf_e_Hrh,LeCanIf_t_TxCanID);
}
else
{
/*Avoid Warning*/
}
break;
}
else
{
/*Avoid Warning*/
}
}
}
else
{
}
CanIf_EnterCritical();
TreatCanIf_TxQueue();
CanIf_LeaveCritical();
}
#endif
/****************************************************************************************
@函数名称 : void CanIf_MainFunction(void)
@参数 : void
@返回值 : void
@描述 : 10ms周期调用
@最后编辑时间 : 2015/03/14
@版本 : V1.0
@备注 : CanIf层TASK
*****************************************************************************************/
void CanIf_MainFunction(void)
{
if( COM_FALSE != SeCanIf_u_IsInit )
{
if( (CANIF_CS_STOP == TeCanIf_e_ControllerMode) && (CANTRCV_STANDBY == TeCanTrcv_e_WorkMode) )
{
/*有总线唤醒事件,在此增加代码*/
}
else
{
}
}
else
{
/*Avoid Warning*/
}
}