<acronym id="s8ci2"><small id="s8ci2"></small></acronym>
<rt id="s8ci2"></rt><rt id="s8ci2"><optgroup id="s8ci2"></optgroup></rt>
<acronym id="s8ci2"></acronym>
<acronym id="s8ci2"><center id="s8ci2"></center></acronym>
0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

ZYNQ SOC案例開發:AXI DMA使用解析及環路測試

電子設計 ? 來源:csdn ? 作者:沒落騎士 ? 2020-12-31 09:52 ? 次閱讀

一、AXI DMA介紹

本篇博文講述AXI DMA的一些使用總結,硬件IP子系統搭建與SDK C代碼封裝參考米聯客ZYNQ教程。若想讓ZYNQ的PS與PL兩部分高速數據傳輸,需要利用PS的HP(高性能)接口通過AXI_DMA完成數據搬移,這正符合PG021 AXI DMA v7.1 LogiCORE IP Product Guide中介紹的AXI DMA的應用場景:The AXI DMA provides high-speed data movement between system memory and an AXI4-Stream-based target IP such as AXI Ethernet.

如圖,AXI DMA主要包括Memory Map和 Stream兩部分接口,前者連接PS子系統,后者則連接帶有流接口的PL IP核。

o4YBAF9uKIOATJUNAAE0P3Z7-_o177.png

其最簡單的事直接寄存器模式(Simple DMA),這里需要注意地址對齊的問題:當沒有使能地址重對齊的情況下,如果AXI Memory Map數據位寬是32bit,則搬移數據所在地址必須在0x0,0x4,0x8等起始地址上。接下來關注DMA IP核配置界面主要參數

pIYBAF9uKIaAYldxAAE4qoOga5I101.png

AXI DMA可以有兩個傳輸方向:讀通道和寫通道,依次為MM2S和S2MM方向。也就是說“讀”和“寫”是DMA主動對CPU發起的操作。重點查看以下幾個參數:

1 Width of Buffer Length Register:

在直接寄存器模式下,它指定在MM2S_LENGTH和S2MM_LENGTH寄存器的有效比特數。MM2S_LENGTH寄存器指定了MM2S通道傳輸數據字節數,當CPU寫入非零值時開始進行PS到PL的數據搬移,而S2MM_LENGTH對應另一個數據流方向。比特數直接與對應寄存器可寫入的最大數直接相關,傳輸最大字節數= 2^(Width of Buffer Length Register)。此處保持默認14bit,也就是說啟動DMA傳輸的最大數據量是16384byte。

2 Memory Map Data Width:

該參數指定了Memory Map側數據接口寬度,選定32bit后搬移數據所在內存地址必須與4對齊。

3 Max Burst Size:

之前在講解PS子系統內部的DMA時介紹過DMA的Burst概念,即分批次傳輸數據塊。官方IP核文檔解釋為:

o4YBAF9uKIeAbLC0AAC8N-b_FIg486.png

理解起來burst size確定了突發周期的最大數值,也就是burst size越大,突發粒度越大(單次傳輸的數據個數越多)。這與PS端DMA有所區別,顯然與 PS DMA的burst length意義相近。筆者也進行過嘗試,當啟動傳輸數據量相同時,burst size設置較大情況下,每批次傳輸數據量更多。

二、AXI DMA Loop IP子系統

在利用ZYNQ搭建系統時,經常需要利用各種IP核做所謂的“計算加速”,將重復性高 計算量大 占用較大CPU資源的底層處理交給各個IP核完成。這時PS ->DMA ->PL -> DMA -> PS的環路架構非常適用。這里使用AXI Stream Data FIFO代替自定義IP核作為演示,硬件IP子系統如下:

pIYBAF9uKI2ASmNmAAUnucDov-k027.png

三、SDK 官方demo解析

首先分析下官方的demo。

pIYBAF9uKI-ABMg7AAE0T6naMPY767.png

/******************************************************************************
*
* Copyright (C) 2010 - 2016 Xilinx, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Use of the Software is limited solely to applications:
* (a) running on a Xilinx device, or
* (b) that interact with a Xilinx device through a bus or interconnect.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of the Xilinx shall not be used
* in advertising or otherwise to promote the sale, use or other dealings in
* this Software without prior written authorization from Xilinx.
*
******************************************************************************/
/*****************************************************************************/
/**
*
* @file xaxidma_example_simple_intr.c
*
* This file demonstrates how to use the xaxidma driver on the Xilinx AXI
* DMA core (AXIDMA) to transfer packets.in interrupt mode when the AXIDMA core
* is configured in simple mode
*
* This code assumes a loopback hardware widget is connected to the AXI DMA
* core for data packet loopback.
*
* To see the debug print, you need a Uart16550 or uartlite in your system,
* and please set "-DDEBUG" in your compiler options. You need to rebuild your
* software executable.
*
* Make sure that MEMORY_BASE is defined properly as per the HW system. The
* h/w system built in Area mode has a maximum DDR memory limit of 64MB. In
* throughput mode, it is 512MB. These limits are need to ensured for
* proper operation of this code.
*
*
*

 * MODIFICATION HISTORY:
 *
 * Ver   Who  Date     Changes
 * ----- ---- -------- -------------------------------------------------------
 * 4.00a rkv  02/22/11 New example created for simple DMA, this example is for
 *                  simple DMA,Added interrupt support for Zynq.
 * 4.00a srt  08/04/11 Changed a typo in the RxIntrHandler, changed
 *               XAXIDMA_DMA_TO_DEVICE to XAXIDMA_DEVICE_TO_DMA
 * 5.00a srt  03/06/12 Added Flushing and Invalidation of Caches to fix CRs
 *               648103, 648701.
 *               Added V7 DDR Base Address to fix CR 649405.
 * 6.00a srt  03/27/12 Changed API calls to support MCDMA driver.
 * 7.00a srt  06/18/12 API calls are reverted back for backward compatibility.
 * 7.01a srt  11/02/12 Buffer sizes (Tx and Rx) are modified to meet maximum
 *               DDR memory limit of the h/w system built with Area mode
 * 7.02a srt  03/01/13 Updated DDR base address for IPI designs (CR 703656).
 * 9.1   adk  01/07/16 Updated DDR base address for Ultrascale (CR 799532) and
 *               removed the defines for S6/V6.
 * 9.2   vak  15/04/16 Fixed compilation warnings in the example
 * 

*
* ***************************************************************************
*/

/***************************** Include Files *********************************/

#include "xaxidma.h"
#include "xparameters.h"
#include "xil_exception.h"
#include "xdebug.h"

#ifdef XPAR_UARTNS550_0_BASEADDR
#include "xuartns550_l.h" /* to use uartns550 */
#endif

#ifdef XPAR_INTC_0_DEVICE_ID
#include "xintc.h"
#else
#include "xscugic.h"
#endif

/************************** Constant Definitions *****************************/

/*
* Device hardware build related constants.
*/

#define DMA_DEV_ID XPAR_AXIDMA_0_DEVICE_ID

#ifdef XPAR_AXI_7SDDR_0_S_AXI_BASEADDR
#define DDR_BASE_ADDR XPAR_AXI_7SDDR_0_S_AXI_BASEADDR
#elif XPAR_MIG7SERIES_0_BASEADDR
#define DDR_BASE_ADDR XPAR_MIG7SERIES_0_BASEADDR
#elif XPAR_MIG_0_BASEADDR
#define DDR_BASE_ADDR XPAR_MIG_0_BASEADDR
#elif XPAR_PSU_DDR_0_S_AXI_BASEADDR
#define DDR_BASE_ADDR XPAR_PSU_DDR_0_S_AXI_BASEADDR
#endif

#ifndef DDR_BASE_ADDR
#warning CHECK FOR THE VALID DDR ADDRESS IN XPARAMETERS.H, /
DEFAULT SET TO 0x01000000
#define MEM_BASE_ADDR 0x01000000
#else
#define MEM_BASE_ADDR (DDR_BASE_ADDR + 0x1000000)
#endif

#ifdef XPAR_INTC_0_DEVICE_ID
#define RX_INTR_ID XPAR_INTC_0_AXIDMA_0_S2MM_INTROUT_VEC_ID
#define TX_INTR_ID XPAR_INTC_0_AXIDMA_0_MM2S_INTROUT_VEC_ID
#else
#define RX_INTR_ID XPAR_FABRIC_AXIDMA_0_S2MM_INTROUT_VEC_ID
#define TX_INTR_ID XPAR_FABRIC_AXIDMA_0_MM2S_INTROUT_VEC_ID
#endif

#define TX_BUFFER_BASE (MEM_BASE_ADDR + 0x00100000)
#define RX_BUFFER_BASE (MEM_BASE_ADDR + 0x00300000)
#define RX_BUFFER_HIGH (MEM_BASE_ADDR + 0x004FFFFF)

#ifdef XPAR_INTC_0_DEVICE_ID
#define INTC_DEVICE_ID XPAR_INTC_0_DEVICE_ID
#else
#define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID
#endif

#ifdef XPAR_INTC_0_DEVICE_ID
#define INTC XIntc
#define INTC_HANDLER XIntc_InterruptHandler
#else
#define INTC XScuGic
#define INTC_HANDLER XScuGic_InterruptHandler
#endif

/* Timeout loop counter for reset
*/
#define RESET_TIMEOUT_COUNTER 10000

#define TEST_START_VALUE 0xC
/*
* Buffer and Buffer Descriptor related constant definition
*/
#define MAX_PKT_LEN 0x100

#define NUMBER_OF_TRANSFERS 10

/* The interrupt coalescing threshold and delay timer threshold
* Valid range is 1 to 255
*
* We set the coalescing threshold to be the total number of packets.
* The receive side will only get one completion interrupt for this example.
*/

/**************************** Type Definitions *******************************/

/***************** Macros (Inline Functions) Definitions *********************/

/************************** Function Prototypes ******************************/
#ifndef DEBUG
extern void xil_printf(const char *format, ...);
#endif

#ifdef XPAR_UARTNS550_0_BASEADDR
static void Uart550_Setup(void);
#endif

static int CheckData(int Length, u8 StartValue);
static void TxIntrHandler(void *Callback);
static void RxIntrHandler(void *Callback);

static int SetupIntrSystem(INTC * IntcInstancePtr,
XAxiDma * AxiDmaPtr, u16 TxIntrId, u16 RxIntrId);
static void DisableIntrSystem(INTC * IntcInstancePtr,
u16 TxIntrId, u16 RxIntrId);

/************************** Variable Definitions *****************************/
/*
* Device instance definitions
*/

static XAxiDma AxiDma; /* Instance of the XAxiDma */

static INTC Intc; /* Instance of the Interrupt Controller */

/*
* Flags interrupt handlers use to notify the application context the events.
*/
volatile int TxDone;
volatile int RxDone;
volatile int Error;

/*****************************************************************************/
/**
*
* Main function
*
* This function is the main entry of the interrupt test. It does the following:
* Set up the output terminal if UART16550 is in the hardware build
* Initialize the DMA engine
* Set up Tx and Rx channels
* Set up the interrupt system for the Tx and Rx interrupts
* Submit a transfer
* Wait for the transfer to finish
* Check transfer status
* Disable Tx and Rx interrupts
* Print test status and exit
*
* @param None
*
* @return
* - XST_SUCCESS if example finishes successfully
* - XST_FAILURE if example fails.
*
* @note None.
*
******************************************************************************/
int main(void)
{
int Status;
XAxiDma_Config *Config;
int Tries = NUMBER_OF_TRANSFERS;
int Index;
u8 *TxBufferPtr;
u8 *RxBufferPtr;
u8 Value;

TxBufferPtr = (u8 *)TX_BUFFER_BASE ;
RxBufferPtr = (u8 *)RX_BUFFER_BASE;
/* Initial setup for Uart16550 */
#ifdef XPAR_UARTNS550_0_BASEADDR

Uart550_Setup();

#endif

xil_printf("/r/n--- Entering main() --- /r/n");

Config = XAxiDma_LookupConfig(DMA_DEV_ID);
if (!Config) {
xil_printf("No config found for %d/r/n", DMA_DEV_ID);

return XST_FAILURE;
}

/* Initialize DMA engine */
Status = XAxiDma_CfgInitialize(&AxiDma, Config);

if (Status != XST_SUCCESS) {
xil_printf("Initialization failed %d/r/n", Status);
return XST_FAILURE;
}

if(XAxiDma_HasSg(&AxiDma)){
xil_printf("Device configured as SG mode /r/n");
return XST_FAILURE;
}

/* Set up Interrupt system */
Status = SetupIntrSystem(&Intc, &AxiDma, TX_INTR_ID, RX_INTR_ID);
if (Status != XST_SUCCESS) {

xil_printf("Failed intr setup/r/n");
return XST_FAILURE;
}

/* Disable all interrupts before setup */

XAxiDma_IntrDisable(&AxiDma, XAXIDMA_IRQ_ALL_MASK,
XAXIDMA_DMA_TO_DEVICE);

XAxiDma_IntrDisable(&AxiDma, XAXIDMA_IRQ_ALL_MASK,
XAXIDMA_DEVICE_TO_DMA);

/* Enable all interrupts */
XAxiDma_IntrEnable(&AxiDma, XAXIDMA_IRQ_ALL_MASK,
XAXIDMA_DMA_TO_DEVICE);

XAxiDma_IntrEnable(&AxiDma, XAXIDMA_IRQ_ALL_MASK,
XAXIDMA_DEVICE_TO_DMA);

/* Initialize flags before start transfer test */
TxDone = 0;
RxDone = 0;
Error = 0;

Value = TEST_START_VALUE;

for(Index = 0; Index TxBufferPtr[Index] = Value;

Value = (Value + 1) & 0xFF;
}

/* Flush the SrcBuffer before the DMA transfer, in case the Data Cache
* is enabled
*/
Xil_DCacheFlushRange((UINTPTR)TxBufferPtr, MAX_PKT_LEN);
#ifdef __aarch64__
Xil_DCacheFlushRange((UINTPTR)RxBufferPtr, MAX_PKT_LEN);
#endif

/* Send a packet */
for(Index = 0; Index

Status = XAxiDma_SimpleTransfer(&AxiDma,(UINTPTR) RxBufferPtr,
MAX_PKT_LEN, XAXIDMA_DEVICE_TO_DMA);

if (Status != XST_SUCCESS) {
return XST_FAILURE;
}

Status = XAxiDma_SimpleTransfer(&AxiDma,(UINTPTR) TxBufferPtr,
MAX_PKT_LEN, XAXIDMA_DMA_TO_DEVICE);

if (Status != XST_SUCCESS) {
return XST_FAILURE;
}

/*
* Wait TX done and RX done
*/
while (!TxDone && !RxDone && !Error) {
/* NOP */
}

if (Error) {
xil_printf("Failed test transmit%s done, "
"receive%s done/r/n", TxDone? "":" not",
RxDone? "":" not");

goto Done;

}

/*
* Test finished, check data
*/
Status = CheckData(MAX_PKT_LEN, 0xC);
if (Status != XST_SUCCESS) {
xil_printf("Data check failed/r/n");
goto Done;
}
}

xil_printf("AXI DMA interrupt example test passed/r/n");

/* Disable TX and RX Ring interrupts and return success */

DisableIntrSystem(&Intc, TX_INTR_ID, RX_INTR_ID);

Done:
xil_printf("--- Exiting main() --- /r/n");

return XST_SUCCESS;
}

#ifdef XPAR_UARTNS550_0_BASEADDR
/*****************************************************************************/
/*
*
* Uart16550 setup routine, need to set baudrate to 9600 and data bits to 8
*
* @param None
*
* @return None
*
* @note None.
*
******************************************************************************/
static void Uart550_Setup(void)
{

XUartNs550_SetBaud(XPAR_UARTNS550_0_BASEADDR,
XPAR_XUARTNS550_CLOCK_HZ, 9600);

XUartNs550_SetLineControlReg(XPAR_UARTNS550_0_BASEADDR,
XUN_LCR_8_DATA_BITS);
}
#endif

/*****************************************************************************/
/*
*
* This function checks data buffer after the DMA transfer is finished.
*
* We use the static tx/rx buffers.
*
* @param Length is the length to check
* @param StartValue is the starting value of the first byte
*
* @return
* - XST_SUCCESS if validation is successful
* - XST_FAILURE if validation is failure.
*
* @note None.
*
******************************************************************************/
static int CheckData(int Length, u8 StartValue)
{
u8 *RxPacket;
int Index = 0;
u8 Value;

RxPacket = (u8 *) RX_BUFFER_BASE;
Value = StartValue;

/* Invalidate the DestBuffer before receiving the data, in case the
* Data Cache is enabled
*/
#ifndef __aarch64__
Xil_DCacheInvalidateRange((u32)RxPacket, Length);
#endif

for(Index = 0; Index if (RxPacket[Index] != Value) {
xil_printf("Data error %d: %x/%x/r/n",
Index, RxPacket[Index], Value);

return XST_FAILURE;
}
Value = (Value + 1) & 0xFF;
}

return XST_SUCCESS;
}

/*****************************************************************************/
/*
*
* This is the DMA TX Interrupt handler function.
*
* It gets the interrupt status from the hardware, acknowledges it, and if any
* error happens, it resets the hardware. Otherwise, if a completion interrupt
* is present, then sets the TxDone.flag
*
* @param Callback is a pointer to TX channel of the DMA engine.
*
* @return None.
*
* @note None.
*
******************************************************************************/
static void TxIntrHandler(void *Callback)
{

u32 IrqStatus;
int TimeOut;
XAxiDma *AxiDmaInst = (XAxiDma *)Callback;

/* Read pending interrupts */
IrqStatus = XAxiDma_IntrGetIrq(AxiDmaInst, XAXIDMA_DMA_TO_DEVICE);

/* Acknowledge pending interrupts */

XAxiDma_IntrAckIrq(AxiDmaInst, IrqStatus, XAXIDMA_DMA_TO_DEVICE);

/*
* If no interrupt is asserted, we do not do anything
*/
if (!(IrqStatus & XAXIDMA_IRQ_ALL_MASK)) {

return;
}

/*
* If error interrupt is asserted, raise error flag, reset the
* hardware to recover from the error, and return with no further
* processing.
*/
if ((IrqStatus & XAXIDMA_IRQ_ERROR_MASK)) {

Error = 1;

/*
* Reset should never fail for transmit channel
*/
XAxiDma_Reset(AxiDmaInst);

TimeOut = RESET_TIMEOUT_COUNTER;

while (TimeOut) {
if (XAxiDma_ResetIsDone(AxiDmaInst)) {
break;
}

TimeOut -= 1;
}

return;
}

/*
* If Completion interrupt is asserted, then set the TxDone flag
*/
if ((IrqStatus & XAXIDMA_IRQ_IOC_MASK)) {

TxDone = 1;
}
}

/*****************************************************************************/
/*
*
* This is the DMA RX interrupt handler function
*
* It gets the interrupt status from the hardware, acknowledges it, and if any
* error happens, it resets the hardware. Otherwise, if a completion interrupt
* is present, then it sets the RxDone flag.
*
* @param Callback is a pointer to RX channel of the DMA engine.
*
* @return None.
*
* @note None.
*
******************************************************************************/
static void RxIntrHandler(void *Callback)
{
u32 IrqStatus;
int TimeOut;
XAxiDma *AxiDmaInst = (XAxiDma *)Callback;

/* Read pending interrupts */
IrqStatus = XAxiDma_IntrGetIrq(AxiDmaInst, XAXIDMA_DEVICE_TO_DMA);

/* Acknowledge pending interrupts */
XAxiDma_IntrAckIrq(AxiDmaInst, IrqStatus, XAXIDMA_DEVICE_TO_DMA);

/*
* If no interrupt is asserted, we do not do anything
*/
if (!(IrqStatus & XAXIDMA_IRQ_ALL_MASK)) {
return;
}

/*
* If error interrupt is asserted, raise error flag, reset the
* hardware to recover from the error, and return with no further
* processing.
*/
if ((IrqStatus & XAXIDMA_IRQ_ERROR_MASK)) {

Error = 1;

/* Reset could fail and hang
* NEED a way to handle this or do not call it??
*/
XAxiDma_Reset(AxiDmaInst);

TimeOut = RESET_TIMEOUT_COUNTER;

while (TimeOut) {
if(XAxiDma_ResetIsDone(AxiDmaInst)) {
break;
}

TimeOut -= 1;
}

return;
}

/*
* If completion interrupt is asserted, then set RxDone flag
*/
if ((IrqStatus & XAXIDMA_IRQ_IOC_MASK)) {

RxDone = 1;
}
}

/*****************************************************************************/
/*
*
* This function setups the interrupt system so interrupts can occur for the
* DMA, it assumes INTC component exists in the hardware system.
*
* @param IntcInstancePtr is a pointer to the instance of the INTC.
* @param AxiDmaPtr is a pointer to the instance of the DMA engine
* @param TxIntrId is the TX channel Interrupt ID.
* @param RxIntrId is the RX channel Interrupt ID.
*
* @return
* - XST_SUCCESS if successful,
* - XST_FAILURE.if not succesful
*
* @note None.
*
******************************************************************************/
static int SetupIntrSystem(INTC * IntcInstancePtr,
XAxiDma * AxiDmaPtr, u16 TxIntrId, u16 RxIntrId)
{
int Status;

#ifdef XPAR_INTC_0_DEVICE_ID

/* Initialize the interrupt controller and connect the ISRs */
Status = XIntc_Initialize(IntcInstancePtr, INTC_DEVICE_ID);
if (Status != XST_SUCCESS) {

xil_printf("Failed init intc/r/n");
return XST_FAILURE;
}

Status = XIntc_Connect(IntcInstancePtr, TxIntrId,
(XInterruptHandler) TxIntrHandler, AxiDmaPtr);
if (Status != XST_SUCCESS) {

xil_printf("Failed tx connect intc/r/n");
return XST_FAILURE;
}

Status = XIntc_Connect(IntcInstancePtr, RxIntrId,
(XInterruptHandler) RxIntrHandler, AxiDmaPtr);
if (Status != XST_SUCCESS) {

xil_printf("Failed rx connect intc/r/n");
return XST_FAILURE;
}

/* Start the interrupt controller */
Status = XIntc_Start(IntcInstancePtr, XIN_REAL_MODE);
if (Status != XST_SUCCESS) {

xil_printf("Failed to start intc/r/n");
return XST_FAILURE;
}

XIntc_Enable(IntcInstancePtr, TxIntrId);
XIntc_Enable(IntcInstancePtr, RxIntrId);

#else

XScuGic_Config *IntcConfig;

/*
* Initialize the interrupt controller driver so that it is ready to
* use.
*/
IntcConfig = XScuGic_LookupConfig(INTC_DEVICE_ID);
if (NULL == IntcConfig) {
return XST_FAILURE;
}

Status = XScuGic_CfgInitialize(IntcInstancePtr, IntcConfig,
IntcConfig->CpuBaseAddress);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}

XScuGic_SetPriorityTriggerType(IntcInstancePtr, TxIntrId, 0xA0, 0x3);

XScuGic_SetPriorityTriggerType(IntcInstancePtr, RxIntrId, 0xA0, 0x3);
/*
* Connect the device driver handler that will be called when an
* interrupt for the device occurs, the handler defined above performs
* the specific interrupt processing for the device.
*/
Status = XScuGic_Connect(IntcInstancePtr, TxIntrId,
(Xil_InterruptHandler)TxIntrHandler,
AxiDmaPtr);
if (Status != XST_SUCCESS) {
return Status;
}

Status = XScuGic_Connect(IntcInstancePtr, RxIntrId,
(Xil_InterruptHandler)RxIntrHandler,
AxiDmaPtr);
if (Status != XST_SUCCESS) {
return Status;
}

XScuGic_Enable(IntcInstancePtr, TxIntrId);
XScuGic_Enable(IntcInstancePtr, RxIntrId);

#endif

/* Enable interrupts from the hardware */

Xil_ExceptionInit();
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
(Xil_ExceptionHandler)INTC_HANDLER,
(void *)IntcInstancePtr);

Xil_ExceptionEnable();

return XST_SUCCESS;
}

/*****************************************************************************/
/**
*
* This function disables the interrupts for DMA engine.
*
* @param IntcInstancePtr is the pointer to the INTC component instance
* @param TxIntrId is interrupt ID associated w/ DMA TX channel
* @param RxIntrId is interrupt ID associated w/ DMA RX channel
*
* @return None.
*
* @note None.
*
******************************************************************************/
static void DisableIntrSystem(INTC * IntcInstancePtr,
u16 TxIntrId, u16 RxIntrId)
{
#ifdef XPAR_INTC_0_DEVICE_ID
/* Disconnect the interrupts for the DMA TX and RX channels */
XIntc_Disconnect(IntcInstancePtr, TxIntrId);
XIntc_Disconnect(IntcInstancePtr, RxIntrId);
#else
XScuGic_Disconnect(IntcInstancePtr, TxIntrId);
XScuGic_Disconnect(IntcInstancePtr, RxIntrId);
#endif
}

xaxidma_example_simple_intr.c

主函數中依次完成了:DMA初始化,建立中斷系統,使能DMA中斷,初始化標志位及發送數據,啟動DMA傳輸以及數據檢測。中斷部分的內容與PS DMA非常相近,傳輸完成后進入的中斷函數中僅置位了發送或接收完成標志位:
static void TxIntrHandler(void *Callback)
{

u32 IrqStatus;
int TimeOut;
XAxiDma *AxiDmaInst = (XAxiDma *)Callback;

/* Read pending interrupts */
IrqStatus = XAxiDma_IntrGetIrq(AxiDmaInst, XAXIDMA_DMA_TO_DEVICE);

/* Acknowledge pending interrupts */

XAxiDma_IntrAckIrq(AxiDmaInst, IrqStatus, XAXIDMA_DMA_TO_DEVICE);

/*
* If no interrupt is asserted, we do not do anything
*/
if (!(IrqStatus & XAXIDMA_IRQ_ALL_MASK)) {

return;
}

/*
* If error interrupt is asserted, raise error flag, reset the
* hardware to recover from the error, and return with no further
* processing.
*/
if ((IrqStatus & XAXIDMA_IRQ_ERROR_MASK)) {

Error = 1;

/*
* Reset should never fail for transmit channel
*/
XAxiDma_Reset(AxiDmaInst);

TimeOut = RESET_TIMEOUT_COUNTER;

while (TimeOut) {
if (XAxiDma_ResetIsDone(AxiDmaInst)) {
break;
}

TimeOut -= 1;
}

return;
}

/*
* If Completion interrupt is asserted, then set the TxDone flag
*/
if ((IrqStatus & XAXIDMA_IRQ_IOC_MASK)) {

TxDone = 1;
}
}

/*****************************************************************************/
/*
*
* This is the DMA RX interrupt handler function
*
* It gets the interrupt status from the hardware, acknowledges it, and if any
* error happens, it resets the hardware. Otherwise, if a completion interrupt
* is present, then it sets the RxDone flag.
*
* @param Callback is a pointer to RX channel of the DMA engine.
*
* @return None.
*
* @note None.
*
******************************************************************************/
static void RxIntrHandler(void *Callback)
{
u32 IrqStatus;
int TimeOut;
XAxiDma *AxiDmaInst = (XAxiDma *)Callback;

/* Read pending interrupts */
IrqStatus = XAxiDma_IntrGetIrq(AxiDmaInst, XAXIDMA_DEVICE_TO_DMA);

/* Acknowledge pending interrupts */
XAxiDma_IntrAckIrq(AxiDmaInst, IrqStatus, XAXIDMA_DEVICE_TO_DMA);

/*
* If no interrupt is asserted, we do not do anything
*/
if (!(IrqStatus & XAXIDMA_IRQ_ALL_MASK)) {
return;
}

/*
* If error interrupt is asserted, raise error flag, reset the
* hardware to recover from the error, and return with no further
* processing.
*/
if ((IrqStatus & XAXIDMA_IRQ_ERROR_MASK)) {

Error = 1;

/* Reset could fail and hang
* NEED a way to handle this or do not call it??
*/
XAxiDma_Reset(AxiDmaInst);

TimeOut = RESET_TIMEOUT_COUNTER;

while (TimeOut) {
if(XAxiDma_ResetIsDone(AxiDmaInst)) {
break;
}

TimeOut -= 1;
}

return;
}

/*
* If completion interrupt is asserted, then set RxDone flag
*/
if ((IrqStatus & XAXIDMA_IRQ_IOC_MASK)) {

RxDone = 1;
}
}

intrHandler

DMA啟動傳輸部分如下,調用庫函數XAxiDma_SimpleTransfer。以第一個為例,是將RxBufferPtr為數據首地址,MAX_PKT_LEN為字節數,XAXIDMA_DEVICE_TO_DMA為傳輸方向啟動DMA傳輸數據。MAX_PKT_LEN不能超過之前IP核配置參數指定的16384byte,XAXIDMA_DEVICE_TO_DMA和XAXIDMA_DMA_TO_DEVICE依次指PL-> DMA ->PS以及PS->DMA -> PL方向,也就是PL就是其中的DEVICE。DMA啟動函數只有一個地址,這是與PS端DMA最大的區別,因為數據搬移的另一側是帶有無地址的流接口的IP核,該側“地址”由硬件連接決定。

o4YBAF9uKJGAUdpcAACVWDBNQ6s335.png

再來看看搬移數據內存首地址RxBufferPtr和TxBufferPtr.從下邊的定義可見MEM_BASE_ADDR是DDR_BASE_ADDR加上一段偏移量的結果,DDR基地址數值從xparameters.h中查看。

o4YBAF9uKJOACK2QAACyTdi29gs886.jpg

四、函數重用封裝

官方的代碼比較亂,都寫在main函數里,米聯客教程init_intr_sys()函數完成整個中斷系統的建立,將官方demo中main函數DMA測試之前關于中斷部分的代碼全部封裝其中,包括DMA中斷初始化,中斷控制器初始化,使能中斷異常,連接DMA發送與接收中斷,DMA中斷使能五個過程。

o4YBAF9uKJSAIm49AABrFCoVo1Q716.png

五、AXI總線信號ILA波形分析

AXI Stream主要接口:

tdata:數據tkeep:字節有效指示tlast:幀尾指示tready:準備就緒tvalid:數據有效指示

MM2S方向一旦tvalid拉高則觸發ILA抓取信號波形。一幀數據有64個,每個數據32bit(4byte),一共正好為C代碼中MAX_PKT_LEN數值,即256byte。

其中他keep信號比較關鍵。如當stream位寬為16bit,傳輸數據量為255byte時,tkeep信號在最后一個stream數據對應位置是2'b01指示第128個16bit數中最后一個數的高字節為upsize過程中無效填充數據。

后續本人會利用System Generator設計算法IP,之后集成到IP Integerator中作為CPU外設進行板級驗證。繼續學習!

編輯:hfy


聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • 寄存器
    +關注

    關注

    30

    文章

    5162

    瀏覽量

    118084
  • cpu
    cpu
    +關注

    關注

    68

    文章

    10510

    瀏覽量

    207175
  • 數據傳輸
    +關注

    關注

    9

    文章

    1581

    瀏覽量

    63764
  • Zynq
    +關注

    關注

    9

    文章

    600

    瀏覽量

    46769
  • AXI
    AXI
    +關注

    關注

    1

    文章

    126

    瀏覽量

    16326
收藏 人收藏

    評論

    相關推薦

    SoC設計中總線協議AXI4與AXI3的主要區別詳解

    AXI4和AXI3是高級擴展接口(Advanced eXtensible Interface)的兩個不同版本,它們都是用于SoC(System on Chip)設計中的總線協議,用于處理器和其它外設之間的高速數據傳輸。
    的頭像 發表于 05-10 11:29 ?797次閱讀
    <b class='flag-5'>SoC</b>設計中總線協議<b class='flag-5'>AXI</b>4與<b class='flag-5'>AXI</b>3的主要區別詳解

    沒用過zynq今天在看解析是發現汽車的CID上有用這個,不知道zynq有什么優勢?

    沒用過zynq今天在看解析是發現汽車的CID上有用這個,不知道zynq有什么優勢?
    發表于 04-23 15:01

    STM32H7使用DMA方式讀取SD卡,DMA緩沖是否只能處于AXI SRAM?

    除了512K的 AXI SRAM,還有沒有其他的SRAM 區域能訪問到? 因為我想這整個512K 的AXI SRAM 做其他用途,變量都定義到其它的SRAM 區域。但這樣SD卡 DMA 就不能用了。
    發表于 04-18 06:00

    Xilinx高性能PCIe DMA控制器IP,8個DMA通道

    或Scather Gather DMA,提供FIFO/AXI4-Stream用戶接口。 基于PCI Express Integrated Block,Multi-Channel PCIe RDMA
    的頭像 發表于 02-22 11:11 ?456次閱讀
    Xilinx高性能PCIe <b class='flag-5'>DMA</b>控制器IP,8個<b class='flag-5'>DMA</b>通道

    環路電阻怎么測試好壞

    測試環路電阻的好壞是電力系統運行和設備安全的重要環節。環路電阻測試是通過測量電路的絕緣電阻來確定電路的質量。環路電阻
    的頭像 發表于 12-20 13:59 ?1046次閱讀

    使用 PCIE 更新 AMD ZYNQ? 的 QSPI Flash 參考設計

    /r/en-US/ug585-zynq-7000-SoC-TRM 環境需求 硬件環境: ZC706 開發板 Windows10/11 或者 Ubuntu20.04 主機 軟件環境: Vivado
    發表于 11-30 18:49

    ZYNQ的ARM和FPGA數據交互——AXI交互最重要的細節

    大部分器件的接口要求,提供互聯架構的靈活性與獨立性。 (1)AXI總線 總線是一組傳輸通道,是各種邏輯器件構成的傳輸數據的通道,一般由數據線、地址線、控制線等構成。在ZYNQ中支持三種AXI總線
    發表于 11-03 10:51

    如何在Zynq SoC上開始使用FreeRTOS

    該項目演示如何在 Zynq SoC 上開始使用 FreeRTOS。
    的頭像 發表于 10-18 09:44 ?707次閱讀
    如何在<b class='flag-5'>Zynq</b> <b class='flag-5'>SoC</b>上開始使用FreeRTOS

    什么是AXI?AXI如何工作?

    Xilinx 從 Spartan-6 和 Virtex-6 器件開始采用高級可擴展接口 (AXI) 協議作為知識產權 (IP) 內核。Xilinx 繼續將 AXI 協議用于針對 7 系列和 Zynq-7000 All Progr
    的頭像 發表于 09-27 09:50 ?788次閱讀
    什么是<b class='flag-5'>AXI</b>?<b class='flag-5'>AXI</b>如何工作?

    Zynq-7000 SoC的安全啟動應用說明

    電子發燒友網站提供《Zynq-7000 SoC的安全啟動應用說明.pdf》資料免費下載
    發表于 09-13 11:46 ?1次下載
    <b class='flag-5'>Zynq</b>-7000 <b class='flag-5'>SoC</b>的安全啟動應用說明

    Zynq-7000 SoC:嵌入式設計教程

    電子發燒友網站提供《Zynq-7000 SoC:嵌入式設計教程.pdf》資料免費下載
    發表于 09-13 09:20 ?3次下載
    <b class='flag-5'>Zynq</b>-7000 <b class='flag-5'>SoC</b>:嵌入式設計教程

    基于AXI總線的DDR3讀寫測試

    本文開源一個FPGA項目:基于AXI總線的DDR3讀寫。之前的一篇文章介紹了DDR3簡單用戶接口的讀寫方式:《DDR3讀寫測試》,如果在某些項目中,我們需要把DDR掛載到AXI總線上,那就要通過MIG IP核提供的
    的頭像 發表于 09-01 16:20 ?2655次閱讀
    基于<b class='flag-5'>AXI</b>總線的DDR3讀寫<b class='flag-5'>測試</b>

    嵌入式HLS 案例開發步驟分享——基于Zynq-7010/20工業開發板(3)

    測試前的準備工作。 HLS 工程生成的 IP 核為 HLS_accel_0。圖 64 4.4.1 PL 端 IP 核測試 Vivado 工程說明浮點矩陣乘法運算加速器 IP 核通過 AXI
    發表于 08-24 14:52

    伺服環路ADC測試的基礎知識介紹

    伺服環路測試可以確定模數轉換器 (ADC) 傳遞函數。本文將介紹伺服環路 ADC 測試的基礎知識,并說明幾種不同的伺服環路
    的頭像 發表于 08-21 15:33 ?1034次閱讀
    伺服<b class='flag-5'>環路</b>ADC<b class='flag-5'>測試</b>的基礎知識介紹

    SoC Designer AXI4協議包的用戶指南

    這是SoC Designer AXI4協議包的用戶指南。該協議包包含SoC Designer組件、探針和ARM AXI4協議的事務端口接口(包括對AMBA4
    發表于 08-10 06:30
    亚洲欧美日韩精品久久_久久精品AⅤ无码中文_日本中文字幕有码在线播放_亚洲视频高清不卡在线观看
    <acronym id="s8ci2"><small id="s8ci2"></small></acronym>
    <rt id="s8ci2"></rt><rt id="s8ci2"><optgroup id="s8ci2"></optgroup></rt>
    <acronym id="s8ci2"></acronym>
    <acronym id="s8ci2"><center id="s8ci2"></center></acronym>