📄 m7i43_hm2.comp
字号:
//// Copyright (C) 2007-2008 Sebastian Kuzminsky//// 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA////// NOTE: This driver is deprecated, and will be removed in the future!// All users are encouraged to transition to the hostmot2 driver,// which is being actively developed!//component m7i43_hm2 """RTAI driver for the Mesa Electronics 7i43 EPP Anything IO board with HostMot2 firmware.""";description """NOTE: This driver is deprecated, and will be removed in the future!All users are encouraged to transition to the hostmot2 driver, which is being actively developed!m7i43_hm2 is an RTAI device driver that interfaces the Mesa 7i43 board withthe HostMot2 firmware to the EMC2 HAL. Both the 200K and the 400K FPGAsare supported.The driver talks with the 7i43 over the parallel port, not over USB. USBcan be used to power the 7i43, but not to talk to it. USB communicationwith the 7i43 will not be supported any time soon, since USB has poorreal-time qualities.The driver sends the HostMot2 firmware to the board at module load time.The board should be ready to accept new firmware before loading thedriver, ie both the INIT and DONE lights should be on..SS Jumper settingsThe board must be configured to get its firmware from the EPP port. To dothis, jumpers W4 and W5 must both be down, ie toward the USB connector.The board must be configured to power on whether or not the USB interfaceis active. This is done by setting jumper W7 up, ie away from the edgeof the board..SS FirmwareThe HostMot2 firmware provides encoders, PWM generators, step/dirgenerators, and general purpose I/O pins (GPIOs). These things are called"Functions". The firmware is configured, at firmware compile time,to provide zero or more instances of each of these four Functions.The firmware also provides a watchdog function, described in the Watchdogsection below..SS Communicating with the boardThe 7i43 communicates with the EMC computer over EPP, the EnhancedParallel Port. This provides about 1 MBps of throughput, and thecommunication latency is very predictable and reasonably low.EPP is very reliable under normal circumstances, but bad cablingor excessively long cabling runs may cause communication timeouts.The driver exports a parameter named m7i43_hm2.<BoardNum>.epp_errors toinform HAL of this condition. When the driver detects an EPP timeout,it sets epp_errors to 1 and stops communicating with the 7i43 board.Setting epp_errors back to 0 makes the driver start trying to communicatewith the 7i43 again..SS WatchdogThe 7i43 FPGA firmware implements a watchdog function. The timeoutis settable a driver load time using the watchdog_timeout_ns modparamdescribed below. The "pet-watchdog" function must be called no morethan that many nanoseconds appart, or the watchdog will bite.When the watchdog bites, all board's I/O pins revert to inputs (pulledhigh), and all communication with the board stops. This condition isreported to HAL by the watchdog.has-bit pin going high. The user mustset the pin back to low to restart communication with the board..SS Board I/O PinsThe 7i43 board has 48 I/O pins, 0-23 on the P4 connector and 24-47 on theP3 connector (see Mesa Electronics' manual for details on the pinout).Each pin can be configured, at driver load time, to serve one of twopurposes: either as a particular I/O pin of a particular Function instance(encoder, pwmgen, or stepgen), or as a general purpose digital I/O pin.By default all firmware functions are enabled, and all the board's pinsare used by the Function instances.The user can disable Function instances at driver load time, by specifyingthe module parameters num_encoders, num_pwmgens, and num_stepgens(described above). Any pins which belong to Function instances thathave been disabled automatically become GPIOs..SS encoderVery basic support, more to come. This is what's implemented so far:Encoders have names like "m7i43_hm2.<BoardNum>.encoder.<Instance>".Instance is a two-digit number that corresponds to the HostMot2 encoderinstance number. There are 'num_encoders' instances, starting with 00.In HM2, each encoder uses three input IO pins: A, B, and Index (sometimesalso known as Z). Index is currently not used, this will be fixed inthe nearish future.Each encoder instance has the following pins and parameters:Pins:(s32 out) count: Number of encoder counts since the previous reset.(Like CDI.)(float out) position: Encoder position (count / scale). (Like CDI.)Parameters:(float r/w) scale: Converts from 'count' units to 'position' units.(Like CDI.).SS pwmgenVery basic support, more to come. This is what's implemented so far:pwmgens have names like "m7i43_hm2.<BoardNum>.pwmgen.<Instance>".Instance is a two-digit number that corresponds to the HostMot2 pwmgeninstance number. There are 'num_pwmgens' instances, starting with 00.In HM2, each pwmgen uses three output IO pins: Not-Enable, Out0, andOut1.The function of the Out0 and Out1 IO pins varies with output-typeparameter (see below).The m7i43_hm2 pwmgen representation is modeled on the pwmgen softwarecomponent. Each pwmgen instance has the following pins and parameters:Pins:(bit input) enable: If true, the pwmgen will set its Not-Enable pinfalse and output its PWM and Direction signals. If 'enable' is false,pwmgen will set its Not-Enable pin true and not output any signals.(float input) value: The current pwmgen command value, in arbitrary units.Parameters:(float rw) scale: Scaling factor to convert 'value' from arbitrary unitsto duty cycle: dc = value / scale. Duty cycle has an effective rangeof -1.0 to +1.0 inclusive.(s32 rw) output-type: This emulates the output_type load-time argumentto the software pwmgen component. This parameter may be changed atruntime, but most of the time you probably want to set it at startup andthen leave it alone. Accepted values are 1 (PWM on Out0 and Directionon Out1) and 2 (Up on Out0 and Down on Out1)..SS stepgenVery basic support. This is what's implemented so far:stepgens have names like "m7i43_hm2.<BoardNum>.stepgen.<Instance>.Instance is a two-digit number that corresponds to the HostMot2 stepgeninstance number. There are 'num_stepgens' instances, starting with 00.Currently only Step/Dir output and Position-mode control is supported.Each stepgen allocates 6 IO pins, but only uses two: Step and Directionoutputs.The m7i43_hm2 stepgen representation is modeled on the stepgen softwarecomponent. Each stepgen instance has the following pins and parameters:Pins:(float input) position_cmd: Target of stepper motion, in arbitraryposition units.(float output) counts: Feedback position in counts (number of steps).(float output) position-fb: Feedback position in arbitrary position units(counts / position_scale).(float output) velocity-fb: Feedback velocity in arbitrary positionunits per second.Params:(float r/w) position_scale: Converts from counts to position units.position = counts / position_scale(float r/w) steplen: Duration of the step signal, in seconds.(float r/w) stepspace: Minimum interval between step signals, in seconds.(float r/w) dirsetup: Minimum duration of stable Direction signal beforea step begins, in seconds.(float r/w) dirhold: Minimum duration of stable Direction signal aftera step ends, in seconds..SS General Purpose I/OPins which are not used by one of the Functions above areexported to HAL as GPIO pins. GPIO pins have names like"m7i43_hm2.<BoardNum>.gpio.<PinNum>". PinNum is a three-digit numberthat corresponds to the I/O Pin number as given in Mesa Electronics'manual for the 7i43 board.Each GPIO has the following pins:(bit out) in & in_not: State (normal and inverted) of the hardwareinput pin. (Like CDI for Digital Input).(bit in) out: Value to be written (possibly inverted) to the hardwareoutput pin. (Like the CDI for Digital Output.)Each GPIO has the following params:(bin r/w) is_output: If set to 1, the GPIO is an output, and the valuesof the "in" and "in_not" HAL pins are undefined. If set to 0, the GPIOis an input, and writes to the "out" HAL pin have no effect.(bin r/w) invert_output: If set to 1, the value that will appear onthe board's I/O pin will be the inverse of the value written to HAL's"out" pin. (This corresponds to the 'invert' parameter in the CDI forDigital Output.)""";pin in bit ignore "ignore this pin, comp needs it";option singleton;option extra_setup;option extra_cleanup;function gpio_read nofp "Read GPIO pins.";function gpio_write nofp "Write GPIO pins.";function encoder_update_counters nofp "Read encoder counts.";function encoder_capture_position fp "Compute encoder position.";function pwmgen_update fp "Write pwmgen values.";function stepgen_update fp "Update stepgen values.";function pet_watchdog nofp "Pet the watchdog to keep it from biting us for a while.";modparam int ioaddr = 0x378"""The base address of the parallel port.""";modparam int ioaddr_hi = 0"""The secondary address of the parallel port, used to set EPP mode.0 means to use ioaddr + 0x400.""";modparam int epp_wide = 1"""Set to zero to disable the "wide EPP mode". "Wide" mode allows a 16-and 32-bit EPP transfers, which can reduce the time spent in the readand write functions. However, this may not work on all EPP parallelports.""";modparam int num_encoders = -1"""Defaults to -1, which means "use all the encoder instances thefirmware has". If num_encoders is smaller than the number of encoderinstances present in the firmware, only the first num_encoders instancesare enabled; all later encoder instances are disabled and their I/O pinsbecome digital I/O pins.""";modparam int num_pwmgens = -1"""Defaults to -1, which means "use all the pwmgen instances thefirmware has". If num_pwmgens is smaller than the number of pwmgeninstances present in the firmware, only the first num_pwmgens instancesare enabled; all later pwmgen instances are disabled and their I/O pinsbecome digital I/O pins.""";modparam int num_stepgens = -1"""Defaults to -1, which means "use all the stepgen instances thefirmware has". If num_stepgens is smaller than the number of stepgeninstances present in the firmware, only the first num_stepgens instancesare enabled; all later stepgen instances are disabled and their I/O pinsbecome digital I/O pins.""";modparam int watchdog_timeout_ns = 1000000"""Watchdog timeout in nanoseconds. Defaults to 1,000,000 ns (1 ms).The pet_watchdog() function must be called at least this frequently,or it will bite. When the watchdog bites, all I/O pins are reset toinputs (high with pullups) and all communication with the 7i43 stops.Each board exports a binary HAL pin called "watchdog.has_bit", which isset to 1 when the watchdog bites. When this pin is True, the driver willnot communicate with the board. When the user sets the pin to False,the driver will reset the board's I/O pins to the configuration selectedat load-time, and communications will resume.""";modparam int debug_epp = 0"""Developer/debug use only! Enable debug logging of most EPPtransfers.""";modparam int debug_idrom = 0"""Developer/debug use only! Enable debug logging of the HostMot2IDROM header.""";modparam int debug_module_descriptors = 0"""Developer/debug use only! Enable debug logging of the HostMot2Module Descriptors.""";modparam int debug_pin_descriptors = 0"""Developer/debug use only! Enable debug logging of the HostMot2Pin Descriptors.""";modparam int debug_functions = 0"""Developer/debug use only! Enable debug logging of the HostMot2Functions used.""";license "GPL";;;#include <asm/io.h>#include "rtapi_math.h"#include "hal/drivers/m7i43_hm2.h"#include "hal/drivers/mesa7i43-firmware/m7i43-firmware-hm2-svst4_4s.h"#include "hal/drivers/mesa7i43-firmware/m7i43-firmware-hm2-svst4_4b.h"// #include "hal/drivers/mesa7i43-firmware/m7i43-firmware-hm2-sv8s.h"// #include "hal/drivers/mesa7i43-firmware/m7i43-firmware-hm2-sv8b.h"// #include "hal/drivers/mesa7i43-firmware/m7i43-firmware-hm2-svst4_6b.h"//// the 7i43 board is tracked by this//m7i43_t board;// // EPP I/O code// static inline void m7i43_epp_addr8(__u8 addr) { outb(addr, ioaddr + M7I43_EPP_ADDRESS_OFFSET); DEBUG(debug_epp, "selected address 0x%02X\n", addr);}static inline void m7i43_epp_addr16(__u16 addr) { outb((addr & 0x00FF), ioaddr + M7I43_EPP_ADDRESS_OFFSET); outb((addr >> 8), ioaddr + M7I43_EPP_ADDRESS_OFFSET); DEBUG(debug_epp, "selected address 0x%04X\n", addr);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -