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 a user file, e.g. can_cfg.c, and filled with the corresponding configuration values.
Example
...
The internal CAN bus controller #0 of the TriCore 1796 shall be used for a simple test protocol. The communication parameters are specified to:
- Standard CAN Identifiers (11 Bits)
- Baud rate shall be 250 kbit/s
Source code
...
#include can_bus.h
/* CAN Bus Configuration */
const CANBUS_PARA
CanCfg = {
...
250000L, /*-2-*/
0L, /*-3-*/
0L, /*-4-*/
TC1796_Init, TC1796_Open, TC1796_Close, /*-5-*/
TC1796_IoCtl, TC1796_Read, TC1796_Write,
{ 10, 11, 12, 13, 14, 15, 16} /*-6-*/
};
Description
...
- Configure CAN bus layer to use standard CAN-Identifiers
...
- Bus speed shall be 250000 bit/s
...
- Bus node name for usage in can bus layer
...
- Driver device of low level device drivers
...
- Links to low level device driver functions
...
- Trivial mapping of function codes, which are needed from the low level device driver
Additional Information
...
- The CAN bus configuration in the example is done as a global constant to safe RAM space and get a write protected configuration.
...
- This variable must be declared global, because the configuration data will be read during initialization and using the CAN bus layer.
...
- Separation of bus node from driver device is necessary when different CAN modules are used, i.e. on a processor with integrated CAN module and also external CAN module(s).
Example
...
On a MPC565 processor TouCAN A, B, C are used and also 3 external SJA1000 CAN modules. Then 6 CAN nodes are available (range 0-5), but driver devices from TouCAN range 0-2 and driver devices from SJA1000 do also range from 0-2.
In this case a possible configuration could be:
Configuration TouCAN A |
Configuration TouCAN B |
Configuration TouCAN C |
Configuration SJA1000 1 |
Configuration SJA1000 2 |
Configuration SJA1000 3 |
If only one CAN device is used then bus node and driver device can be set to equal values.