インテルのみ表示可能 — GUID: kpx1642636828307
Ixiasoft
インテルのみ表示可能 — GUID: kpx1642636828307
Ixiasoft
7.9.2. DMA 受信チャネル
typedef void (alt_rxchan_done)(void* handle, void* data); int alt_dma_rxchan_prepare (alt_dma_rxchan dma, void* data, alt_u32 length, alt_rxchan_done* done, void* handle);
この関数を呼び出すと、最大 length バイトのデータがアドレス data に配置されるように、受信リクエストがチャネル dma にポストされます。この関数は、DMA トランザクションが完了する前に戻ります。戻り値は、リクエストが正常にキューに入れられたかどうかを示します。負の戻り値は、リクエストが失敗したことを示します。トランザクションが完了すると、ユーザー指定の関数 done() が引数 handle とともに呼び出され、受信データへのポインターおよび通知が提供されます。
特定のエラーにより、DMA 転送が完了しない場合があります。通常、これは転送に関与するコンポーネントが読み取りまたは書き込み要求に応答しないなどの壊滅的なハードウェア障害が原因です。DMA 転送が完了しない場合 (つまり、length 未満のバイトが転送される場合)、関数 done() が呼び出されることはありません。
DMA 受信チャネルを操作する目的で、alt_dma_rxchan_depth() および alt_dma_rxchan_ioctl() の2つの追加関数が提供されています。
alt_dma_rxchan_depth() は、デバイスのキューに入れることができる受信リクエストの最大数を返します。 alt_dma_rxchan_ioctl() は、受信デバイスのデバイス固有の操作を実行します。
#include <stdio.h> #include <stddef.h> #include <stdlib.h> #include "sys/alt_dma.h" #include "alt_types.h" /* flag used to indicate the transaction is complete */ volatile int dma_complete = 0; /* function that is called when the transaction completes */ void dma_done (void* handle, void* data) { dma_complete = 1; } int main (void) { alt_u8 buffer[1024]; alt_dma_rxchan rx; /* Obtain a handle for the device */ if ((rx = alt_dma_rxchan_open ("/dev/dma_0")) == NULL) { printf ("Error: failed to open device\n"); exit (1); } else { /* Post the receive request */ if (alt_dma_rxchan_prepare (rx, buffer, 1024, dma_done, NULL) < 0) { printf ("Error: failed to post receive request\n"); exit (1); } /* Wait for the transaction to complete */ while (!dma_complete); printf ("Transaction complete\n"); alt_dma_rxchan_close (rx); } return 0; }