can200-0.2

所属分类:通讯编程
开发工具:C/C++
文件大小:45KB
下载次数:13
上传日期:2007-04-01 15:22:52
上 传 者mo1
说明:  This version 0.2 of driver for a simple CAN bus interface. 一个CAN 总线接口程序,供大家分享!
(This is version 0.2 of driver for a simple CA N bus interface. A CAN bus interface procedures for the sharing!)

文件列表:
can200-0.2\Makefile (747, 2000-03-25)
can200-0.2\can200.c (31987, 2000-03-25)
can200-0.2\can200.h (2073, 2000-03-25)
can200-0.2\can_test.c (2059, 2000-03-25)
can200-0.2\hardware\can200.png (16080, 2000-03-14)
can200-0.2\hardware\can200_small.png (6544, 2000-03-14)
can200-0.2\hardware\Thumbs.db (7680, 2007-04-01)
can200-0.2\hardware (0, 2007-04-01)
can200-0.2\82c200.h (5474, 2000-03-25)
can200-0.2\COPYING (17989, 1998-10-16)
can200-0.2\can200.lsm (542, 2000-03-25)
can200-0.2\TODO (318, 2000-03-25)
can200-0.2 (0, 2007-04-01)

This is version 0.2 of my driver for a simple CAN bus interface. 2000 03 25 Copyright (c) 2000 Martin Homuth-Rosemann This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Hardware ======== The interface consists of a CAN controller Philips 82C200 (or its successor SJA100) and a CAN bus interface Philips 82C250 or 82C251. Very little glue electronic allows the connection to an EPP printer port. The schematics "can200.png" are included in this driver tarball. In EPP mode the port speed (reading and writing) is about 500 kByte/s. So it is possible to transfer at CAN bitrates up to 1 Mbit/s. For low speed applications (up to 125 kbit/s) the driver can compiled for PS/2 (bidirectional) parallel ports found on some older PCs. The driver emulates the EPP protocoll in software at a speed of about 100 kByte/s. The interface and driver were tested under Linux kernel version 2.2.14 on a i386 PC architecture. Care was taken to be compatible to kernel versions 2.0.xx. Installing the Driver ===================== Type make to build the driver "can200.o", the device descriptors "can20k" and "can40k" and the test program "can_test". make load inserts the driver module, make test starts a test program. If there is no other CAN device connected to the interface the test program returns with Input/output error. The driver uses major = 60. The minor numbers select the speed: Minor Speed ----------------- 0 10kbit/s 1 20kbit/s 2 40kbit/s 3 50kbit/s 4 100kbit/s 5 125kbit/s Programming Interface ===================== The can device driver transfers can messages to or from user programs in fixed size 20 byte blocks. The first 13 bytes show the layout of the SJA100 TX and RX buffer. Received frames contain pad, status and timestamp field. These fields are ignored on transmit. ------+-------+------------------------------------------------ Addr. I Field I bit8 bit6 bit5 bit4 bit3 bit2 bit1 bit0 ------+-------+------------------------------------------------ 0 I info I EFF RTR 0 0 DLC.3 DLC.2 DLC.1 DLC.0 1 I id0 I ID.28 ID.27 ID.26 ID.25 ID.24 ID.23 ID.22 ID.21 EFF=0: 2 I id1 I ID.20 ID.19 ID.18 RTR 0 0 0 0 EFF=1: 2 I id1 I ID.20 ID.19 ID.18 ID.17 ID.16 ID.15 ID.14 ID.13 " 3 I id2 I ID.12 ID.11 ID.10 ID.9 ID.8 ID.7 ID.6 ID.5 " 4 I id3 I ID.4 ID.3 ID.2 ID.1 ID.0 RTR 0 0 5 I data0 I Data byte 1 6 I data1 I Data byte 2 7 I data2 I Data byte 3 8 I data3 I Data byte 4 9 I data4 I Data byte 5 10 I data5 I Data byte 6 11 I data6 I Data byte 7 12 I date7 I Data byte 8 ------+-------+------------------------------------------------ 13 pad unsigned char pad, incremented on every receive 14-15 status unsigned short status, 0 = ok. (TBD) 16-20 time- unsigned long timestamp ( jiffies ) stamp ------+-------+------------------------------------------------ Unused data bytes are ignored on transmit, in received frames zero is returned. This example shows the programming of the can interface: #include "can200.h" ... int can; can_msg_t msg; can = open( "/dev/can20k", O_RDWR ); if ( can >= 0 ) { /* open ok */ while ( CAN_MSG_LEN == read( can, &msg, CAN_MSG_LEN ) ) { /* we got a message, do something ... */ ... if (...) /* end of processing... */ break; } close( can ); } ... The can device operates also in nonblocking mode: ... can = open( "/dev/can20k", O_RDWR | O_NONBLOCK ); if ( can >= 0 ) { /* open ok */ sleep( 2 ); while ( CAN_MSG_LEN == read( can, msg, CAN_MSG_LEN ) ) { /* process all messages already received */ /* leave the loop if no mor msg */ ... } close( can ); } You can switch between the two mode with the fcntl call: ... fcntl( can, F_SETFL, 0 ); /* blocking mode */ ... fcntl( can, F_SETFL, O_NONBLOCK ); /* nonblocking mode */ ... The homepage of the can200 project is located at: http://private.addcom.de/horo/can200/index.html

近期下载者

相关文件


收藏者