//*****************************************************************************
// (C) Automotive Lighting Reutlingen GmbH
// Tuebinger Strasse 123, 72762 Reutlingen, Germany
//
// Automotive Lighting Reutlingen GmbH owns all the rights to this work.
// This work shall not be copied, reproduced, used, modified, transferred
// or its information shall not be disclosed without the prior written
// authorization of Automotive Lighting Reutlingen GmbH.
//*****************************************************************************
//-----------------------------------------------------------------------------
/// \file ComBuf.c
///
/// \brief
///
/// \descr
///
/// Additional information can be found in the design description (Link:
/// MDDD)
///
/// \author Ramona-Andreea Bolboaca (f33613c)
/// mailTo:ramona-andreea.bolboaca(at)magnetimarelli.com
//-----------------------------------------------------------------------------
//=============================================================================
// Includes
//=============================================================================
#include
#include
//=============================================================================
// Generate buffer list over X-Macro
//=============================================================================
#define MAC_COMBUF_DECL_ENUM
//lint -e451 Header file repeatedly included but does not have a standard include guard
#include
//lint +e451 Header file repeatedly included but does not have a standard include guard
#undef MAC_COMBUF_DECL_ENUM
#define MAC_COMBUF_MAKE_TX_BUFFER
//lint -e451 Header file repeatedly included but does not have a standard include guard
#include
//lint +e451 Header file repeatedly included but does not have a standard include guard
#undef MAC_COMBUF_MAKE_TX_BUFFER
#define MAC_COMBUF_MAKE_RX_BUFFER
//lint -e451 Header file repeatedly included but does not have a standard include guard
#include
//lint +e451 Header file repeatedly included but does not have a standard include guard
#undef MAC_COMBUF_MAKE_RX_BUFFER
#define MAC_COMBUF_CREATE_BUFFER_LIST
//lint -e451 Header file repeatedly included but does not have a standard include guard
#include
//lint +e451 Header file repeatedly included but does not have a standard include guard
#undef MAC_COMBUF_CREATE_BUFFER_LIST
//=============================================================================
// Private functions declaration
//=============================================================================
static void ComBuf_TxConfirmation( ComBufID bufID, NotifResultType Result );
//=============================================================================
// Macros
//=============================================================================
// This is first ID which comes from AL Flasher
#define COMBUF_USER_DEF_SERVICE 0xBB
// Value which shall pe added to service ID for positive answer
#define COMBUF_POSITIVE_ANSWER 0x40
//=============================================================================
// Public functions definition
//=============================================================================
//-----------------------------------------------------------------------------
/// \brief
///
/// \descr
///
/// \param bufID
///
/// \return boolean
//-----------------------------------------------------------------------------
boolean ComBuf_RxRequestReceived(ComBufID bufID )
{
boolean ret = comBuf[bufID].requestReceived;
if ( ret == TRUE)
{
comBuf[bufID].requestReceived = FALSE;
}
return ret;
}
//-----------------------------------------------------------------------------
/// \brief
///
/// \descr
///
/// \param ucSID
/// \param NegCode
///
/// \return void
//-----------------------------------------------------------------------------
void ComBuf_TxNegResp( ComBufID bufID, uint8 ucSID, uint8 NegCode )
{
comBuf[bufID].pduTxMessage.SduLength = 3u;
comBuf[bufID].pduTxMessage.SduDataPtr[0] = 0x7Fu;
comBuf[bufID].pduTxMessage.SduDataPtr[1] = ucSID;
comBuf[bufID].pduTxMessage.SduDataPtr[2] = NegCode;
}
//-----------------------------------------------------------------------------
/// \brief
///
/// \descr
///
/// \param bufID
/// \param cmdLevel
/// \param ucSID
/// \param pMsgContext
///
/// \return void
//-----------------------------------------------------------------------------
void ComBuf_TxPosResp( ComBufID bufID, uint8_t cmdLevel, uint8 ucSID, MsgContextType *pMsgContext )
{
(void)ucSID;
if (cmdLevel == 0U)
{
#ifdef PRJ_TYP_Sb015
comBuf[bufID].pduTxMessage.SduDataPtr[cmdLevel] = COMBUF_USER_DEF_SERVICE + COMBUF_POSITIVE_ANSWER;
comBuf[bufID].pduTxMessage.SduDataPtr[cmdLevel + 1] = ucSID;
comBuf[bufID].pduTxMessage.SduLength += 2U;
#else
comBuf[bufID].pduTxMessage.SduDataPtr[cmdLevel] += (uint8)COMBUF_POSITIVE_ANSWER;
comBuf[bufID].pduTxMessage.SduLength += 1U;
#endif
comBuf[bufID].pduTxMessage.SduLength += pMsgContext->resDataLen ;
}
}
//-----------------------------------------------------------------------------
/// \brief
///
/// \descr
///
/// \param Result
///
/// \return void
//-----------------------------------------------------------------------------
void ComBuf_RxIndication( ComBufID bufID, NotifResultType Result )
{
/*if the request has failed, stop processing and free resources*/
if (Result != NTFRSLT_OK)
{
/* >> GAN:2008-02-06 In case any concurrent message is received here, block it*/
if (comBuf[bufID].rxBufferState != NO_CONCURRENT_REQUEST )
{
comBuf[bufID].rxBufferState = NO_CONCURRENT_REQUEST;
//return;
}
/* << GAN:2008-02-06 In case any concurrent message is received here, block it*/
//Dcm_ResetTimers();
//return;
}
else
{
if(comBuf[bufID].rxBufferState == CONCURRENT_REQUEST )
{
comBuf[bufID].rxBufferState = NO_CONCURRENT_REQUEST;
}
comBuf[bufID].requestReceived = TRUE; // Command received
}
}
//-----------------------------------------------------------------------------
/// \brief
///
/// \descr
///
/// \param Result
///
/// \return void
//-----------------------------------------------------------------------------
//=============================================================================
// Private functions definition
//=============================================================================
static void ComBuf_TxConfirmation( ComBufID bufID, NotifResultType Result )
{
// PRQA S 3112 1 // parameter not used at the moment
(void)Result;
comBuf[bufID].txBufferState = NO_CONCURRENT_REQUEST; // free the Tx-buffer (Dcm_PduTxMessage)
}
//-----------------------------------------------------------------------------
/// \brief
///
/// \descr
///
/// \param PduInfoPtr
///
/// \return BufReq_ReturnType
//-----------------------------------------------------------------------------
// PRQA S 1503 1 // not used at the moment
BufReq_ReturnType ComBuf_TxProvide(ComBufID bufID, PduInfoTypeComBufPtr* PduInfoPtr)
{
BufReq_ReturnType ret = BUFREQ_E_NOT_OK;
if( comBuf[bufID].txBufferState == NO_CONCURRENT_REQUEST )
{
comBuf[bufID].txBufferState = CONCURRENT_REQUEST;
comBuf[bufID].pduTxMessage.SduLength = comBuf[bufID].txBufferSize;
*PduInfoPtr = &comBuf[bufID].pduTxMessage;
ret = BUFREQ_OK;
}
return ret;
}
//-----------------------------------------------------------------------------
/// \brief
///
/// \descr
///
/// \param bufID
/// \param PduInfoPtr
///
/// \return BufReq_ReturnType
//-----------------------------------------------------------------------------
BufReq_ReturnType ComBuf_RxProvide( ComBufID bufID, PduInfoTypeComBufPtr* PduInfoPtr )
{
BufReq_ReturnType ret = BUFREQ_E_NOT_OK;
if( comBuf[bufID].rxBufferState == NO_CONCURRENT_REQUEST)
{
comBuf[bufID].rxBufferState = CONCURRENT_REQUEST;
comBuf[bufID].pduRxMessage.SduLength = comBuf[bufID].rxBufferSize;
*PduInfoPtr = &comBuf[bufID].pduRxMessage;
ret = BUFREQ_OK;
}
return ret;
}
//-----------------------------------------------------------------------------
/// \brief
///
/// \descr
///
/// \param bufID
///
/// \return PduInfoTypeComBufPtr
//-----------------------------------------------------------------------------
// PRQA S 1503 1 // not used at the moment
PduInfoTypeComBufPtr ComBuf_RxGetBuffer( ComBufID bufID )
{
return &comBuf[bufID].pduRxMessage;
}
//-----------------------------------------------------------------------------
/// \brief
///
/// \descr
///
/// \param bufID
///
/// \return PduInfoTypeComBufPtr
//-----------------------------------------------------------------------------
// PRQA S 1503 1 // not used at the moment
PduInfoTypeComBufPtr ComBuf_TxGetBuffer( ComBufID bufID )
{
return &comBuf[bufID].pduTxMessage;
}
//-----------------------------------------------------------------------------
/// \brief
///
/// \descr
///
/// \param bufID
///
/// \return void
//-----------------------------------------------------------------------------
//=============================================================================
// Public functions definition
//=============================================================================
void ComBuf_TxReset( ComBufID bufID )
{
comBuf[bufID].pduTxMessage.SduLength = 0;
}
//-----------------------------------------------------------------------------
/// \brief Interface helper for inserting new data in the Buffer Tx
///
/// \descr
///
/// \param bufID
/// \param data
///
/// \return uint8_t
//-----------------------------------------------------------------------------
// PRQA S 1503 1 // not used at the moment
uint16 ComBuf_TxAdd (ComBufID bufID, const uint8_t data )
{
if (comBuf[bufID].pduTxMessage.SduLength < comBuf[bufID].txBufferSize)
{
comBuf[bufID].pduTxMessage.SduDataPtr[comBuf[bufID].pduTxMessage.SduLength] = data;
comBuf[bufID].pduTxMessage.SduLength++;
}
return comBuf[bufID].pduTxMessage.SduLength;
}
//-----------------------------------------------------------------------------
/// \brief
///
/// \descr
///
/// \param bufID
///
/// \return uint16_t
//-----------------------------------------------------------------------------
// PRQA S 1503 1 // not used at the moment
uint16 ComBuf_TxGetBufferSize (ComBufID bufID)
{
return comBuf[bufID].txBufferSize;
}
//-----------------------------------------------------------------------------
/// \brief
///
/// \descr
///
/// \param bufID
///
/// \return uint16_t
//-----------------------------------------------------------------------------
// PRQA S 1503 1 // not used at the moment
uint16 ComBuf_RxGetBufferSize (ComBufID bufID)
{
return comBuf[bufID].rxBufferSize;
}
//-----------------------------------------------------------------------------
/// \brief
///
/// \descr
///
/// \param bufID
///
/// \return void
//-----------------------------------------------------------------------------
void ComBuf_TxSend( ComBufID bufID )
{
Std_ReturnType rslt;
// send response
rslt = CanTp_Transmit( &comBuf[bufID].pduTxMessage );
if( rslt != E_OK )
{
/*sending was not possible */
ComBuf_TxConfirmation(bufID, NTFRSLT_E_NOT_OK );
}
}
//-----------------------------------------------------------------------------
/// \brief
///
/// \descr
///
/// \param bufID
/// \param cmdLevel
/// \param ucSID
/// \param pMsgContext
///
/// \return void
//-----------------------------------------------------------------------------
void ComBuf_GetMsgContext ( ComBufID bufID, uint8_t cmdLevel, uint8_t *ucSID, MsgContextType *pMsgContext )
{
pMsgContext->reqData = &(comBuf[bufID].pduRxMessage.SduDataPtr[cmdLevel + 1U]);
pMsgContext->reqDataLen = comBuf[bufID].pduRxMessage.SduLength - ((uint16)cmdLevel + 1U);
pMsgContext->reqDataSize = comBuf[bufID].rxBufferSize - ((uint16)cmdLevel + 1U);
pMsgContext->resData = &(comBuf[bufID].pduTxMessage.SduDataPtr[cmdLevel + 1U]);
pMsgContext->resDataLen = 0;
pMsgContext->resDataSize = comBuf[bufID].txBufferSize - ((uint16)cmdLevel + 1U);
comBuf[bufID].pduTxMessage.SduDataPtr[cmdLevel] = comBuf[bufID].pduRxMessage.SduDataPtr[cmdLevel];
*ucSID = comBuf[bufID].pduRxMessage.SduDataPtr[cmdLevel];
}
//-----------------------------------------------------------------------------
/// \brief Interface helper for inserting new data in the response of Message Context
///
/// \descr
///
/// \param pMsgContext
/// \param data
///
/// \return uint16
//-----------------------------------------------------------------------------
// PRQA S 1503 1 // not used at the moment
uint16 ComBuf_AddToMsgContext (MsgContextType *pMsgContext, const uint8_t data )
{
if (pMsgContext->resDataLen < pMsgContext->resDataSize) //size guard
{
pMsgContext->resData[pMsgContext->resDataLen] = data;
pMsgContext->resDataLen++;
}
return pMsgContext->resDataLen;
}
//-----------------------------------------------------------------------------
/// \brief
///
/// \descr
///
/// \param pMsgContext
/// \param data
///
/// \return uint16
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
/// \brief Interface helper for inserting new multibyte data in the response of Message Context
///
/// \descr
///
/// \param pMsgContext
/// \param data
/// \param unLen
/// \param boMotorolaByteOrder : TRUE = Motorola, FALSE = Intel
///
/// \return uint16
//-----------------------------------------------------------------------------
// PRQA S 1503 1 // not used at the moment
uint16 ComBuf_AddToMsgContextMultiByte (MsgContextType *pMsgContext, const uint8_t *pData, uint16 unLen, boolean boMotorolaByteOrder)
{
uint16 unIdx;
uint8 ucByte;
if ((pMsgContext->resDataLen + unLen) < pMsgContext->resDataSize) //size guard
{
for(unIdx = 0u; unIdx< unLen; unIdx++)
{
if(boMotorolaByteOrder == TRUE)
{
ucByte = pData[unLen - 1u - unIdx];
}
else
{
ucByte = pData[unIdx];
}
pMsgContext->resData[pMsgContext->resDataLen] = ucByte;
pMsgContext->resDataLen++;
}
}
return pMsgContext->resDataLen;
}