Home
user manual
Contents
1. t2 tv_sec t1 tv_sec 1000000 H t2 tv_usec tl tv_usec t2 tv_sec tl tv_sec 1000000 H t2 tv_usec tl1 tv_usec N_SAMPLE return 0 4 4 4 4 insn convention subdev insn data format NOTE 2 INSN BITS data 0 reserved data 1 DI value 3 INSN BITS data 0 channel mask For example DO at channel 2 mask data 1 DO value would be 0x4 and value should be 0x4 or Oxf 15 INSN BITS data 0 pid of user case data 1 0 clear a pid from driver data 1 action dealing data 1 1 append a pid to driver with pid in data 0 data 1 2 clear all pid in driver 4 4 4 5 insn special hint 1 PCM 3730 In INSN_BITS function of DI the low 8 bits of data 1 correspond to the IDI bits 0 7 and the next high 16 bits correspond to the DI bits 0 16 In INSN_BITS function of DO the low 8 bits of data 1 correspond to the IDO bits 0 7 and the next high 16 bits correspond to the DO bits 0 16 4 5 Advantech test example manuals Advantech provides test example for each DAQ cards as well as manuals which located at the document directory of test package test Doc lt card id gt manual pdf Please refer to these manuals for usage of each cases 5 comedilib functions description 5 1 Device file operation function comedi_t comedi_open char fn Opens a comedi device specified by the filename fn Confidential Advantech Automation Corporation 2001 Page 36 of 41 L
2. Advantech Automation Corporation Advantech Device Driver for Linux User s manual Version lt 2 4 gt Linux driver development User s Manual Date 8 3 2004 Edwin Revision History 2003 5 1 lt 2 1 gt Add pcil 784 modify installation Edwin instructions 2003 5 20 United Linux testing 2004 1 7 lt 2 3 gt Add pem3730 add insn convention and Eddy Yang special hint of pcm3730 7 15 2004 lt 2 4 gt Add supported cards table Zhang dongdong Confidential Advantech Automation Corporation 2001 Page 2 of 41 Linux driver development Date 8 3 2004 Edwin Table of Contents 1 Introduction 4 1 1 Features 4 1 2 Definitions Acronyms and Abbreviations 4 13 Overview 4 14 References 5 2 Comedi installation instructions 6 2 1 Comedi 0 7 60 installation 6 2 1 1 Patch for comedi 6 2 1 2 Linux source 7 2 1 3 RTAI support 10 2 1 4 RTLinux support 10 2 1 5 Configuration 10 2 1 6 Compiling 10 2 1 7 Installation 11 2 1 8 Module Autoloading 11 2 1 9 Upgrading 11 2 1 10 Un installation 11 2 1 11 Hack 12 2 2 Comedilib 0 7 19 installation 12 3 Package configuration 12 3 1 The existent drivers 12 32 Adding driver to original comedi 13 3 3 Running Comedi 13 34 Multi cards co existence 14 4 Programming with comedi 15 4 1 Relationship between user program and device driver 15 42 Call flow of user s program 16 43 Subdevice 16 44 Subdevice operator mode 17 44 1 Director
3. gt comedi_open setup comedi_cmd structure EATA comedi_cmd tend een ne gt comedi_close Confidential Advantech Automation Corporation 2001 Page 24 of 41 Linux driver development User s Manual Date 8 3 2004 Edwin 4 4 3 1 Command mode structure subdevice fla scan_begin_src g src type start acquisition start each scan scan_begin_arg convert_src convert_arg scan_end_src data start each convert the end of each scan stop the acquisition i struct comedi_cmd_struct unsigned int subdev the subdevice that the command is sent to unsigned int flags flags Wake up at the end of every scan amd gt flags TRIG WAKE EOS Us a real time interrupt if available and gt flags TRIG RT each event requires a trigger which is specified by asourceand an argument For example to specify Confidential Advantech Automation Corporation 2001 Page 25 of 41 Linux driver development Date _8 3 2004 Edwin an external digital line 3 as a source you would use src TRIG_EXT and arg 3 unsigned int start src The start of acquisition is controlled by start src TRIG NOW Thestart src event occurs start arg nanoseconds ke after comedi_command is called Currently AE only start_arg 0 is supported TRIG_FOLLOW For an output device The start_src event occ
4. 2001 Page 19 of 41 Linux driver development Date _8 3 2004 Edwin 0 software trigger 1 timed acquisition 2 timed acquisition with 2 timers a major timer amp a minor timer 3 external trigger 4 external trigger amp a minor timer TRI G_NONE TRI G_TIMER TRIG EXT subdevice data number of scans trigger source 4 4 2 2 comparison between 5 modes 4 4 2 2 1 mode 0 0 is one shot Actually some of the drivers will return as many samples as you ask i e trig n for the channels you specify Others will limit it to a reasonable number that will finish in 1 10 ms and the rest only return 1 for the first channel specified The idea here is at the convenience of the driver preferably fast 44222 model mode 1 is timed acquisition with a single timer For example if you request channels 2 4 and 6 in mode 1 with the number of samples trig n 2 and a timer value that corresponds to 100 us the driver programs the device to measure inputs at these times time chan 0 us 2 100 us 4 200 6 300 2 400 4 500 6 If you board can support mode 2 mode 1 is not necessary Comedilib will eventually emulate it Confidential Advantech Automation Corporation 2001 Page 20 of 41 Linux driver development Date _8 3 2004 Edwin 44223 mode 2 mode 2 is similar but has 2 timers a major timer trig timeval and a minor timer trig timevall Takin
5. gt chanlist chanlist cmd gt chanlist len n chan cmd gt data capdata cmd gt data len 10 sizeof sampl_t Confidential Advantech Automation Corporation 2001 Page 30 of 41 Linux driver development Date _8 3 2004 Edwin chanlist OJ CR PACK chan 0 rangearef chanlist 1 CR_PACK dan lrangearef chanlist 2 CR_PA CK chan 2 range aref chanlist 3J CR_PA CK chan 3 rangearef do_cmd dev amp and return 0 void do and comedi_t dev comedi_amd cmd int total 0 int ret i data int go ret comedi_command dev cmd if ret lt 0 comedi_perror comedi_command return go 1 while go ret read comedi_fileno dev buf BUFSZ if ret lt 0 if errno EAGAIN usleep 10000 Jelse go 0 perror read Jelse if ret 0 Confidential Advantech Automation Corporation 2001 Page 31 of 41 Linux driver development Date _8 3 2004 Edwin go 0 jelse static int col 0 inti total ret for i O i lt ret 2 i printf d sampl_t buf i printf f comedi_to phys float sampl_t buf li srange col maxdata col col if col n_chan printf n col 0 4 4 4 insn mode Insn mode can almost be used for every type of subdevice When using insn mode we need to setup insn type so comedi could call different function with the different insn type In device driver we need to has different insn function referring to differe
6. scripts linux_flags L Ixdialog Y Comedilib 0 7 19 tgz This distribution contains only the user space library More information please refer to comedilib 0 7 19 README Y Test tar gz This distribution contains testing cases on the driver Test cases are based on comedilib 0 7 19 1 4 References COMEDI Official web site http stm Ibl gov comedi or http www comedi org The IO Port Programming Mini HOWTO http www linuxdoc org HOW TO mini IO Port Programming html Linux Kernel Module Programming Guide http www linuxdoc org LDP lkmpg mpg html Kernel Hacker s Guide http www linuxdoc org LDP khg HyperNews get khg html Confidential Advantech Automation Corporation 2001 Page 5 of 41 Linux driver development Date _8 3 2004 Edwin Linux Device Drivers 2nd Edition http www xml com ldd chapter book index html RTAI web site http www rtai org or http www aero polimi it rtai 2 Comedi installation instructions 2 1 Comedi 0 7 60 installation 2 1 1 Patch for comedi When using comedi in RedHat9 or compiling with gcc 3 x x you should patch comedi package Patching process as follow 1 decompressing file patch tgz tar xvfz patch tgz The directory construction is patch comedi 0 7 60 gcc3 patch patch file for gcc3 problem comedi 0 7 60 redhat9 patch patch file for redhat9 problem README readme file 2 patch for gcc3 x x If your OS such a
7. you must run lilo to activate your configurations sbin lilo v GRUB Edit your grub configuration file to append a new item vi boot grub menu lst this location is where you installed grub append such new lines to locate your kernel title linux 2 x x any name kernel hd0 1 vmlinz 2 x x root dev hdal 7 Reboot system and select the new kernel 2 1 2 2 Linux distribution kernel Setup Since each Linux distribution has made some modification to its own kernel package it might cause some problem to use these kernel sources Here we provide some suggestions to use these kernels according to each Linux distribution however the compiling success is not guaranteed In this section kernel packages quoted as linux 2 x x following are ones that released together with specific Linux distributions 2 1 2 2 1 Redhat Confidential Advantech Automation Corporation 2001 Page 8 of 41 Linux driver development User s Manual Date 8 3 2004 Edwin Red Hat users note Kernel sources that are distributed with Red Hat Linux are NOT supported because they are too heavily modified However there is some information in Documentation comedi redhat notes on how to use Red Hat kernels The following steps are tested under Redhat 7 x Redhat 8 0 and Redhat 9 0 NOTICE that Redhat 9 0 releases with gcc 3 2 2 which seems to cause some problem when compiling comedilib You should change gcc version to 3 2 3 or earlier version
8. 1 Page 39 of 41 Linux driver development User s Manual Date 8 3 2004 Edwin Returns on sucess comedi_data_write returns 0 If there is an error 1 is returned y intcomedi_dio_read comedi_t it unsigned int subd unsigned int chan unsigned int bit This function reads the status of channel belonging to the digital input subdevice Argument it is the values return from comedi_open subd is the index of the subdevice chan is the index of the channel bit contains the result 0 or 1 Returns return 0 on success returns 1 on failure This function is equivalent to comedi_data_read it subd chan 0 0 bit Y _ int comedi_dio_write comedi_t it unsigned int subd unsigned int chan unsigned int bit This function reads the status of channel belonging to the digital input subdevice Argument it is the values return from comedi_open subd is the index the the subdevice chan is the index of the channel belonging to the digital output device bit contains the data that will be write to the channel 0 or 1 Returns return 0 on success returns 1 on failure _ int comedi_dio_bitfield comedi_t it unsigned int subd unsigned int write_mask unsigned int bits This function allows multiple channels to be read simultaneously from a digital input or digital I O device Argument it is the values return from comedi_open subd is the index of the subdevice write mask is the mask of a channel bit contains th
9. CI 1710HG PCI 1711 PCI 1713 PCI 1720 PCI 1731 pcil712 0 PCI 1712 pcil716 0 PCI 1716 Pcil721 0 PCI 1721 Pcil730 0 PCI 1730 PCI 1733 PCI 1734 Pcil750 0 PCI 1750 Pcil751 0 PCI 1751 Pcil753 0 PCI 1753 PCI 1753E MIC 3753 Pcil75x 0 PCI 1752 PCI 1754 PCI 1756 MIC 3756 Pcil760 0 PCI 1760 Pcil761 0 PCI 1761 MIC 3761 Pcil762 0 PCI 1762 Pcil780 0 PCI 1780 Pcil784 0 PCI 1784 Pcl711 0 PCL 711 Confidential Advantech Automation Corporation 2001 Page 12 of 41 Linux driver development Date _8 3 2004 Edwin Pcl724 0 PCL 724 PCL 722 PCL 731 Pcl725 0 PCL 725 Pcl726 0 PCL 726 PCL 727 PCL 728 Pcl812 0 PCL 812 Pcl818 0 PCL 818 Pcm3718 0 PCM 3718 Pcm3730 0 PCM 3730 3 2 Adding driver to original comedi Y If a comedi package downloaded from the web site was already installed a newly written device driver could be added into the comedi environment Put your driver source code into directory comedi 0 7 60 comedi drivers To add a driver to comedi first you should make distclean to remove original comedi settings Then edit comedi 0 7 60 comedi Config in and append a new line for example dep tristate PCI 1730 CONFIG COMEDI PCI1730 SCONFIG COMEDI which describes the module dependency for comedi Y Next you should edit comedi 0 7 60 comedi drivers Makefile to add a new make option for the driver For example obj CONFIG_COMEDI_PCI1730 pc
10. _COMEDI SUBD COUNTER Counter COMEDI SUBD TIMER Timer e _COMEDI SUBD MEMORY Memory e g EEPROM or dual ported RAM Confidential Advantech Automation Corporation 2001 Page 37 of 41 Linux driver development User s Manual Date 8 3 2004 Edwin e COMEDI SUBD_CALIB Calibration DACs e COMEDI SUBD_ PROC Processor or DSP start_subdevice define the starting subdevice number Returns If it finds the requested subdevice it returns its index If it does not locate the requested subdevice it returns 1 and sets the comedi error number to subdevice not found If there is an error the function returns 1 and sets the appropriate error 5 3 Driver information acquirement y char comedi get driver _name comedi_t it This function returns the name of a driver Argument it is the values return from comedi_open Returns a pointer to a string containing the name of the driver being used by comedi for the comedi device represented by it This pointer is valid until the comedi descriptor it is closed returns NULL if there is an error y char comedi get board _name comedi_t it This function returns the name of the device Argument it is the values return from comedi_open Return a pointer to a string containing the name of the device This pointer is valid until the comedi descriptor it is closed returns NULL if there is an error y _intcomedi get subdevice_type comedi_t it unsigned int subdevice This
11. ange structure that contains information that can be used to convert sample values to or from physical units The pointer is valid until the comedi device it is closed If there is an error NULL is returned 5 4 Data acquisition funcion intcomedi_data_read comedi_t it unsigned int subd unsigned int chan unsigned int range unsigned int aref lsampl_t data This function Reads a single sample from the subdevice Argument it is the values return from comedi_open subd is the index of the subdevice chan is the index of the channel range is the range index of a subdevice aref is analog reference type For the A D conversion if appropriate the device is configured to use range specification range and if appropriate analog reference type aref Analog reference types that are not supported by the device are silently ignored data contain the result data Returns On sucess comedi_data_read returns 0 If there is an error 1 is returned _ int comedi_data_write comedi_t it unsigned int subd unsigned int chan unsigned int range unsigned int aref lsampl_t data This function writes a single sample on the channel of a subdevice Argument it is the values return from comedi_open subd is the index of the subdevice chan is the index of the channel range is the range index of a subdevice aref is analog reference type data contain the result data Confidential Advantech Automation Corporation 200
12. e unsigned int mode mode include mode0 model mode4 7 unsigned int flags TRIG_BOGUS do the motions TRIG_DITHER enable dithering Confidential Advantech Automation Corporation 2001 Page 18 of 41 Linux driver development Edwin TRIG_DEGLITCH enable deglitching TRIG_RT perform op in real time TRIG_CONFIG perform configuration not triggering TRIG_WAKE_EOS wake up on end of scan events TRIG_WRITE write to bidirectional devices unsigned int n_chan number of channels unsigned int chanlist channel range list the channel list determined which channels are sampled In general chanlist_len isthe same as scan end arg Most boards require this sampl_t data data list size depends on subd flags unsigned int n number of scans unsigned int trigsrc TRIG ANY TRIG NONE never trigger TRIG NOW trigger now N ns TRIG FOLLOW trigger on next lower level trig TRIG_TIME trigger at time N ns TRIG_TIMER trigger at rate N ns TRIG COUNT trigger when count reaches N TRIG_EXT trigger on external signal N TRIG_INT trigger on comedi internal signal N unsigned int trigvar major timer value unsigned inttrigvarl minor timer value unsigned int data len data list size depends on subd flags unsigned int unused 3 unused Confidential Advantech Automation Corporation
13. e dev comedi since the major number has changed 2 1 10 Un installation Run make distclean to uninstall comedi 0 7 60 from your Linux Anyway you should manually delete some modules located at lib modules 2 x x comedi Confidential Advantech Automation Corporation 2001 Page 11 of 41 Linux driver development Date _8 3 2004 Edwin 2 1 11 Hack The newer kernels have the concept of module licenses Comedi releases do not cover this point So update amcc5933 c to avoid taint the kernel prompting Packages provided are configured properly with this no problem when installing If console did not display kernel config messages type echo 8 gt proc sys kernel printk 2 2 Comedilib 0 7 19 installation Compile using make If this doesn t work make sure you have the basic tools installed to compile If you can successfully compile other things consult the author as he has probably made a mistake Install using make install as root This installs the files lusr lib libcomedi so 0 3 lusr include comedi h lusr include comedilib h and other things if your OS is redhat 9 run ldconfig usr local lib If you run Debian GNU Linux comedilib is packaged as the packages libcomedi0 and libcomedi dev These are available as part of woody 3 Package configuration 3 1 The existent drivers Driver name Supported cards pcil710 0 PCI 1710 P
14. e data that will be write to the channel 0 or 1 Returns return 0 on success returns 1 on failure comedi_trigger comedi_t it comedi_trig trig This function instructs comedi to perform the command specified by the trigger structure Argument it is the values return from comedi_open trig is the comedi_trig structure as we motioned before Results depend on the particular command being issued If there is an error 1 is returned Y comedi_command comedi_t it comedi_cmd cmd Confidential Advantech Automation Corporation 2001 Page 40 of 41 Linux driver development User s Manual Date 8 3 2004 Edwin This function instructs comedi to perform the command specified by the command structure Argument it is the values return from comedi_open cmd is the comedi_cmd structure as we motioned before Results depend on the particular command being issued If there is an error 1 is returned Y comedi_do_insn comedi_t it comedi_insn insn This function instructs comedi to perform the command specified by the insn structure Argument it is the values return from comedi_open insn is the comedi_insn structure as we motioned before Results depend on the particular command being issued If there is an error 1 is returned Confidential Advantech Automation Corporation 2001 Page 41 of 41
15. e your configuration Alternatively if you already have a configuration file you could config your kernel by make oldconfig cp p YOUR CONFIG FILE config config make oldconfig 4 Make dependencies After configuration you must make dependencies make dep Confidential Advantech Automation Corporation 2001 Page 7 of 41 Linux driver development User s Manual Date 8 3 2004 Edwin 5 Produce bootable kernel image and get ready to boot using the new kernel make bzImage make modules make modules_install These three steps would compile the source package into a bootable kernel image due to your own configuration and also install modules into lib modules 2 x x make install This step would copy the target image into boot and setup to boot your new kernel If you have successfully finished above operations you might find some new files in boot directory such as vmlinuz 2 x x and System map 2 x x 6 Append anew item to your bootloader to boot the kernel Finally you might be able to boot your new kernel In most cases your Linux might use LILO or GRUB as the boot manager here are some instructions for them respectively LILO Edit your lilo configuration file to append a new item vi etc lilo conf append such new lines to locate your kernel image boot vmlinuz 2 x x label linux 2 x x any name you want to name it root dev hdal Here is your location read only Finally
16. edi mail list would give your more information of RTLinux comedi installation Advantech drivers are not tested with RTLinux performances of the drivers are not guaranteed 2 1 5 Configuration First change to a directory that you have write permission cd usr local tar zxvf comedi 0 7 60 tgz This command will depress the comedi into the comedi 0 7 60 directory Thus the package would be extracted to usr local comedi 0 7 60 After unpack the comedi package you may configure using make config This will ask you the location of the Linux kernel source tree If it detects that you have a kernel patched for RTAI or RTLinux it will also ask you for the location of the RTAI or RTLinux source directory Then the configuration script will ask questions for a couple general Comedi features and then whether or not compile each driver make config If you want to reconfigure comedi use make distclean and make 2 1 6 Compiling Compile using make If this fails for some reason send the _entire_ build log to the mailing list Without the build log it is impossible to find problems Confidential Advantech Automation Corporation 2001 Page 10 of 41 Linux driver development Date _8 3 2004 Edwin make 2 1 7 Installation Install using make install as root This installs the files make install lib modules lt lt kernel version gt gt misc comedi o lib modules lt lt kernel version gt g
17. function get an integer describing the type of subdevice that belongs to the comedi device Argument it is the values return from comedi_open subdevice is the index of the subdevice Returns the type of this subdevice 1 is returned if is there is an error intcomedi_ get n_channels comedi_t it unsigned int subdevice This function gets the number of channels of a subdevice Argument it is the values return from comedi_open subdevice is the index of the subdevice Returns the number of a subdevice channels 1 is returned if is there is an error y lsampl_t comedi get maxdata comedi_t it unsigned int subdevice unsigned int chan This function gets the maximum valid data value for channel of a subdevice Argument it is the values return from comedi_open Confidential Advantech Automation Corporation 2001 Page 38 of 41 Linux driver development User s Manual Date 8 3 2004 Edwin subdevice is the index of the subdevice chan is the index of the channel Returns the maximum valid data value of the channel or returns 0 on error Y _comedi range comedi get range comedi_t it unsigned int subdevice unsigned int chan unsigned int range This function gets the range for channel of a subdevice Argument it is the values return from comedi_open subdevice is the index of the subdevice chan is the index of the channel range is the range index of a subdevice Returns a pointer to a comedi_ r
18. g the previous example but with a major timer of 1000 us and a minor timer of 100 us inputs are measured at these times time chan 0 us 100 us 200 1000 1100 1200 NS A N OA A N 44224 mode 3 mode 3 is like mode 1 except that an external trigger is used If t n represents the time of the nth trigger inputs are measured at the following times time chan t t 2 t 3 4 t 5 t 6 NS A N OA A N 44225 mode 4 mode 4 uses an external trigger and a minor timer With a minor timer of 100 us we get time chan t 1 2 t 1 100 us 4 t 1 200 us 6 t 2 2 t 2 100 us 4 t 2 200 us 6 As a bit of background mode 2 amp 4 are the most useful Mode 1 is the only supported by many boards Mode 3 is the only supported by a few boards Mode 3 could be useful to synchronize multiple boards if the master board is capable of exporting a trigger signal 4 4 2 3 Trigger mode example include lt stdio h gt Confidential Advantech Automation Corporation 2001 Page 21 of 41 Linux driver development Date _8 3 2004 Edwin include lt comedilib h gt char filename dev comedi0 int verbose flag comedi_t device int subdevice 0 int channel O int aref int range O void main int argc char argv comedi_trig it unsigned int chanspec int save_errno int ret device comedi_open filename if ldevic printf E comedi_open s s n filename strerror ermno memse
19. h illustrate it more explicitly 3 4 Multi cards co existence Y Device files located at dev comediX by default there is 4 device files coemdi0 comedil comedi2 comedi3 More device files could be appended manually Y Comedi_config could bind device file to module pcil730 Specific card could be identified with pci bus and slot which could be passed through comedi_config command parameters If you have more than 4 card in the same system you should manually add nodes just as make dev does n mknod m 666 dev comediX c 98 X n Here X is the number of your nodes might be 5 6 etc Confidential Advantech Automation Corporation 2001 Page 14 of 41 Linux driver development Date 8 3 2004 User s Manual Edwin 4 Programming with comedi 4 1 Relationship between user program and device driver 1 1 Comedi 1 2 User config and allocate resource io irq etc subdevide access module subdevice free resource Confidential Advantech Automation Corporation 2001 Page 15 of 41 Linux driver development Date _8 3 2004 Edwin 4 2 Call flow of user s program open device SANS gt comedi_open comedi_findsubdevic find subdevice EED gt e by type0 config subdevice data read amp write Setndnsts 4 different access modes ze ee et Herde gt comedi_close 4 3 Subdevice In comedi the different functions of device are imaged t
20. hat device name is appropriate for your hardware The option list user should partition parameter in option list with comma is to supply additional information such as I O address IRQ DMA channels and other jumper settings Information about option lists appropriate for a driver is in drivers txt The following commands are examples usr sbin eomedi_config dev eomedi0 pcil730 0 10 this command combines device dev comedi0 to module pcil 730 located at pci bus0 slot 10 Remember here we use a device name so if you want to use pcil733 cards which are sharing the same driver with pcil730 you should replace pcil730 with pcil733 in this command lusr sbin comedi_config dev comedi0 pci818 0x300 5 3 read buffer 1024 Try a man comedi_config for information on how to use this utility Scripts have been written for a few of the drivers with very complicated option lists these are found in the etc directory For example if you use only one PCI 1710 card you should run sbin modprobe comedi sbin modprobe adv_pcil710 usr sbin comedi_config dev comedi0 pci1710 Attention different driver may have different options so you need to read driver document for more information At the beginning of each driver s source file there are the descriptions of how to fill in the above parameters the users may fill in them accordingly You can find this information also in comedi 0 7 60 Documentation comedi drivers txt whic
21. idential Advantech Automation Corporation 2001 Page 9 of 41 Linux driver development Date 8 3 2004 Edwin 1 Make dependencies of the kernel source just as the stand way cd usr sre ln s linux 2 x x x linux make mrproper make menuconfig xconfig oldconfig config make dep 2 Modify comedi package Edit file comedi kvmem h replace line include lt asm pgtable h gt with include lt linux highmem h gt Otherwise you will probably have the prompt Unresolved symbol kmap_pagetable when inserting mode comedi o 3 Compile and install comedi pacakge 2 1 3 RTAI support If you want to use the real time capabilities of Comedi with RTAI you need to compile and install RTAI first It is necessary to use the rthal patch instead of the copyto scripts Known working versions are RTAI 1 6 RTAI 24 1 4 and current RTAI CVS Remember to enable Kcomedilib support since you will be accessing Comedi from other kernel modules Comedi mail list would give your more information of RTAI comedi installation Advantech drivers are not tested with RTAI performances of the drivers are not guaranteed 2 1 4 RTLinux support If you want to use the real time capabilities of Comedi with RT Linux you need to compile RT Linux both the kernel and the modules first Known working versions are 2 x and 3 0 Remember to enable Kcomedilib support since you will be accessing Comedi from other kernel modules Com
22. il730 0 Remember that the variable here must be consistent to the line in Config in file Y Run make to reconfigure comedi 0 7 60 select the new driver Y Run make to compile Then make install to install the module into Linux 3 3 Running Comedi To use comedi the driver module and the core Comedi modules must be loaded into the kernel This is done by a command similar to sbin modprobe lt lt driver gt gt If your module dependencies are set up correctly this will load both comedi o and your driver If you get unresolved symbols check the FAQ or the mailing list archives Also look at the man pages for modprobe and insmod To unload the module run sbin rmmod lt lt driver gt gt In order to configure a driver module to use a particular device file dev comediN and a particular device you need to use the command usr sbin comedi_config which is part of the comedilib distribution Comedi_config is invoked using usr sbin comedi_config dev comedi0 lt device name gt lt option list gt Confidential Advantech Automation Corporation 2001 Page 13 of 41 Linux driver development Date 8 3 2004 Edwin The device name may or may not be the same as the module name In general if the device type can be auto probed as with ISA PnP or PCI devices the device name will be the same as the module name Otherwise you will need to check Documentation comedi drivers txt for information about w
23. inux driver development Date _8 3 2004 Edwin Argument fn is a device filename such as dev comedi0 Returns NULL on error On sucess it returns a handle that is given as a parameter to other libcomedi functions Y void comedi_close comedi_t it Closes a device previously opened by comedi_open Argument it is the values return from comedi_open int comedi_fileno comedi_t it This function returns the integer descriptor for the handle it It is equivalent to the standard function fileno Argument it is the values return from comedi_open Return If it is an invalid comedi_t pointer the function returns 1 and sets the appropriate libcomedi error value 5 2 Subdevice operation function y _intcomedi get n_subdevices comedi_t it This function returns the number of subdevices associated with the comedi descriptor it Argument it is the values return from comedi_open Returns Argument it is the values return from comedi_open or 1 if there is an error _intcomedi find _subdevice by type comedi_t it int type unsigned int start subdevice This function tries to locate a subdevice belonging to comedi device it Argument type is one of subdevice type include e COMEDI SUBD_UNUSED Subdevice has no functionality e COMEDI SUBD Al Analog input e COMEDI SUBD_ AO Analog output e COMEDI SUBD DI Digital input e COMEDI SUBD DO Digital output e COMEDI SUBD DIO Digital input output e
24. inux kernel and configure it The other way informs you the way to configure kernels in some popular Linux release such as RedHat Debian Mandrake etc General setup We strongly recommend to use a standard Linux kernel distributed by http www kernel org this section describes the most common steps to setup the kernel This operation is independent to Linux releases Read the instructions if you have problem compiling the kernels http www tldp org HO WTO Kernel HOWTO 1 Get a copy of the kernel source that matches the kernel you are running Download a kernel from http www kernel org or from a mirror site nearby The compressed tar archive in this directory can be downloaded using a web browser or a command line program such as wget wget no directories retr symlinks http www kernel org pub linux kernel v2 4 linux 2 x x tar gz 2 Copy the package into a directory that you have writes permission and unpack kernel cp linux 2 x x tar gz usr sre ted usr sre tar jxvf linux 2 x x tar bz2 This command is for bz2 kernel tar zxvf linux 2 x x tar gz This command is for gz kernel 3 Configure your kernel Change into your kernel source directory cd linux 2 x x make menuconfig Then you would be provided with a graphic user interface to configure your kernel Configuration steps is far beyond our scope please refer to some other manuals After configuration you should exit and choos save to sav
25. medi_data_read comedi_data_write comedi_dio_read comedi_dio_write etc The program steps are illustrated in the follow figure open device data read amp write data output gt comedi_open directory data read amp write functions fsb ss gt comedi_close Confidential Advantech Automation Corporation 2001 Page 17 of 41 Linux driver development Date 8 3 2004 Edwin This is an example illustrate how to use this mode include lt stdio h gt include lt comedilib h gt int subdev 0 data input subdevice int chan 0 data input channel int range 0 channel range int aref AREF_GROUND channel aref int main int argc char argv comedi_t it int chan 0 Isampl_t data it comedi_open dev comedi0 comedi_ data read it subdev chan rangearef amp data printf d n data return O 4 4 2 Trigger mode This is an old way and will be removed from comedi in the later versions It is suggested to use command mode rather than this mode Most of our drivers support Trigger mode Since it is an old mode by default drivers comment this part off by undefining some macro variables undef CONFIG_COMEDI MODEO To enable trigger mode just rebuild the driver by defining that macro variable define CONFIG_COMEDI MODEO 4 4 2 1 comedi trigger structure struct comedi trig_struct unsigned int subdev subdevic
26. nfidential Advantech Automation Corporation 2001 Page 29 of 41 Linux driver development Date 8 3 2004 Edwin The timing of the beginning of each scan is controlled by scan begin TRIG TIMER specifies that scan start events occur periodically at a rate of scan begin arg nanoseconds between scans cmd gt scan begin src TRIG FOLLOW cmd gt scan begin arg O The timing between each sample in a scan is controlled by convert Like above TRIG TIMER spedfies that convert events occur periodically at a rate of convert arg nanoseconds between scans cmd gt convert_src TRIG TIMER cmd gt convert_arg 100000 The end of each scan is almost always specified using TRIG COUNT with the argument being the same as the number of channels in the chanlist You could probably find a device that allows something else but it would be strange cmd gt scan end src TRIG COUNT cmd gt scan end arg n chan number of channels The end of acquisition is controlled by stop src and stop arg The src will typically be TRIG COUNT or TRIG NONE Specifying TRIG COUNT will stop acquisition after stop arg number of scans or TRIG NONE will cause acquisition to continue until stopped using comedi_cancel cmd gt stop_src TRIG_COUNT cmd gt stop_arg N_SCANS the channel list determined which channels are sampled In general chanlist len is the same as scan end arg Most boards require this cmd
27. nt insn type The insn structure also has some other data item we can use to do various operations So the obviously difference between insn mode and command mode is different type insn call different function in the driver while the command mode simply send a command to the driver 4 4 4 1 Insn mode usage Confidential Advantech Automation Corporation 2001 Page 32 of 41 Linux driver development User s Manual Date 8 3 2004 Edwin open device alk setup structure gt comedi_open weende comedi_insn EN EE gt comedi_close 4 4 4 2 insn structure INSN_REA INSN_WRITE INSN_BITS INSN_CONFIG INSN_WAI CR PACK channel range aref Confidential Advantech Automation Corporation 2001 Page 33 of 41 number of the examples subdevice chanspec struct comedi_insn_struct unsigned int insn Linux driver development Date _8 3 2004 Edwin what would the insn do INSN_GTOD perform a gettimeofday see comedi_fops c In 589 INSN READ do analog input read INSN_WRITE output data INSN_BITS di do bit operatoin INSN_CONFIG dio config the transfer direction INSN_WAIT delay for data ns See comdei_fops c In600 unsigned int n Hoop time of insn operation must lt 256 up Isampl_t data data buffer pointer where the samples been put ay unsigned int subdev the subdevice that the c
28. o subdevice So the varies functions of the hardware are show as subdevices such as DI DO Al AO are all treated as different subdevices Note that COMEDI SUBD FAKE is a special type of subdevice used in digital input interrupt handling Subdevice type Subdevice series number Description COMEDI SUBD Al 0 Analog Input COMEDI_SUBD_AO Analog output COMEDI_SUBD_DI Digital input COMEDI_SUBD_DO Digital output COMEDI_SUBD_DIO Digital input and output BWIN Confidential Advantech Automation Corporation 2001 Page 16 of 41 Linux driver development Date 8 3 2004 Edwin COMEDI SUBD COUNTER 5 Counter COMEDI SUBD TIMER 6 timer COMEDI SUBD MEMORY 7 Memory EEPROM DPRAM COMEDI SUBD CALIB 8 Calibration DAC COMEDI SUBD PROC 9 DSP COMEDI SUBD UNUSED 10 Unused COMEDI SUBD FAKE 15 FAKE device 44 Subdevice operator mode MODE Simple read amp write mode easy for program but only can get one sample from one call trigger mode has 5 modes one mode image to a device work mode use command ioctl allows us to specify what causes each action that is taken during acquisition insn mode through different function to realize different control Command mode 4 4 1 Directory data read and write mode This is the easiest way to control a device comedilib has a common function to realize this operation These function are co
29. ommand is sent to unsigned int chanspec unsigned int unused 3 4 4 4 3 insn example include lt comedilib h gt define N SAMPLE 8 char filename dev comedi0 comedi_t device int subdevice 0 int channel 0 int aref int range 0 Confidential Advantech Automation Corporation 2001 Page 34 of 41 Linux driver development Date _8 3 2004 Edwin int main int argc char argv Isampl_t data N_SAM PLE int save errno int ret i comedi_insn insn 3 comedi_insnlist il intn_ channels n_range device comedi_open filename if ldevice printf E comedi_open s s n filename strerror errno memset amp il 0 sizeof il memset insn 0 sizeof insn il n_insns 3 il insns insn insn O insn INSN_GTOD insn O n 2 insn O data void amp t1 insn 1 subdev subdevice insn 1 insn INSN READ insn 1 n N_ SAMPLE insn 1 chanspec CR PACK channel range 0 insn 1 data amp data insn 2 insn INSN_GTOD insn 2 n 2 insn 2 data void amp t2 ret comedi_ do insnlist device amp il Confidential Advantech Automation Corporation 2001 Page 35 of 41 Linux driver development Date _8 3 2004 Edwin save errno errno if ret lt 0 printf W comedi_do_insn errno d s n save_errno strerror save_errno for i 0 i lt N SAMPLE i printf d datalil printf nread time ld us navr time ld us n
30. pled In general chanlist_len isthe same as scan end arg Most boards require this unsigned int chanlist_len sampl_t data data list size depends on subd flags unsigned int data_len Hength of data 4 4 3 2 command example include lt stdio h gt include lt comedilib h gt define N_SCANS 10 defineN_CHANS 16 char filename dev comediO int subdevice 0 Confidential Advantech Automation Corporation 2001 Page 28 of 41 Linux driver development Date _8 3 2004 Edwin int chan 0 int range 0 int aref AREF GROUND intn_ chan 1 define BUFSZ 100 char buf BUFSZ sampl_t capdata 50 unsigned int chanlist N_CHANS void do_and comedi_t dev comedi_cmd amd int main int argc char argv comedi_t dev comedi_and cmd dev comedi_open filename if ldev perror filename exit 1 memset cmd 0 sizeof cmd cmd gt subdev subdevice cmd flags 0 each event requires a trigger which is spedfied by a source and an argument For example to specify an external digital line 3 as a source you would use src TRIG EXT and arg 3 In this case we specify using TRIG_NOW to start acquisition immediately when the command is issued The argument of TRIG NOW is number of nsec after NOW but no driver supports it yet Also no driver currently supports using a start_src other than TRIG_NOW cmd gt start_src TRIG_NOW cmd gt start_arg 0 Co
31. s Redhat 8 0 9 0 and Fedora uses gec3xx compiler this patch file is needed Patch comedi package with the following commands Is comedi 0 7 60 patch cd comedi 0 7 60 patch p1 lt patch comedi 0 7 60 gcc3 patch 3 patch for redhat 9 If your OS is Redhat 9 0 with its original kernel this patch file is needed Patch comedi package with the following commands Is comedi 0 7 60 patch cd comedi 0 7 60 patch p1 lt patch comedi 0 7 60 redhat9 patch More detail please README file Confidential Advantech Automation Corporation 2001 Page 6 of 41 Linux driver development User s Manual Date 8 3 2004 Edwin 2 1 2 2 1 2 1 Linux source In order to compile the Comedi modules you will need to have a correctly configured Linux kernel source tree The best way to get one is to download a tarball from kernel org and compile your own kernel Comedi should work with most 2 2 and 2 4 Linux kernels Support for 2 0 3x is not actively maintained but it should work and bugs will be fixed as they are reported The following steps will almost set up your kernel sources correctly You will also need write permission to the kernel source directory the first time you run comedi s make config so you might want to unpack the kernel source into a directory you own There are two ways to prepare Linux kernel source One is a standard way that we strongly recommend to which is to download a standard L
32. s with Redhat 9 0 1 Pre configuration operation cd usr sre 1n s linux 2 x x linux make a symbol link to source dir cd linux make mrproper clear any configuration must do cp configs kernel 2 4 18 1686 config config Copy the correct configuration file to config according to your hardware structure make oldconfig Alternatively you could make manuconfig to produce your own config file make menuconfig make dep Make dependency 2 Special modification Edit usr src include linux version h This file is generated by make dep Modify UST_RELEASE item to linux 2 x x Originally there might be some other options as linux 2 x xcustom linux 2 x xsmp etc This would cause comedi driver installation problem Make sure your system structure uname r This would prompt you your current kernel modify UST_RELEASE identical to it 3 Make dependencies again make dep 2 1 2 2 2 Debian Mandrake The kernel package of Debian or Mandrake releases is a standard one which is quite compatible for comedi installation Following the general way to configure the kernel cd usr sre ln s linux 2 x x x linux make mrproper make menuconfig xconfig oldconfig config make dep 2 1 2 2 3 SuSE UnitedLinux Kernel package of SuSE 8 x is a4 GB memory supported kernel thus the comedi package should be configured to fit the kernel It s a hack from mail list of comedi mail list but it works Conf
33. t amp it 0 sizeof it it subdev subdevice set the subdevice it mode 0 set mode in mode 0 it n_chan 1 the length of channel list it chanlist amp chanspec set the channel list it data sampl_t amp data the acquisition data itn 1 number of the acquisition data chanspec CR_PACK channel range 0 setup the channel ret comedi_trigger device amp it do trigger save errno errno if ret lt O printf W comedi_trig_ioctl errno d s n save errno strerror save errno Confidential Advantech Automation Corporation 2001 Page 22 of 41 Linux driver development Date _8 3 2004 Edwin printf data d n data 44 24 Trigger mode usage open device ak structure gt comedi_open tent eee E gt comedi_close Confidential Advantech Automation Corporation 2001 Page 23 of 41 User s Manual Date 8 3 2004 Edwin Linux driver development 4 4 3 Command mode Command mode is the most powerful mode The command structure includes the command structure to control the device and then the comedilib function would execute this command With command structure we can setup data IO trigger source conversion start and end time etc After we set this parameters in the command structure comedilib would pass these parameters and execute command as we wished open device nt
34. t misc kcomedilib o lib modules lt lt kernel version gt gt misc lt lt driver files gt gt 0 You need to create device files to access the hardware from a user process These can be created using make dev The following special files will be created dev comedi0 dev comedil dev comedi2 dev comedi3 Next you should compile and install comedilib Refer to section 2 2 2 1 8 Module Autoloading If you like to autoload your modules put the following lines into etc modules conf this does not apply for PCMCIA cards alias char major 98 comedi alias char major 98 0 your_driver post install your_driver usr sbin comedi_config dev comedi0 your_driver lt lt options gt gt Alternatively for complicated option lists the scripts in etc are designed to be copied into etc so that you could put the following lines into etc conf modules alias char major 98 0 dt282x post install dt282x etc dt282x conf 2 1 9 Upgrading From versions prior to 0 6 0 you will need to edit and recompile all programs that use comedi or comedilib since the names of functions and ioctls have changed From versions prior to 0 5 0 you will need to recompile all programs that use comedi or comedilib since the interface to both of these has changed No changes should need to be made to the source of the programs The format for parameters of comedi_config has changed From versions prior to 0 4 0 you will need to run make dev again to recreat
35. tion level device independence Works with Linux kernel from 2 2 x to 2 4 x Driver released together with comedi 0 7 60 and comedilib 0 7 19 1 2 Definitions Acronyms and Abbreviations Definition Explain COMEDI Linux Control amp Measurement Device Interface Al Analog input AO Analog output DI Digital input DO Digital output insn Instruction mode I O cmd Command mode I O 1 3 Overview Comedi is a collection of Advantech drivers for data acquisition hardware These drivers work with Linux and also with Linux combined with the real time extensions RTAI and RTLinux The Comedi core which ties all the drivers together allows applications to be written that are completely hardware independent The distribution of Advantech Linux driver has the following structures Comedi 0 7 60 tar gz This distribution contains just the Comedi kernel modules More information please refer to comedi 0 7 60 README Confidential Advantech Automation Corporation 2001 Page 4 of 41 Linux driver development Date _8 3 2004 Edwin Following is the structure of comedi 0 7 60 comedi 0 7 60 main COMEDI dir Documentation documentations about install configure and develop comedi L notes t comedi working dir drivers drivers including source code and o files kcomedilib kernel space library debian include h files that COMEDI driver needs H asm linux patches ib
36. urs Re when data is written to the buffer TRIG_EXT start event occurs when an external trigger 4 signal occurs e g a rising edge of a digital line start_arg chooses the particular digital de line TRIG_INT start event occurs on a Comedi internal signal ke which is typically caused by an INSN_TRIG Ae instruction a unsigned int start_arg argument unsigned int scan_begin_src The start of acquisition is controlled by start src TRIG NOW Thestart src event occurs start_arg nanoseconds ke after comedi_command is called Currently bs only start_arg 0 is supported TRIG_FOLLOW For an output device Thestart src event occurs when data is written to the buffer TRIG_EXT start event occurs when an external trigger r signal occurs e g a rising edge of a digital line start_arg chooses the particular digital t line TRIG_INT start event occurs on a Comedi internal signal a which is typically caused by an INSN_TRIG instruction Confidential Advantech Automation Corporation 2001 Page 26 of 41 Linux driver development Date _8 3 2004 Edwin unsigned int scan begin arg An ns unsigned int convert_src The timing between each sample in a scan is controlled by convert TRIG_TIMER Conversion events occur periodically Re The time between convert events is Be convert_arg nanoseconds TRIG_EXT Conversion events occur when an external trigger signal occ
37. urs e g a rising edge of a digital line convert_arg chooses the particular digital 7 line TRIG_NOW All conversion events in a scan occur simultaneously Even though itis invalid we specify 1 ns here It will be adjusted later to a valid value by comedi_command_test unsigned int convert_arg Xn ns unsigned int scan end src The timing between each sample in a scan is controlled by convert TRIG TIMER Conversion events occur periodically Be The time between convert events is He convert_arg nanoseconds TRIG_EXT Conversion events occur when an external trigger en signal occurs e g arising edge of a digital ne line convert_arg chooses the particular digital line TRIG_NOW All conversion events in a scan occur simultaneously Even though it is invalid we specify 1 ns here It will be adjusted later to a valid value by comedi_command_test Confidential Advantech Automation Corporation 2001 Page 27 of 41 Linux driver development Date _8 3 2004 Edwin unsigned int scan end arg number of channels unsigned int stop_ src The end of acquisition is controlled by stop_srcand stop_arg TRIG COUNT stop acquisition after stop arg scans TRIG NONE continuous acquisition until stopped using comedi_cancel unsigned int stop_arg number of channels unsigned int chanlist channel range list the channel list determined which channels are sam
38. y data read and write mode 17 44 2 Trigger mode 18 44 3 Command mode 24 444 insn mode 32 45 Advantech test example manuals 36 5 comedilib functions description 36 5 1 Device file operation function 36 5 2 Subdevice operation function 37 5 3 Driver information acquirement 38 5 4 Data acquisition funcion 39 Confidential Advantech Automation Corporation 2001 Page 3 of 41 Linux driver development Date _8 3 2004 Edwin User s Manual 1 Introduction Drivers for Advantech data acquisition boards and motion control cards for Linux are developed on COMEDI Linux Control amp Measurement Device Interface The COMEDI project develops open source drivers tools and libraries for data acquisition COMEDI is a collection of drivers for a variety of common data acquisition plug in boards The drivers are implemented as a core Linux kernel module providing common functionality and individual low level driver modules COMEDILIB is a user space library that provides a developer friendly interface to comedi devices Included in the comedilib distribution is documentation configuration and calibration utilities and demonstration programs This document describes usage of Advantech Linux drivers with COMEDI in general Information on specific production please refer to the heading remarks in the driver s source code 1 1 Features Integrated real time support for most hardware High level library comedilib Applica
Download Pdf Manuals
Related Search
Related Contents
bomba ls-60td - Multiquip Inc. Fiche 4 - Les grades légaux - Union des villes et communes de 3 axes Cnc driver kit User manual Canadien Food Agence canadienne Inspection Ageney d`inspection 取扱説明書 Toshiba Portégé Z10T-A OWNER`S MANUAL SIstema de Control y Registro de Casos Interestatales del Estado de AMB-VANIR Copyright © All rights reserved.
Failed to retrieve file