eLua platform interface - CAN


This part of the platform interface groups functions related to the CAN interface(s) of the MCU..

Data structures, constants and types

// eLua CAN ID types

Constants used to define whether the message ID is standard or extended..


int platform_can_exists( unsigned id );

Checks if the platform has the hardware CAN specified as argument. Implemented in src/common.c, it uses the NUM_CAN macro that must be defined in the platform's platform_conf.h file (see here for details). For example:

#define NUM_CAN   1      // The platform has one CAN interface

Arguments: id - CAN interface ID.

Returns: 1 if the CAN interface exists, 0 otherwise

u32 platform_can_setup( unsigned id, u23 clock );

This function is used to initialize the CAN hardware and set the bus clock.


  • id - CAN interface ID.
  • clock - the clock of the CAN bus, maximum speed is generally 1000000 (1 Mbit)

Returns: the actual speed set for the CAN interface. Depending on the hardware, this may have a different value than the clock argument.

int platform_can_recv( unsigned id, u32 *canid, u8 *idtype, u8 *len, u8 *data );

Receive CAN bus message.


Returns: PLATFORM_OK for success, PLATFORM_UNDERFLOW for error. (see here for details)