int mite_sync_output_dma(struct mite_channel *mite_chan, comedi_async * async) { int count; u32 nbytes_ub, nbytes_lb; unsigned int old_alloc_count; u32 stop_count = async->cmd.stop_arg * cfc_bytes_per_scan(async->subdevice); old_alloc_count = async->buf_read_alloc_count; // read alloc as much as we can comedi_buf_read_alloc(async, async->prealloc_bufsz); nbytes_lb = mite_bytes_read_from_memory_lb(mite_chan); if (async->cmd.stop_src == TRIG_COUNT && (int)(nbytes_lb - stop_count) > 0) nbytes_lb = stop_count; nbytes_ub = mite_bytes_read_from_memory_ub(mite_chan); if (async->cmd.stop_src == TRIG_COUNT && (int)(nbytes_ub - stop_count) > 0) nbytes_ub = stop_count; if ((int)(nbytes_ub - old_alloc_count) > 0) { rt_printk("mite: DMA underrun\n"); async->events |= COMEDI_CB_OVERFLOW; return -1; } count = nbytes_lb - async->buf_read_count; if (count <= 0) { return 0; } if (count) { comedi_buf_read_free(async, count); async->events |= COMEDI_CB_BLOCK; } return 0; }
int mite_sync_input_dma(struct mite_channel *mite_chan, comedi_async * async) { int count; unsigned int nbytes, old_alloc_count; const unsigned bytes_per_scan = cfc_bytes_per_scan(async->subdevice); old_alloc_count = async->buf_write_alloc_count; // write alloc as much as we can comedi_buf_write_alloc(async, async->prealloc_bufsz); nbytes = mite_bytes_written_to_memory_lb(mite_chan); if ((int)(mite_bytes_written_to_memory_ub(mite_chan) - old_alloc_count) > 0) { rt_printk("mite: DMA overwrite of free area\n"); async->events |= COMEDI_CB_OVERFLOW; return -1; } count = nbytes - async->buf_write_count; /* it's possible count will be negative due to * conservative value returned by mite_bytes_written_to_memory_lb */ if (count <= 0) { return 0; } comedi_buf_write_free(async, count); async->scan_progress += count; if (async->scan_progress >= bytes_per_scan) { async->scan_progress %= bytes_per_scan; async->events |= COMEDI_CB_EOS; } async->events |= COMEDI_CB_BLOCK; return 0; }
void cfc_inc_scan_progress(struct comedi_subdevice *s, unsigned int num_bytes) { struct comedi_async *async = s->async; unsigned int scan_length = cfc_bytes_per_scan(s); async->scan_progress += num_bytes; if (async->scan_progress >= scan_length) { async->scan_progress %= scan_length; async->events |= COMEDI_CB_EOS; } }
static void increment_scan_progress(comedi_subdevice *subd, unsigned int num_bytes) { comedi_async *async = subd->async; unsigned int scan_length = cfc_bytes_per_scan(subd); async->scan_progress += num_bytes; if (async->scan_progress >= scan_length) { async->scan_progress %= scan_length; async->events |= COMEDI_CB_EOS; } }