pynq.lib.dma Module

class pynq.lib.dma.DMA(description, *args, **kwargs)[source]

Bases: pynq.overlay.DefaultIP

Class for Interacting with the AXI Simple DMA Engine

This class provides two attributes for the read and write channels. The read channel copies data from the stream into memory and the write channel copies data from memory to the output stream. Both channels have an identical API consisting of transfer and wait functions. If interrupts have been enabled and connected for the DMA engine then wait_async is also present.

Buffers to be transferred must be allocated through the Xlnk driver using the cma_array function either directly or indirectly. This means that Frames from the video subsystem can be transferred using this class.

recvchannel

_DMAChannel – The stream to memory channel

sendchannel

_DMAChannel – The memory to stream channel

bindto = ['xilinx.com:ip:axi_dma:7.1']
class pynq.lib.dma.LegacyDMA(address, direction=1, attr_dict=None)[source]

Bases: object

Python class which controls DMA.

This is a generic DMA class that can be used to access main memory.

The DMA direction can be:

(0)`DMA_TO_DEV` : DMA sends data to PL.

(1)`DMA_FROM_DEV` : DMA receives data from PL.

(3)`DMA_BIDIRECTIONAL` : DMA can send/receive data from PL.

buf

cffi.FFI.CData – A pointer to physically contiguous buffer.

bufLength

int – Length of internal buffer in bytes.

phyAddress

int – Physical address of the DMA device.

DMAengine

cdata ‘XAxiDma *’ – DMA engine instance defined in C. Not to be directly modified.

DMAinstance

cdata ‘XAxiDma_Config *’ – DMA configuration instance struct. Not to be directly modified.

direction

int – The direction indicating whether DMA sends/receives data from PL.

Configuration

dict – Current DMAinstance configuration values.

Note

If this class is parsed on an unsupported architecture it will issue a warning and leave the class variables libxlnk and libdma undefined

DMA_BIDIRECTIONAL = 3
DMA_FROM_DEV = 1
DMA_TO_DEV = 0
DMA_TRANSFER_LIMIT_BYTES = 8388607
DefaultConfig = {'DeviceId': 0, 'HasSg': 0, 'Mm2SBurstSize': 16, 'S2MmDataWidth': 64, 'Mm2sNumChannels': 1, 'AddrWidth': 32, 'HasS2MmDRE': 0, 'HasStsCntrlStrm': 0, 'HasMm2SDRE': 0, 'BaseAddr': <cdata 'uint32_t *' NULL>, 'MicroDmaMode': 0, 'S2MmNumChannels': 1, 'S2MmBurstSize': 64, 'HasS2Mm': 1, 'HasMm2S': 0, 'Mm2SDataWidth': 32}
DeviceId = 0
LIB_SEARCH_PATH = '/home/docs/checkouts/readthedocs.org/user_builds/pynq/checkouts/v2.0/pynq/lib'
configure(attr_dict=None)[source]

Reconfigure and Reinitialize the DMA IP.

Uses a user provided dict to reinitialize the DMA. This method also frees the internal buffer associated with current object.

The keys in attr_dict should exactly match the ones used in default config. All the keys are not required. The default configuration is defined in self.DefaultConfig dict. Users can reinitialize the DMA with new configuratiuon after creating the object.

Parameters:attr_dict (dict) – A dictionary specifying DMA configuration values.
Returns:
Return type:None
create_buf(num_bytes, cacheable=0)[source]

Allocate physically contiguous memory buffer.

Allocates/Reallocates buffer needed for DMA operations.

Possible values for parameter cacheable are:

1: the memory buffer is cacheable.

0: the memory buffer is non-cacheable.

Note

This buffer is allocated inside the kernel space using xlnk driver. The maximum allocatable memory is defined at kernel build time using the CMA memory parameters. For Pynq-Z1 kernel, it is specified as 128MB.

Parameters:
  • num_bytes (int) – Length of the allocated array in bytes.
  • cacheable (int) – Indicating whether or not the memory buffer is cacheable
Returns:

Return type:

None

ffi = <cffi.api.FFI object>
free_buf()[source]

Free the memory buffer associated with this object.

Use this to free a previously allocated memory buffer. This is specially useful for reallocations.

Parameters:None
Returns:
Return type:None
get_buf(width=32)[source]

Get a CFFI pointer to object’s internal buffer.

This can be accessed like a regular array in python. The width can be either 32 or 64.

Parameters:width (int) – The data width in the buffer.
Returns:An CFFI object which can be accessed similar to arrays in C.
Return type:cffi.FFI.CData
get_ndarray(shape=None, dtype=<class 'numpy.float32'>, cacheable=0)[source]

Get a numpy ndarray of the DMA buffer, if shape is provided the buffer is resized to fit the specified shape.

Parameters:
  • shape (int array) – Shape of the numpy array to return
  • dtype (numpy.dtype) – Type of the numpy array to return
  • cacheable (int) – Passed to create_buf if a shape is provided
Returns:

Numpy view of the DMA buffer

Return type:

numpy.ndarray

memapi = <cffi.api.FFI object>
transfer(num_bytes=-1, direction=-1)[source]

Transfer data using DMA (Non-blocking).

Used to initiate transfer of data between a physically contiguous buffer and PL. The buffer should be allocated using create_buf or get_ndarray before this call.

The num_bytes defaults to the buffer size and be both less than or equal to the buffer size and DMA_TRANSFER_LIMIT_BYTES.

Possible values for direction are:

(0)`DMA_TO_DEV` : DMA sends data to PL.

(1)`DMA_FROM_DEV` : DMA receives data from PL.

If the direction is not specified it uses the direction passed at initialisation. This is not valid for bidirectional DMA.

Parameters:
  • num_bytes (int) – Number of bytes to transfer.
  • direction (int) – Direction in which DMA transfers data.
Returns:

Return type:

None

wait(wait_timeout=10)[source]

Block till DMA is busy or a timeout occurs.

Default value of timeout is 10 seconds.

Parameters:wait_timeout (int) – Time to wait in seconds before timing out wait operation.
Returns:
Return type:None
class pynq.lib.dma.timeout(seconds=1, error_message='Timeout')[source]

Bases: object

Internal timeout functions.

This class is only used internally.

handle_timeout(signum, frame)[source]