# CAN Module

The controller area network (CAN) API provides a set of functions for configuring and using the CAN module, a serial communications protocol. Functions are provided to setup and configure the module operating options, setup the different types of message objects, send and read messages, and setup and handle interrupts and events.

group `can_api`

  Defines

  `CAN_RAM_INIT_KEY` (0xAU)
  `CAN_RAM_INIT_MASK` (0x003FU)
  `CAN_INIT_PARITY_DISABLE` (0x1400U)
  `CAN_MSG_OBJ_TX_INT_ENABLE` CAN_IF1MCTL_TXIE

    This indicates that transmit interrupts should be enabled, or are enabled.

  `CAN_MSG_OBJ_RX_INT_ENABLE` CAN_IF1MCTL_RXIE

    This indicates that receive interrupts should be enabled, or are enabled.

  `CAN_MSG_OBJ_USE_ID_FILTER` (0x00000001U)

    This indicates that a message object will use or is using filtering based on the object’s message identifier.

  `CAN_MSG_OBJ_USE_DIR_FILTER` CAN_IF1MSK_MDIR

    This indicates that a message object will use or is using filtering based on the direction of the transfer.

  `CAN_MSG_OBJ_USE_EXT_FILTER` CAN_IF1MSK_MXTD

    This indicates that a message object will use or is using message identifier filtering based on the extended identifier.

  `CAN_MSG_OBJ_FIFO` (0x00000002U)

    This indicates that this message object is part of a FIFO structure and not the final message object in a FIFO.

  `CAN_MSG_OBJ_NO_FLAGS` (0x00000000U)

    This indicates that a message object has no flags set.

  `CAN_INT_ERROR` (0x00000008UL)

    This flag is used to allow a CAN controller to generate error interrupts.

  `CAN_INT_STATUS` (0x00000004UL)

    This flag is used to allow a CAN controller to generate status interrupts.

  `CAN_INT_IE0` (0x00000002UL)

    This flag is used to allow a CAN controller to generate interrupts on interrupt line 0

  `CAN_INT_IE1` (0x00020000UL)

    This flag is used to allow a CAN controller to generate interrupts on interrupt line 1

  `CAN_STATUS_PERR` (0x00000100U)

    CAN controller has detected a parity error.

  `CAN_STATUS_BUS_OFF` (0x00000080U)

    CAN controller has entered a Bus Off state.

  `CAN_STATUS_EWARN` (0x00000040U)

    CAN controller error level has reached warning level.

  `CAN_STATUS_EPASS` (0x00000020U)

    CAN controller error level has reached error passive level.

  `CAN_STATUS_RXOK` (0x00000010U)

    A message was received successfully since the last read of this status.

  `CAN_STATUS_TXOK` (0x00000008U)

    A message was transmitted successfully since the last read of this status.

  `CAN_STATUS_LEC_MSK` (0x00000007U)

    This is the mask for the last error code field.

  `CAN_STATUS_LEC_NONE` (0x00000000U)

    There was no error.

  `CAN_STATUS_LEC_STUFF` (0x00000001U)

    A bit stuffing error has occurred.

  `CAN_STATUS_LEC_FORM` (0x00000002U)

    A formatting error has occurred.

  `CAN_STATUS_LEC_ACK` (0x00000003U)

    An acknowledge error has occurred.

  `CAN_STATUS_LEC_BIT1` (0x00000004U)

    The bus remained a bit level of 1 for longer than is allowed.

  `CAN_STATUS_LEC_BIT0` (0x00000005U)

    The bus remained a bit level of 0 for longer than is allowed.

  `CAN_STATUS_LEC_CRC` (0x00000006U)

    A CRC error has occurred.

  `CAN_GLOBAL_INT_CANINT0` (0x00000001U)

    CANINT0 global interrupt bit.

  `CAN_GLOBAL_INT_CANINT1` (0x00000002U)

    CANINT1 global interrupt bit.

  `CAN_INT_INT0ID_STATUS` (0x8000U)

    Status of INT0ID.

  `CAN_IF1ARB_STD_ID_S` (18U)

    IF1 Arbitration Standard ID Shift Offset.

  `CAN_IF1ARB_STD_ID_M` (0x1FFC0000U)

    IF1 Arbitration Standard ID Mask.

  `CAN_IF2ARB_STD_ID_S` (18U)

    IF2 Arbitration Standard ID Shift Offset.

  `CAN_IF2ARB_STD_ID_M` (0x1FFC0000U)

    IF2 Arbitration Standard ID Mask.

  Enums

  enum `CAN_MsgFrameType`

    This data type is used to decide between STD_ID or EXT_ID for a mailbox. This is used when calling the CAN_setupMessageObject() function.

    Values:

    enumerator `CAN_MSG_FRAME_STD`

      Set the message ID frame to standard.

    enumerator `CAN_MSG_FRAME_EXT`

      Set the message ID frame to extended.

  enum `CAN_MsgObjType`

    This definition is used to determine the type of message object that will be set up via a call to the CAN_setupMessageObject() API.

    Values:

    enumerator `CAN_MSG_OBJ_TYPE_TX`

      Transmit message object.

    enumerator `CAN_MSG_OBJ_TYPE_TX_REMOTE`

      Transmit remote request message object.

    enumerator `CAN_MSG_OBJ_TYPE_RX`

      Receive message object.

    enumerator `CAN_MSG_OBJ_TYPE_RXTX_REMOTE`

      Remote frame receive remote, with auto-transmit message object.

  enum `CAN_ClockSource`

    This definition is used to determine the clock source that will be set up via a call to the CAN_selectClockSource() API.

    Values:

    enumerator `CAN_CLOCK_SOURCE_SYS` = 0x0

      Peripheral System Clock Source.

    enumerator `CAN_CLOCK_SOURCE_XTAL` = 0x1

      External Oscillator Clock Source.

    enumerator `CAN_CLOCK_SOURCE_AUX` = 0x2

      Auxiliary Clock Input Source.

  Functions

  void `CAN_writeDataReg`(const uint16_t *const data, uint32_t address, uint32_t size)
  void `CAN_readDataReg`(uint16_t *data, const uint32_t address, uint32_t size)
  void `CAN_initRAM`(uint32_t base)

    Initializes the CAN controller’s RAM.

    Performs the initialization of the RAM used for the CAN message objects.

    Parameters

      - `base`: is the base address of the CAN controller.

    Return

      None.

  void `CAN_selectClockSource`(uint32_t base, CAN_ClockSource source)

    Select CAN Clock Source

    This function selects the specified clock source for the CAN controller.

    Parameters

      - `base`: is the base address of the CAN controller.

      - `source`: is the clock source to use for the CAN controller.

    The source parameter can be any one of the following:

    - CAN_CLOCK_SOURCE_SYS - Peripheral System Clock

    - CAN_CLOCK_SOURCE_XTAL - External Oscillator

    - CAN_CLOCK_SOURCE_AUX - Auxiliary Clock Input from GPIO

    Return

      None.

  void `CAN_startModule`(uint32_t base)

    Starts the CAN Module’s Operations

    This function starts the CAN module’s operations after initialization, which includes the CAN protocol controller state machine of the CAN core and the message handler state machine to begin controlling the CAN’s internal data flow.

    Parameters

      - `base`: is the base address of the CAN controller.

    Return

      None.

  void `CAN_enableController`(uint32_t base)

    Enables the CAN controller.

    Enables the CAN controller for message processing. Once enabled, the controller will automatically transmit any pending frames, and process any received frames. The controller can be stopped by calling

    CAN_disableController().
    Parameters

      - `base`: is the base address of the CAN controller to enable.

    Return

      None.

  void `CAN_disableController`(uint32_t base)

    Disables the CAN controller.

    Disables the CAN controller for message processing. When disabled, the controller will no longer automatically process data on the CAN bus. The controller can be restarted by calling

    CAN_enableController(). The state of the CAN controller and the message objects in the controller are left as they were before this call was made.
    Parameters

      - `base`: is the base address of the CAN controller to disable.

    Return

      None.

  void `CAN_enableTestMode`(uint32_t base, uint16_t mode)

    Enables the test modes of the CAN controller.

    Enables test modes within the controller. The following valid options for

    mode can be OR’ed together:

    - CAN_TEST_SILENT - Silent Mode

    - CAN_TEST_LBACK - Loopback Mode

    - CAN_TEST_EXL - External Loopback Mode

    Parameters

      - `base`: is the base address of the CAN controller.

      - `mode`: are the the test modes to enable.

    Note

      Loopback mode and external loopback mode can not be enabled at the same time.

    Return

      None.

  void `CAN_disableTestMode`(uint32_t base)

    Disables the test modes of the CAN controller.

    Disables test modes within the controller and clears the test bits.

    Parameters

      - `base`: is the base address of the CAN controller.

    Return

      None.

  uint32_t `CAN_getBitTiming`(uint32_t base)

    Get the current settings for the CAN controller bit timing.

    This function reads the current configuration of the CAN controller bit clock timing.

    Parameters

      - `base`: is the base address of the CAN controller.

    Return

      Returns the value of the bit timing register.

  void `CAN_enableMemoryAccessMode`(uint32_t base)

    Enables direct access to the RAM.

    Enables direct access to the RAM while in Test mode.

    Parameters

      - `base`: is the base address of the CAN controller.

    Note

      Test Mode must first be enabled to use this function.

    Return

      None.

  void `CAN_disableMemoryAccessMode`(uint32_t base)

    Disables direct access to the RAM.

    Disables direct access to the RAM while in Test mode.

    Parameters

      - `base`: is the base address of the CAN controller.

    Return

      None.

  void `CAN_setInterruptionDebugMode`(uint32_t base, bool enable)

    Sets the interruption debug mode of the CAN controller.

    This function sets the interruption debug mode of the CAN controller. When the

    enable parameter is true, CAN will be configured to interrupt any transmission or reception and enter debug mode immediately after it is requested. When false, CAN will wait for a started transmission or reception to be completed before entering debug mode.
    Parameters

      - `base`: is the base address of the CAN controller.

      - `enable`: is a flag to enable or disable the interruption debug mode.

    Return

      None.

  void `CAN_enableDMARequests`(uint32_t base)

    Enables DMA Requests from the CAN controller.

    Enables the CAN controller DMA request lines for each of the 3 interface register sets. To actually assert the request line, the DMA Active bit must be set in the corresponding interface CMD register.

    Parameters

      - `base`: is the base address of the CAN controller to enable.

    Return

      None.

  void `CAN_disableDMARequests`(uint32_t base)

    Disables DMA Requests from the CAN controller.

    Disables the CAN controller DMA request lines for each of the 3 interface register sets.

    Parameters

      - `base`: is the base address of the CAN controller to enable.

    Return

      None.

  void `CAN_disableAutoBusOn`(uint32_t base)

    Disables Auto-Bus-On.

    Disables the Auto-Bus-On feature of the CAN controller.

    Parameters

      - `base`: is the base address of the CAN controller.

    Return

      None.

  void `CAN_enableAutoBusOn`(uint32_t base)

    Enables Auto-Bus-On.

    Enables the Auto-Bus-On feature of the CAN controller. Be sure to also configure the Auto-Bus-On time using the CAN_setAutoBusOnTime function.

    Parameters

      - `base`: is the base address of the CAN controller.

    Return

      None.

  void `CAN_setAutoBusOnTime`(uint32_t base, uint32_t time)

    Sets the time before a Bus-Off recovery sequence is started.

    This function sets the number of clock cycles before a Bus-Off recovery sequence is started by clearing the Init bit.

    Parameters

      - `base`: is the base address of the CAN controller.

      - `time`: is number of clock cycles before a Bus-Off recovery sequence is started.

    Note

      To enable this functionality, use CAN_enableAutoBusOn().

    Return

      None.

  void `CAN_enableInterrupt`(uint32_t base, uint32_t intFlags)

    Enables individual CAN controller interrupt sources.

    Enables specific interrupt sources of the CAN controller. Only enabled sources will cause a processor interrupt.

    Parameters

      - `base`: is the base address of the CAN controller.

      - `intFlags`: is the bit mask of the interrupt sources to be enabled.

    The intFlags parameter is the logical OR of any of the following:

    - CAN_INT_ERROR - a controller error condition has occurred

    - CAN_INT_STATUS - a message transfer has completed, or a bus error has been detected

    - CAN_INT_IE0 - allow CAN controller to generate interrupts on interrupt line 0

    - CAN_INT_IE1 - allow CAN controller to generate interrupts on interrupt line 1

    Return

      None.

  void `CAN_disableInterrupt`(uint32_t base, uint32_t intFlags)

    Disables individual CAN controller interrupt sources.

    Disables the specified CAN controller interrupt sources. Only enabled interrupt sources can cause a processor interrupt.

    Parameters

      - `base`: is the base address of the CAN controller.

      - `intFlags`: is the bit mask of the interrupt sources to be disabled.

    The intFlags parameter has the same definition as in the CAN_enableInterrupt() function.

    Return

      None.

  uint32_t `CAN_getInterruptMux`(uint32_t base)

    Get the CAN controller Interrupt Line set for each mailbox

    Gets which interrupt line each message object should assert when an interrupt occurs. Bit 0 corresponds to message object 32 and then bits 1 to 31 correspond to message object 1 through 31 respectively. Bits that are asserted indicate the message object should generate an interrupt on interrupt line 1, while bits that are not asserted indicate the message object should generate an interrupt on line 0.

    Parameters

      - `base`: is the base address of the CAN controller.

    Return

      Returns the value of the interrupt muxing register.

  void `CAN_setInterruptMux`(uint32_t base, uint32_t mux)

    Set the CAN controller Interrupt Line for each mailbox

    Selects which interrupt line each message object should assert when an interrupt occurs. Bit 0 corresponds to message object 32 and then bits 1 to 31 correspond to message object 1 through 31 respectively. Bits that are asserted indicate the message object should generate an interrupt on interrupt line 1, while bits that are not asserted indicate the message object should generate an interrupt on line 0.

    Parameters

      - `base`: is the base address of the CAN controller.

      - `mux`: bit packed representation of which message objects should generate an interrupt on a given interrupt line.

    Return

      None.

  void `CAN_enableRetry`(uint32_t base)

    Enables the CAN controller automatic retransmission behavior.

    Enables the automatic retransmission of messages with detected errors.

    Parameters

      - `base`: is the base address of the CAN controller.

    Return

      None.

  void `CAN_disableRetry`(uint32_t base)

    Disables the CAN controller automatic retransmission behavior.

    Disables the automatic retransmission of messages with detected errors.

    Parameters

      - `base`: is the base address of the CAN controller.

    Return

      None.

  bool `CAN_isRetryEnabled`(uint32_t base)

    Returns the current setting for automatic retransmission.

    Reads the current setting for the automatic retransmission in the CAN controller and returns it to the caller.

    Parameters

      - `base`: is the base address of the CAN controller.

    Return

      Returns true if automatic retransmission is enabled, false otherwise.

  bool `CAN_getErrorCount`(uint32_t base, uint32_t *rxCount, uint32_t *txCount)

    Reads the CAN controller error counter register.

    Reads the error counter register and returns the transmit and receive error counts to the caller along with a flag indicating if the controller receive counter has reached the error passive limit. The values of the receive and transmit error counters are returned through the pointers provided as parameters.

    Parameters

      - `base`: is the base address of the CAN controller.

      - `rxCount`: is a pointer to storage for the receive error counter.

      - `txCount`: is a pointer to storage for the transmit error counter.

    After this call, rxCount will hold the current receive error count and txCount will hold the current transmit error count.

    Return

      Returns true if the receive error count has reached the error passive limit, and false if the error count is below the error passive limit.

  uint16_t `CAN_getStatus`(uint32_t base)

    Reads the CAN controller error and status register.

    Reads the error and status register of the CAN controller.

    Parameters

      - `base`: is the base address of the CAN controller.

    Return

      Returns the value of the register.

  uint32_t `CAN_getTxRequests`(uint32_t base)

    Reads the CAN controller TX request register.

    Reads the TX request register of the CAN controller.

    Parameters

      - `base`: is the base address of the CAN controller.

    Return

      Returns the value of the register.

  uint32_t `CAN_getNewDataFlags`(uint32_t base)

    Reads the CAN controller new data status register.

    Reads the new data status register of the CAN controller for all message objects.

    Parameters

      - `base`: is the base address of the CAN controller.

    Return

      Returns the value of the register.

  uint32_t `CAN_getValidMessageObjects`(uint32_t base)

    Reads the CAN controller valid message object register.

    Reads the valid message object register of the CAN controller.

    Parameters

      - `base`: is the base address of the CAN controller.

    Return

      Returns the value of the register.

  uint32_t `CAN_getInterruptCause`(uint32_t base)

    Get the CAN controller interrupt cause.

    This function returns the value of the interrupt register that indicates the cause of the interrupt.

    Parameters

      - `base`: is the base address of the CAN controller.

    Return

      Returns the value of the interrupt register.

  uint32_t `CAN_getInterruptMessageSource`(uint32_t base)

    Get the CAN controller pending interrupt message source.

    Returns the value of the pending interrupts register that indicates which messages are the source of pending interrupts.

    Parameters

      - `base`: is the base address of the CAN controller.

    Return

      Returns the value of the pending interrupts register.

  void `CAN_enableGlobalInterrupt`(uint32_t base, uint16_t intFlags)

    CAN Global interrupt Enable function.

    Enables specific CAN interrupt in the global interrupt enable register

    Parameters

      - `base`: is the base address of the CAN controller.

      - `intFlags`: is the bit mask of the interrupt sources to be enabled.

    The intFlags parameter is the logical OR of any of the following:

    - CAN_GLOBAL_INT_CANINT0 - Global Interrupt Enable bit for CAN INT0

    - CAN_GLOBAL_INT_CANINT1 - Global Interrupt Enable bit for CAN INT1

    Return

      None.

  void `CAN_disableGlobalInterrupt`(uint32_t base, uint16_t intFlags)

    CAN Global interrupt Disable function.

    Disables the specific CAN interrupt in the global interrupt enable register

    Parameters

      - `base`: is the base address of the CAN controller.

      - `intFlags`: is the bit mask of the interrupt sources to be disabled.

    The intFlags parameter is the logical OR of any of the following:

    - CAN_GLOBAL_INT_CANINT0 - Global Interrupt bit for CAN INT0

    - CAN_GLOBAL_INT_CANINT1 - Global Interrupt bit for CAN INT1

    Return

      None.

  void `CAN_clearGlobalInterruptStatus`(uint32_t base, uint16_t intFlags)

    CAN Global interrupt Clear function.

    Clear the specific CAN interrupt bit in the global interrupt flag register.

    Parameters

      - `base`: is the base address of the CAN controller.

      - `intFlags`: is the bit mask of the interrupt sources to be cleared.

    The intFlags parameter is the logical OR of any of the following:

    - CAN_GLOBAL_INT_CANINT0 - Global Interrupt bit for CAN INT0

    - CAN_GLOBAL_INT_CANINT1 - Global Interrupt bit for CAN INT1

    Return

      None.

  bool `CAN_getGlobalInterruptStatus`(uint32_t base, uint16_t intFlags)

    Get the CAN Global Interrupt status.

    Check if any interrupt bit is set in the global interrupt flag register.

    Parameters

      - `base`: is the base address of the CAN controller.

      - `intFlags`: is the bit mask of the interrupt sources to be enabled.

    The intFlags parameter is the logical OR of any of the following:

    - CAN_GLOBAL_INT_CANINT0 - Global Interrupt bit for CAN INT0

    - CAN_GLOBAL_INT_CANINT1 - Global Interrupt bit for CAN INT1

    Return

      True if any of the requested interrupt bits are set. False, if none of the requested bits are set.

  void `CAN_initModule`(uint32_t base)

    Initializes the CAN controller

    This function initializes the message RAM, which also clears all the message objects, and places the CAN controller in an init state. Write access to the configuration registers is available as a result, allowing the bit timing and message objects to be setup.

    Parameters

      - `base`: is the base address of the CAN controller.

    Note

      To exit the initialization mode and start the CAN module, use the CAN_startModule() function.

    Return

      None.

  void `CAN_setBitRate`(uint32_t base, uint32_t clock, uint32_t bitRate, uint16_t bitTime)

    Sets the CAN Bit Timing based on requested Bit Rate.

    This function sets the CAN bit timing values for the bit rate passed in the

    bitRate and bitTime parameters based on the clock parameter. The CAN bit clock is calculated to be an average timing value that should work for most systems. If tighter timing requirements are needed, then the CAN_setBitTiming() function is available for full customization of all of the CAN bit timing values.
    Parameters

      - `base`: is the base address of the CAN controller.

      - `clock`: is the CAN module clock frequency before the bit rate prescaler (Hertz)

      - `bitRate`: is the desired bit rate (bits/sec)

      - `bitTime`: is the number of time quanta per bit required for desired bit time (Tq) and must be in the range from 8 to 25

    Note

      Not all bit-rate and bit-time combinations are valid. For combinations that would yield the correct bit-rate, refer to the DCAN_CANBTR_values.xlsx file in the “docs” directory. The CANBTR register values calculated by the function CAN_setBitRate may not be suitable for your network parameters. If this is the case and you have computed the correct values for your network, you could directly write those parameters in CANBTR register using the function CAN_setBitTiming.

    Return

      None.

  void `CAN_setBitTiming`(uint32_t base, uint16_t prescaler, uint16_t prescalerExtension, uint16_t tSeg1, uint16_t tSeg2, uint16_t sjw)

    Manually set the CAN controller bit timing.

    This function sets the various timing parameters for the CAN bus bit timing: baud rate prescaler, prescaler extension, time segment 1, time segment 2, and the Synchronization Jump Width.

    Parameters

      - `base`: is the base address of the CAN controller.

      - `prescaler`: is the baud rate prescaler

      - `prescalerExtension`: is the baud rate prescaler extension

      - `tSeg1`: is the time segment 1

      - `tSeg2`: is the time segment 2

      - `sjw`: is the synchronization jump width

    Return

      None.

  void `CAN_clearInterruptStatus`(uint32_t base, uint32_t intClr)

    Clears a CAN interrupt source.

    This function can be used to clear a specific interrupt source. The

    intClr parameter should be either a number from 1 to 32 to clear a specific message object interrupt or can be the following:

    - CAN_INT_INT0ID_STATUS - Clears a status interrupt.

    Parameters

      - `base`: is the base address of the CAN controller.

      - `intClr`: is a value indicating which interrupt source to clear.

    It is not necessary to use this function to clear an interrupt. This should only be used if the application wants to clear an interrupt source without taking the normal interrupt action.

    Return

      None.

  void `CAN_setupMessageObject`(uint32_t base, uint32_t objID, uint32_t msgID, CAN_MsgFrameType frame, CAN_MsgObjType msgType, uint32_t msgIDMask, uint32_t flags, uint16_t msgLen)

    Setup a Message Object

    This function sets the various values required for a message object.

    Parameters

      - `base`: is the base address of the CAN controller.

      - `objID`: is the message object number to configure (1-32).

      - `msgID`: is the CAN message identifier used for the 11 or 29 bit identifiers

      - `frame`: is the CAN ID frame type

      - `msgType`: is the message object type

      - `msgIDMask`: is the CAN message identifier mask used when identifier filtering is enabled

      - `flags`: is the various flags and settings to be set for the message object

      - `msgLen`: is the number of bytes of data in the message object (0-8)

    The frame parameter can be one of the following values:

    - CAN_MSG_FRAME_STD - Standard 11 bit identifier

    - CAN_MSG_FRAME_EXT - Extended 29 bit identifier

    The msgType parameter can be one of the following values:

    - CAN_MSG_OBJ_TYPE_TX - Transmit Message

    - CAN_MSG_OBJ_TYPE_TX_REMOTE - Transmit Remote Message

    - CAN_MSG_OBJ_TYPE_RX - Receive Message

    - CAN_MSG_OBJ_TYPE_RXTX_REMOTE - Receive Remote message with auto-transmit

    The flags parameter can be set as CAN_MSG_OBJ_NO_FLAGS if no flags are required or the parameter can be a logical OR of any of the following values:

    - CAN_MSG_OBJ_TX_INT_ENABLE - Enable Transmit Interrupts

    - CAN_MSG_OBJ_RX_INT_ENABLE - Enable Receive Interrupts

    - CAN_MSG_OBJ_USE_ID_FILTER - Use filtering based on the Message ID

    - CAN_MSG_OBJ_USE_EXT_FILTER - Use filtering based on the Extended Message ID

    - CAN_MSG_OBJ_USE_DIR_FILTER - Use filtering based on the direction of the transfer

    - CAN_MSG_OBJ_FIFO - Message object is part of a FIFO structure and isn’t the final message object in FIFO

    If filtering is based on message identifier, the value CAN_MSG_OBJ_USE_ID_FILTER has to be logically ORed with the flag parameter and CAN_MSG_OBJ_USE_EXT_FILTER also has to be ORed for message identifier filtering to be based on the extended identifier.

    Note

      The msgLen

      Parameter for the Receive Message Object is a “don’t

      care” but its value should be between 0-8 due to the assert.

    Return

      None.

  void `CAN_sendMessage`(uint32_t base, uint32_t objID, uint16_t msgLen, const uint16_t *msgData)

    Sends a Message Object

    This function is used to transmit a message object and the message data, if applicable.

    Parameters

      - `base`: is the base address of the CAN controller.

      - `objID`: is the object number to configure (1-32).

      - `msgLen`: is the number of bytes of data in the message object (0-8)

      - `msgData`: is a pointer to the message object’s data

    Note

      The message object requested by the objID must first be setup using the CAN_setupMessageObject() function.

    Return

      None.

  void `CAN_sendRemoteRequestMessage`(uint32_t base, uint32_t objID)

    Sends a Remote Request Message Object

    This function is used to transmit a remote request message object.

    Parameters

      - `base`: is the base address of the CAN controller.

      - `objID`: is the object number to configure (1-32).

    Note

      The message object requested by the objID must first be setup using the CAN_setupMessageObject() function with CAN_MSG_OBJ_TYPE_TX_REMOTE as msgType flag.

    Return

      None.

  bool `CAN_readMessage`(uint32_t base, uint32_t objID, uint16_t *msgData)

    Reads the data in a Message Object

    This function is used to read the data contents of the specified message object in the CAN controller. The data returned is stored in the

    msgData parameter.
    Parameters

      - `base`: is the base address of the CAN controller.

      - `objID`: is the object number to read (1-32).

      - `msgData`: is a pointer to the array to store the message data

    Note

      1. The message object requested by the objID must first be setup using the CAN_setupMessageObject() function.

      2. If the DLC of the received message is larger than the msgData buffer provided, then it is possible for a buffer overflow to occur.

    Return

      Returns true if new data was retrieved, else returns false to indicate no new data was retrieved.

  bool `CAN_readMessageWithID`(uint32_t base, uint32_t objID, CAN_MsgFrameType *frameType, uint32_t *msgID, uint16_t *msgData)

    Reads the data and Message ID in a Message Object

    This function is used to read the data contents and the Message ID of the specified message object in the CAN controller.The Message returned is stored in the

    msgID parameter and its type in frameType parameter. The data returned is stored in the msgData parameter.
    Parameters

      - `base`: is the base address of the CAN controller.

      - `objID`: is the object number to read (1-32).

      - `frameType`: is a pointer to the CAN_MsgFrameType to store the message type that has been received in the mailbox The frameType parameter shall be filled as of the following values:

        - CAN_MSG_FRAME_STD - Standard 11 bit identifier

        - CAN_MSG_FRAME_EXT - Extended 29 bit identifier This parameter is filled when return value is true for this function.

      - `msgID`: is a pointer to storage for the received Message ID Filled when the return value is true for this function.

      - `msgData`: is a pointer to the array to store the message data Filled with read Data when the return value is true for this function.

    Note

      1. The message object requested by the objID must first be setup using the CAN_setupMessageObject() function.

    Return

      Returns true if new data was retrieved, else returns false to indicate no new data was retrieved.

  void `CAN_transferMessage`(uint32_t base, uint16_t interface, uint32_t objID, bool direction, bool dmaRequest)

    Transfers a CAN message between the IF registers and Message RAM.

    This function transfers the contents of the interface registers to message RAM or vice versa depending on the value passed to direction. This function is designed to be used with DMA transfers.

    Parameters

      - `base`: is the base address of the CAN controller.

      - `interface`: is the interface to use for the transfer. Valid value are 1 or 2.

      - `objID`: is the object number to transfer (1-32).

      - `direction`: is the direction of the transfer. False is Message RAM to IF, True is IF to Message RAM.

      - `dmaRequest`: asserts the DMA request line after a transfer if set to True.

    Return

      None.

  void `CAN_clearMessage`(uint32_t base, uint32_t objID)

    Clears a message object so that it is no longer used.

    This function frees(disables) the specified message object from use. Once a message object has been cleared, it will no longer automatically send or receive messages, or generate interrupts.

    Parameters

      - `base`: is the base address of the CAN controller.

      - `objID`: is the message object number to disable (1-32).

    Return

      None.

  void `CAN_disableMessageObject`(uint32_t base, uint32_t objID)

    Disables specific message object

    This function disables the specific message object. Once the message object has been disabled it will be ignored by the message handler until it is configured again.

    Parameters

      - `base`: is the base address of the CAN controller.

      - `objID`: is the message object number to disable (1-32).

    Return

      None.

  void `CAN_disableAllMessageObjects`(uint32_t base)

    Disables all message objects

    This function disables all message objects. Once a message object has been disabled it will be ignored by the message handler until it is configured again. All message objects are disabled automatically on reset, however this function can be used to restart CAN operations without an external reset.

    Parameters

      - `base`: is the base address of the CAN controller.

    Return

      None.

The following describes important details and recommendations when using the CAN API.

Once system control enables the CAN module, CAN_initModule() needs to be called with the desired CAN module base to put the controller in the init state, initialize the message RAM, and enable access to the configuration registers. Next, use CAN_setBitRate() to set the CAN bit timing values for the bit rate and timing parameters. For tighter timing requirements, use CAN_setBitTiming() instead.

To setup any of the types of message objects, use CAN_setupMessageObject().

Once all of the module configurations are setup, CAN_startModule() starts the CAN module’s operations and disables access to the configuration registers.

If the application needs to disable message processing on the CAN controller, use CAN_disableController() to disable the message processing. Message processing can be re-enabled using CAN_enableController().

The code for this module is contained in driverlib/can.c, with driverlib/can.h containing the API declarations for use by applications.