From: Frank Mori Hess Date: Tue, 19 Jun 2001 19:35:33 +0000 (+0000) Subject: put generic i8254_load function in 8253.h for loading a 8254 counter X-Git-Tag: r0_7_60~159 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b95ff9406bb1154409f0a529910a2b56f5fa6128;p=comedi.git put generic i8254_load function in 8253.h for loading a 8254 counter --- diff --git a/comedi/drivers/8253.h b/comedi/drivers/8253.h index e86219cf..87e01911 100644 --- a/comedi/drivers/8253.h +++ b/comedi/drivers/8253.h @@ -180,6 +180,35 @@ static inline void i8253_cascade_ns_to_timer_2div(int i8253_osc_base, return; } +/* Programs 8254 counter chip. I don't know if this works for 8253. + * base_address is the lowest io address for the chip (the address of counter 0). + * counter_number is the counter you want to load (0,1 or 2) + * count is the number to load into the counter. + * You probably want to use mode 2. + * FMH + */ +static inline int i8254_load(unsigned int base_address, + unsigned int counter_number, unsigned int count, unsigned int mode) +{ + unsigned char byte; + static const int counter_control = 3; + + if(counter_number > 2) return -1; + if(count > 0xffff) return -1; + if(mode > 5) return -1; + if(mode == 2 && count == 1) return -1; + + byte = counter_number << 6; + byte |= 0x30; // load low then high byte + byte |= (mode << 1); // set counter mode + outb(byte, base_address + counter_control); + byte = count & 0xff; // lsb of counter value + outb(byte, base_address + counter_number); + byte = (count >> 8) & 0xff; // msb of counter value + outb(byte, base_address + counter_number); + + return 0; +} #endif diff --git a/comedi/drivers/das1800.c b/comedi/drivers/das1800.c index cb57040f..a920c2b8 100644 --- a/comedi/drivers/das1800.c +++ b/comedi/drivers/das1800.c @@ -150,8 +150,7 @@ TODO: #define DAS1800_BURST_LENGTH 0x8 #define DAS1800_BURST_RATE 0x9 #define DAS1800_QRAM_ADDRESS 0xa -#define DAS1800_COUNTER(a) (0xc + a) -#define DAS1800_COUNTER_CONTROL 0xf +#define DAS1800_COUNTER 0xc #define IOBASE2 0x400 //offset of additional ioports used on 'ao' cards @@ -180,7 +179,6 @@ static int das1800_do_winsn(comedi_device *dev, comedi_subdevice *s, comedi_insn static int das1800_do_wbits(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); int das1800_set_frequency(comedi_device *dev); -int das1800_load_counter(comedi_device *dev, unsigned int counterNumber, unsigned int counterValue, unsigned int mode); unsigned int burst_convert_arg(unsigned int convert_arg, int round_mode); unsigned int suggest_transfer_size(comedi_device *dev, unsigned long ns); @@ -1379,7 +1377,7 @@ int setup_counters(comedi_device *dev, comedi_cmd cmd) if(cmd.stop_src == TRIG_EXT) { // load counter 0 in mode 0 - das1800_load_counter(dev, 0, cmd.stop_arg, 0); + i8254_load(dev->iobase + DAS1800_COUNTER, 0, cmd.stop_arg, 0); } return 0; @@ -1690,35 +1688,15 @@ int das1800_set_frequency(comedi_device *dev) int err = 0; // counter 1, mode 2 - if(das1800_load_counter(dev, 1, devpriv->divisor1, 2)) err++; + if(i8254_load(dev->iobase + DAS1800_COUNTER, 1, devpriv->divisor1, 2)) err++; // counter 2, mode 2 - if(das1800_load_counter(dev, 2, devpriv->divisor2, 2)) err++; + if(i8254_load(dev->iobase + DAS1800_COUNTER, 2, devpriv->divisor2, 2)) err++; if(err) return -1; return 0; } -/* programs onboard intel 82c54 counter chip */ -int das1800_load_counter(comedi_device *dev, unsigned int counterNumber, unsigned int counterValue, unsigned int mode) -{ - unsigned char byte; - - if(counterNumber > 2) return -1; - if(counterValue == 1 || counterValue > 0xffff) return -1; - if(mode > 5) return -1; - - byte = counterNumber << 6; - byte = byte | 0x30; // load low then high byte - byte = byte | (mode << 1); // set counter mode - outb(byte, dev->iobase + DAS1800_COUNTER_CONTROL); - byte = counterValue & 0xff; // lsb of counter value - outb(byte, dev->iobase + DAS1800_COUNTER(counterNumber)); - byte = counterValue >> 8; // msb of counter value - outb(byte, dev->iobase + DAS1800_COUNTER(counterNumber)); - return 0; -} - /* converts requested conversion timing to timing compatible with * hardware, used only when card is in 'burst mode' */ diff --git a/comedi/drivers/das800.c b/comedi/drivers/das800.c index c426daf4..9a84e11b 100644 --- a/comedi/drivers/das800.c +++ b/comedi/drivers/das800.c @@ -103,6 +103,7 @@ NOTES: #define CONV_CONTROL 0xa0 #define SCAN_LIMITS 0xc0 #define ID 0xe0 +#define DAS800_8254 4 #define DAS800_STATUS2 7 #define STATUS2_HCEN 0x80 #define STATUS2_INTE 0X20 @@ -270,7 +271,6 @@ static int das800_do_winsn(comedi_device *dev, comedi_subdevice *s, comedi_insn static int das800_do_wbits(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); int das800_probe(comedi_device *dev); int das800_set_frequency(comedi_device *dev); -int das800_load_counter(unsigned int counterNumber, unsigned int counterValue, comedi_device *dev); /* checks and probes das-800 series board type */ int das800_probe(comedi_device *dev) @@ -943,28 +943,10 @@ int das800_set_frequency(comedi_device *dev) { int err = 0; - if(das800_load_counter(1, devpriv->divisor1, dev)) err++; - if(das800_load_counter(2, devpriv->divisor2, dev)) err++; + if(i8254_load(dev->iobase + DAS800_8254, 1, devpriv->divisor1, 2)) err++; + if(i8254_load(dev->iobase + DAS800_8254, 2, devpriv->divisor2, 2)) err++; if(err) return -1; return 0; } - -int das800_load_counter(unsigned int counterNumber, unsigned int counterValue, comedi_device *dev) -{ - unsigned char byte; - - if(counterNumber > 2) return -1; - if(counterValue == 1 || counterValue > 0xffff) return -1; - - byte = counterNumber << 6; - byte = byte | 0x30; // load low then high byte - byte = byte | 0x4; // set counter mode 2 - outb(byte, dev->iobase + 0x7); - byte = counterValue & 0xff; // lsb of counter value - outb(byte, dev->iobase + 0x4 + counterNumber); - byte = counterValue >> 8; // msb of counter value - outb(byte, dev->iobase + 0x4 + counterNumber); - return 0; -}