首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

NIOSII的DMA的问题!

NIOSII的DMA的问题!

我在NIOSII 增加了一个DMA, Read Master接了一个8bit PIOcore,这个PIO接了一个计数器,然后我想利用DMA不停地从这个端口读入数据并存入SDRAM,我的程序如下:


#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[2024];
  alt_dma_rxchan rx;
/* Obtain a handle for the device */
if ((rx = alt_dma_rxchan_open ("/dev/dma")) == NULL)
{
  printf ("Error: failed to open device");
  exit (1);
}
else
{
/* Post the receive request */
  alt_dma_rxchan_ioctl(rx,ALT_DMA_SET_MODE_8,NULL);
  alt_dma_rxchan_ioctl(rx,ALT_DMA_RX_ONLY_ON,(void*)0x008010A0);
  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");
  int i;
  for (i=0; i<=1023; i++)
  { 
    printf("i%d = %d\n", i, buffer);
  }
 
  alt_dma_rxchan_close (rx);
}
return 0;
}


结果,内存的数据明显丢失了计数器的数据:


i0 = 12
i1 = 13
i2 = 13
i3 = 13
i4 = 13
i5 = 14
i6 = 14
i7 = 14
i8 = 14
i9 = 15
i10 = 16
i11 = 18
i12 = 18
i13 = 18
i14 = 20
i15 = 23
i16 = 25
i17 = 27
i18 = 29
i19 = 32
i20 = 34
i21 = 35
i22 = 36
i23 = 37
i24 = 39
i25 = 41
i26 = 43
i27 = 45
i28 = 48
i29 = 50
i30 = 52
i31 = 53
i32 = 54
i33 = 55
i34 = 55
i35 = 57
i36 = 59
i37 = 62
i38 = 64
i39 = 66
i40 = 68
i41 = 71
i42 = 72
i43 = 73
i44 = 73
i45 = 74
i46 = 76
i47 = 80
i48 = 83
i49 = 85
i50 = 88
i51 = 90
i52 = 92
i53 = 93
i54 = 94
i55 = 95
i56 = 97
i57 = 99
i58 = 102
i59 = 104
i60 = 106
i61 = 108
i62 = 111
i63 = 112
i64 = 113
i65 = 113
i66 = 114
i67 = 116
i68 = 119
i69 = 121
i70 = 123
i71 = 126
i72 = 128
i73 = 130
i74 = 131
i75 = 132
i76 = 133
i77 = 133
i78 = 135
i79 = 137
i80 = 140
i81 = 142
i82 = 144
i83 = 146
i84 = 149
i85 = 150
i86 = 151
i87 = 152
i88 = 154
i89 = 156
i90 = 158
i91 = 160
i92 = 163
i93 = 165
i94 = 167
i95 = 168
i96 = 169
i97 = 170
i98 = 172
i99 = 174
i100 = 176


请问如何能够保证不丢失数据的从一个确定的端口用DMA不停的读出一串数据并且依次存入内存?


我的外设有控制信号,问题是如何引入到DMA中??


谢谢大虾指导!!


 

是不是你的定时器启动的早了
好好学习,天天向上
感觉没有问题,和例子差不多啊!
liyasi 你好,你的问题解决了吗?我的dma操作,在调用dma_done,程序就跑飞了,能帮忙吗?
谢谢啊?
好好学习,天天向上
返回列表