您好,欢迎来到二三四教育网。
搜索
您的当前位置:首页【转载】Nios II DMA: memory to memory

【转载】Nios II DMA: memory to memory

来源:二三四教育网

转载:

 

#include <stdio.h>

#include <stdlib.h>

#include "unistd.h"

#include "string.h"

#include "io.h"

#include "system.h"

#include "sys/alt_dma.h"

#include "sys/alt_cache.h"

#include "sys/alt_irq.h"

#include "alt_types.h"

#include "sys/alt_irq.h"

 

#include "altera_avalon_dma_regs.h"

#include "altera_avalon_uart_regs.h"

 

 

volatile alt_u8 chr[20] = {1,2,3,4,6,5,7,8,9,10,

                        11,12,13,14,15,16,17,18,19,20} ;//数据源

static volatile int rx_done = 0;

 

static void done (void* handle, void* data)

{

rx_done++;

IOWR(LED_BASE,0, rx_done);//LED显示rx_done的变化

}

 

int main (int argc, char* argv[], char* envp[])

{

alt_u8 i="0";

int rc;

alt_dma_txchan txchan;

alt_dma_rxchan rxchan;

void * tx_data = (void*) chr;

alt_u8 *rx = (alt_u8 *)ONCHIP_RAM_BASE;

void* rx_buffer = (void*) ONCHIP_RAM_BASE;//0x00801000; /* pointer to rx buffer */

IOWR(LED_BASE,0, 0);

{

   printf ("%c\n",*(rx+i));

}

printf ("Let's begin!\n");

 

if ((txchan = alt_dma_txchan_open("/dev/DMA0")) == NULL)

{

printf ("Failed to open transmit channel\n");

}

 

if ((rxchan = alt_dma_rxchan_open("/dev/DMA0")) == NULL)

{

printf ("Failed to open receive channel\n");

}

 

if ((rc = alt_dma_txchan_send (txchan,

tx_data,

20,

NULL,

NULL)) < 0)

{

printf ("Failed to post transmit request, reason = %i\n", rc);

}

 

if ((rc = alt_dma_rxchan_prepare (rxchan,

rx_buffer,

20,

done,

NULL)) < 0)

{

printf ("Failed to post read request, reason = %i\n", rc);

 

}

while (!rx_done);

printf ("Transfer successful!\n");

for(i =0;i<20;i++)

{

}

while(1);

return 0;

}

 

 

转载于:https://www.cnblogs.com/kongtiao/archive/2011/09/23/2185793.html

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- how234.cn 版权所有 赣ICP备2023008801号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务