CAN#

This module provides low-level access to the Leaderboard’s two CAN interfaces, intended to be used for car CAN and motor CAN. The implemenation allows for custom receive and transmit callbacks, which aid in creating higher-level drivers (see CANBus Driver).

group BSP_CAN

Enums

enum CAN_t#

Values:

enumerator CAN_1#
enumerator CAN_3#
enumerator NUM_CAN#

Functions

void BSP_CAN_Init(CAN_t bus, callback_t rxEvent, callback_t txEnd, uint16_t *idWhitelist, uint8_t idWhitelistSize)#

Initializes the CAN module that communicates with the rest of the electrical system.

Parameters:
  • bus – : The bus to initialize. Should only be either CAN_1 or CAN_3.

  • rxEvent – : the function to execute when recieving a message. NULL for no action.

  • txEnd – : the function to execute after transmitting a message. NULL for no action.

  • idWhitelist – : the idWhitelist to use for message filtering. NULL for no filtering.

  • idWhitelistSize – : the size of the idWhitelist, if it is not NULL.

  • rxEvent – : the function to execute when recieving a message. NULL for no action.

  • txEnd – : the function to execute after transmitting a message. NULL for no action.

Returns:

None

Returns:

None

ErrorStatus BSP_CAN_Write(CAN_t bus, uint32_t id, uint8_t data[8], uint8_t len)#

Writes a message to the specified CAN line.

Writes a message to the specified CAN line.

Parameters:
  • bus – the proper CAN line to write to defined by the CAN_t enum

  • id – the hex ID for the message to be sent

  • data – pointer to the array containing the message

  • len – length of the message in bytes

  • id – : Message of ID. Also indicates the priority of message. The lower the value, the higher the priority.

  • data – : data to be transmitted. The max is 8 bytes.

  • length – : num of bytes of data to be transmitted. This must be <= 8 bytes or else the rest of the message is dropped.

Returns:

number of bytes transmitted (0 if unsuccessful)

Returns:

ERROR if module was unable to transmit the data onto the CAN bus. SUCCESS indicates data was transmitted.

ErrorStatus BSP_CAN_Read(CAN_t bus, uint32_t *id, uint8_t *data)#

Reads the message on the specified CAN line.

Reads the message on the specified CAN line.

Note

Non-blocking statement

Parameters:
  • id – pointer to integer to store the message ID that was read

  • data – pointer to integer array to store the message in bytes

  • id – : pointer to store id of the message that was received.

  • data – : pointer to store data that was received. Must be 8bytes or bigger.

Returns:

number of bytes read (0 if unsuccessful)

Pre:

The data parameter must be at least 8 bytes or hardfault may occur.

Returns:

ERROR if nothing was received so ignore id and data that was received. SUCCESS indicates data was received and stored.