Macros | Functions
mcan.c File Reference

The file implements the MCAN Driver for XWR16xx/XWR18xx/XWR68xx. More...

#include <stdint.h>
#include <ti/common/hw_types.h>
#include <ti/common/sys_common.h>
#include <ti/drivers/canfd/include/hw_mcanss.h>
#include <ti/drivers/canfd/include/canfd_internal.h>

Macros

#define MCANSS_MSG_RAM_NUM   (1U)
 MCAN MSG RAM BANK number for ECC AGGR.
 
#define MCANSS_RX_BUFFER_MAX   (64U)
 Maximum Number of Rx Buffers.
 
#define MCANSS_TX_BUFFER_MAX   (32U)
 Maximum Number of Tx Buffers.
 
#define MCANSS_STD_ID_FILTER_SIZE_WORDS   (1U)
 Macro for standard Message ID filter.
 
#define MCANSS_EXT_ID_FILTER_SIZE_WORDS   (2U)
 Macro for extended Message ID filter.
 
#define MCANSS_INTR_LINE_EN_MASK   ((MCAN_ILE_EINT0_MASK | MCAN_ILE_EINT1_MASK))
 Macro for Interrupt Line enable mask.
 
#define MCANSS_TX_BUFFER_ELEM_ID_SHIFT   (0U)
 Mask and shift for Tx Buffers elements.
 
#define MCANSS_RX_BUFFER_ELEM_ID_SHIFT   (0U)
 Mask and shift for Rx Buffers elements.
 
#define MCANSS_STD_ID_FILTER_SFID2_SHIFT   (0U)
 Mask and shift for Standard Message ID Filter Elements.
 
#define MCANSS_EXT_ID_FILTER_EFID2_SHIFT   (0U)
 Extended Message ID Filter Element.
 

Functions

static void MCAN_writeProtectedRegAccessUnlock (uint32_t baseAddr)
 This API will unblock write access to write protected registers. More...
 
static void MCAN_writeProtectedRegAccessLock (uint32_t baseAddr)
 This API will block write access to write protected registers. More...
 
static void MCAN_eccLoadRegister (uint32_t baseAddr, uint32_t regOffset)
 This API will load the register from ECC memory bank. More...
 
static void MCAN_readMsg (uint32_t baseAddr, uint32_t elemAddr, MCAN_RxBufElement *elem)
 This API will read the message object from Message RAM. More...
 
static void MCAN_writeMsg (uint32_t baseAddr, uint32_t elemAddr, const MCAN_TxBufElement *elem)
 This API will write the message object to Message RAM. More...
 
static uint32_t MCAN_getDataSize (uint32_t dlc)
 This API will return payload depending on 'dlc' field. More...
 
static uint32_t MCAN_getMsgObjSize (uint32_t elemSize)
 This API will return message object size. More...
 
void MCAN_reset (uint32_t baseAddr)
 This API is used to initiate reset for MCAN module. More...
 
uint32_t MCAN_isInReset (uint32_t baseAddr)
 This function checks if the MCAN module is in Reset. More...
 
uint32_t MCAN_isFDOpEnable (uint32_t baseAddr)
 This API will return flexible data rate operation status MCAN module. More...
 
uint32_t MCAN_isMemInitDone (uint32_t baseAddr)
 This function checks if the memory initialization is done for MCAN module. More...
 
void MCAN_setOpMode (uint32_t baseAddr, uint32_t mode)
 This API will set MCAN module mode of operation. More...
 
uint32_t MCAN_getOpMode (uint32_t baseAddr)
 This API will return MCAN module mode of operation. More...
 
int32_t MCAN_init (uint32_t baseAddr, const CANFD_MCANInitParams *initParams)
 This API will initialize MCAN module. More...
 
int32_t MCAN_config (uint32_t baseAddr, const CANFD_MCANInitParams *configParams)
 This API will configure MCAN module. More...
 
void MCAN_eccConfig (uint32_t baseAddr, const CANFD_MCANECCConfigParams *configParams)
 This API will enable/disable ECC on the Message RAM. More...
 
int32_t MCAN_setBitTime (uint32_t baseAddr, const MCAN_BitTimingParams *configParams)
 This API will configure a bit timings for MCAN module. More...
 
int32_t MCAN_msgRAMConfig (uint32_t baseAddr, const MCAN_MsgRAMConfigParams *msgRAMConfigParams)
 This API will configure Different sections of Message RAM. More...
 
int32_t MCAN_setExtIDAndMask (uint32_t baseAddr, uint32_t idMask)
 This API will configure Extended ID AND Mask. More...
 
void MCAN_writeMsgRam (uint32_t baseAddr, uint32_t memType, uint32_t bufNum, const MCAN_TxBufElement *elem)
 This API is used to write Tx message to message RAM. More...
 
int32_t MCAN_txBufAddReq (uint32_t baseAddr, uint32_t bufNum)
 This API will set Tx Buffer Add Request. More...
 
void MCAN_getNewDataStatus (uint32_t baseAddr, MCAN_RxNewDataStatus *newDataStatus)
 This API will return New Data Message Status. More...
 
void MCAN_clearNewDataStatus (uint32_t baseAddr, const MCAN_RxNewDataStatus *newDataStatus)
 This API clear New Data Message Status. More...
 
void MCAN_readMsgRam (uint32_t baseAddr, uint32_t memType, uint32_t bufNum, uint32_t fifoNum, MCAN_RxBufElement *elem)
 This API is used to read received message form message RAM. More...
 
void MCAN_addStdMsgIDFilter (uint32_t baseAddr, uint32_t filtNum, const MCAN_StdMsgIDFilterElement *elem)
 This API is used to add Standard Message ID Filter Element. More...
 
void MCAN_addExtMsgIDFilter (uint32_t baseAddr, uint32_t filtNum, const MCAN_ExtMsgIDFilterElement *elem)
 This API is used to add Extended Message ID Filter Element. More...
 
void MCAN_lpbkModeEnable (uint32_t baseAddr, uint32_t lpbkMode, uint32_t enable)
 This API will enable/disable Loop Back Test Mode for MCAN module. More...
 
void MCAN_getErrCounters (uint32_t baseAddr, CANFD_MCANErrCntStatus *errCounter)
 This API will return error counter status for MCAN module. More...
 
void MCAN_getProtocolStatus (uint32_t baseAddr, CANFD_MCANProtocolStatus *protStatus)
 This API will return protocol status for MCAN module. More...
 
void MCAN_enableIntr (uint32_t baseAddr, uint32_t intrMask, uint32_t enable)
 This API is used to enable/disable interrupts. More...
 
void MCAN_selectIntrLine (uint32_t baseAddr, uint32_t intrMask, uint32_t lineNum)
 This API is used to select interrupt line. More...
 
void MCAN_enableIntrLine (uint32_t baseAddr, uint32_t lineNum, uint32_t enable)
 This API is used to enable/disable selected interrupt line. More...
 
uint32_t MCAN_getIntrStatus (uint32_t baseAddr)
 This API will return interrupt status. More...
 
void MCAN_clearIntrStatus (uint32_t baseAddr, uint32_t intrMask)
 This API is used to clear the interrupt status. More...
 
void MCAN_getHighPriorityMsgStatus (uint32_t baseAddr, MCAN_HighPriorityMsgInfo *hpm)
 This API will return High Priority Message Status. More...
 
void MCAN_getRxFIFOStatus (uint32_t baseAddr, MCAN_RxFIFOStatus *fifoStatus)
 This API will Rx FIFO status. More...
 
int32_t MCAN_writeRxFIFOAck (uint32_t baseAddr, uint32_t fifoNum, uint32_t idx)
 This API will write Rx FIFO Acknowledgement. More...
 
void MCAN_getTxFIFOQueStatus (uint32_t baseAddr, MCAN_TxFIFOStatus *fifoStatus)
 This API will Tx FIFO status. More...
 
uint32_t MCAN_getTxBufReqPend (uint32_t baseAddr)
 This API will return Tx Buffer Request Pending status. More...
 
int32_t MCAN_txBufCancellationReq (uint32_t baseAddr, uint32_t buffNum)
 This API will set Tx Buffer Cancellation Request. More...
 
uint32_t MCAN_getTxBufTransmissionStatus (uint32_t baseAddr)
 This API will return Tx Buffer Transmission Occurred status. More...
 
uint32_t MCAN_txBufCancellationStatus (uint32_t baseAddr)
 This API will return Transmit Buffer Cancellation Finished status. More...
 
int32_t MCAN_txBufTransIntrEnable (uint32_t baseAddr, uint32_t bufNum, uint32_t enable)
 This API is used to enable/disable Tx Buffer Transmission Interrupt. More...
 
int32_t MCAN_getTxBufCancellationIntrEnable (uint32_t baseAddr, uint32_t bufNum, uint32_t enable)
 This API is used to enable/disable Tx Buffer Cancellation Finished Interrupt. More...
 
void MCAN_getTxEventFIFOStatus (uint32_t baseAddr, MCAN_TxEventFIFOStatus *fifoStatus)
 This API will Tx Event FIFO status. More...
 
void MCAN_addClockStopRequest (uint32_t baseAddr, uint32_t enable)
 This API add clock stop request for MCAN module to put it in power down mode. More...
 
int32_t MCAN_writeTxEventFIFOAck (uint32_t baseAddr, uint32_t idx)
 This API will write Event FIFO Acknowledge Index. More...
 
void MCAN_eccForceError (uint32_t baseAddr, const CANFD_MCANECCErrForceParams *eccErr)
 This API will Force Error on ECC. More...
 
void MCAN_eccGetErrorStatus (uint32_t baseAddr, CANFD_MCANECCErrStatus *eccErr)
 This API will return ECC Error status. More...
 
void MCAN_eccClearErrorStatus (uint32_t baseAddr, uint32_t errType)
 This API is used to clear the ECC Error status. More...
 
void MCAN_eccWriteEOI (uint32_t baseAddr, uint32_t errType)
 This API is used to write End of Interrupt for ECC interrupt. More...
 
void MCAN_eccEnableIntr (uint32_t baseAddr, uint32_t errType, uint32_t enable)
 This API is used to enable ECC interrupt. More...
 
uint32_t MCAN_eccGetIntrStatus (uint32_t baseAddr, uint32_t errType)
 This API is used to get ECC interrupt status. More...
 
void MCAN_eccClearIntrStatus (uint32_t baseAddr, uint32_t errType)
 This API is used to clear ECC interrupt status. More...
 
void MCAN_extTSCounterConfig (uint32_t baseAddr, uint32_t prescalar)
 This API will configure external timestamp counter for MCAN module. More...
 
void MCAN_extTSCounterEnable (uint32_t baseAddr, uint32_t enable)
 This API will enable/disable fast external time stamp counter for MCAN module. More...
 
void MCAN_extTSEnableIntr (uint32_t baseAddr, uint32_t enable)
 This API will enable/disable External TimeStamp Counter Overflow Interrupt for MCAN module. More...
 
void MCAN_extTSWriteEOI (uint32_t baseAddr)
 This API is used to write End of Interrupt for External TimeStamp Counter Overflow Interrupt. More...
 
uint32_t MCAN_extTSGetUnservicedIntrCount (uint32_t baseAddr)
 This API returns Number of unserviced rollover/overflow interrupts for external TimeStamp counter. More...
 
void MCAN_getRevisionId (uint32_t baseAddr, MCAN_RevisionId *revId)
 This API is used get the MCAN revision ID. More...
 
uint32_t MCAN_getClockStopAck (uint32_t baseAddr)
 This API get clock stop acknowledgement for MCAN module. It return whether MCAN is power down mode or not. More...
 
void MCAN_extTSSetRawStatus (uint32_t baseAddr)
 This API will set External TimeStamp Counter Overflow Interrupt Raw status for MCAN module. More...
 
void MCAN_extTSClearRawStatus (uint32_t baseAddr)
 This API will clear External TimeStamp Counter Overflow Interrupt raw status for MCAN module. More...
 
uint32_t MCAN_getRxPinState (uint32_t baseAddr)
 This API will return Rx pin state of MCAN module. More...
 
void MCAN_setTxPinState (uint32_t baseAddr, uint32_t state)
 This API will set Tx pin state of MCAN module. More...
 
uint32_t MCAN_getTxPinState (uint32_t baseAddr)
 This API will return Tx pin state of MCAN module. More...
 
uint32_t MCAN_getTSCounterVal (uint32_t baseAddr)
 This API will return current timestamp counter value. More...
 
uint32_t MCAN_getClkStopAck (uint32_t baseAddr)
 This API will return clock stop acknowledgement for MCAN module. More...
 
void MCAN_getBitTime (uint32_t baseAddr, MCAN_BitTimingParams *configParams)
 This API will get the configured bit timings for MCAN module. More...
 
void MCAN_resetTSCounter (uint32_t baseAddr)
 This API will reset timestamp counter value. More...
 
uint32_t MCAN_getTOCounterVal (uint32_t baseAddr)
 This API will return current time-out counter value. More...
 
void MCAN_eccAggrGetRevisionId (uint32_t baseAddr, MCAN_ECCAggrRevisionId *revId)
 This API is used get the ECC AGGR revision ID. More...
 
void MCAN_eccWrapGetRevisionId (uint32_t baseAddr, MCAN_ECCWrapRevisionId *revId)
 This API is used get the ECC Wrapper revision ID. More...
 
uint32_t MCAN_extTSIsIntrEnable (uint32_t baseAddr)
 This API returns External TimeStamp Counter Overflow Interrupt enable status for MCAN module. More...
 
uint32_t MCAN_getEndianVal (uint32_t baseAddr)
 This function return endianness value of MCAN module. More...
 
uint32_t MCAN_getExtIDANDMassk (uint32_t baseAddr)
 This API will get the configured Extended ID AND Mask. More...
 

Detailed Description

The file implements the MCAN Driver for XWR16xx/XWR18xx/XWR68xx.

NOTE: (C) Copyright 2016 Texas Instruments, Inc.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

Neither the name of Texas Instruments Incorporated nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Function Documentation

static void MCAN_eccLoadRegister ( uint32_t  baseAddr,
uint32_t  regOffset 
)
static

This API will load the register from ECC memory bank.

Parameters
baseAddrBase Address of the MCAN Registers.
regOffsetOffset of the register to read.
Returns
None.
static uint32_t MCAN_getDataSize ( uint32_t  dlc)
static

This API will return payload depending on 'dlc' field.

Parameters
dlcData Length Code.
Returns
data size Size of the payload.
static uint32_t MCAN_getMsgObjSize ( uint32_t  elemSize)
static

This API will return message object size.

Parameters
elemSizeSize of the message element.
Returns
message object size Size of the message object stored in Message RAM.
static void MCAN_readMsg ( uint32_t  baseAddr,
uint32_t  elemAddr,
MCAN_RxBufElement *  elem 
)
static

This API will read the message object from Message RAM.

Parameters
baseAddrBase Address of the MCAN Registers.
elemAddrAddress of the message object.
elemMessage Object. Refer struct MCAN_RxBufElement.
Returns
None.
static void MCAN_writeMsg ( uint32_t  baseAddr,
uint32_t  elemAddr,
const MCAN_TxBufElement *  elem 
)
static

This API will write the message object to Message RAM.

Parameters
baseAddrBase Address of the MCAN Registers.
elemAddrAddress of the message object.
elemMessage Object. Refer struct MCAN_TxBufElement.
Returns
None.
static void MCAN_writeProtectedRegAccessLock ( uint32_t  baseAddr)
static

This API will block write access to write protected registers.

Parameters
baseAddrBase Address of the MCAN Registers.
Returns
None.
static void MCAN_writeProtectedRegAccessUnlock ( uint32_t  baseAddr)
static

This API will unblock write access to write protected registers.

Parameters
baseAddrBase Address of the MCAN Registers.
Returns
None.

Copyright 2020, Texas Instruments Incorporated