Software Drivers

xdmaps.c File Reference

#include <string.h>
#include "xstatus.h"
#include "xdmaps.h"
#include "xil_io.h"
#include "xil_cache.h"
#include "xil_printf.h"

Defines

#define INLINE   __inline
#define XDMAPS_MOV_SAR   0x0
#define XDMAPS_MOV_CCR   0x1
#define XDMAPS_MOV_DAR   0x2
#define XDMAPS_CCR_SINGLE_BYTE   (0x0)
#define XDMAPS_CCR_M2M_SINGLE_BYTE   ((0x1 << 14) | 0x1)
#define XDMAPS_MAX_WAIT   4000

Functions

int XDmaPs_CfgInitialize (XDmaPs *InstPtr, XDmaPs_Config *Config, u32 EffectiveAddr)
int XDmaPs_ResetManager (XDmaPs *InstPtr)
int XDmaPs_ResetChannel (XDmaPs *InstPtr, unsigned int Channel)
void XDmaPs_FaultISR (XDmaPs *InstPtr)
int XDmaPs_SetDoneHandler (XDmaPs *InstPtr, unsigned Channel, XDmaPsDoneHandler DoneHandler, void *CallbackRef)
int XDmaPs_SetFaultHandler (XDmaPs *InstPtr, XDmaPsFaultHandler FaultHandler, void *CallbackRef)
INLINE int XDmaPs_Instr_DMAEND (char *DmaProg)
INLINE void XDmaPs_Memcpy4 (char *Dst, char *Src)
INLINE int XDmaPs_Instr_DMAGO (char *DmaProg, unsigned int Cn, u32 Imm, unsigned int Ns)
INLINE int XDmaPs_Instr_DMALD (char *DmaProg)
INLINE int XDmaPs_Instr_DMALP (char *DmaProg, unsigned Lc, unsigned LoopIterations)
INLINE int XDmaPs_Instr_DMALPEND (char *DmaProg, char *BodyStart, unsigned Lc)
INLINE int XDmaPs_Instr_DMAMOV (char *DmaProg, unsigned Rd, u32 Imm)
INLINE int XDmaPs_Instr_DMANOP (char *DmaProg)
INLINE int XDmaPs_Instr_DMARMB (char *DmaProg)
INLINE int XDmaPs_Instr_DMASEV (char *DmaProg, unsigned int EventNumber)
INLINE int XDmaPs_Instr_DMAST (char *DmaProg)
INLINE int XDmaPs_Instr_DMAWMB (char *DmaProg)
INLINE unsigned XDmaPs_ToEndianSwapSizeBits (unsigned int EndianSwapSize)
INLINE unsigned XDmaPs_ToBurstSizeBits (unsigned BurstSize)
u32 XDmaPs_ToCCRValue (XDmaPs_ChanCtrl *ChanCtrl)
int XDmaPs_ConstructSingleLoop (char *DmaProgStart, int CacheLength, char *DmaProgLoopStart, int LoopCount)
int XDmaPs_ConstructNestedLoop (char *DmaProgStart, int CacheLength, char *DmaProgLoopStart, unsigned int LoopCountOuter, unsigned int LoopCountInner)
int XDmaPs_GenDmaProg (XDmaPs *InstPtr, unsigned int Channel, XDmaPs_Cmd *Cmd)
int XDmaPs_FreeDmaProg (XDmaPs *InstPtr, unsigned int Channel, XDmaPs_Cmd *Cmd)
int XDmaPs_Start (XDmaPs *InstPtr, unsigned int Channel, XDmaPs_Cmd *Cmd, int HoldDmaProg)
int XDmaPs_IsActive (XDmaPs *InstPtr, unsigned int Channel)
void XDmaPs_DoneISR_0 (XDmaPs *InstPtr)
void XDmaPs_DoneISR_1 (XDmaPs *InstPtr)
void XDmaPs_DoneISR_2 (XDmaPs *InstPtr)
void XDmaPs_DoneISR_3 (XDmaPs *InstPtr)
void XDmaPs_DoneISR_4 (XDmaPs *InstPtr)
void XDmaPs_DoneISR_5 (XDmaPs *InstPtr)
void XDmaPs_DoneISR_6 (XDmaPs *InstPtr)
void XDmaPs_DoneISR_7 (XDmaPs *InstPtr)
void XDmaPs_Print_DmaProg (XDmaPs_Cmd *Cmd)

Detailed Description

This file contains the implementation of the interface functions for XDmaPs driver. Refer to the header file xdmaps.h for more detailed information.

 MODIFICATION HISTORY:
 Ver   Who  	Date     Changes
 ----- ------ -------- ----------------------------------------------
 1.00	hbm    08/19/2010 First Release
 1.00  nm     05/25/2011 Updated for minor doxygen corrections
 1.02a sg     05/16/2012 Made changes for doxygen and moved some function
			  header from the xdmaps.h file to xdmaps.c file
			  Other cleanup for coding guidelines and CR 657109
			  and CR 657898
 1.03a sg     07/16/2012 changed inline to __inline for CR665681
 1.04a nm     10/22/2012 Fixed CR# 681671.
 1.05a nm     04/15/2013 Fixed CR# 704396. Removed warnings when compiled
			  with -Wall and -Wextra option in bsp.
	       05/01/2013 Fixed CR# 700189. Changed XDmaPs_BuildDmaProg()
			  function description.
			  Fixed CR# 704396. Removed unused variables
			  UseM2MByte & MemBurstLen from XDmaPs_BuildDmaProg()
			  function.
 1.07a asa    11/02/13. Made changes to fix compilation issues for iarcc.
			   Removed the PDBG prints. By default they were always
			   defined out and never used. The PDBG is non-standard for
			   Xilinx drivers and no other driver does something similar.
			   Since there is no easy way to fix compilation issues with
			   the IARCC compiler around PDBG, it is better to remove it.
			   Users can always use xil_printfs if they want to debug.
 

Define Documentation

#define INLINE   __inline
#define XDMAPS_CCR_M2M_SINGLE_BYTE   ((0x1 << 14) | 0x1)
#define XDMAPS_CCR_SINGLE_BYTE   (0x0)
#define XDMAPS_MAX_WAIT   4000
#define XDMAPS_MOV_CCR   0x1
#define XDMAPS_MOV_DAR   0x2
#define XDMAPS_MOV_SAR   0x0

Function Documentation

int XDmaPs_CfgInitialize ( XDmaPs InstPtr,
XDmaPs_Config Config,
u32  EffectiveAddr 
)

Initializes a specific XDmaPs instance such that it is ready to be used. The data format of the device is setup for 8 data bits, 1 stop bit, and no parity by default. The baud rate is set to a default value specified by Config->DefaultBaudRate if set, otherwise it is set to 19.2K baud. The receive FIFO threshold is set for 8 bytes. The default operating mode of the driver is polled mode.

Parameters:
InstPtr is a pointer to the XDmaPs instance.
Config is a reference to a structure containing information about a specific XDmaPs driver.
EffectiveAddr is the device base address in the virtual memory address space. The caller is responsible for keeping the address mapping from EffectiveAddr to the device physical base address unchanged once this function is invoked. Unexpected errors may occur if the address mapping changes after this function is called. If address translation is not used, pass in the physical address instead.
Returns:
  • XST_SUCCESS on initialization completion
Note:
None.
int XDmaPs_ConstructNestedLoop ( char *  DmaProgStart,
int  CacheLength,
char *  DmaProgLoopStart,
unsigned int  LoopCountOuter,
unsigned int  LoopCountInner 
)

Construct a nested loop with only DMALD and DMAST in the inner loop body. It uses loop counter 1 for the outer loop and loop counter 0 for the inner loop.

Parameters:
DmaProgStart is the very start address of the DMA program. This is used to calculate whether the loop is in a cache line.
CacheLength is the icache line length, in terms of bytes. If it's zero, the performance enhancement feature will be turned off.
DmaProgLoopStart The starting address of the loop (DMALP).
LoopCountOuter The outer loop count. Loop count - 1 will be used to initialize the loop counter.
LoopCountInner The inner loop count. Loop count - 1 will be used to initialize the loop counter.
Returns:
The number byes the nested loop program has.
Note:
None.
int XDmaPs_ConstructSingleLoop ( char *  DmaProgStart,
int  CacheLength,
char *  DmaProgLoopStart,
int  LoopCount 
)

Construct a loop with only DMALD and DMAST as the body using loop counter 0. The function also makes sure the loop body and the lpend is in the same cache line.

Parameters:
DmaProgStart is the very start address of the DMA program. This is used to calculate whether the loop is in a cache line.
CacheLength is the icache line length, in terms of bytes. If it's zero, the performance enhancement feature will be turned off.
DmaProgLoopStart The starting address of the loop (DMALP).
LoopCount The inner loop count. Loop count - 1 will be used to initialize the loop counter.
Returns:
The number of bytes the loop has.
Note:
None.
void XDmaPs_DoneISR_0 ( XDmaPs InstPtr  ) 

Driver done interrupt service routine for channel 0. We need this done ISR mainly because the driver needs to release the DMA program buffer. This is the one that connects the GIC

Parameters:
InstPtr is the DMA instance.
Returns:
None.
Note:
None.
void XDmaPs_DoneISR_1 ( XDmaPs InstPtr  ) 

Driver done interrupt service routine for channel 1. We need this done ISR mainly because the driver needs to release the DMA program buffer. This is the one that connects the GIC

Parameters:
InstPtr is the DMA instance.
Returns:
None.
Note:
None.
void XDmaPs_DoneISR_2 ( XDmaPs InstPtr  ) 

Driver done interrupt service routine for channel 2. We need this done ISR mainly because the driver needs to release the DMA program buffer. This is the one that connects the GIC

Parameters:
InstPtr is the DMA instance.
Returns:
None.
Note:
None.
void XDmaPs_DoneISR_3 ( XDmaPs InstPtr  ) 

Driver done interrupt service routine for channel 3. We need this done ISR mainly because the driver needs to release the DMA program buffer. This is the one that connects the GIC

Parameters:
InstPtr is the DMA instance.
Returns:
None.
Note:
None.
void XDmaPs_DoneISR_4 ( XDmaPs InstPtr  ) 

Driver done interrupt service routine for channel 4. We need this done ISR mainly because the driver needs to release the DMA program buffer. This is the one that connects the GIC

Parameters:
InstPtr is the DMA instance.
Returns:
None.
Note:
None.
void XDmaPs_DoneISR_5 ( XDmaPs InstPtr  ) 

Driver done interrupt service routine for channel 5. We need this done ISR mainly because the driver needs to release the DMA program buffer. This is the one that connects the GIC

Parameters:
InstPtr is the DMA instance.
Returns:
None.
Note:
None.
void XDmaPs_DoneISR_6 ( XDmaPs InstPtr  ) 

Driver done interrupt service routine for channel 6. We need this done ISR mainly because the driver needs to release the DMA program buffer. This is the one that connects the GIC

Parameters:
InstPtr is the DMA instance.
Returns:
None.
Note:
None.
void XDmaPs_DoneISR_7 ( XDmaPs InstPtr  ) 

Driver done interrupt service routine for channel 7. We need this done ISR mainly because the driver needs to release the DMA program buffer. This is the one that connects the GIC

Parameters:
InstPtr is the DMA instance.
Returns:
None.
Note:
None.
void XDmaPs_FaultISR ( XDmaPs InstPtr  ) 

Driver fault interrupt service routine This is the one that connects the GIC

Parameters:
InstPtr is the DMA instance.
Returns:
None.
Note:
None.
int XDmaPs_FreeDmaProg ( XDmaPs InstPtr,
unsigned int  Channel,
XDmaPs_Cmd Cmd 
)

Free the DMA program buffer that is pointed by the GeneratedDmaProg field of the command.

Parameters:
InstPtr is then DMA instance.
Channel is the DMA channel number.
Cmd is the DMA command.
Returns:
XST_SUCCESS on success. XST_FAILURE if there is any error.
Note:
None.
int XDmaPs_GenDmaProg ( XDmaPs InstPtr,
unsigned int  Channel,
XDmaPs_Cmd Cmd 
)

Generate a DMA program based for the DMA command, the buffer will be pointed by the GeneratedDmaProg field of the command.

Parameters:
InstPtr is then DMA instance.
Channel is the DMA channel number.
Cmd is the DMA command.
Returns:
- XST_SUCCESS on success.
  • XST_FAILURE if it fails
Note:
None.
INLINE int XDmaPs_Instr_DMAEND ( char *  DmaProg  ) 

Construction function for DMAEND instruction. This function fills the program buffer with the constructed instruction.

Parameters:
DmaProg the DMA program buffer, it's the starting address for the instruction being constructed
Returns:
The number of bytes for this instruction which is 1.
Note:
None.
INLINE int XDmaPs_Instr_DMAGO ( char *  DmaProg,
unsigned int  Cn,
u32  Imm,
unsigned int  Ns 
)

Construction function for DMAGO instruction. This function fills the program buffer with the constructed instruction.

Parameters:
DmaProg is the DMA program buffer, it's the starting address for the instruction being constructed
Cn is the Channel number, 0 - 7
Imm is 32-bit immediate number written to the Channel Program Counter.
Ns is Non-secure flag. If Ns is 1, the DMA channel operates in the Non-secure state. If Ns is 0, the execution depends on the security state of the DMA manager: DMA manager is in the Secure state, DMA channel operates in the Secure state. DMA manager is in the Non-secure state, DMAC aborts.
Returns:
The number of bytes for this instruction which is 6.
Note:
None
INLINE int XDmaPs_Instr_DMALD ( char *  DmaProg  ) 

Construction function for DMALD instruction. This function fills the program buffer with the constructed instruction.

Parameters:
DmaProg the DMA program buffer, it's the starting address for the instruction being constructed
Returns:
The number of bytes for this instruction which is 1.
Note:
None.
INLINE int XDmaPs_Instr_DMALP ( char *  DmaProg,
unsigned  Lc,
unsigned  LoopIterations 
)

Construction function for DMALP instruction. This function fills the program buffer with the constructed instruction.

Parameters:
DmaProg is the DMA program buffer, it's the starting address for the instruction being constructed
Lc is the Loop counter register, can either be 0 or 1.
LoopIterations,: the number of interations, LoopInterations - 1 will be encoded in the DMALP instruction.
Returns:
The number of bytes for this instruction which is 2.
Note:
None.
INLINE int XDmaPs_Instr_DMALPEND ( char *  DmaProg,
char *  BodyStart,
unsigned  Lc 
)

Construction function for DMALPEND instruction. This function fills the program buffer with the constructed instruction.

Parameters:
DmaProg is the DMA program buffer, it's the starting address for the instruction being constructed
BodyStart is the starting address of the loop body. It is used to calculate the bytes of backward jump.
Lc is the Loop counter register, can either be 0 or 1.
Returns:
The number of bytes for this instruction which is 2.
Note:
None.
INLINE int XDmaPs_Instr_DMAMOV ( char *  DmaProg,
unsigned  Rd,
u32  Imm 
)

Construction function for DMAMOV instruction. This function fills the program buffer with the constructed instruction.

Parameters:
DmaProg is the DMA program buffer, it's the starting address for the instruction being constructed
Rd is the register id, 0 for SAR, 1 for CCR, and 2 for DAR
Imm is the 32-bit immediate number
Returns:
The number of bytes for this instruction which is 6.
Note:
None.
INLINE int XDmaPs_Instr_DMANOP ( char *  DmaProg  ) 

Construction function for DMANOP instruction. This function fills the program buffer with the constructed instruction.

Parameters:
DmaProg is the DMA program buffer, it's the starting address for the instruction being constructed
Returns:
The number of bytes for this instruction which is 1.
Note:
None.
INLINE int XDmaPs_Instr_DMARMB ( char *  DmaProg  ) 

Construction function for DMARMB instruction. This function fills the program buffer with the constructed instruction.

Parameters:
DmaProg is the DMA program buffer, it's the starting address for the instruction being constructed
Returns:
The number of bytes for this instruction which is 1.
Note:
None.
INLINE int XDmaPs_Instr_DMASEV ( char *  DmaProg,
unsigned int  EventNumber 
)

Construction function for DMASEV instruction. This function fills the program buffer with the constructed instruction.

Parameters:
DmaProg is the DMA program buffer, it's the starting address for the instruction being constructed
EventNumber is the Event number to signal.
Returns:
The number of bytes for this instruction which is 2.
Note:
None.
INLINE int XDmaPs_Instr_DMAST ( char *  DmaProg  ) 

Construction function for DMAST instruction. This function fills the program buffer with the constructed instruction.

Parameters:
DmaProg is the DMA program buffer, it's the starting address for the instruction being constructed
Returns:
The number of bytes for this instruction which is 1.
Note:
None.
INLINE int XDmaPs_Instr_DMAWMB ( char *  DmaProg  ) 

Construction function for DMAWMB instruction. This function fills the program buffer with the constructed instruction.

Parameters:
DmaProg is the DMA program buffer, it's the starting address for the instruction being constructed
Returns:
The number of bytes for this instruction which is 1.
Note:
None.
int XDmaPs_IsActive ( XDmaPs InstPtr,
unsigned int  Channel 
)

Checks whether the DMA channel is active or idle.

Parameters:
InstPtr is the DMA instance.
Channel is the DMA channel number.
Returns:
0: if the channel is idle 1: otherwise
Note:
None.
INLINE void XDmaPs_Memcpy4 ( char *  Dst,
char *  Src 
)
void XDmaPs_Print_DmaProg ( XDmaPs_Cmd Cmd  ) 

Print the Dma Prog Contents.

Parameters:
Cmd is the command buffer.
Returns:
None.
Note:
None.
int XDmaPs_ResetChannel ( XDmaPs InstPtr,
unsigned int  Channel 
)

Reset the specified DMA Channel.

Parameters:
InstPtr is the DMA instance.
Channel is the channel to be reset.
Returns:
0 on success, -1 on time out
Note:
None.
int XDmaPs_ResetManager ( XDmaPs InstPtr  ) 

Reset the DMA Manager.

Parameters:
InstPtr is the DMA instance.
Returns:
0 on success, -1 on time out
Note:
None.
int XDmaPs_SetDoneHandler ( XDmaPs InstPtr,
unsigned  Channel,
XDmaPsDoneHandler  DoneHandler,
void *  CallbackRef 
)

Set the done handler for a channel.

Parameters:
InstPtr is the DMA instance.
Channel is the channel number.
DoneHandler is the done interrupt handler.
CallbackRef is the callback reference data.
Returns:
None.
Note:
None.
int XDmaPs_SetFaultHandler ( XDmaPs InstPtr,
XDmaPsFaultHandler  FaultHandler,
void *  CallbackRef 
)

Set the fault handler for a channel.

Parameters:
InstPtr is the DMA instance.
FaultHandler is the fault interrupt handler.
CallbackRef is the callback reference data.
Returns:
None.
Note:
None.
int XDmaPs_Start ( XDmaPs InstPtr,
unsigned int  Channel,
XDmaPs_Cmd Cmd,
int  HoldDmaProg 
)

Start a DMA command. The command can only be invoked when the channel is idle. The driver takes the command, generates DMA program if needed, then pass the program to DMAC to execute.

Parameters:
InstPtr is then DMA instance.
Channel is the DMA channel number.
Cmd is the DMA command.
HoldDmaProg is tag indicating whether the driver can release the allocated DMA buffer or not. If a user wants to examine the generated DMA program, the flag should be set to 1. After the DMA program is finished, a user needs to explicity free the buffer.
Returns:
  • XST_SUCCESS on success
  • XST_DEVICE_BUSY if DMA is busy
  • XST_FAILURE on other failures
Note:
None.
INLINE unsigned XDmaPs_ToBurstSizeBits ( unsigned  BurstSize  ) 

Conversion function from the burst size to the bit encoding of the CCR

Parameters:
BurstSize is the burst size. It's the data width. In terms of bytes, it could be 1, 2, 4, 8, 16, 32, 64, or 128. It must be no larger than the bus width. (We are using DMA assembly syntax.)
Note:
None.
u32 XDmaPs_ToCCRValue ( XDmaPs_ChanCtrl ChanCtrl  ) 

Conversion function from PL330 bus transfer descriptors to CCR value. All the values passed to the functions are in terms of assembly languages, not in terms of the register bit encoding.

Parameters:
ChanCtrl is the Instance of XDmaPs_ChanCtrl.
Returns:
The 32-bit CCR value.
Note:
None.
INLINE unsigned XDmaPs_ToEndianSwapSizeBits ( unsigned int  EndianSwapSize  ) 

Conversion function from the endian swap size to the bit encoding of the CCR

Parameters:
EndianSwapSize is the endian swap size, in terms of bits, it could be 8, 16, 32, 64, or 128(We are using DMA assembly syntax)
Returns:
The endian swap size bit encoding for the CCR.
Note:
None.