履歴: 電気回路/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/11 18:07:45)

@@ -2,6 +2,12 @@
#contents
+* 概要 [#f674dcb8]
+
+Zynq で DMA 処理するために勉強中の内容です。
+
+まだ動かせていないので間違ったことも多いと思います。
+
* axi_dma のドキュメント [#e7f3007e]
デザインダイアグラム上で axi_dma IP を右クリックして
@@ -11,8 +17,39 @@
など。
+* 後で読む [#te8e7275]
+
+Zynq DMA 用 Linux ドライバ:~
+https://github.com/bmartini/zynq-xdma
+
+[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]
+自分で Linux ドライバを作るときやベアメタルでは
+Xilinx の低レベルドライバを使うことになる。
+
C:\Xilinx\SDK\2016.4\data\embeddedsw\XilinxProcessorIPLib\drivers\axidma_v9_3\src
というようなディレクトリにソースコードが、
@@ -513,6 +550,13 @@
エラー処理を飛ばして読んでみます。
+割り込みについて 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
@@ -537,11 +581,7 @@
// Initialize the XAxiDma device.
CfgPtr = XAxiDma_LookupConfig(DeviceId);
- assert(CfgPtr);
-
- Status = XAxiDma_CfgInitialize(&AxiDma, CfgPtr);
- assert(Status == XST_SUCCESS);
-
+ XAxiDma_CfgInitialize(&AxiDma, CfgPtr);
assert(! XAxiDma_HasSg(&AxiDma)); // SG mode でないことを確認
// Disable interrupts, we use polling mode
@@ -554,14 +594,12 @@
Xil_DCacheFlushRange((UINTPTR)TxBufferPtr, MAX_PKT_LEN);
// 受信要求
- Status = XAxiDma_SimpleTransfer(&AxiDma,(UINTPTR) RxBufferPtr,
+ XAxiDma_SimpleTransfer(&AxiDma,(UINTPTR) RxBufferPtr,
MAX_PKT_LEN, XAXIDMA_DEVICE_TO_DMA);
- assert(Status == XST_SUCCESS);
// 送信要求
- Status = XAxiDma_SimpleTransfer(&AxiDma,(UINTPTR) TxBufferPtr,
+ XAxiDma_SimpleTransfer(&AxiDma,(UINTPTR) TxBufferPtr,
MAX_PKT_LEN, XAXIDMA_DMA_TO_DEVICE);
- assert(Status == XST_SUCCESS);
// 終わるのを待つ
while ( (XAxiDma_Busy(&AxiDma,XAXIDMA_DEVICE_TO_DMA)) ||
@@ -573,3 +611,191 @@
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);
+ }