To configure a CAN bus interface, a global (optional: const) variable of the type CANBUS_PARA
(defined in can_bus.h) must be allocated in the configuration file can_cfg.c
, and filled with the corresponding configuration values.
CAN Bus Interface Config
The RX600 CAN Driver will be used as an example to describe the communication parameters required in can_cfg.c.
Code Block | ||||
---|---|---|---|---|
| ||||
#include "can_bus.h" const CANBUS_PARA CanCfg = { /* --------------- CAN BUS CONFIGURATION -------------- */ CAN_FALSE, [1] /* EXTENDED FLAG */ 1000000L, [2] /* BAUDRATE */ 0, [3] /* BUS NODE */ 0, [4] /* BUS DEVICE */ [5] /* DRIVER FUNCTIONS */ RX600_CAN_Init, /* Init */ RX600_CAN_Open, /* Open */ RX600_CAN_Close, /* Close */ RX600_CAN_IoCtl, /* IoCtl */ RX600_CAN_Read, /* Read */ RX600_CAN_Write, /* Write */ { /* DRIVER IO FUNCTION CODES */ IO_RX600_CAN_SET_BAUDRATE, [6] /* Set Baud Rate */ IO_RX600_CAN_START, /* Start */ IO_RX600_CAN_STOP, /* Stop */ IO_RX600_CAN_RX_STANDARD, /* Rx Standard */ IO_RX600_CAN_RX_EXTENDED, /* Rx Extended */ IO_RX600_CAN_TX_READY, /* Tx Ready */ IO_RX600_CAN_GET_NODE_STATUS, /* Get Node Status */ } }; |
A CAN Bus Configuration
...
MUST be declared global because the configuration data will be used both during initialization and in the CAN Bus Layer. Also, it is done this way to save RAM Space and get a write-protected configuration.
Node & Device Separation
Anchor | ||||
---|---|---|---|---|
|
...