📄 core.c
字号:
/* * can_core - can4linux CAN driver module set tagprg="global -t $1" * * can4linux -- LINUX CAN device driver source * * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * Copyright (c) 2001 port GmbH Halle/Saale * (c) 2001 Heinz-J黵gen Oertel (oe@port.de) * Claus Schroeter (clausi@chemie.fu-berlin.de) *------------------------------------------------------------------ * $Header: /z2/cvsroot/products/0530/software/can4linux/src/core.c,v 1.12 2008/11/24 11:31:02 oe Exp $ * *-------------------------------------------------------------------------- * * * * *-------------------------------------------------------------------------- *//****************************************************************************//*** \mainpage can4linux - CAN network device driver*The LINUX CAN drivercan be used to control the CAN bus (http://www.can_cia.org)connected to a PC running LINUX or embedded LINUX systems using uClinux.Different interface boards and target micro controlllers are supported(see TARGET=VARIABLE in Makefile).The most popular interfaces are theAT-CAN-MINI http://www.port.de/engl/canprod/hw_at.htmlandCPC-PCI http://www.port.de/engl/canprod/hw_cpcpci.html .This project was done in cooperation with the LINUX LLP Projectto control laboratory or automation devices via CAN.It started already in 1995 and is now considered as mature.The former and older can4linux version 1.xdid support many different interface boards.It was possible to use different kinds of boards at the same time.Up to four boards could be placed in one computer.With this feature it was possible to use /dev/can0 and/dev/can2 for two boards AT-CAN-MINI with SJA1000and /dev/can1 and /dev/can3 with two CPC-XT equipped with Intel 82527.\b Attention: This can4linux version isn't supported anymore \b !Instead the \b new version has to be compiled for the target hardware.It was unlikely in the past that a PC or embedded devicewas equipped with different CAN controllers.In all these configurationsthe programmer sees the same driver interface withopen(), close(), read(), write() and ioctl() calls( can_open(), can_close(), can_read(), can_write(), can_ioctl() ).The driver itself is highly configurableusing the /proc interface of the LINUX kernel. The following listing shows a typical configuration with three boards: \code$ grep . /proc/sys/Can/\*/proc/sys/Can/AccCode: -1 -1 -1 -1/proc/sys/Can/AccMask: -1 -1 -1 -1/proc/sys/Can/Base: 800 672 832 896/proc/sys/Can/Baud: 125 125 125 250/proc/sys/Can/Chipset: SJA1000/proc/sys/Can/IOModel: pppp/proc/sys/Can/IRQ: 5 7 3 5/proc/sys/Can/Outc: 250 250 250 0/proc/sys/Can/Overrun: 0 0 0 0/proc/sys/Can/RxErr: 0 0 0 0/proc/sys/Can/Timeout: 100 100 100 100/proc/sys/Can/TxErr: 0 0 0 0/proc/sys/Can/dbgMask: 0/proc/sys/Can/version: 3.0_ATCANMINI_PELICAN\endcodeThis above mentioned full flexibilityis not needed in embedded applications.For this applications, a stripped-down version exists.It uses the same programming interfacebut does the most configurations at compile time.That means especially that only one CAN controller support witha special register access method is compiled into the driver.Actually the only CAN controller supported by this versionis the Philips SJA 1000 in both the compatibility mode \b BasicCAN and the Philips \b PeliCAN mode (compile time selectable).The version of can4linux currently available at the uClinux CVS treeis also supporting the Motorola FlexCAN module as ist is implementedon Motorolas ColdFire 5282 CPU and the Analog Devices BlackFin DSP with CAN.Since version 3.4.6 can4linux assumes that your distribution uses \b udev to have the device`/dev/can[0-9]' automatically created.It is usually necessary to change the device access rights set by \b udev .With the Fedora Core >= 4 or SuSE/novell you can do: \codeecho 'KERNEL=="[Cc]an*", NAME="%k", MODE="0666"' \ > /etc/udev/rules.d/91-Can.rules\endcodeAlternatively create the device inodes in/lib/udev/devices .At system start-up,the contents of that directory is copied to the /dev directorywith the same ownership and permissions as the files in /lib/udev/devices. The driver creates class Can,with information in /sys/class/Can/See also udev (7)The following sections are describing the \e sysctl entries.\par AccCode/AccMaskcontents of the message acceptance mask and acceptance code registersof 82x200/SJA1000 compatible CAN controllers (see can_ioctl()).\par BaseCAN controllers base address for each board.Depending of the \e IOModel entry that can be a memory or I/O address.(read-only for PCI boards)\par Baudused bit rate for this board in Kbit/s\par Chipsetname of the supported CAN chip used with this boardsRead only for this version.\par IOModelone letter for each port. Readonly.Read the CAN register access model.The following models are currently supported:\li m - memory access, the registers are directly mapped into memory\li f - fast register access, special mode for the 82527 uses memory locations for register addresses (ELIMA)\li p - port I/O, 80x86 specific I/O address range (AT-CAN-MINI)\li b - special mode for the B&R CAN card, two special I/O addresses for register addressing and accessSince version 2.4 set at compile time.\par IRQused IRQ numbers, one value for each board.(read-only for PCI boards)\par Outcvalue of the output control register of the CAN controllerSince version 2.4 set at compile time.A board specific value is used when the module the first time is loaded.This board specific value can be reloded by writing the value 0to \e Outc .\parWith the most boards using a Philips SJA1000,by changing the value of the \e Outc it is possibleto inhibit generating the CAN Acknowledge.Using this feature, it is possible to implement a \b listen \b onlymode.Please refer the CAN controller documenattion for more details.\parAnother way is implementing access to the \b mode register with an\e ioctl () call in later \e can4linux versions.\par Overruncounter for overrun conditions in the CAN controller\par RxErrcounter for CAN controller rx error conditions\par Timeouttime out value for waiting for a successful transmission\par TxErrcounter for CAN controller tx error conditions\par dbgMaskif compiled with debugging support, writing a value greater then 0 enables debugging to \b syslogd .The value is bit coded.\codeBit 0 print all debug messagesBit 1 print function entry messageBit 2 print function exit messageBit 3 print if a function branches intwo differnt branchesBit 4 print debug data statements\endcode\par versionread only entry containing the drivers version numberPlease see also at can_ioctl() for some additional descriptions.For initially writing these sysctl entries after loading the driver(or at any time) a shell script utility does exist.It uses a board configuration file that is written over \e /proc/sys/Can .\codeutils/cansetup port.conf\endcodeor, like used in the Makefile:\codeCONFIG := $(shell uname -n)# load host specific CAN configurationload: @echo "Loading etc/$(CONFIG).conf CAN configuration" utils/cansetup etc/$(CONFIG).conf echo 0 >/proc/sys/Can/dbgMask\endcodeExample *.conf files are located in the \e etc/ directory.\noteThis documentation was created using the wonderful tool\b Doxygen http://www.doxygen.org/index.html .Die Dokumentation wurde unter Verwendung von\b Doxygen http://www.doxygen.org/index.htmlerstellt*/#include <linux/init.h>#include <linux/fs.h> /* register_chrdev() */#include <linux/pci.h>#include "defs.h"#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0) # include <linux/device.h>#endif#ifndef DOXYGEN_SHOULD_SKIP_THISMODULE_AUTHOR("H.-J.Oertel <oe@port.de>");MODULE_DESCRIPTION("CAN fieldbus driver");MODULE_LICENSE("GPL");#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0) MODULE_VERSION("3.5");#endif#define CANREGDEVNAME "Can"int IRQ_requested[MAX_CHANNELS] = { 0 };int Can_minors[MAX_CHANNELS] = { 0 }; /* used as IRQ dev_id */int Can_major = CAN_MAJOR; #endif /* DOXYGEN_SHOULD_SKIP_THIS *//*There's a C99 way of assigning to elements of a structure,and this is definitely preferred over using the GNU extension.gcc 2.95, supports the new C99 syntax.The meaning is clear, and you should be awarethat any member of the structure which you don't explicitly assignwill be initialized to NULL by gcc.*/static struct file_operations can_fops = { .owner = THIS_MODULE, .open = can_open, .release = can_close, .read = can_read, .write = can_write, .poll = can_select, .ioctl = can_ioctl, .fasync = can_fasync,};static struct class *can_class;#ifndef DOXYGEN_SHOULD_SKIP_THIS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -