履歴: 電気回路/zynq/DMA処理
各行は、その日時に書かれた内容です。追加・削除は、1 つ前の版との行数の差です (全 12 版)。「差分」は比較する版、「基準」は比べる相手の版を選びます
| 日時 | タイトル | 文字数 | 追加 | 削除 | 内容 | 差分 | 基準 |
|---|---|---|---|---|---|---|---|
| 2017/2/13 17:38:01 | 電気回路/zynq/DMA処理 最新版 | 40,681 | +1 | -1 | 表示 | 差分 | — |
| 2017/2/13 17:38:01 | 電気回路/zynq/DMA処理 | 40,687 | +3 | -0 | 表示 | 差分 | 選択 |
| 2017/2/13 8:38:01 | 電気回路/zynq/DMA処理 | 40,646 | +4 | -3 | 表示 | 差分 | 選択 |
| 2017/2/13 8:38:01 | 電気回路/zynq/DMA処理 | 40,665 | +7 | -5 | 表示 | 差分 | 選択 |
| 2017/2/13 8:38:01 | 電気回路/zynq/DMA処理 | 40,604 | +126 | -53 | 表示 | 差分 | 選択 |
| 2017/2/13 8:07:15 | 電気回路/zynq/DMA処理 | 38,696 | +221 | -6 | 表示 | 差分 | 選択 |
| 2017/2/12 17:58:52 | 電気回路/zynq/DMA処理 | 32,687 | +229 | -286 | 表示 | 差分 | 選択 |
| 2017/2/12 13:35:09 | 電気回路/zynq/DMA処理 | 32,574 | +307 | -59 | 表示 | 差分 | 選択 |
| 2017/2/11 18:07:45 | 電気回路/zynq/DMA処理 | 24,593 | +10 | -1 | 表示 | 表示中 | 選択 |
| 2017/2/11 18:07:45 | 電気回路/zynq/DMA処理 | 24,305 | +235 | -9 | 表示 | 差分 | 選択 |
| 2017/2/11 9:49:18 | 電気回路/zynq/DMA処理 | 17,700 | +244 | -1 | 表示 | 差分 | 選択 |
| 2017/2/11 3:44:02 | 電気回路/zynq/DMA処理 | 8,398 | — | — | 表示 | — | 基準 |
基準: 電気回路/zynq/DMA処理 (2017/2/11 3:44:02) → 比較: 電気回路/zynq/DMA処理 (2017/2/11 18:07:45)
@@ -2,10 +2,74 @@
#contents
+* 概要 [#f674dcb8]
+
+Zynq で DMA 処理するために勉強中の内容です。
+
+まだ動かせていないので間違ったことも多いと思います。
+
+* axi_dma のドキュメント [#e7f3007e]
+
+デザインダイアグラム上で axi_dma IP を右クリックして
+[IP Documentations] から各種ドキュメントが出る。
+
+https://www.xilinx.com/products/intellectual-property/axi_dma.html#overview
+
+など。
+
+* 後で読む [#te8e7275]
+
+Zynq DMA 用 Linux ドライバ:~
+https://github.com/bmartini/zynq-xdma
+
+その使用例?:~
+https://tobygomersallwordpresscom.wordpress.com/2016/02/11/xilinx-zynq-using-dma-to-transfer-data-to-the-linux-userspace/
+
+上手に動かさないと速度が出ない:~
+https://github.com/bmartini/zynq-xdma/issues/6
+
+Zynq DMA 用 Linux ドライバ2:~
+https://github.com/bmartini/zynq-axis.git
+
+[stackoverflow] Linux DMAドライバのインスタンス化および利用方法~
+http://qiita.com/wstone/items/ab4d47a3690bb1a9bf4c ~
+
+AXI DMA with Zynq Running Linux Accepted Solution [Solved] ~
+https://forums.xilinx.com/t5/Embedded-Linux/AXI-DMA-with-Zynq-Running-Linux/td-p/522755 ~
+
+
+* キャッシュについて [#g64cc687]
+
+** ACP について [#uf2e1786]
+
+accelerator coherency port を使うとキャッシュコヒーレンシーを
+アプリケーション側で制御しなくても良くなるみたい?
+
+http://marsee101.blog19.fc2.com/blog-entry-2297.html
+
+* udmabuf [#o0e80ea9]
+
+DMA バッファとして使うメモリ領域に Linux のユーザーアプリケーションから
+アクセスするには udmabuf を使うのが良いらしい?
+
+http://qiita.com/ikwzm/items/cc1bb33ff43a491440ea
+
* Xilinx の XAxiDma ドライバ [#b6740db8]
-** ヘッダファイルの説明書き日本語訳 [#z33ce603]
+自分で Linux ドライバを作るときやベアメタルでは
+Xilinx の低レベルドライバを使うことになる。
+C:\Xilinx\SDK\2016.4\data\embeddedsw\XilinxProcessorIPLib\drivers\axidma_v9_3\src
+
+というようなディレクトリにソースコードが、
+
+C:\Xilinx\SDK\2016.4\data\embeddedsw\XilinxProcessorIPLib\drivers\axidma_v9_3\doc/html/api/index.html
+
+にドキュメントがある。[File List] から各ヘッダファイル *.h
+をクリックして関数一覧を見るのがわかりやすそう
+
+** ドキュメントトップの日本語訳 [#z33ce603]
+
以下は AXI DMA エンジンドライバの API です。
DMA 機能の全詳細はハードウェアのスペックを参照してください。
@@ -33,6 +97,9 @@
*** Scatter-Gather DMA (SGDMA) [#q9fc2618]
+(訳注:axi_dma では IP のカスタマイズで [Enable Scatter Gather Engine]
+をオンにしないとこの機能は使えない)
+
SGDMA ではユーザーアプリケーションがメモリ上に次善に準備した一連の転送処理設定を、
ハードウェアが順に処理します。この処理中にユーザーアプリケーションが介在する
必要はありません。また、処理中に新たな処理内容を追加することも可能であり、
@@ -330,3 +397,414 @@
さらに、xdebug.h の中の "#undef DEBUG" という行をコメントアウトして下さい。
** API メモ [#od119c43]
+
+*** xaxidma.h [#ef2e999d]
+
+- enum Direction { XAXIDMA_DMA_TO_DEVICE, XAXIDMA_DEVICE_TO_DMA };
+- XAxiDma_BdRing * XAxiDma_GetTxRing(XAxiDma * InstancePtr);
+- XAxiDma_BdRing * XAxiDma_GetRxRing(XAxiDma * InstancePtr);
+- XAxiDma_BdRing * XAxiDma_GetRxIndexRing(XAxiDma * InstancePtr, int RingIndex);
+- bool XAxiDma_HasSg(XAxiDma * InstancePtr);
+- void XAxiDma_IntrEnable(XAxiDma * InstancePtr, uint Mask, int Direction);
+- uint XAxiDma_IntrGetEnabled(XAxiDma * InstancePtr, int Direction);
+- void XAxiDma_IntrDisable(XAxiDma * InstancePtr, uint Mask, int Direction);
+- uint XAxiDma_IntrGetIrq(XAxiDma * InstancePtr, int Direction);
+- void XAxiDma_IntrAckIrq(XAxiDma * InstancePtr, uint Mask, int Direction);
+- XAxiDma_Config *XAxiDma_LookupConfig(u32 DeviceId);
+- int XAxiDma_CfgInitialize(XAxiDma * InstancePtr, XAxiDma_Config *Config);
+- void XAxiDma_Reset(XAxiDma * InstancePtr);
+- int XAxiDma_ResetIsDone(XAxiDma * InstancePtr);
+- int XAxiDma_Pause(XAxiDma * InstancePtr);
+- int XAxiDma_Resume(XAxiDma * InstancePtr);
+- u32 XAxiDma_Busy(XAxiDma *InstancePtr,int Direction);
+- u32 XAxiDma_SimpleTransfer(XAxiDma *InstancePtr, UINTPTR BuffAddr, u32 Length,int Direction);
+- int XAxiDma_SelectKeyHole(XAxiDma *InstancePtr, int Direction, int Select);
+- int XAxiDma_SelectCyclicMode(XAxiDma *InstancePtr, int Direction, int Select);
+- int XAxiDma_Selftest(XAxiDma * InstancePtr);
+
+*** xaxidma_bdring.h [#tb54f8b9]
+
+- int XAxiDma_BdRingCntCalc(u32 Alignment, u32 Bytes);
+- int XAxiDma_BdRingMemCalc(u32 Alignment, u32 NumBd)
+- int XAxiDma_BdRingGetCnt(XAxiDma_BdRing* RingPtr)
+- int XAxiDma_BdRingGetFreeCnt(XAxiDma_BdRing* RingPtr)
+- void XAxiDma_BdRingSnapShotCurrBd(XAxiDma_BdRing* RingPtr)
+-- RingPtr->IsRxChannel, RingPtr->ChanBase, RingPtr->RingIndex を設定してから呼び出す
+-- ハードウェアから現在値を読み出した値により RingPtr->BdaRestart, RingPtr->ChanBase
+がセットされる
+- XAxiDma_Bd * XAxiDma_BdRingGetCurrBd(XAxiDma_BdRing* RingPtr)
+- XAxiDma_Bd *XAxiDma_BdRingNext(XAxiDma_BdRing* RingPtr, XAxiDma_Bd *BdPtr)
+-- 配列上で次の XAxiDma_Bd を返す。連結リストの Next ではない
+-- Ring なので最後の要素の Next は最初の要素になる
+- XAxiDma_Bd *XAxiDma_BdRingPrev(XAxiDma_BdRing* RingPtr, XAxiDma_Bd *BdPtr)
+-- 配列上で前の XAxiDma_Bd を返す。連結リストの Prev ではない
+-- Ring なので最初の要素の Prev は最後の要素になる
+- u32 XAxiDma_BdRingGetSr(XAxiDma_BdRing* RingPtr)
+-- Sr はステータスレジスタ
+- u32 XAxiDma_BdRingGetError(XAxiDma_BdRing* RingPtr)
+-- ステータスレジスタにエラービットのマスクをかけて返す
+-- 内容を見るには XAXIDMA_ERR_*_MASK と & を取る (xaxidma_hw.h)
+- int XAxiDma_BdRingHwIsStarted(XAxiDma_BdRing* RingPtr)
+-- Halt か Not Halt かを見る
+- int XAxiDma_BdRingBusy(XAxiDma_BdRing* RingPtr)
+-- 実際に転送中かを見る
+- void XAxiDma_BdRingIntEnable(XAxiDma_BdRing* RingPtr, u32 Mask)
+-- XAXIDMA_CR_OFFSET レジスタを設定する
+- u32 XAxiDma_BdRingIntGetEnabled(XAxiDma_BdRing* RingPtr)
+-- XAXIDMA_CR_OFFSET レジスタを読む
+- void XAxiDma_BdRingIntDisable(XAxiDma_BdRing* RingPtr, u32 Mask)
+-- XAXIDMA_CR_OFFSET レジスタを設定する
+- u32 XAxiDma_BdRingGetIrq(XAxiDma_BdRing* RingPtr)
+-- IRQ_OFFSET レジスタを読む
+-- アプリケーションは XAXIDMA_IRQ_*** 定数と & を取って解釈する
+- void XAxiDma_BdRingAckIrq(XAxiDma_BdRing* RingPtr)
+- int XAxiDma_StartBdRingHw(XAxiDma_BdRing* RingPtr);
+- int XAxiDma_UpdateBdRingCDesc(XAxiDma_BdRing* RingPtr);
+- u32 XAxiDma_BdRingCreate(XAxiDma_BdRing * RingPtr, UINTPTR PhysAddr, UINTPTR VirtAddr, u32 Alignment, int BdCount);
+- int XAxiDma_BdRingClone(XAxiDma_BdRing * RingPtr, XAxiDma_Bd * SrcBdPtr);
+- int XAxiDma_BdRingAlloc(XAxiDma_BdRing * RingPtr, int NumBd, XAxiDma_Bd ** BdSetPtr);
+- int XAxiDma_BdRingUnAlloc(XAxiDma_BdRing * RingPtr, int NumBd, XAxiDma_Bd * BdSetPtr);
+- int XAxiDma_BdRingToHw(XAxiDma_BdRing * RingPtr, int NumBd, XAxiDma_Bd * BdSetPtr);
+- int XAxiDma_BdRingFromHw(XAxiDma_BdRing * RingPtr, int BdLimit, XAxiDma_Bd ** BdSetPtr);
+- int XAxiDma_BdRingFree(XAxiDma_BdRing * RingPtr, int NumBd, XAxiDma_Bd * BdSetPtr);
+- int XAxiDma_BdRingStart(XAxiDma_BdRing * RingPtr);
+- int XAxiDma_BdRingSetCoalesce(XAxiDma_BdRing * RingPtr, u32 Counter, u32 Timer);
+- void XAxiDma_BdRingGetCoalesce(XAxiDma_BdRing * RingPtr, u32 *CounterPtr, u32 *TimerPtr);
+
+*** xaxidma_bd.h [#ac50fffc]
+
+BD は
+
+typedef u32 XAxiDma_Bd[XAXIDMA_BD_NUM_WORDS];
+
+のように構造体じゃなく u32 の配列として定義されているのだけれど、
+
+ LANG:c
+ typedef struct {
+ XAxiDma_Bd *Next; // 64bit 次の BD
+ void *Buffer; // 64bit バッファーアドレス
+ struct {
+ u8 TDest; // 8bit
+ u8 TReserved1; // 8bit
+ u8 TId; // 8bit
+ u8 TReserved2; // 8bit
+ u8 TUser; // 8bit
+ u8 TReserved3; // 8bit
+ u8 ARCache; // 8bit
+ u8 ARUser; // 8bit
+ } MultiChannelControl; // 32bit MCCTL
+ u16 Stride; // 16bit
+ u3 Reserved0; // 3bit
+ u13 VSize; // 13bit
+ u16 Control; // 16bit
+ u16 Length; // 16bit 転送長
+ struct {
+ u26 ;
+ struct {
+ u1 RXEOF; // 1bit Last rx packet
+ u1 RXSOF; // 1bit First rx packet
+ struct {
+ u1 InternalError; // 1bit
+ u1 SlaveError; // 1bit
+ u1 DecodeError; // 1bit
+ } StatusErrorBits; // 4bit
+ u1 Completed; // 1bit
+ } StatusBits; // 6bit
+ } Status; // 32bit STS
+ u32 User0; // 32bit
+ u32 User1; // 32bit
+ u32 User2; // 32bit
+ u32 User3; // 32bit
+ u32 User4; // 32bit
+ u32 Id; // 32bit
+ u32 HasSTSCNTRL; // 32bit
+ u32 HasDRE; // 32bit
+ } XAxiDma_Bd;
+
+と考えればいいみたい。
+
+個々のフィールドにアクセスするために
+
+- XAxiDma_BdClear(BdPtr) // ゼロフィルする
+- XAxiDma_BdGetCtrl(BdPtr) // Control
+- XAxiDma_BdSetCtrl(BdPtr, Data); // Control
+- XAxiDma_BdGetSts(BdPtr) // Status
+- XAxiDma_BdGetLength(BdPtr, LengthMask) // 設定した転送長
+- XAxiDma_BdSetLength(BdPtr, LenBytes, LengthMask); // 転送長
+- XAxiDma_BdSetId(BdPtr, u32 Id) // アプリケーションが付ける任意の ID
+- XAxiDma_BdGetId(BdPtr) // アプリケーションが付けた任意の ID
+- XAxiDma_BdGetBufAddr(BdPtr)
+- XAxiDma_BdSetBufAddr(BdPtr, Addr);
+- XAxiDma_BdSetBufAddrMicroMode(BdPtr, Addr);
+- XAxiDma_BdHwCompleted(BdPtr) // Status の Completed ビットを読む
+- XAxiDma_BdGetActualLength(BdPtr, LengthMask) // Status の転送されたデータ長を取り出す
+- XAxiDma_BdSetTId(BdPtr, TId) // MCCTL の TId フィールド
+- XAxiDma_BdGetTId(BdPtr) // MCCTL の TId フィールド
+- XAxiDma_BdSetTDest(BdPtr, TDest) // MCCTL の TDest フィールド
+- XAxiDma_BdGetTDest(BdPtr) // MCCTL の TDest フィールド
+- XAxiDma_BdSetTUser(BdPtr, TUser) // MCCTL の TUser フィールド
+- XAxiDma_BdGetTUser(BdPtr) // MCCTL の TUser フィールド
+- XAxiDma_BdSetARCache(BdPtr, ARCache) // MCCTL の ARCache フィールド
+- XAxiDma_BdGetARCache(BdPtr) // MCCTL の ARCache フィールド
+- XAxiDma_BdSetARUser(BdPtr, ARUser) // MCCTL の ARUser フィールド
+- XAxiDma_BdGetARUser(BdPtr) // MCCTL の ARUser フィールド
+- XAxiDma_BdSetStride(BdPtr, Stride)
+- XAxiDma_BdGetStride(BdPtr)
+- XAxiDma_BdSetVSize(BdPtr, VSize)
+- XAxiDma_BdGetVSize(BdPtr)
+- XAxiDma_BdGetAppWord(BdPtr, Offset, int *Valid);
+- XAxiDma_BdSetAppWord(BdPtr, Offset, Word);
+
+* Xilinx の XAxiDma ドライバのサンプルを読む [#e3026669]
+
+エラー処理を飛ばして読んでみます。
+
+割り込みについて XPAR_INTC_0_DEVICE_ID による #ifdef があるけれど、
+Zynq は GIC を持っているので、XPAR_INTC_0_DEVICE_ID をセットしない、
+xscugic.h ベースのコードを追えばいいはず。
+
+Zynq での割り込み使用例:~
+https://japan.xilinx.com/support/answers/50572.html
+
+** xaxidma_example_simple_poll.c [#xf15a662]
+
+ LANG:c
+ void main()
+ {
+ /* Run the poll example for simple transfer */
+ XAxiDma_SimplePollExample(DMA_DEV_ID);
+ }
+
+ int XAxiDma_SimplePollExample(u16 DeviceId)
+ {
+ XAxiDma_Config *CfgPtr;
+ int Status;
+ int Tries = NUMBER_OF_TRANSFERS;
+ int Index;
+ u8 *TxBufferPtr;
+ u8 *RxBufferPtr;
+ u8 Value;
+
+ TxBufferPtr = (u8 *)TX_BUFFER_BASE;
+ RxBufferPtr = (u8 *)RX_BUFFER_BASE;
+
+ // Initialize the XAxiDma device.
+ CfgPtr = XAxiDma_LookupConfig(DeviceId);
+ XAxiDma_CfgInitialize(&AxiDma, CfgPtr);
+ assert(! XAxiDma_HasSg(&AxiDma)); // SG mode でないことを確認
+
+ // Disable interrupts, we use polling mode
+ XAxiDma_IntrDisable(&AxiDma, XAXIDMA_IRQ_ALL_MASK, XAXIDMA_DEVICE_TO_DMA);
+ XAxiDma_IntrDisable(&AxiDma, XAXIDMA_IRQ_ALL_MASK, XAXIDMA_DMA_TO_DEVICE);
+
+ InitializeTxBuffer(TxBufferPtr);
+
+ // キャッシュのフラッシュ
+ Xil_DCacheFlushRange((UINTPTR)TxBufferPtr, MAX_PKT_LEN);
+
+ // 受信要求
+ XAxiDma_SimpleTransfer(&AxiDma,(UINTPTR) RxBufferPtr,
+ MAX_PKT_LEN, XAXIDMA_DEVICE_TO_DMA);
+
+ // 送信要求
+ XAxiDma_SimpleTransfer(&AxiDma,(UINTPTR) TxBufferPtr,
+ MAX_PKT_LEN, XAXIDMA_DMA_TO_DEVICE);
+
+ // 終わるのを待つ
+ while ( (XAxiDma_Busy(&AxiDma,XAXIDMA_DEVICE_TO_DMA)) ||
+ (XAxiDma_Busy(&AxiDma,XAXIDMA_DMA_TO_DEVICE)) ) {
+ /* Wait */
+ }
+
+ // キャッシュの Invalidate
+ Xil_DCacheInvalidateRange((UINTPTR)RxPacket, MAX_PKT_LEN);
+ return XST_SUCCESS;
+ }
+
+** xaxidma_example_simple_intr.c [#l75492f1]
+
+ LANG:c
+ #include "xscugic.h"
+
+ void 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;
+
+ Config = XAxiDma_LookupConfig(DMA_DEV_ID);
+ XAxiDma_CfgInitialize(&AxiDma, Config);
+
+ assert(!XAxiDma_HasSg(&AxiDma));
+
+ // Set up Interrupt system
+ SetupIntrSystem(&Intc, &AxiDma, TX_INTR_ID, RX_INTR_ID);
+
+ // 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;
+
+ InitializeTxBuffer(TxBuffer);
+
+ // Flush the SrcBuffer before the DMA transfer, in case the Data Cache is enabled
+ Xil_DCacheFlushRange((UINTPTR)TxBufferPtr, MAX_PKT_LEN);
+
+ // Send a packet
+ for(Index = 0; Index < Tries; Index ++) {
+
+ XAxiDma_SimpleTransfer(&AxiDma,(UINTPTR) RxBufferPtr,
+ MAX_PKT_LEN, XAXIDMA_DEVICE_TO_DMA);
+ XAxiDma_SimpleTransfer(&AxiDma,(UINTPTR) TxBufferPtr,
+ MAX_PKT_LEN, XAXIDMA_DMA_TO_DEVICE);
+
+ // Wait TX done and RX done
+ while (!TxDone && !RxDone && !Error) {
+ // NOP
+ }
+ assert(!Error);
+
+ // Transfer finished, check data
+ Xil_DCacheInvalidateRange((u32)RxPacket, Length);
+ Status = CheckData(MAX_PKT_LEN, 0xC);
+ assert(Status == XST_SUCCESS);
+ }
+
+ // Disable TX and RX Ring interrupts and return success
+ DisableIntrSystem(&Intc, TX_INTR_ID, RX_INTR_ID);
+ }
+
+ static void TxIntrHandler(void *Callback)
+ {
+ u32 IrqStatus;
+ int TimeOut;
+ XAxiDma *AxiDmaInst = (XAxiDma *)Callback;
+
+ // Read and acknowledge pending interrupts
+ IrqStatus = XAxiDma_IntrGetIrq(AxiDmaInst, XAXIDMA_DMA_TO_DEVICE);
+ 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;
+ }
+
+ static void RxIntrHandler(void *Callback)
+ {
+ u32 IrqStatus;
+ int TimeOut;
+ XAxiDma *AxiDmaInst = (XAxiDma *)Callback;
+
+ // Read and acknowledge pending interrupts
+ IrqStatus = XAxiDma_IntrGetIrq(AxiDmaInst, XAXIDMA_DEVICE_TO_DMA);
+ 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;
+ }
+
+ static int SetupIntrSystem(INTC * IntcInstancePtr,
+ XAxiDma * AxiDmaPtr, u16 TxIntrId, u16 RxIntrId)
+ {
+ int Status;
+
+ XScuGic_Config *IntcConfig;
+
+ // Initialize the interrupt controller driver so that it is ready to use.
+ XScuGic_LookupConfig(INTC_DEVICE_ID);
+ XScuGic_CfgInitialize(IntcInstancePtr, IntcConfig,
+ IntcConfig->CpuBaseAddress);
+
+ 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.
+ XScuGic_Connect(IntcInstancePtr, TxIntrId,
+ (Xil_InterruptHandler)TxIntrHandler, AxiDmaPtr);
+
+ XScuGic_Connect(IntcInstancePtr, RxIntrId,
+ (Xil_InterruptHandler)RxIntrHandler, AxiDmaPtr);
+
+ XScuGic_Enable(IntcInstancePtr, TxIntrId);
+ XScuGic_Enable(IntcInstancePtr, RxIntrId);
+
+ // Enable interrupts from the hardware
+ Xil_ExceptionInit();
+ Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
+ (Xil_ExceptionHandler)INTC_HANDLER,
+ (void *)IntcInstancePtr);
+
+ Xil_ExceptionEnable();
+
+ return XST_SUCCESS;
+ }
+
+ static void DisableIntrSystem(INTC * IntcInstancePtr,
+ u16 TxIntrId, u16 RxIntrId)
+ {
+ XScuGic_Disconnect(IntcInstancePtr, TxIntrId);
+ XScuGic_Disconnect(IntcInstancePtr, RxIntrId);
+ }