eLua platform interface - CAN
Overview
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
enum
{
ELUA_CAN_ID_STD = 0,
ELUA_CAN_ID_EXT
};
Constants used to define whether the message ID is standard or extended..
Functions
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.
Arguments:
- 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.
void platform_can_send( unsigned id, u32 canid, u8 idtype, u8 len, const u8 *data );
Send message over the CAN bus.
Arguments:
- id - CAN interface ID.
- canid - CAN identifier number.
- canidtype - identifier type as defined here
- len - message length in bytes (8 or fewer)
- message - pointer to message, 8 or fewer bytes in length
Returns: nothing.
int platform_can_recv( unsigned id, u32 *canid, u8 *idtype, u8 *len, u8 *data );
Receive CAN bus message.
Arguments:
- id - CAN interface ID.
- canid - pointer where CAN identifier number will be written.
- canidtype - pointer where identifier type as defined here will be written
- len - pointer where message length in bytes will be written
- message - pointer to message buffer (8 bytes in lenth)
Returns: PLATFORM_OK for success, PLATFORM_UNDERFLOW for error. (see here for details)