首页 新闻 会员 周边

NIOS dma通讯问题 from rs232 to SDRAM

0
悬赏园豆:5 [待解决问题]

有个问题困扰我块半个月,实在解决不了,请求高手帮忙。
方案是:利用DMA,实现从RS232发送数据,SDRAM接收数据,然后通过串口检查是不是我发送的信息,检查方式通过上位机串口调试软件发送信息,然后将发送出去的信息,并传回到JTAG端和RS232端(此时RS232端通过文件显示输出)。
问题:怎么也得不到我发送出去的信息,返回的数据跟发送的数据不一致,或者发送不出去。(另一个程序从SDRAM发送到串口是OK的,说明串口没问题),版本10.0+NIOS 10.0

程序代码:
//从RS232接收字符,传到SDRAM,在将所传送的信息,反馈到JTAG和RS232(通过文件形式),检查两者是否正确

//从RS232接收字符,传到SDRAM,在将所传送的信息,反馈到JTAG和RS232(通过文件形式),检查两者是否正确

#include <stdio.h>
#include <stdlib.h>
#include "sys/alt_dma.h"
#include "altera_avalon_uart_regs.h"
#include "altera_avalon_dma_regs.h"
#include "system.h"
#include "alt_types.h"
#include <string.h>

#define TRANSFER_LENGTH  1024
static volatile int tx_done = 0;
static char str[512]={"this is str data\n"};

 

//回调函数
static void done (void* handle)
{
tx_done++;
}


int main()
{
   alt_u8 i;  
   FILE *fp_LCD=0;
   FILE *fp_RS232=0;
   fp_LCD = fopen("/dev/lcd","w"); 
   fp_RS232 = fopen("/dev/rs232","w");   
      
int rc;
alt_dma_rxchan rxchan;
  
void* source = (void*)IOADDR_ALTERA_AVALON_UART_TXDATA(RS232_BASE);/* 源地址 */ 
void* dest = (void*)(SDRAM_BASE+100);
/* 打开发送通道 */
if ((rxchan = alt_dma_rxchan_open("/dev/dma")) == 0)
{ printf ("successful to open transmit channel\n");
exit (1);
}
/* 设置发送地址固定 */
if ((rc = alt_dma_rxchan_ioctl(rxchan, ALT_DMA_RX_ONLY_ON, source)) < 0)
{  printf ("Failed to set ioctl, reason = %i\n", rc);
exit (1);
}
//设置每次接收一个字节,即8位,因为UART每次只发送8位
if((rc = alt_dma_rxchan_ioctl(rxchan,ALT_DMA_SET_MODE_8 ,NULL))<0)
{   printf("Failed to set mode 8\n");
    exit(1);
}


/* 开始接收 */
if ((rc = alt_dma_rxchan_prepare(rxchan, SDRAM_BASE+100, 32, done, NULL)) < 0)
{  printf ("Failed to post transmit request, reason = %i\n", rc);
exit (1);
}
/* 等待接收结束 */
while (!tx_done);
printf ("Transfer to jtag!\n");
fprintf(fp_LCD,"Transfer to lcd! \n");
fprintf(fp_RS232,"Transfer to rs232 ! \n");
//alt_dma_rxchan_close(rxchan);

memcpy(str,SDRAM_BASE+100,256);  // 将SDRAM内容复制到ONCHIP str,并显示输出,以便检查

printf ("%x\n",str);   
fprintf(fp_LCD,str);
fprintf(fp_RS232,str);

printf("%x\n",SDRAM_BASE+100);

alt_dma_rxchan_close(rxchan);

return 0;
}

 

xyguoking的主页 xyguoking | 初学一级 | 园豆:195
提问于:2010-10-28 11:11
< >
分享
所有回答(1)
0

也许你能在这片博文中找到答案,减少困惑时间http://blog.ednchina.com/luosen/1971140/message.aspx

lideli5 | 园豆:205 (菜鸟二级) | 2011-01-02 11:24
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册