nidas  v1.2-1520
Macros | Functions | Variables
ncar_a2d.c File Reference
#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. More...
 
#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. More...
 
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. More...
 
static int ncar_a2d_open (struct inode *inode, struct file *filp)
 User-space open of the A/D device. More...
 
static int ncar_a2d_release (struct inode *inode, struct file *filp)
 User-space close of the A/D device. More...
 
static unsigned int ncar_a2d_poll (struct file *filp, poll_table *wait)
 Support for select/poll on the user device. More...
 
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) More...
 
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. More...
 
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. More...
 
static int getA2DFIFOLevel (struct A2DBoard *brd)
 Get the FIFO fill level: More...
 
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. More...
 
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. More...
 
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 A2DBoardBoardInfo = 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]
 

Macro Definition Documentation

#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

Function Documentation

static void a2d_bottom_half ( struct work_struct *  work)
static
static void A2DAuto ( struct A2DBoard brd)
static
static unsigned short A2DBoardStatus ( struct A2DBoard brd)
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, A2DBoard::base_addr16, and A2DBoard::cmd_addr.

Referenced by getA2DFIFOLevel(), getSerialNumber(), and ppsCallback1().

static void A2DClearFIFO ( struct A2DBoard brd)
static
static void A2DClearSYNC ( struct A2DBoard brd)
static
static int A2DConfig ( struct A2DBoard brd,
int  channel 
)
static
static int A2DConfigAll ( struct A2DBoard brd)
static

References a2dchans, A2DConfig(), and numa2ds.

Referenced by startBoard().

static void A2DEnable1PPS ( struct A2DBoard brd)
static
static void A2DNotAuto ( struct A2DBoard brd)
static
static int A2DSetGain ( struct A2DBoard brd,
int  channel 
)
static
static int A2DSetGainAndOffset ( struct A2DBoard brd)
static
static int A2DSetMaster ( struct A2DBoard brd,
int  channel 
)
static
static void A2DSetSYNC ( struct A2DBoard brd)
static
static int A2DStart ( struct A2DBoard brd,
int  channel,
unsigned int  nloop 
)
static
static int A2DStartAll ( struct A2DBoard brd)
static

References a2dchans, A2DStart(), dtestcnt, dtestnum, and numa2ds.

Referenced by resetBoard(), and startBoard().

static void A2DStopRead ( struct A2DBoard brd,
int  channel 
)
static
static void A2DStopReadAll ( struct A2DBoard brd)
static

References a2dchans, A2DStopRead(), and numa2ds.

Referenced by resetBoard(), startBoard(), and stopBoard().

static short A2DTemp ( struct A2DBoard brd)
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, A2DBoard::busy, A2DBoard::cmd_addr, i2c_get_byte(), i2c_put_byte(), i2c_putAck(), i2c_putNoAck(), i2c_start_sequence(), and i2c_stop_sequence().

Referenced by TemperatureCallback().

static unsigned short AD7725Status ( struct A2DBoard brd,
int  channel 
)
static
static void AD7725StatusAll ( struct A2DBoard brd)
static
static unsigned short AD7725StatusInstrBits ( unsigned short  instr)
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 int addSampleConfig ( struct A2DBoard brd,
struct nidas_a2d_sample_config cfg 
)
static
static int CalVoltIsValid ( int  volt)
static

Referenced by withinRange().

static int CalVoltToBits ( int  volt)
static

Referenced by SetVcal().

static unsigned long CHAN_ADDR16 ( struct A2DBoard brd,
int  channel 
)
inlinestatic
static int configBoard ( struct A2DBoard brd,
struct nidas_a2d_config cfg 
)
static
static void discardA2DFifo ( struct A2DBoard brd)
static
static void do_filters ( struct A2DBoard brd,
dsm_sample_time_t  tt,
const short *  dp 
)
static
static void freeFilters ( struct A2DBoard brd)
static
static int getA2DFIFOLevel ( struct A2DBoard brd)
inlinestatic

Get the FIFO fill level:

Returns
0: empty 1: not empty but less than or = 1/4 full 2: more than 1/4 but less than 1/2 3: more than or = 1/2 but less than 3/4 4: more than or = 3/4 but not totally full 5: full

References A2DBoardStatus(), FIFONOTEMPTY, and FIFONOTFULL.

Referenced by ReadSampleCallback(), and resetBoard().

static int getSerialNumber ( struct A2DBoard brd)
static
static void i2c_clock_hi ( struct A2DBoard brd)
inlinestatic
static void i2c_clock_lo ( struct A2DBoard brd)
inlinestatic
static void i2c_data_hi ( struct A2DBoard brd)
inlinestatic
static void i2c_data_lo ( struct A2DBoard brd)
inlinestatic
static unsigned char i2c_get_byte ( struct A2DBoard brd)
inlinestatic

References A2DBoard::base_addr, i2c_clock_hi(), and i2c_clock_lo().

Referenced by A2DTemp().

static int i2c_getAck ( struct A2DBoard brd)
inlinestatic
static int i2c_put_byte ( struct A2DBoard brd,
unsigned char  byte 
)
inlinestatic
static void i2c_putAck ( struct A2DBoard brd)
inlinestatic
static void i2c_putNoAck ( struct A2DBoard brd)
inlinestatic

References i2c_clock_hi(), i2c_clock_lo(), and i2c_data_hi().

Referenced by A2DTemp().

static void i2c_start_sequence ( struct A2DBoard brd)
inlinestatic
static void i2c_stop_sequence ( struct A2DBoard brd)
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 ( IoPort  ,
"ISA port address of each  board,
e.g.:0x3A0"   
)
MODULE_PARM_DESC ( Master  ,
"Master A/D for the  board 
)
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 
)
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"   
)
MODULE_VERSION ( REPO_REVISION  )
static void ncar_a2d_cleanup ( void  )
static
static int __init ncar_a2d_init ( void  )
static
static long ncar_a2d_ioctl ( struct file *  filp,
unsigned int  cmd,
unsigned long  arg 
)
static
static int ncar_a2d_open ( struct inode *  inode,
struct file *  filp 
)
static
static unsigned int ncar_a2d_poll ( struct file *  filp,
poll_table *  wait 
)
static
static ssize_t ncar_a2d_read ( struct file *  filp,
char __user *  buf,
size_t  count,
loff_t *  f_pos 
)
static
static int ncar_a2d_release ( struct inode *  inode,
struct file *  filp 
)
static

User-space close of the A/D device.

References A2DBoard::deviceName, and stopBoard().

static void ppsCallback1 ( void *  ptr)
static
static void readA2DFifo ( struct A2DBoard brd)
static
static void ReadSampleCallback ( void *  ptr)
static
static int resetBoard ( struct A2DBoard brd)
static
static void resetBoardWorkFunc ( struct work_struct *  work)
static
static void SetCal ( struct A2DBoard brd)
static
static void SetOffset ( struct A2DBoard brd)
static
static void SetVcal ( struct A2DBoard brd)
static
static int startBoard ( struct A2DBoard brd)
static
static int stopBoard ( struct A2DBoard brd)
static
static void TemperatureCallback ( void *  ptr)
static
static int test_ISA_Writes ( struct A2DBoard brd,
int  ioport 
)
static
static void UnSetVcal ( struct A2DBoard brd)
static
static int wait7725Int ( struct A2DBoard brd,
int  channel,
int  ncoef 
)
inlinestatic
static int waitFor1PPS ( struct A2DBoard brd,
irig_callback_func *  ppsfunc 
)
static
int withinRange ( int  volt,
int  gain,
int  offset 
)

References CalVoltIsValid(), and GainOffsetToEnum.

Referenced by ncar_a2d_ioctl().

Variable Documentation

uint a2dchans[NUM_NCAR_A2D_CHANNELS] = { 0,1,2,3,4,5,6,7 }
static
struct A2DBoard* BoardInfo = 0
static
int dtestchan
static

Referenced by test_ISA_Writes().

uint dtestcnt
static

Referenced by A2DStartAll(), and test_ISA_Writes().

int dtestnum
static
int fifoReadFrac = 8
static

Referenced by ncar_a2d_init(), and startBoard().

int GainOffsetToEnum[5][2]
Initial value:
= {
{ X, X},
{ X, 0},
{ 1, 2},
{ X, X},
{ 3, X},
}
#define X
Definition: ncar_a2d.c:1421

Referenced by withinRange().

const unsigned long I2CSCL = 0x2
static
const unsigned long I2CSDA = 0x1
static
int IoPort[MAX_A2D_BOARDS] = { 0x3a0, 0, 0, 0 }
static

Referenced by ncar_a2d_init().

int Master[MAX_A2D_BOARDS] = { -1, -1, -1, -1 }
static

Referenced by startBoard().

struct cdev ncar_a2d_cdev
static

Referenced by ncar_a2d_cleanup(), and ncar_a2d_init().

struct class* ncar_a2d_class
static

Referenced by ncar_a2d_cleanup(), and ncar_a2d_init().

dev_t ncar_a2d_device = MKDEV(0, 0)
static

Referenced by ncar_a2d_cleanup(), and ncar_a2d_init().

struct file_operations ncar_a2d_fops
static
Initial value:
= {
.owner = THIS_MODULE,
.read = ncar_a2d_read,
.open = ncar_a2d_open,
.unlocked_ioctl = ncar_a2d_ioctl,
.release = ncar_a2d_release,
.poll = ncar_a2d_poll,
.llseek = no_llseek,
}
static long ncar_a2d_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
Definition: ncar_a2d.c:2252
static unsigned int ncar_a2d_poll(struct file *filp, poll_table *wait)
Support for select/poll on the user device.
Definition: ncar_a2d.c:2199
static int ncar_a2d_release(struct inode *inode, struct file *filp)
User-space close of the A/D device.
Definition: ncar_a2d.c:2181
static int ncar_a2d_open(struct inode *inode, struct file *filp)
User-space open of the A/D device.
Definition: ncar_a2d.c:2159
static ssize_t ncar_a2d_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)
User-space read on the A/D device.
Definition: ncar_a2d.c:2225

Referenced by ncar_a2d_init().

int nIoPort
static
int nMaster
static
uint numa2ds = NUM_NCAR_A2D_CHANNELS
static
int NumBoards = 0
static

Referenced by ncar_a2d_cleanup(), and ncar_a2d_init().

const int WAITING_FOR_RESET = 1
static
struct workqueue_struct* work_queue = 0
static