GUF-Yocto-34.0-r5756-0
VINCELL
User Manual
The header for i2c-dev is available under:
include/linux/i2c-dev.h
Note:
If i2c-dev is used to access the I2C bus directly, the user is responible for keeping the interop-
erability consistent with all other I2C devices that are controlled by the Linux kernel.
6.7
CAN
CAN bus devices are controlled through the SocketCAN framework in the Linux kernel. As a consequence, CAN
interfaces are network interfaces. Applications receive and transmit CAN messages via the BSD Socket API.
CAN interfaces are configured via the netlink protocol. Additionally, Garz & Fricke Linux systems are shipped
with the
canutils
package to control and test the CAN bus from the command line.
On VINCELL the CAN bus is physically available on connector X39.
Example 1
shows how a CAN bus interface can be set up properly for 125 kBit/s from a Linux console:
root@vincell:~# canconfig can0 bitrate 125000
root@vincell:~# ifconfig can0 up
Note:
Due to the use of the busybox version of the
ip
tool the following sequence does
NOT
work on
Garz & Fricke Linux systems:
root@vincell:~# ip link set can0 type can bitrate 125000
root@vincell:~# ifconfig can0 up
As already stated above, CAN messages can be sent through the BSD Socket API. The structure for a CAN
message is defined in the kernel header
include/linux/can.h
:
struct can_frame {
u32 can_id; /* 29 bit flags */
u8 can_dlc; /* data length code: 0 .. 8 */
u8 data[8];
};
Example 2
shows how to initialize SocketCAN from a C program:
int iSock;
struct sockaddr_can addr;
iSock = socket(PF_CAN, SOCK_RAW, CAN_RAW);
addr.can_family = AF_CAN;
addr.can_ifindex = if_nametoindex("can0");
bind(iSock, (struct sockaddr *)&addr,
sizeof(addr);
Example 3
shows how a CAN message is sent from a C program:
struct can_frame frame;
frame.can_id = 0x123;
frame.can_dlc = 1;
frame.data[0] = 0xAB;
nbytes = write(iSock, &frame,
sizeof(frame));
Example 4
shows how a CAN message is received from a C program:
29