One way is to use the socketCAN On the linux 2.6.29 Kernel.
For setting the bit rate this command is typed to the target's terminal. ex: 1Mbps:
$ echo 1000000 > /sys/devices/platform/mcf-flexcan.1/net\:can1/can_bittiming/bitrate
Then for enabling the can interface:
$ ifconfig can1 ip
Then you can program a linux application using the open source socket can I/F. It is like coding with the socket API but it is on the CAN bus.
So far the experiences has gone OK except when stress testing the CAN interface, the Whole system seems to reboot when running the following CAN loop program. :
while(numofmsg){ nbytes = write(can_socket, &tx_frame, sizeof(struct can_frame)); numofmsg--; // recv() nbytes = recv(can_socket, &rx_frame, sizeof(struct can_frame), MSG_DONTWAIT ); // ...}
now prior to reboot the following message is displayed via the serialk terminal:
Transmission code active 0xc080000
reg->caniflg = 0x3
** MB[1] : CODE=0x6 LEN=8
** RX
OVERRUN
DATA[0]
= 0x4c
DATA[1] = 0x2e
DATA[2] = 0x1
DATA[3] = 0x22
DATA[4] = 0x0
DATA[5] = 0x0
DATA[6] = 0x72
DATA[7] = 0x14
ID = 0x0
Transmission code active 0xc080000
reg->caniflg = 0x3
** MB[1] : CODE=0x6 LEN=8
** RX
OVERRUN
DATA[0] = 0x4c
DATA[1] = 0x2e
DATA[2] = 0x1
DATA[3] = 0x42
DATA[4]
* incomplete received data printing...
* THEN reboot HERE...
every time I looked it rebooting either in the middle of DATA[4] or DATA[3].
Any ideas why?
thanks,
Francois
P.S.socket creation code // create socket if ((can_socket = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) { int err_num = errno; if(verbose)fprintf(stderr, "CAN_Open_Socket() socket() %d", err_num); return -1; // error socket } // bind to specific address strcpy(ifr.ifr_name, "can1" ); ioctl(can_socket, SIOCGIFINDEX, &ifr); addr.can_family = AF_CAN; addr.can_ifindex = ifr.ifr_ifindex; // bind if (bind(can_socket, (struct sockaddr*) &addr, sizeof(addr)) != 0) { int err_num = errno; if(verbose)fprintf(stderr,"CAN_Open_Socket() bind() %d", err_num); return -1; // error socket }