Click here for back issues.
https://www.simulationroom999.com/blog/diagnostic-communication-en-back-issue/
Introduction.
Explanation of the AUTOSAR-Dcm interface.
In this article, the source code of the actual interface part will be explained.
Functions for AUTOSAR-Dcm interface
Explanation of the AUTOSAR-Dcm interface functions are as follows.
- Dcm_ProvideRxBuffer
- Dcm_RxIndication
- PduR_DcmTransmit
- Dcm_TxConfirmation
- Dcm_MainFunction
These structural aspects need to be adjusted.
Well, the interface side will be easy because the difficulty is on the configuration side, which defines the internal behavior of Dcm.
Implementation of functions for AUTOSAR-Dcm interface
The following is the code.
PduInfoType *g_pDcmInfoType = NULL_PTR; // Reference to Dcm transmit/receive buffer
int g_rxcnt = 0; // Receive Counter
int g_txcnt = 0; // Transmission Counter
BufReq_ReturnType _PduR_CanTpCopyRxData(PduIdType PduId, PduInfoType *PduInfoPtr, PduLengthType *RxBufferSizePtr)
{
int i;
PduIdType dcmRxPduId;
PduInfoType *pDcmInfoType;
pDcmInfoType = g_pDcmInfoType;
if( pDcmInfoType != NULL_PTR ){
for (i = 0U; i < PduInfoPtr->SduLength; i++) {
pDcmInfoType->SduDataPtr[g_rxcnt++] = PduInfoPtr->SduDataPtr[i];
}
}
return(BUFREQ_OK);
}
BufReq_ReturnType _PduR_CanTpCopyTxData(PduIdType PduId, PduInfoType *PduInfoPtr, RetryInfoType *RetryInfoPtr, PduLengthType *TxDataCntPtr)
{
int i;
PduInfoType *pDcmInfoType = NULL_PTR;
pDcmInfoType = g_pDcmInfoType;
if( pDcmInfoType != NULL_PTR ){
for (i = 0U; i < PduInfoPtr->SduLength; i++) {
PduInfoPtr->SduDataPtr[i] = pDcmInfoType->SduDataPtr[g_txcnt++];
}
}
return(BUFREQ_OK);
}
Std_ReturnType PduR_DcmTransmit(PduIdType DcmTxPduId, const PduInfoType* PduInfoPtr) {
PduInfoType *pDcmInfoType;
CanTp_Transmit( canTxPduId, PduInfoPtr);
Dcm_ProvideTxBuffer( canTxPduId, &pDcmInfoType, PduInfoPtr->SduLength );
g_pDcmInfoType = pDcmInfoType;
return 0;
}
BufReq_ReturnType _PduR_CanTpStartOfReception(PduIdType PduId, const PduInfoType *PduInfoPtr, PduLengthType TpSduLength, PduLengthType *RxBufferSizePtr)
{
PduIdType dcmPduIdType;
PduInfoType *pDcmInfoType = NULL_PTR;
// Get buffer reference from Dcm
Dcm_ProvideRxBuffer( PduId, TpSduLength, &pDcmInfoType );
g_pDcmInfoType = pDcmInfoType;
g_rxcnt = 0; // Receive counter clear
g_txcnt = 0; // Transmission counter clear
return(BUFREQ_OK);
}
void _PduR_CanTpRxIndication(PduIdType PduId, NotifResultType Result)
{
Dcm_RxIndication(PduId ,Result);
}
void _PduR_CanTpTxConfirmation(PduIdType PduId, NotifResultType Result)
{
Dcm_TxConfirmation(PduId, Result);
}
// Called in 1[ms] cycles
void main_handler()
{
_WaitForSigleObject( hMutex,-1);
CanTp_MainFunction();
Dcm_MainFunction();
_ReleaseMutex(hMutex);
}
Explanation of functions for AUTOSAR-Dcm interface
Let me explain what this code does.
The key point is the following, which is defined in a global variable.
PduInfoType *g_pDcmInfoType = NULL_PTR; // Reference to Dcm transmit/receive buffer
int g_rxcnt = 0; // Receive Counter
int g_txcnt = 0; // Transmission Counter
The Dcm side manages the buffers for transmitting and receiving.
To refer to them, g_pDcmInfoType is used.
The actual number of transmitting and receiving should be counted by g_rxcnt and g_txcnt.
The other function _PduR_CanTpStartOfReception is called at the start of reception, so this is where the buffer for Dcm management is acquired and the various counters are initialized.
That’s all for now, though it’s a simple explanation of how the interfaces add up.
Conclusion
- Review of AUTOSAR-Dcm interface functions.
- I implemented the interface functions of AUTOSAR-Dcm.
Click here for back issues.
コメント