nidas v1.2.3
|
#include <linux/delay.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/ioport.h>
#include <linux/module.h>
#include <linux/poll.h>
#include <linux/unistd.h>
#include <linux/syscalls.h>
#include <linux/version.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <asm/byteorder.h>
#include <asm/io.h>
#include <linux/uaccess.h>
#include <nidas/linux/ver_macros.h>
#include <nidas/linux/util.h>
#include <nidas/linux/irigclock.h>
#include <nidas/linux/isa_bus.h>
#include <nidas/linux/Revision.h>
#include <nidas/linux/klog.h>
#include "ncar_a2d_priv.h"
Macros | |
#define | REPO_REVISION "unknown" |
#define | BOARD_INDEX(boardptr) ((boardptr) - BoardInfo) |
#define | DEVNAME_A2D "ncar_a2d" |
Info for A/D user devices. | |
#define | X -1 |
#define | SHORT_START |
Functions | |
MODULE_AUTHOR ("Chris Burghart <burghart@ucar.edu>") | |
MODULE_DESCRIPTION ("NCAR A/D driver") | |
MODULE_LICENSE ("GPL") | |
MODULE_VERSION (REPO_REVISION) | |
MODULE_PARM_DESC (IoPort, "ISA port address of each board, e.g.: 0x3A0") | |
MODULE_PARM_DESC (Master, "Master A/D for the board, default=first requested channel") | |
MODULE_PARM_DESC (fifoReadFrac, "N: read 1/N of FIFO on each poll, N >= 4") | |
MODULE_PARM_DESC (dtestnum, "Test to run: 0=no test, 1=16 bit write of 0x5555/0xaaaa in 1/2 second loop") | |
MODULE_PARM_DESC (dtestchan, "Channel number for write test 0-7") | |
MODULE_PARM_DESC (dtestcnt, "Number of tests to run") | |
MODULE_PARM_DESC (a2dchans, "Active A2D channels, 0-7, separated by commas") | |
static unsigned long | CHAN_ADDR16 (struct A2DBoard *brd, int channel) |
static int | stopBoard (struct A2DBoard *brd) |
Stop data collection on the selected board. | |
static ssize_t | ncar_a2d_read (struct file *filp, char __user *buf, size_t count, loff_t *pos) |
User-space read on the A/D device. | |
static int | ncar_a2d_open (struct inode *inode, struct file *filp) |
User-space open of the A/D device. | |
static int | ncar_a2d_release (struct inode *inode, struct file *filp) |
User-space close of the A/D device. | |
static unsigned int | ncar_a2d_poll (struct file *filp, poll_table *wait) |
Support for select/poll on the user device. | |
static long | ncar_a2d_ioctl (struct file *filp, unsigned int cmd, unsigned long arg) |
static void | i2c_clock_hi (struct A2DBoard *brd) |
static void | i2c_clock_lo (struct A2DBoard *brd) |
static void | i2c_data_hi (struct A2DBoard *brd) |
static void | i2c_data_lo (struct A2DBoard *brd) |
static void | i2c_start_sequence (struct A2DBoard *brd) |
static void | i2c_stop_sequence (struct A2DBoard *brd) |
static int | i2c_getAck (struct A2DBoard *brd) |
static void | i2c_putNoAck (struct A2DBoard *brd) |
static void | i2c_putAck (struct A2DBoard *brd) |
static unsigned char | i2c_get_byte (struct A2DBoard *brd) |
static int | i2c_put_byte (struct A2DBoard *brd, unsigned char byte) |
static short | A2DTemp (struct A2DBoard *brd) |
Read on-board LM92 temperature sensor via i2c serial bus The signed short returned is (16 * temperature in deg C) | |
static int | wait7725Int (struct A2DBoard *brd, int channel, int ncoef) |
static unsigned short | AD7725Status (struct A2DBoard *brd, int channel) |
static void | AD7725StatusAll (struct A2DBoard *brd) |
static unsigned short | AD7725StatusInstrBits (unsigned short instr) |
AD7725 sets some of the bits of the previous instruction in its status register. | |
static int | A2DSetGain (struct A2DBoard *brd, int channel) |
static int | A2DSetMaster (struct A2DBoard *brd, int channel) |
static int | CalVoltIsValid (int volt) |
static int | CalVoltToBits (int volt) |
static void | UnSetVcal (struct A2DBoard *brd) |
static void | SetVcal (struct A2DBoard *brd) |
static void | SetCal (struct A2DBoard *brd) |
static void | SetOffset (struct A2DBoard *brd) |
static void | A2DSetSYNC (struct A2DBoard *brd) |
static void | A2DClearSYNC (struct A2DBoard *brd) |
static void | A2DEnable1PPS (struct A2DBoard *brd) |
static void | A2DClearFIFO (struct A2DBoard *brd) |
static unsigned short | A2DBoardStatus (struct A2DBoard *brd) |
Return the status from the card. | |
static int | getA2DFIFOLevel (struct A2DBoard *brd) |
Get the FIFO fill level: | |
static void | A2DStopRead (struct A2DBoard *brd, int channel) |
static void | A2DStopReadAll (struct A2DBoard *brd) |
static void | A2DAuto (struct A2DBoard *brd) |
static void | A2DNotAuto (struct A2DBoard *brd) |
static int | A2DStart (struct A2DBoard *brd, int channel, unsigned int nloop) |
static int | A2DStartAll (struct A2DBoard *brd) |
static int | A2DConfig (struct A2DBoard *brd, int channel) |
static int | A2DConfigAll (struct A2DBoard *brd) |
static int | getSerialNumber (struct A2DBoard *brd) |
static void | ppsCallback1 (void *ptr) |
static int | waitFor1PPS (struct A2DBoard *brd, irig_callback_func *ppsfunc) |
static int | A2DSetGainAndOffset (struct A2DBoard *brd) |
static int | addSampleConfig (struct A2DBoard *brd, struct nidas_a2d_sample_config *cfg) |
static void | freeFilters (struct A2DBoard *brd) |
static int | configBoard (struct A2DBoard *brd, struct nidas_a2d_config *cfg) |
int | withinRange (int volt, int gain, int offset) |
static void | do_filters (struct A2DBoard *brd, dsm_sample_time_t tt, const short *dp) |
Invoke filters. | |
static void | a2d_bottom_half (struct work_struct *work) |
static void | discardA2DFifo (struct A2DBoard *brd) |
static void | readA2DFifo (struct A2DBoard *brd) |
static void | ReadSampleCallback (void *ptr) |
static void | TemperatureCallback (void *ptr) |
static int | resetBoard (struct A2DBoard *brd) |
static void | resetBoardWorkFunc (struct work_struct *work) |
static int | startBoard (struct A2DBoard *brd) |
Start data collection on the selected board. | |
static int | test_ISA_Writes (struct A2DBoard *brd, int ioport) |
static void | ncar_a2d_cleanup (void) |
static int __init | ncar_a2d_init (void) |
module_init (ncar_a2d_init) | |
module_exit (ncar_a2d_cleanup) | |
Variables | |
static const int | WAITING_FOR_RESET = 1 |
static int | IoPort [MAX_A2D_BOARDS] = { 0x3a0, 0, 0, 0 } |
static int | Master [MAX_A2D_BOARDS] = { -1, -1, -1, -1 } |
static int | nIoPort |
static int | nMaster |
static int | dtestnum |
static int | dtestchan |
static uint | dtestcnt |
static uint | a2dchans [NUM_NCAR_A2D_CHANNELS] = { 0,1,2,3,4,5,6,7 } |
static uint | numa2ds = NUM_NCAR_A2D_CHANNELS |
static int | fifoReadFrac = 8 |
static int | NumBoards = 0 |
static struct A2DBoard * | BoardInfo = 0 |
static struct workqueue_struct * | work_queue = 0 |
static struct file_operations | ncar_a2d_fops |
static dev_t | ncar_a2d_device = MKDEV(0, 0) |
static struct cdev | ncar_a2d_cdev |
static struct class * | ncar_a2d_class |
static const unsigned long | I2CSCL = 0x2 |
static const unsigned long | I2CSDA = 0x1 |
int | GainOffsetToEnum [5][2] |
#define BOARD_INDEX | ( | boardptr | ) | ((boardptr) - BoardInfo) |
Referenced by startBoard().
#define DEVNAME_A2D "ncar_a2d" |
Info for A/D user devices.
Referenced by ncar_a2d_init().
#define REPO_REVISION "unknown" |
Referenced by ncar_a2d_init().
#define SHORT_START |
#define X -1 |
|
static |
References do_filters(), dsm_sample::length, NUM_NCAR_A2D_CHANNELS, and A2DBoard::sampleWorker.
Referenced by ncar_a2d_init().
|
static |
References A2DAUTO, and A2DIO_FIFO.
Referenced by resetBoard().
|
inlinestatic |
Return the status from the card.
The upper 10 bits of the status are the card serial number, and the lower six bits are:
0x20: PRESYNC Presync bit (NOT USED) 0x10: INV1PPS Inverted 1 PPS pulse 0x08: FIFONOTFULL FIFO not full 0x04: FIFONOTEMPTY FIFO not empty 0x02: FIFOAFAE FIFO contains < 1024 words or > 3072 words 0x01: FIFOHF FIFO half full
References A2DIO_FIFOSTAT.
Referenced by getA2DFIFOLevel(), getSerialNumber(), and ppsCallback1().
|
static |
References A2DIO_FIFO, and FIFOCLR.
Referenced by resetBoard(), and startBoard().
|
static |
References A2DIO_FIFO, and A2DSYNCCK.
Referenced by startBoard().
|
static |
References a2dchans, A2DCONFIGEND, A2DCRCERR, A2DDATAREQ, A2DIDERR, A2DIO_CS_CMD_RD, A2DIO_CS_CMD_WR, A2DIO_DATA, A2DSTAT_INSTR_MASK, AD7725_WRCONFIG, AD7725Status(), AD7725StatusInstrBits(), CHAN_ADDR16(), NUM_NCAR_A2D_CHANNELS, numa2ds, and wait7725Int().
Referenced by A2DConfigAll().
|
static |
References a2dchans, A2DConfig(), and numa2ds.
Referenced by startBoard().
|
static |
References A2D1PPSEBL, and A2DIO_FIFO.
Referenced by resetBoard().
|
static |
References A2DIO_FIFO.
Referenced by ncar_a2d_init(), resetBoard(), and stopBoard().
|
static |
References a2dchans, A2DIO_DATA, NUM_NCAR_A2D_CHANNELS, and numa2ds.
Referenced by A2DSetGainAndOffset().
|
static |
References a2dchans, A2DIO_D2A1, A2DSetGain(), numa2ds, and SetOffset().
Referenced by startBoard().
|
static |
References a2dchans, A2DIO_FIFOSTAT, NUM_NCAR_A2D_CHANNELS, and numa2ds.
Referenced by startBoard().
|
static |
References A2DIO_FIFO, A2DSYNC, and A2DSYNCCK.
Referenced by resetBoard().
|
static |
References a2dchans, A2DIO_CS_CMD_RD, A2DIO_CS_CMD_WR, A2DSTAT_INSTR_MASK, AD7725_READDATA, AD7725StatusInstrBits(), CHAN_ADDR16(), dtestnum, NUM_NCAR_A2D_CHANNELS, and numa2ds.
Referenced by A2DStartAll().
|
static |
References a2dchans, A2DStart(), dtestcnt, dtestnum, and numa2ds.
Referenced by resetBoard(), and startBoard().
|
static |
References A2DIO_CS_CMD_RD, A2DIO_CS_CMD_WR, AD7725_ABORT, and CHAN_ADDR16().
Referenced by A2DStopReadAll().
|
static |
References a2dchans, A2DStopRead(), and numa2ds.
Referenced by resetBoard(), startBoard(), and stopBoard().
|
static |
Read on-board LM92 temperature sensor via i2c serial bus The signed short returned is (16 * temperature in deg C)
References A2DIO_FIFO, A2DIO_I2C, i2c_get_byte(), i2c_put_byte(), i2c_putAck(), i2c_putNoAck(), i2c_start_sequence(), and i2c_stop_sequence().
Referenced by TemperatureCallback().
|
static |
References A2DIO_CS_CMD_RD, and CHAN_ADDR16().
Referenced by A2DConfig(), and AD7725StatusAll().
|
static |
References a2dchans, AD7725Status(), NUM_NCAR_A2D_CHANNELS, and numa2ds.
Referenced by ncar_a2d_cleanup(), and stopBoard().
|
inlinestatic |
AD7725 sets some of the bits of the previous instruction in its status register.
For a given instruction, return the value of those status bits, which gives some indication of the success of the previous operation.
References A2DINSTREG00, A2DINSTREG01, A2DINSTREG04, A2DINSTREG05, A2DINSTREG06, A2DINSTREG11, A2DINSTREG12, A2DINSTREG13, and A2DINSTREG15.
Referenced by A2DConfig(), A2DStart(), and ncar_a2d_init().
|
static |
References a2dchans, nidas_a2d_sample_config::bipolar, nidas_a2d_sample_config::channels, nidas_a2d_sample_config::filterData, nidas_a2d_sample_config::filterType, nidas_a2d_sample_config::gain, get_short_filter_methods(), nidas_a2d_sample_config::nFilterData, NUM_NCAR_A2D_CHANNELS, numa2ds, nidas_a2d_sample_config::nvars, nidas_a2d_sample_config::rate, and nidas_a2d_sample_config::sindex.
Referenced by ncar_a2d_ioctl().
|
static |
Referenced by withinRange().
|
static |
Referenced by SetVcal().
|
inlinestatic |
Referenced by A2DConfig(), A2DStart(), A2DStopRead(), AD7725Status(), ncar_a2d_init(), and test_ISA_Writes().
|
static |
References nidas_a2d_config::latencyUsecs, nidas_a2d_config::scanRate, USECS_PER_MSEC, and USECS_PER_SEC.
Referenced by ncar_a2d_ioctl().
|
static |
Referenced by readA2DFifo().
|
static |
Invoke filters.
References NUM_NCAR_A2D_CHANNELS, and SIZEOF_DSM_SAMPLE_HEADER.
Referenced by a2d_bottom_half().
|
static |
Referenced by ncar_a2d_cleanup(), and stopBoard().
|
inlinestatic |
Get the FIFO fill level:
References A2DBoardStatus(), FIFONOTEMPTY, and FIFONOTFULL.
Referenced by ReadSampleCallback(), and resetBoard().
|
static |
References A2DBoardStatus().
Referenced by ncar_a2d_init().
|
inlinestatic |
References I2CSCL.
Referenced by i2c_get_byte(), i2c_getAck(), i2c_put_byte(), i2c_putAck(), i2c_putNoAck(), i2c_start_sequence(), and i2c_stop_sequence().
|
inlinestatic |
Referenced by i2c_get_byte(), i2c_getAck(), i2c_put_byte(), i2c_putAck(), i2c_putNoAck(), and i2c_start_sequence().
|
inlinestatic |
References I2CSDA.
Referenced by i2c_put_byte(), i2c_putAck(), i2c_putNoAck(), i2c_start_sequence(), and i2c_stop_sequence().
|
inlinestatic |
Referenced by i2c_put_byte(), i2c_putAck(), i2c_start_sequence(), and i2c_stop_sequence().
|
inlinestatic |
References i2c_clock_hi(), and i2c_clock_lo().
Referenced by A2DTemp().
|
inlinestatic |
References i2c_clock_hi(), and i2c_clock_lo().
Referenced by i2c_put_byte().
|
inlinestatic |
References i2c_clock_hi(), i2c_clock_lo(), i2c_data_hi(), i2c_data_lo(), and i2c_getAck().
Referenced by A2DTemp().
|
inlinestatic |
References i2c_clock_hi(), i2c_clock_lo(), i2c_data_hi(), and i2c_data_lo().
Referenced by A2DTemp().
|
inlinestatic |
References i2c_clock_hi(), i2c_clock_lo(), and i2c_data_hi().
Referenced by A2DTemp().
|
inlinestatic |
References i2c_clock_hi(), i2c_clock_lo(), i2c_data_hi(), and i2c_data_lo().
Referenced by A2DTemp().
|
inlinestatic |
References i2c_clock_hi(), i2c_data_hi(), and i2c_data_lo().
Referenced by A2DTemp().
MODULE_AUTHOR | ( | "Chris Burghart <burghart@ucar.edu>" | ) |
MODULE_DESCRIPTION | ( | "NCAR A/D driver" | ) |
module_exit | ( | ncar_a2d_cleanup | ) |
module_init | ( | ncar_a2d_init | ) |
MODULE_LICENSE | ( | "GPL" | ) |
MODULE_PARM_DESC | ( | a2dchans | , |
"Active A2D | channels, | ||
0- | 7, | ||
separated by commas" | ) |
MODULE_PARM_DESC | ( | dtestchan | , |
"Channel number for write test 0-7" | ) |
MODULE_PARM_DESC | ( | dtestcnt | , |
"Number of tests to run" | ) |
MODULE_PARM_DESC | ( | dtestnum | , |
"Test to run: | 0 = no test ) |
MODULE_PARM_DESC | ( | fifoReadFrac | , |
"N: read 1/N of FIFO on each | poll, | ||
N >=4" | ) |
MODULE_PARM_DESC | ( | Master | , |
"Master A/D for the | board ) |
MODULE_VERSION | ( | REPO_REVISION | ) |
|
static |
References A2DIOWIDTH, AD7725StatusAll(), BoardInfo, flush_irig_callbacks(), free_dsm_circ_buf(), freeFilters(), ncar_a2d_cdev, ncar_a2d_class, ncar_a2d_device, NumBoards, stopBoard(), unregister_irig_callback(), and work_queue.
Referenced by ncar_a2d_init().
|
static |
References a2d_bottom_half(), a2dchans, A2DCMDADDR, A2DIO_CS_CMD_RD, A2DIO_CS_CMD_WR, A2DIOWIDTH, A2DNotAuto(), A2DSTAT_INSTR_MASK, AD7725_ABORT, AD7725StatusInstrBits(), BoardInfo, CHAN_ADDR16(), DEVNAME_A2D, dtestnum, err, fifoReadFrac, getSerialNumber(), IoPort, IRIG_NUM_RATES, MAX_A2D_BOARDS, ncar_a2d_cdev, ncar_a2d_class, ncar_a2d_cleanup(), ncar_a2d_device, ncar_a2d_fops, numa2ds, NumBoards, REPO_REVISION, resetBoardWorkFunc(), test_ISA_Writes(), UnSetVcal(), and work_queue.
|
static |
References a2dchans, addSampleConfig(), ncar_a2d_setup::calset, configBoard(), ncar_a2d_ocfilter_config::filter, ncar_a2d_setup::gain, IRIG_10_HZ, len, NCAR_A2D_GET_SETUP, NCAR_A2D_GET_STATUS, NCAR_A2D_GET_TEMP, NCAR_A2D_RUN, NCAR_A2D_SET_CAL, NCAR_A2D_SET_OCFILTER, NCAR_A2D_SET_TEMPRATE, NCAR_A2D_STOP, nidas_a2d_sample_config::nFilterData, NIDAS_A2D_CONFIG_SAMPLE, NIDAS_A2D_GET_NCHAN, NIDAS_A2D_SET_CONFIG, NUM_NCAR_A2D_CHANNELS, numa2ds, ncar_a2d_setup::offset, rate, SetCal(), SetVcal(), startBoard(), stopBoard(), UnSetVcal(), ncar_a2d_setup::vcal, and withinRange().
|
static |
User-space open of the A/D device.
References BoardInfo, I2CSCL, I2CSDA, IRIG_NUM_RATES, and NUM_NCAR_A2D_CHANNELS.
|
static |
Support for select/poll on the user device.
References WAITING_FOR_RESET.
|
static |
User-space read on the A/D device.
References nidas_circbuf_read(), and WAITING_FOR_RESET.
|
static |
User-space close of the A/D device.
References stopBoard().
|
static |
References A2DBoardStatus(), and INV1PPS.
Referenced by resetBoard().
|
static |
References A2DIO_FIFO, discardA2DFifo(), NUM_NCAR_A2D_CHANNELS, and work_queue.
Referenced by ReadSampleCallback().
|
static |
References getA2DFIFOLevel(), readA2DFifo(), WAITING_FOR_RESET, and work_queue.
Referenced by resetBoard().
|
static |
References A2DAuto(), A2DClearFIFO(), A2DEnable1PPS(), A2DNotAuto(), A2DSetSYNC(), A2DStartAll(), A2DStopReadAll(), flush_irig_callbacks(), getA2DFIFOLevel(), IRIG_NUM_RATES, ppsCallback1(), ReadSampleCallback(), register_irig_callback(), TemperatureCallback(), unregister_irig_callback(), waitFor1PPS(), and WAITING_FOR_RESET.
Referenced by resetBoardWorkFunc(), and startBoard().
|
static |
References resetBoard(), and A2DBoard::resetWorker.
Referenced by ncar_a2d_init().
|
static |
References a2dchans, A2DIO_SYSCTL, and numa2ds.
Referenced by ncar_a2d_ioctl().
|
static |
References a2dchans, A2DIO_SYSCTL, and numa2ds.
Referenced by A2DSetGainAndOffset().
|
static |
References A2DIO_CALV, CalVoltToBits(), and UnSetVcal().
Referenced by ncar_a2d_ioctl().
|
static |
Start data collection on the selected board.
This is only called via user space initiation (i.e., through the NCAR_A2D_RUN ioctl).
References a2dchans, A2DClearFIFO(), A2DClearSYNC(), A2DConfigAll(), A2DSetGainAndOffset(), A2DSetMaster(), A2DStartAll(), A2DStopReadAll(), BOARD_INDEX, fifoReadFrac, HWFIFODEPTH, IRIG_NUM_RATES, irigClockRateToEnum(), Master, A2DBoard::nFifoValues, NUM_NCAR_A2D_CHANNELS, numa2ds, A2DBoard::pollRate, realloc_dsm_circ_buf(), resetBoard(), USECS_PER_MSEC, and USECS_PER_SEC.
Referenced by ncar_a2d_ioctl().
|
static |
Stop data collection on the selected board.
References A2DNotAuto(), A2DStopReadAll(), AD7725StatusAll(), flush_irig_callbacks(), free_dsm_circ_buf(), freeFilters(), NUM_NCAR_A2D_CHANNELS, unregister_irig_callback(), and work_queue.
Referenced by ncar_a2d_cleanup(), ncar_a2d_ioctl(), and ncar_a2d_release().
|
static |
References A2DTemp(), and NCAR_A2D_TEMPERATURE_INDEX.
Referenced by resetBoard().
|
static |
References A2DIO_CS_CMD_WR, CHAN_ADDR16(), dtestchan, dtestcnt, dtestnum, and ioport.
Referenced by ncar_a2d_init().
|
static |
References A2DIO_CALV.
Referenced by ncar_a2d_init(), ncar_a2d_ioctl(), and SetVcal().
|
inlinestatic |
References A2DIO_SYSCTL.
Referenced by A2DConfig().
|
static |
References IRIG_100_HZ, register_irig_callback(), and unregister_irig_callback().
Referenced by resetBoard().
int withinRange | ( | int | volt, |
int | gain, | ||
int | offset ) |
References CalVoltIsValid(), and GainOffsetToEnum.
Referenced by ncar_a2d_ioctl().
|
static |
|
static |
Referenced by ncar_a2d_cleanup(), ncar_a2d_init(), and ncar_a2d_open().
|
static |
Referenced by test_ISA_Writes().
|
static |
Referenced by A2DStartAll(), and test_ISA_Writes().
|
static |
Referenced by A2DStart(), A2DStartAll(), ncar_a2d_init(), and test_ISA_Writes().
|
static |
Referenced by ncar_a2d_init(), and startBoard().
int GainOffsetToEnum[5][2] |
|
static |
Referenced by i2c_clock_hi(), and ncar_a2d_open().
|
static |
Referenced by i2c_data_hi(), and ncar_a2d_open().
|
static |
Referenced by ncar_a2d_init().
|
static |
Referenced by startBoard().
|
static |
Referenced by ncar_a2d_cleanup(), and ncar_a2d_init().
|
static |
Referenced by ncar_a2d_cleanup(), and ncar_a2d_init().
|
static |
Referenced by ncar_a2d_cleanup(), and ncar_a2d_init().
|
static |
Referenced by ncar_a2d_init().
|
static |
|
static |
|
static |
|
static |
Referenced by ncar_a2d_cleanup(), and ncar_a2d_init().
|
static |
Referenced by ncar_a2d_poll(), ncar_a2d_read(), ReadSampleCallback(), and resetBoard().
|
static |
Referenced by ncar_a2d_cleanup(), ncar_a2d_init(), readA2DFifo(), ReadSampleCallback(), and stopBoard().