};
/* COUNTER OBJECT ------------------------------------------------ */
-struct enc_private {
+struct s626_enc_info {
/* Pointers to functions that differ for A and B counters: */
/* Return clock enable. */
- uint16_t(*get_enable)(struct comedi_device *dev, struct enc_private *k);
+ uint16_t(*get_enable)(struct comedi_device *dev,
+ const struct s626_enc_info *k);
/* Return interrupt source. */
uint16_t(*get_int_src)(struct comedi_device *dev,
- struct enc_private *k);
+ const struct s626_enc_info *k);
/* Return preload trigger source. */
uint16_t(*get_load_trig)(struct comedi_device *dev,
- struct enc_private *k);
+ const struct s626_enc_info *k);
/* Return standardized operating mode. */
- uint16_t(*get_mode)(struct comedi_device *dev, struct enc_private *k);
+ uint16_t(*get_mode)(struct comedi_device *dev,
+ const struct s626_enc_info *k);
/* Generate soft index strobe. */
- void (*pulse_index)(struct comedi_device *dev, struct enc_private *k);
+ void (*pulse_index)(struct comedi_device *dev,
+ const struct s626_enc_info *k);
/* Program clock enable. */
- void (*set_enable)(struct comedi_device *dev, struct enc_private *k,
- uint16_t enab);
+ void (*set_enable)(struct comedi_device *dev,
+ const struct s626_enc_info *k, uint16_t enab);
/* Program interrupt source. */
- void (*set_int_src)(struct comedi_device *dev, struct enc_private *k,
- uint16_t int_source);
+ void (*set_int_src)(struct comedi_device *dev,
+ const struct s626_enc_info *k, uint16_t int_source);
/* Program preload trigger source. */
- void (*set_load_trig)(struct comedi_device *dev, struct enc_private *k,
- uint16_t trig);
+ void (*set_load_trig)(struct comedi_device *dev,
+ const struct s626_enc_info *k, uint16_t trig);
/* Program standardized operating mode. */
- void (*set_mode)(struct comedi_device *dev, struct enc_private *k,
- uint16_t setup, uint16_t disable_int_src);
+ void (*set_mode)(struct comedi_device *dev,
+ const struct s626_enc_info *k, uint16_t setup,
+ uint16_t disable_int_src);
/* Reset event capture flags. */
void (*reset_cap_flags)(struct comedi_device *dev,
- struct enc_private *k);
+ const struct s626_enc_info *k);
uint16_t my_cra; /* address of CRA register */
uint16_t my_crb; /* address of CRB register */
uint16_t my_event_bits[4]; /* bit translations for IntSrc -->RDMISC2 */
};
-#define encpriv ((struct enc_private *)(dev->subdevices+5)->private)
+static const struct s626_enc_info s626_enc_chan_info[];
/* Counter overflow/index event flag masks for RDMISC2. */
#define INDXMASK(C) (1 << (((C) > 2) ? ((C) * 2 - 1) : ((C) * 2 + 4)))
/*
* Read a counter's output latch.
*/
-static uint32_t read_latch(struct comedi_device *dev, struct enc_private *k)
+static uint32_t read_latch(struct comedi_device *dev,
+ const struct s626_enc_info *k)
{
uint32_t value;
* access, 1: A index latches A, 2: B index latches B, 3: A overflow
* latches B.
*/
-static void set_latch_source(struct comedi_device *dev, struct enc_private *k,
- uint16_t value)
+static void set_latch_source(struct comedi_device *dev,
+ const struct s626_enc_info *k, uint16_t value)
{
debi_replace(dev, k->my_crb, ~(CRBMSK_INTCTRL | CRBMSK_LATCHSRC),
value << CRBBIT_LATCHSRC);
/*
* Write value into counter preload register.
*/
-static void preload(struct comedi_device *dev, struct enc_private *k,
+static void preload(struct comedi_device *dev, const struct s626_enc_info *k,
uint32_t value)
{
debi_write(dev, k->my_latch_lsw, value);
}
if (cmd->convert_src == TRIG_TIMER) {
- struct enc_private *k = &encpriv[5];
+ const struct s626_enc_info *k =
+ &s626_enc_chan_info[5];
devpriv->ai_convert_count = cmd->chanlist_len;
k->set_enable(dev, k, CLKENAB_ALWAYS);
struct comedi_subdevice *s = dev->read_subdev;
struct comedi_async *async = s->async;
struct comedi_cmd *cmd = &async->cmd;
- struct enc_private *k;
+ const struct s626_enc_info *k;
uint16_t irqbit;
/* read interrupt type */
/* check interrupt on counters */
if (irqbit & IRQ_COINT1A) {
- k = &encpriv[0];
+ k = &s626_enc_chan_info[0];
/* clear interrupt capture flag */
k->reset_cap_flags(dev, k);
}
if (irqbit & IRQ_COINT2A) {
- k = &encpriv[1];
+ k = &s626_enc_chan_info[1];
/* clear interrupt capture flag */
k->reset_cap_flags(dev, k);
}
if (irqbit & IRQ_COINT3A) {
- k = &encpriv[2];
+ k = &s626_enc_chan_info[2];
/* clear interrupt capture flag */
k->reset_cap_flags(dev, k);
}
if (irqbit & IRQ_COINT1B) {
- k = &encpriv[3];
+ k = &s626_enc_chan_info[3];
/* clear interrupt capture flag */
k->reset_cap_flags(dev, k);
}
if (irqbit & IRQ_COINT2B) {
- k = &encpriv[4];
+ k = &s626_enc_chan_info[4];
/* clear interrupt capture flag */
k->reset_cap_flags(dev, k);
}
}
if (irqbit & IRQ_COINT3B) {
- k = &encpriv[5];
+ k = &s626_enc_chan_info[5];
/* clear interrupt capture flag */
k->reset_cap_flags(dev, k);
}
if (cmd->convert_src == TRIG_TIMER) {
- k = &encpriv[4];
+ k = &s626_enc_chan_info[4];
devpriv->ai_convert_count = cmd->chanlist_len;
k->set_enable(dev, k, CLKENAB_ALWAYS);
}
return divider - 1;
}
-static void s626_timer_load(struct comedi_device *dev, struct enc_private *k,
- int tick)
+static void s626_timer_load(struct comedi_device *dev,
+ const struct s626_enc_info *k, int tick)
{
uint16_t setup =
(LOADSRC_INDX << BF_LOADSRC) | /* Preload upon index. */
struct s626_private *devpriv = dev->private;
uint8_t ppl[16];
struct comedi_cmd *cmd = &s->async->cmd;
- struct enc_private *k;
+ const struct s626_enc_info *k;
int tick;
if (devpriv->ai_cmd_running) {
* set a counter to generate adc trigger at scan_begin_arg
* interval
*/
- k = &encpriv[5];
+ k = &s626_enc_chan_info[5];
tick = s626_ns_to_timer((int *)&cmd->scan_begin_arg,
cmd->flags & TRIG_ROUND_MASK);
* set a counter to generate adc trigger at convert_arg
* interval
*/
- k = &encpriv[4];
+ k = &s626_enc_chan_info[4];
tick = s626_ns_to_timer((int *)&cmd->convert_arg,
cmd->flags & TRIG_ROUND_MASK);
/* uint32_t Preloadvalue; //Counter initial value */
uint16_t value_latchsrc = LATCHSRC_AB_READ;
uint16_t enab = CLKENAB_ALWAYS;
- struct enc_private *k = &encpriv[CR_CHAN(insn->chanspec)];
+ const struct s626_enc_info *k =
+ &s626_enc_chan_info[CR_CHAN(insn->chanspec)];
/* (data==NULL) ? (Preloadvalue=0) : (Preloadvalue=data[0]); */
struct comedi_insn *insn, unsigned int *data)
{
int n;
- struct enc_private *k = &encpriv[CR_CHAN(insn->chanspec)];
+ const struct s626_enc_info *k =
+ &s626_enc_chan_info[CR_CHAN(insn->chanspec)];
for (n = 0; n < insn->n; n++)
data[n] = read_latch(dev, k);
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
{
- struct enc_private *k = &encpriv[CR_CHAN(insn->chanspec)];
+ const struct s626_enc_info *k =
+ &s626_enc_chan_info[CR_CHAN(insn->chanspec)];
/* Set the preload register */
preload(dev, k, data[0]);
/*
* Reset a counter's index and overflow event capture flags.
*/
-static void reset_cap_flags_a(struct comedi_device *dev, struct enc_private *k)
+static void reset_cap_flags_a(struct comedi_device *dev,
+ const struct s626_enc_info *k)
{
debi_replace(dev, k->my_crb, ~CRBMSK_INTCTRL,
CRBMSK_INTRESETCMD | CRBMSK_INTRESET_A);
}
-static void reset_cap_flags_b(struct comedi_device *dev, struct enc_private *k)
+static void reset_cap_flags_b(struct comedi_device *dev,
+ const struct s626_enc_info *k)
{
debi_replace(dev, k->my_crb, ~CRBMSK_INTCTRL,
CRBMSK_INTRESETCMD | CRBMSK_INTRESET_B);
* Return counter setup in a format (COUNTER_SETUP) that is consistent
* for both A and B counters.
*/
-static uint16_t get_mode_a(struct comedi_device *dev, struct enc_private *k)
+static uint16_t get_mode_a(struct comedi_device *dev,
+ const struct s626_enc_info *k)
{
uint16_t cra;
uint16_t crb;
return setup;
}
-static uint16_t get_mode_b(struct comedi_device *dev, struct enc_private *k)
+static uint16_t get_mode_b(struct comedi_device *dev,
+ const struct s626_enc_info *k)
{
uint16_t cra;
uint16_t crb;
* parameters are programmable (all other parms are ignored): ClkMult,
* ClkPol, ClkEnab, IndexSrc, IndexPol, LoadSrc.
*/
-static void set_mode_a(struct comedi_device *dev, struct enc_private *k,
+static void set_mode_a(struct comedi_device *dev, const struct s626_enc_info *k,
uint16_t setup, uint16_t disable_int_src)
{
struct s626_private *devpriv = dev->private;
debi_replace(dev, k->my_crb, ~(CRBMSK_INTCTRL | CRBMSK_CLKENAB_A), crb);
}
-static void set_mode_b(struct comedi_device *dev, struct enc_private *k,
+static void set_mode_b(struct comedi_device *dev, const struct s626_enc_info *k,
uint16_t setup, uint16_t disable_int_src)
{
struct s626_private *devpriv = dev->private;
/*
* Return/set a counter's enable. enab: 0=always enabled, 1=enabled by index.
*/
-static void set_enable_a(struct comedi_device *dev, struct enc_private *k,
- uint16_t enab)
+static void set_enable_a(struct comedi_device *dev,
+ const struct s626_enc_info *k, uint16_t enab)
{
debi_replace(dev, k->my_crb, ~(CRBMSK_INTCTRL | CRBMSK_CLKENAB_A),
enab << CRBBIT_CLKENAB_A);
}
-static void set_enable_b(struct comedi_device *dev, struct enc_private *k,
- uint16_t enab)
+static void set_enable_b(struct comedi_device *dev, const
+ struct s626_enc_info *k, uint16_t enab)
{
debi_replace(dev, k->my_crb, ~(CRBMSK_INTCTRL | CRBMSK_CLKENAB_B),
enab << CRBBIT_CLKENAB_B);
}
-static uint16_t get_enable_a(struct comedi_device *dev, struct enc_private *k)
+static uint16_t get_enable_a(struct comedi_device *dev,
+ const struct s626_enc_info *k)
{
return (debi_read(dev, k->my_crb) >> CRBBIT_CLKENAB_A) & 1;
}
-static uint16_t get_enable_b(struct comedi_device *dev, struct enc_private *k)
+static uint16_t get_enable_b(struct comedi_device *dev,
+ const struct s626_enc_info *k)
{
return (debi_read(dev, k->my_crb) >> CRBBIT_CLKENAB_B) & 1;
}
#ifdef unused
static uint16_t get_latch_source(struct comedi_device *dev,
- struct enc_private *k)
+ const struct s626_enc_info *k)
{
return (debi_read(dev, k->my_crb) >> CRBBIT_LATCHSRC) & 3;
}
* register into the counter. 0=ThisCntr_Index, 1=ThisCntr_Overflow,
* 2=OverflowA (B counters only), 3=disabled.
*/
-static void set_load_trig_a(struct comedi_device *dev, struct enc_private *k,
- uint16_t trig)
+static void set_load_trig_a(struct comedi_device *dev,
+ const struct s626_enc_info *k, uint16_t trig)
{
debi_replace(dev, k->my_cra, ~CRAMSK_LOADSRC_A,
trig << CRABIT_LOADSRC_A);
}
-static void set_load_trig_b(struct comedi_device *dev, struct enc_private *k,
- uint16_t trig)
+static void set_load_trig_b(struct comedi_device *dev,
+ const struct s626_enc_info *k, uint16_t trig)
{
debi_replace(dev, k->my_crb, ~(CRBMSK_LOADSRC_B | CRBMSK_INTCTRL),
trig << CRBBIT_LOADSRC_B);
}
static uint16_t get_load_trig_a(struct comedi_device *dev,
- struct enc_private *k)
+ const struct s626_enc_info *k)
{
return (debi_read(dev, k->my_cra) >> CRABIT_LOADSRC_A) & 3;
}
static uint16_t get_load_trig_b(struct comedi_device *dev,
- struct enc_private *k)
+ const struct s626_enc_info *k)
{
return (debi_read(dev, k->my_crb) >> CRBBIT_LOADSRC_B) & 3;
}
* index/overflow events. int_source: 0=Disabled, 1=OverflowOnly,
* 2=IndexOnly, 3=IndexAndOverflow.
*/
-static void set_int_src_a(struct comedi_device *dev, struct enc_private *k,
- uint16_t int_source)
+static void set_int_src_a(struct comedi_device *dev,
+ const struct s626_enc_info *k, uint16_t int_source)
{
struct s626_private *devpriv = dev->private;
k->my_event_bits[int_source];
}
-static void set_int_src_b(struct comedi_device *dev, struct enc_private *k,
- uint16_t int_source)
+static void set_int_src_b(struct comedi_device *dev,
+ const struct s626_enc_info *k, uint16_t int_source)
{
struct s626_private *devpriv = dev->private;
uint16_t crb;
k->my_event_bits[int_source];
}
-static uint16_t get_int_src_a(struct comedi_device *dev, struct enc_private *k)
+static uint16_t get_int_src_a(struct comedi_device *dev,
+ const struct s626_enc_info *k)
{
return (debi_read(dev, k->my_cra) >> CRABIT_INTSRC_A) & 3;
}
-static uint16_t get_int_src_b(struct comedi_device *dev, struct enc_private *k)
+static uint16_t get_int_src_b(struct comedi_device *dev,
+ const struct s626_enc_info *k)
{
return (debi_read(dev, k->my_crb) >> CRBBIT_INTSRC_B) & 3;
}
/*
* Return/set the clock multiplier.
*/
-static void set_clk_mult(struct comedi_device *dev, struct enc_private *k,
- uint16_t value)
+static void set_clk_mult(struct comedi_device *dev,
+ const struct s626_enc_info *k, uint16_t value)
{
k->set_mode(dev, k, ((k->get_mode(dev, k) & ~STDMSK_CLKMULT) |
(value << STDBIT_CLKMULT)), FALSE);
}
-static uint16_t get_clk_mult(struct comedi_device *dev, struct enc_private *k)
+static uint16_t get_clk_mult(struct comedi_device *dev,
+ const struct s626_enc_info *k)
{
return (k->get_mode(dev, k) >> STDBIT_CLKMULT) & 3;
}
/*
* Return/set the clock polarity.
*/
-static void set_clk_pol(struct comedi_device *dev, struct enc_private *k,
- uint16_t value)
+static void set_clk_pol(struct comedi_device *dev,
+ const struct s626_enc_info *k, uint16_t value)
{
k->set_mode(dev, k, ((k->get_mode(dev, k) & ~STDMSK_CLKPOL) |
(value << STDBIT_CLKPOL)), FALSE);
}
-static uint16_t get_clk_pol(struct comedi_device *dev, struct enc_private *k)
+static uint16_t get_clk_pol(struct comedi_device *dev,
+ const struct s626_enc_info *k)
{
return (k->get_mode(dev, k) >> STDBIT_CLKPOL) & 1;
}
/*
* Return/set the clock source.
*/
-static void set_clk_src(struct comedi_device *dev, struct enc_private *k,
- uint16_t value)
+static void set_clk_src(struct comedi_device *dev,
+ const struct s626_enc_info *k, uint16_t value)
{
k->set_mode(dev, k, ((k->get_mode(dev, k) & ~STDMSK_CLKSRC) |
(value << STDBIT_CLKSRC)), FALSE);
}
-static uint16_t get_clk_src(struct comedi_device *dev, struct enc_private *k)
+static uint16_t get_clk_src(struct comedi_device *dev,
+ const struct s626_enc_info *k)
{
return (k->get_mode(dev, k) >> STDBIT_CLKSRC) & 3;
}
/*
* Return/set the index polarity.
*/
-static void set_index_pol(struct comedi_device *dev, struct enc_private *k,
- uint16_t value)
+static void set_index_pol(struct comedi_device *dev,
+ const struct s626_enc_info *k, uint16_t value)
{
k->set_mode(dev, k, ((k->get_mode(dev, k) & ~STDMSK_INDXPOL) |
((value != 0) << STDBIT_INDXPOL)), FALSE);
}
-static uint16_t get_index_pol(struct comedi_device *dev, struct enc_private *k)
+static uint16_t get_index_pol(struct comedi_device *dev,
+ const struct s626_enc_info *k)
{
return (k->get_mode(dev, k) >> STDBIT_INDXPOL) & 1;
}
/*
* Return/set the index source.
*/
-static void set_index_src(struct comedi_device *dev, struct enc_private *k,
- uint16_t value)
+static void set_index_src(struct comedi_device *dev,
+ const struct s626_enc_info *k, uint16_t value)
{
k->set_mode(dev, k, ((k->get_mode(dev, k) & ~STDMSK_INDXSRC) |
((value != 0) << STDBIT_INDXSRC)), FALSE);
}
-static uint16_t get_index_src(struct comedi_device *dev, struct enc_private *k)
+static uint16_t get_index_src(struct comedi_device *dev,
+ const struct s626_enc_info *k)
{
return (k->get_mode(dev, k) >> STDBIT_INDXSRC) & 1;
}
/*
* Generate an index pulse.
*/
-static void pulse_index_a(struct comedi_device *dev, struct enc_private *k)
+static void pulse_index_a(struct comedi_device *dev,
+ const struct s626_enc_info *k)
{
uint16_t cra;
debi_write(dev, k->my_cra, cra);
}
-static void pulse_index_b(struct comedi_device *dev, struct enc_private *k)
+static void pulse_index_b(struct comedi_device *dev,
+ const struct s626_enc_info *k)
{
uint16_t crb;
debi_write(dev, k->my_crb, crb);
}
-static struct enc_private enc_private_data[] = {
+static const struct s626_enc_info s626_enc_chan_info[] = {
{
.get_enable = get_enable_a,
.get_int_src = get_int_src_a,
static void counters_init(struct comedi_device *dev)
{
int chan;
- struct enc_private *k;
+ const struct s626_enc_info *k;
uint16_t setup =
(LOADSRC_INDX << BF_LOADSRC) | /* Preload upon index. */
(INDXSRC_SOFT << BF_INDXSRC) | /* Disable hardware index. */
* Disable all counter interrupts and clear any captured counter events.
*/
for (chan = 0; chan < S626_ENCODER_CHANNELS; chan++) {
- k = &encpriv[chan];
+ k = &s626_enc_chan_info[chan];
k->set_mode(dev, k, setup, TRUE);
k->set_int_src(dev, k, 0);
k->reset_cap_flags(dev, k);
s->subdev_flags = SDF_WRITABLE | SDF_READABLE | SDF_LSAMPL;
s->n_chan = S626_ENCODER_CHANNELS;
s->maxdata = 0xffffff;
- s->private = enc_private_data;
s->range_table = &range_unknown;
s->insn_config = s626_enc_insn_config;
s->insn_read = s626_enc_insn_read;