Skip to content

Commit d615416

Browse files
bigguinessgregkh
authored andcommitted
staging: comedi: pcl818: introduce pcl818_ai_write_sample()
This driver can acquire analog input samples during the async command with DMA, by using the FIFO, or sample-by-sample using the End-Of-Conversion interrupt. All three methods do the following sequence: 1) check for channel dropout 2) add the sample to the async buffer 3) advance the channel dropout detection and detect the end of the command Merge this sequence into a new helper function. Signed-off-by: H Hartley Sweeten <[email protected]> Reviewed-by: Ian Abbott <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3e6cb74 commit d615416

File tree

1 file changed

+9
-32
lines changed

1 file changed

+9
-32
lines changed

drivers/staging/comedi/drivers/pcl818.c

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,12 @@ static int pcl818_ai_eoc(struct comedi_device *dev,
454454
return -EBUSY;
455455
}
456456

457-
static bool pcl818_ai_dropout(struct comedi_device *dev,
458-
struct comedi_subdevice *s,
459-
unsigned int chan)
457+
static bool pcl818_ai_write_sample(struct comedi_device *dev,
458+
struct comedi_subdevice *s,
459+
unsigned int chan, unsigned int val)
460460
{
461461
struct pcl818_private *devpriv = dev->private;
462+
struct comedi_cmd *cmd = &s->async->cmd;
462463
unsigned int expected_chan;
463464

464465
expected_chan = devpriv->act_chanlist[devpriv->act_chanlist_pos];
@@ -469,16 +470,10 @@ static bool pcl818_ai_dropout(struct comedi_device *dev,
469470
(devpriv->usefifo) ? "FIFO" : "IRQ",
470471
chan, expected_chan);
471472
s->async->events |= COMEDI_CB_ERROR;
472-
return true;
473+
return false;
473474
}
474-
return false;
475-
}
476475

477-
static bool pcl818_ai_next_chan(struct comedi_device *dev,
478-
struct comedi_subdevice *s)
479-
{
480-
struct pcl818_private *devpriv = dev->private;
481-
struct comedi_cmd *cmd = &s->async->cmd;
476+
comedi_buf_write_samples(s, &val, 1);
482477

483478
devpriv->act_chanlist_pos++;
484479
if (devpriv->act_chanlist_pos >= devpriv->act_chanlist_len)
@@ -506,13 +501,7 @@ static void pcl818_handle_eoc(struct comedi_device *dev,
506501
}
507502

508503
val = pcl818_ai_get_sample(dev, s, &chan);
509-
510-
if (pcl818_ai_dropout(dev, s, chan))
511-
return;
512-
513-
comedi_buf_write_samples(s, &val, 1);
514-
515-
pcl818_ai_next_chan(dev, s);
504+
pcl818_ai_write_sample(dev, s, chan, val);
516505
}
517506

518507
static void pcl818_handle_dma(struct comedi_device *dev,
@@ -535,13 +524,7 @@ static void pcl818_handle_dma(struct comedi_device *dev,
535524
val = ptr[i];
536525
chan = val & 0xf;
537526
val = (val >> 4) & s->maxdata;
538-
539-
if (pcl818_ai_dropout(dev, s, chan))
540-
break;
541-
542-
comedi_buf_write_samples(s, &val, 1);
543-
544-
if (!pcl818_ai_next_chan(dev, s))
527+
if (!pcl818_ai_write_sample(dev, s, chan, val))
545528
break;
546529
}
547530
}
@@ -576,13 +559,7 @@ static void pcl818_handle_fifo(struct comedi_device *dev,
576559

577560
for (i = 0; i < len; i++) {
578561
val = pcl818_ai_get_fifo_sample(dev, s, &chan);
579-
580-
if (pcl818_ai_dropout(dev, s, chan))
581-
break;
582-
583-
comedi_buf_write_samples(s, &val, 1);
584-
585-
if (!pcl818_ai_next_chan(dev, s))
562+
if (!pcl818_ai_write_sample(dev, s, chan, val))
586563
break;
587564
}
588565
}

0 commit comments

Comments
 (0)