履歴: 電気回路/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 9:49:18) → 比較: 電気回路/zynq/DMA処理 (2017/2/12 17:58:52)

@@ -2,6 +2,23 @@
#contents
+* 概要 [#f674dcb8]
+
+Zynq で DMA 処理するために勉強中の内容です。
+
+まだ動かせていないので間違ったことも多いと思います。
+
+- Xilinx のベアメタルドライバ
+-- Linux とはコンパチビリティのないドライバ
+- Xilinx の Linux ドライバ
+-- Linux 上で他のデバイスドライバから使われることを想定したドライバ
+-- ユーザーアプリケーションから使うものではない
+- サードパーティーの bperez77/xilinx_axidma
+-- Xilinx の Linux ドライバの上に構築された汎用ドライバ
+-- /dev/axidma 経由で簡単に DMA 転送が行える
+
+ということで、bperez77/xilinx_axidma を使えば良さそうに思えています。
+
* axi_dma のドキュメント [#e7f3007e]
デザインダイアグラム上で axi_dma IP を右クリックして
@@ -11,8 +28,247 @@
など。
+* キャッシュについて [#g64cc687]
+
+** ACP について [#uf2e1786]
+
+accelerator coherency port を使うとキャッシュコヒーレンシーを
+アプリケーション側で制御しなくても良くなるみたい?
+
+http://marsee101.blog19.fc2.com/blog-entry-2297.html
+
+* bperez77/xilinx_axidma の使い方を調べる [#h7b14a1c]
+
+これが使えるとかなり楽ができそう。
+
+https://github.com/bperez77/xilinx_axidma
+
+** カーネルオプションを確認 [#c50efd43]
+
+z-turn 付属のカーネルにおいて
+
+- CONFIG_CMA=y
+- CONFIG_DMA_CMA=y
+- CONFIG_XILINX_DMAENGINES=y
+- CONFIG_XILINX_AXIDMA=y
+- CONFIG_XILINX_AXIVDMA=y
+- CONFIG_DMA_SHARED_BUFFER=y
+
+のうち、CONFIG_XILINX_DMAENGINES が無かったが、代わりに
+
+- CONFIG_XILINX_DMA_ENGINES=y
+
+があったので、Xilinx 製のドライバは初めから入っているみたい。
+
+
+** Device Tree [#ia885cc1]
+
+[[電気回路/HDL/VivadoでAXIバスを利用#sf57016a]] で作ったデバイスは、
+
+- address = 0x40400000
+- irq = GIC の F2P[4]
+- s2mm のみ
+- データ幅 32
+
+DTS における割り込み番号の設定方法は、
+http://qiita.com/ikwzm/items/b22592c31cdbb9ab6cf7 によれば、
+
+> interrupts=<0x0 0x1d 0x4> の2番目のパラメータの0x1d(十進数で29)が割り込み番号を指定しています。DMAコントローラーの割り込みはPS部のIRQ_F2P[0]に接続しています。ZYNQのテクニカルリファレンスマニュアルによれば、IRQ_F2P[0]は汎用割り込みコントローラー(GIC)内の共有ペリフェラル割り込み(SPI)の61番を通じて割り込みがかかります。このパラメータには61から32引いた値を設定するようです。
+>
+>interrupts=<0x0 0x1d 0x4>の1番目のパラメータはGIC内部の割り込みの種類を指定します。GIC内部には共有ペリフェラル割り込み(SPI)の他にCPUプライベートペリフェラル割り込み(PPI)とソフトウェア生成割り込み(SGI)があります。共有ペリフェラル割り込み(SPI)を使う場合は0を指定します。
+>
+>interrupts=<0x0 0x1d 0x4>の3番目のパラメータは割り込み信号がエッジトリガーかレベルトリガーかを指定します。1を指定するとエッジトリガー、4を指定するとレベルトリガーになります。
+
+とのことなので、今の場合は
+- 0 = 共有ペリフェラル割り込み(SPI)
+- 33 = 61 + 4 - 32 = 33
+- 4 = レベルトリガー
+
+インクルードファイルを使わない場合 &clkc = 1, &intc = 3 として、
+
+ axidma_chrdev: axidma_chrdev@0 {
+ compatible = "xlnx,axidma-chrdev";
+ dmas = <&axi_dma_0 0>;
+ dma-names = "rx_channel";
+ };
+
+ axi_dma_0: axidma0@40400000 {
+ compatible = "xlnx,axi-dma", "xlnx,axi-dma-6.03.a", "xlnx,axi-dma-1.00.a";
+ reg = <0x40400000 0x10000>;
+ xlnx,include-sg;
+ #dma-cells = <1>;
+
+ dma-s2mm-channel@40400000 {
+ compatible = "xlnx,axi-dma-s2mm-channel";
+ dma-channels = <1>;
+ xlnx,datawidth = <32>;
+ xlnx,device-id = <0x0>;
+ clocks = <1 15>;
+ clock-names = "axis";
+ interrupt-parent = <3>;
+ interrupts = <0 33 4>;
+ };
+ };
+
+となりそうです?
+
+http://qiita.com/ikwzm/items/aae3dab578e28c13bc65 によると
+clocks = 15 は fclk0 のことのようなのですが、どこで調べられるのかよくわかっていません。。。
+
+** axidma デバイスが登録された [#nb7fbf42]
+
+起動メッセージに、
+
+ xilinx-dma 40400000.axidma0: Probing xilinx axi dma engine...Successful
+
+が現れ、
+
+ LANG:console
+ $ ls /sys/class/dma/dma1chan0/device/driver/
+ 40400000.axidma0 bind uevent unbind
+
+となっているので、まずは xilinx の axidma が登録されたことになります。
+これ自体はユーザーアプリケーションから直接使えるものではないので、
+この上に構築された汎用ドライバである bperez77/xilinx_axidma をかぶせて使うことになります。
+
+
+** bperez77/xilinx_axidma ドライバのビルド [#i70128a3]
+
+ LANG:console
+ $ git clone https://github.com/bperez77/xilinx_axidma.git
+ $ cd xilinx_axidma
+ $ make CROSS_COMPILE=arm-linux-gnueabihf- ARCH=arm KBUILD_DIR=/home/osamu/linux-zturn
+ make -C /home/osamu/linux-zturn M=/home/osamu/xilinx_axidma/driver modules
+ make[1]: Entering directory '/home/osamu/linux-zturn'
+ CC [M] /home/osamu/xilinx_axidma/driver/axi_dma.o
+ CC [M] /home/osamu/xilinx_axidma/driver/axidma_dma.o
+ In file included from /home/osamu/xilinx_axidma/driver/axidma_dma.c:25:0:
+ /home/osamu/xilinx_axidma/driver/version_portability.h: In function ‘axidma_setup_vdma_config’:
+ /home/osamu/xilinx_axidma/driver/version_portability.h:133:15: error: ‘struct xilinx_vdma_config’ has no member named ‘vsize’
+ dma_config->vsize = height; // Height of the image (in lines)
+ ^
+ /home/osamu/xilinx_axidma/driver/version_portability.h:134:15: error: ‘struct xilinx_vdma_config’ has no member named ‘hsize’
+ dma_config->hsize = width * depth; // Width of the image (in bytes)
+ ^
+ /home/osamu/xilinx_axidma/driver/version_portability.h:135:15: error: ‘struct xilinx_vdma_config’ has no member named ‘stride’
+ dma_config->stride = width * depth; // Number of bytes to process per line
+ ^
+ /home/osamu/xilinx_axidma/driver/version_portability.h: In function ‘axidma_to_xilinx_type’:
+ /home/osamu/xilinx_axidma/driver/version_portability.h:154:59: error: ‘XILINX_DMA_IP_VDMA’ undeclared (first use in this function)
+ return (dma_type == AXIDMA_DMA) ? XILINX_DMA_IP_DMA : XILINX_DMA_IP_VDMA;
+ ^
+ /home/osamu/xilinx_axidma/driver/version_portability.h:154:59: note: each undeclared identifier is reported only once for each function it appears in
+ /home/osamu/xilinx_axidma/driver/axidma_dma.c: In function ‘axidma_prep_transfer’:
+ /home/osamu/xilinx_axidma/driver/axidma_dma.c:198:32: error: ‘DMA_COMPL_SKIP_DEST_UNMAP’ undeclared (first use in this function)
+ dma_flags = DMA_CTRL_ACK | DMA_COMPL_SKIP_DEST_UNMAP | DMA_PREP_INTERRUPT;
+ ^
+ /home/osamu/xilinx_axidma/driver/axidma_dma.c: In function ‘axidma_start_transfer’:
+ /home/osamu/xilinx_axidma/driver/axidma_dma.c:271:30: error: ‘DMA_SUCCESS’ undeclared (first use in this function)
+ } else if (status != DMA_SUCCESS) {
+ ^
+ In file included from /home/osamu/xilinx_axidma/driver/axidma_dma.c:25:0:
+ /home/osamu/xilinx_axidma/driver/version_portability.h: In function ‘axidma_to_xilinx_type’:
+ /home/osamu/xilinx_axidma/driver/version_portability.h:155:1: error: control reaches end of non-void function [-Werror=return-type]
+ }
+ ^
+ cc1: all warnings being treated as errors
+ scripts/Makefile.build:318: recipe for target '/home/osamu/xilinx_axidma/driver/axidma_dma.o' failed
+ make[2]: *** [/home/osamu/xilinx_axidma/driver/axidma_dma.o] Error 1
+ Makefile:1310: recipe for target '_module_/home/osamu/xilinx_axidma/driver' failed
+ make[1]: *** [_module_/home/osamu/xilinx_axidma/driver] Error 2
+ make[1]: Leaving directory '/home/osamu/linux-zturn'
+ driver/Makefile:83: recipe for target 'driver/axidma.ko' failed
+ make: *** [driver/axidma.ko] Error 2
+ $ grep -A11 "struct xilinx_vdma_config {" ../linux-zturn/include/linux/amba/xilinx_dma.h
+ struct xilinx_vdma_config {
+ int frm_dly;
+ int gen_lock;
+ int master;
+ int frm_cnt_en;
+ int park;
+ int park_frm;
+ int coalesc;
+ int delay;
+ int reset;
+ int ext_fsync;
+ };
+ $ head -3 ../linux-zturn/Makefile
+ VERSION = 3
+ PATCHLEVEL = 15
+ SUBLEVEL = 0
+ $ # https://github.com/bperez77/xilinx_axidma/issues/14
+ $ jed driver/version_portability.h
+ + #if LINUX_VERSION_CODE < KERNEL_VERSION(3,15,0)
+ + dma_config->vsize = height; // Height of the image (in lines)
+ + dma_config->hsize = width * depth; // Width of the image (in bytes)
+ + dma_config->stride = width * depth; // Number of bytes to process per line
+ + #endif
+ ...
+
+ + #ifdef XILINX_DMA_IP_VDMA
+ + BUG_ON(dma_type != AXIDMA_DMA && dma_type != AXIDMA_VDMA);
+ + return (dma_type == AXIDMA_DMA) ? XILINX_DMA_IP_DMA : XILINX_DMA_IP_VDMA;
+ + #else
+ + BUG_ON(dma_type != AXIDMA_DMA);
+ + return XILINX_DMA_IP_DMA;
+ + #endif
+ ...
+
+ + #ifndef DMA_SUCCESS
+ + // DMA_SUCCESS was renamed to DMA_COMPLETE (indicates a DMA transaction is done)
+ + #define DMA_SUCCESS DMA_COMPLETE
+ + #endif
+ +
+ + #ifndef DMA_COMPL_SKIP_DEST_UNMAP
+ + // The skip destination unmap DMA control option was removed in between 3.0 and 3.15 ?
+ + #define DMA_COMPL_SKIP_DEST_UNMAP 0
+ + #endif
+ $ make CROSS_COMPILE=arm-linux-gnueabihf- ARCH=arm KBUILD_DIR=/home/osamu/linux-zturn
+ $ ls outputs/
+ axidma.ko axidma_benchmark axidma_display_image axidma_transfer libaxidma.so
+
+4.x 向けに対策されている内容の一部が先取りして入っているようで、
+3.15 に対して同様の対策が必要になっているようです。
+そのあたりを見ながら無理矢理書き換えたところ、コンパイルが通りました。
+
+** インストール [#sa8cbf2c]
+
+axidma.ko と libaxidma.so を z-turn 上の Linux へコピーして、
+
+ LANG:console
+ $ sudo chown root:root axidma.ko libaxidma.so
+ $ sudo cp libaxidma.so /usr/local/lib/
+ $ sudo mkdir -p /lib/modules/3.15.0-xilinx/kernel/drivers/dma/xilinx/
+ $ sudo cp axidma.ko /lib/modules/3.15.0-xilinx/kernel/drivers/dma/xilinx/
+ $ sudo insmod axidma.ko
+ $ dmesg | tail
+ [ 469.438795] axidma: axidma_dma.c: axidma_dma_init: 674: DMA: Found 0 transmit channels and 1 receive channels.
+ [ 469.447790] axidma: axidma_dma.c: axidma_dma_init: 676: VDMA: Found 0 transmit channels and 0 receive channels.
+ $ ls /dev/axidma
+ /dev/axidma
+
+正しく入ったみたい。
+
+** bootarg の設定 [#q00cefa6]
+
+devicetree.dts
+
+ chosen {
+ bootargs = "console=ttyPS0,115200 earlyprintk root=/dev/mmcblk0p2 rootwait cma=25M";
+ };
+
+のように cma=25M を追加した。
+
+
+** 使ってみる [#wda13c3c]
+
+(以下未稿)
+
* Xilinx の XAxiDma ドライバ [#b6740db8]
+自分で Linux ドライバを作るときやベアメタルでは
+Xilinx の低レベルドライバを使うことになる?
+
C:\Xilinx\SDK\2016.4\data\embeddedsw\XilinxProcessorIPLib\drivers\axidma_v9_3\src
というようなディレクトリにソースコードが、
@@ -509,67 +765,237 @@
- XAxiDma_BdGetAppWord(BdPtr, Offset, int *Valid);
- XAxiDma_BdSetAppWord(BdPtr, Offset, Word);
-* サンプルを読む [#e3026669]
+* Xilinx の XAxiDma ドライバのサンプルを読む [#e3026669]
エラー処理を飛ばして読んでみます。
-** xaxidma_example_simple_poll.c [#xf15a662]
+割り込みについて 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_intr.c [#l75492f1]
+
++ XAxiDma_LookupConfig(DeviceId) で DeviceId に対するハードウェア情報を得る (xaxidma_sinit.c)
++ XAxiDma_CfgInitialize(&AxiDma, CfgPtr); によりハードウェア情報を元に AxiDma を設定する
+-- 内部で呼ばれる XAxiDma_Reset がタイムアウトすると失敗する (AxiDma.Initialized == 0 となる)
++ XAxiDma_HasSg(&AxiDma) で SG モードかどうかを判別 (AxiDma.HasSg, CfgPtr->HasSg に対応)
+-- SG モード対応だと Simple モードでは動作しない???
++ SetupIntrSystem 内で割り込みを設定
+++ XScuGic_LookupConfig(INTC_DEVICE_ID); でハードウェア情報を得る
+++ XScuGic_CfgInitialize(IntcPtr,IntcConfig,IntcConfig->CpuBaseAddress); で Intc を設定
+++ XScuGic_SetPriorityTriggerType で Priority = 0xA0, TriggerType = 0x3 にする
+--- Priority は小さいほど高い。8 の倍数が有効。
+--- TriggerType = 3 は Rising edge sensitive
+++ XScuGic_Connect(IntcPtr, XxIntrId, XxIntrHandler, AxiDmaPtr); で割り込みハンドラを設定
+++ XScuGic_Enable(IntcPtr, XxIntrId); で割り込みを許可
+++ Xil_ExceptionInit(); これ、実際には何もしない。 (lib\bsp\standalone_vX.X\src\arm\common\xil_exception.c)
+++ Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, INTC_HANDLER, IntcPtr); 割り込みハンドラを登録
+--- INTC_HANDLER は xscugic_intr.c の XScuGic_InterruptHandler を指しており、
+そこから GIC へ登録したハンドラが呼ばれる
+++ Xil_ExceptionEnable(); で cpsr の XIL_EXCEPTION_IRQ で指定したビットをクリアする
++ XAxiDma_IntrDisable で一旦 DMA からの割り込み信号送出を禁止する
++ XAxiDma_IntrEnable で DMA からの割り込み信号送出を許可する
++ Xil_DCacheFlushRange で送信バッファのキャッシュをメモリに書き出す
++ XAxiDma_SimpleTransfer で送受信の要求
++ 割り込みハンドラで
+++ 引数から AxiDma へのポインタを得る
+++ XAxiDma_IntrGetIrq により対応する IRQ 番号を得る
+++ IrqStatus & XAXIDMA_IRQ_ALL_MASK で割り込みが生じたか確かめる
+--- いくつかの割り込み信号線をまとめている場合にも対応できる
+++ XAxiDma_IntrAckIrq により対応する IRQ に Acknowledge を送る
+++ IrqStatus & XAXIDMA_IRQ_ERROR_MASK ならエラーで割り込みが生じた
+--- XAxiDma_Reset して HALT 状態から戻す
+--- アプリケーションにエラーを通知する
+++ IrqStatus & XAXIDMA_IRQ_IOC_MASK なら正常終了
++ Xil_DCacheInvalidateRange で受信バッファのキャッシュ内容を無効化
++ DisableIntrSystem 内で割り込みハンドラを解除する
+++ XScuGic_Disconnect で GIC から割り込みハンドラを解除する
+
LANG:c
- void main()
+ #include "xscugic.h"
+
+ void main(void)
{
- /* Run the poll example for simple transfer */
- XAxiDma_SimplePollExample(DMA_DEV_ID);
+ 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);
}
- int XAxiDma_SimplePollExample(u16 DeviceId)
+ static void TxIntrHandler(void *Callback)
{
- XAxiDma_Config *CfgPtr;
- int Status;
- int Tries = NUMBER_OF_TRANSFERS;
- int Index;
- u8 *TxBufferPtr;
- u8 *RxBufferPtr;
- u8 Value;
+ u32 IrqStatus;
+ int TimeOut;
+ XAxiDma *AxiDmaInst = (XAxiDma *)Callback;
- TxBufferPtr = (u8 *)TX_BUFFER_BASE;
- RxBufferPtr = (u8 *)RX_BUFFER_BASE;
+ // Read and acknowledge pending interrupts
+ IrqStatus = XAxiDma_IntrGetIrq(AxiDmaInst, XAXIDMA_DMA_TO_DEVICE);
+ XAxiDma_IntrAckIrq(AxiDmaInst, IrqStatus, XAXIDMA_DMA_TO_DEVICE);
- // Initialize the XAxiDma device.
- CfgPtr = XAxiDma_LookupConfig(DeviceId);
- assert(CfgPtr);
+ // If no interrupt is asserted, we do not do anything
+ if (!(IrqStatus & XAXIDMA_IRQ_ALL_MASK))
+ return;
- Status = XAxiDma_CfgInitialize(&AxiDma, CfgPtr);
- assert(Status == XST_SUCCESS);
+ // 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;
- assert(! XAxiDma_HasSg(&AxiDma)); // SG mode でないことを確認
+ // Reset should never fail for transmit channel
+ XAxiDma_Reset(AxiDmaInst);
- // 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);
+ TimeOut = RESET_TIMEOUT_COUNTER;
+ while (TimeOut) {
+ if (XAxiDma_ResetIsDone(AxiDmaInst))
+ break;
+ TimeOut -= 1;
+ }
+ return;
+ }
- InitializeTxBuffer(TxBufferPtr);
+ // If Completion interrupt is asserted, then set the TxDone flag
+ if ((IrqStatus & XAXIDMA_IRQ_IOC_MASK))
+ TxDone = 1;
+ }
- // キャッシュのフラッシュ
- Xil_DCacheFlushRange((UINTPTR)TxBufferPtr, MAX_PKT_LEN);
+ static void RxIntrHandler(void *Callback)
+ {
+ u32 IrqStatus;
+ int TimeOut;
+ XAxiDma *AxiDmaInst = (XAxiDma *)Callback;
- // 受信要求
- Status = XAxiDma_SimpleTransfer(&AxiDma,(UINTPTR) RxBufferPtr,
- MAX_PKT_LEN, XAXIDMA_DEVICE_TO_DMA);
- assert(Status == XST_SUCCESS);
+ // Read and acknowledge pending interrupts
+ IrqStatus = XAxiDma_IntrGetIrq(AxiDmaInst, XAXIDMA_DEVICE_TO_DMA);
+ XAxiDma_IntrAckIrq(AxiDmaInst, IrqStatus, XAXIDMA_DEVICE_TO_DMA);
- // 送信要求
- Status = XAxiDma_SimpleTransfer(&AxiDma,(UINTPTR) TxBufferPtr,
- MAX_PKT_LEN, XAXIDMA_DMA_TO_DEVICE);
- assert(Status == XST_SUCCESS);
+ // If no interrupt is asserted, we do not do anything
+ if (!(IrqStatus & XAXIDMA_IRQ_ALL_MASK))
+ return;
- // 終わるのを待つ
- while ( (XAxiDma_Busy(&AxiDma,XAXIDMA_DEVICE_TO_DMA)) ||
- (XAxiDma_Busy(&AxiDma,XAXIDMA_DMA_TO_DEVICE)) ) {
- /* Wait */
- }
+ // 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;
- // キャッシュの Invalidate
- Xil_DCacheInvalidateRange((UINTPTR)RxPacket, MAX_PKT_LEN);
- return XST_SUCCESS;
+ // 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);
+ }