<< Previous | Next >>

DMApoll

word DMApoll( int dmaChannel, word * bufCount );

Description

This is a low-level DMA function for determining how much data has been transferred by the specified DMA channel. Since DMA is asynchronous to the CPU, this returns a lower bound on the actually completed transfer.

IMPORTANT: Owing to the way the DMA channels are designed, this function will not give a valid result for the first buffer in a linked list or chain, or if there is only one buffer defined (with no link or array sequencing). To get around this limitation, define the first buffer as a dummy transfer of one byte from memory to the same memory, and link this initial dummy buffer to the desired list or array of buffer descriptors. Take the dummy buffer into account when interpreting the bufCount value returned. If you service an interrupt from the dummy buffer completion, you will know when it is valid to poll.

This function is mainly intended for endless DMA loops (e.g., receiving into a circular buffer from a serial port) thus the above restriction should not be too onerous in practice.

Parameters

dmaChannel
DMA channel number to poll (0-7).

bufCount
Pointer to variable in which the completed buffer count will be written. The return value contains the number of bytes remaining (not yet transferred) in this buffer. The buffer count wraps around modulo 256.

Return Value

The number of bytes remaining in the buffer indicated by *bufCount. This ranges from 0, if completed, up to the total size of the buffer, if not yet started. If the size of any single transfer was 65536 bytes, then the return value is ambiguous as to whether it means "0" or "65536."

Library

DMA.LIB

See Also

DMAloadBufDesc, DMAsetDirect


Dynamic C Functions << Previous | Next >> rabbit.com