230 likes | 340 Views
DMA Driver APIs. DMA State Diagram Loading Driver and Opening Channel DMA Channel Attributes Loading Data to a Channel Unloading Data from a Channel. DMA Driver State Diagram. dmaLoadDriver(). Idle. dmaCloseChannel(). dmaUnloadChannel(). dmaOpenChannel(). dmaCloseChannel(). Enabled.
E N D
DMA Driver APIs DMA State Diagram Loading Driver and Opening Channel DMA Channel Attributes Loading Data to a Channel Unloading Data from a Channel
DMA Driver State Diagram dmaLoadDriver() Idle dmaCloseChannel() dmaUnloadChannel() dmaOpenChannel() dmaCloseChannel() Enabled Disabled dmaDisableChannel() dmaEnableChannel() dmaLoadChannel()
Loading DMA Driver prototype: int dmaLoadDriver(void) Returns 0 always.
Opening a DMA Channel prototype: int dmaOpenChannel( int *channel_ID, int channel_type, unsigned int option_flags, int ring_size, dmaReleaseType release_rtn) example: rc = dmaOpenChannel ( &channel_id, DMA_FIFO_1_TX, (DMA_MEM_TO_MEM_MODE | DMA_DADDR_INCR | DMA_SADDR_INCR), 64, releaseFunction); Returns Error Code
dmaOpenChannel Return Codes Possible Return Values for dmaOpenChannel() DMA_SUCCESS DMA_DRIVER_UNLOADED DMA_INVALID_FLAG DMA_CHANNEL_INUSE DMA_INVALID_RING_SIZE DMA_CALLBACK_UNDEFINED MA_INVALID_STATE DMA_SYSTEM_ERROR DMA_CHANNEL_UNSUPPORTED
Channel ID prototype: int dmaOpenChannel( int *channel_ID, int channel_type, unsigned int option_flags, int ring_size, dmaReleaseType (release_rtn) Handle for opened channel, used in various DMA APIs.
Channel Type prototype: int dmaOpenChannel( int *channel_ID, int channel_type, unsigned int option_flags, int ring_size, dmaReleaseType release_rtn) Peripheral FIFO Memory “Fly-By Write” DMA DMA_FIFO_1_TX (Channel 4) Peripheral FIFO Memory “Fly-By Read” DMA DMA_FIFO_1_RX (Channel 3)
DMA Operation Mode DMA_MEM_TO_MEM Burst Transfer Size DMA_8_BYTE_BURST DMA_16_BYTE_BURST Channel Request Source DMA_EXTERNAL_REQ Source Address Increment DMA_SRC_INCR Destination Address Increment DMA_DADDR_INC DMA Transaction Operand Size DMA_8_BIT DMA_16_BIT Option Flags • prototype: int dmaOpenChannel( • int *channel_ID, • int channel_type, • unsigned int option_flags, • int ring_size, • dmaReleaseType release_rtn) These Flags Configure the DMA Channel Control Registers
option_flags: DMA_Operation Mode Peripheral FIFO Memory DMA Default Setting “Fly-By” OR Peripheral FIFO Memory DMA Memory Memory DMA • DMA_MEM_TO_MEM
option_flags : Burst Transfer Size BCLK Default Setting TA* • DMA_8_BYTE_BURST TA* • DMA_16_BYTE_BURST TA* 1 Long Word (4 Bytes) 2 Long Words (8 Bytes) 4 Long Words (16 Bytes)
option_flags : Channel Request Source Net+ARM DREQ* DACK* DONE* Default Setting Internal Fly-By peripheral* OR Mem-to-Mem under software control Peripheral Net+ARM DREQ* DACK* DONE* Peripheral • DMA_EXTERNAL_REQ *Note: Internal Fly-By hardwired to ENI RX and ENI TX
option_flags : Address Increment Applies to Memory-to-Memory DMA only. Source Memory Destination Memory Source Range DMA_SRC_INCR DMA Destination Range • DMA_DADDR_INC Source Memory Destination Memory Default Setting DMA Destination Range • DMA_DADDR_INC Source Location *Note: It never makes sense to NOT increment the destination address
option_flags : DMA Transaction Operand Size 32-bit Peripheral FIFO Memory Default Setting DMA 8-bit Peripheral FIFO Memory DMA DMA_8_BIT 16-bit Peripheral FIFO Memory DMA DMA_16_BIT
DMA Channel Ring Size prototype: int dmaOpenChannel( int *channel_ID, int channel_type, unsigned int option_flags, int ring_size, dmaReleaseType release_rtn) • Ring Size = Number of Buffer Descriptors: • Max 64 for Mem-to-Mem • Max 128 for Fly-By
DMA Channel ring_size System Memory DMA Channel Buffer Descriptor Pointer Buffer Descriptor Ring Area (CONTIGUOUS) dmaOpenChannel() allocates BD ring area from heap, based on int ring_size.
Release Callback prototype: int dmaOpenChannel( int *channel_ID, int channel_type, unsigned int option_flags, int ring_size, dmaReleaseType release_rtn) prototype: void (*dmaReleaseType) (int channel_ID, dmaMessageType *request_msg) Enabled The defined callback will be called when the dmaLoadChannel() request has completed, with input parameters channel_ID and *request_msg. dmaLoadChannel()
Loading a Channel Loading a channel configures the previously allocated Buffer Descriptors. prototype: int dmaLoadChannel( int channel_ID, dmaMessageType request_msg) typedef structdmaMessageStruct { struct dmaMessageStruct *next; void *src_addr; void *dst_addr; long length; long status; long error_value; long reserved[4]; } dmaMessageType;
Fly-By Read Loading Memory Peripheral FIFO Destination Area Set up enough dmaMessageType’s to accommodate all expected data. *next Address of next dmaMessageType if more than 32Kbytes needed. *src_addr Not Used *dst_addr Start of Destination (incrementing) length Up to 32Kbytes
Fly-By Write Loading Memory Peripheral FIFO Source Data Area Set up enough dmaMessageType’s to accommodate outgoing data. *next Address of next dmaMessageType if more than 32Kbytes needed. *src_addr Start of Data Buffer (incrementing) *dst_addr Not Used length Up to 32Kbytes
Memory to Memory Loading Memory Memory Destination Source Data Area Set up enough dmaMessageType’s to accommodate outgoing data. *next Address of next dmaMessageType if more than 32Kbytes needed. *src_addr Start of Source Data Buffer (incrementing) *dst_addr Start of Destination Buffer (incrementing) length Up to 32Kbytes
UnLoading a Channel UnLoading a channel is called to remove a processed request from the DMA’s queue when no release callback is supplied. prototype: int dmaUnloadChannel( int channel_ID, dmaMessageType *request_msg, int wait_time) System Memory DMA Channel Unused Unused Unload Buffer Descriptor Pointer Used Buffer Descriptors Used Note: Each request_msg uses one buffer descriptor.
Request Processing - no Release Callback dmaLoadChannel() dmaUnloadChannel() fills emptied by DMA Channel Release Queue* DMA Channel Request Queue emptied by fills DMA ISR * Not built when a release callback is provided
DMA API SUmmary • Load the driver - dmaLoadDriver • Open a channel - dmaOpenChannel • Set channel ID, type, options, buffer ring size, release callback • Load the channel • Flyby – source or destination address • Memory to memory – both source and dest • Unload the channel if no release callback supplied