305baafe8f84001d124efccffff46f52

来自「基于ALTERA公司的NIOSII的串口通信DMA传输设计」· 代码 · 共 36 行

TXT
36
字号
#include <stdio.h>
#include <string.h>
#include "system.h"
#include "sys/alt_dma.h"
volatile int curve_data[10000];

int main(void)
{
  /*  char* msg = "Hello from Nios II!";
    FILE* fp;
    fp = fopen("/dev/uart_0","r+");
    if(fp){
        fprintf(fp,"%s",msg);
        fclose(fp);
    }*/
    alt_dma_rxchan rx;
    /* Obtain a handle for the device */
    if((rx = alt_dma_rxchan_open ("/dev/dma_0")) != NULL){
        printf("start\n");
        while(1){
            alt_dma_rxchan_ioctl(rx,ALT_DMA_SET_MODE_8,NULL);
            alt_dma_rxchan_ioctl(rx,ALT_DMA_RX_ONLY_ON,(void*)UART_0_BASE);
            if(alt_dma_rxchan_prepare (rx, SDRAM_0_BASE, 1024, NULL, NULL) < 0){
                printf ("Error: failed to post receive request\n");
            }
            //while (!dma_complete);
            int i;
            for(i=0; i<=10; i++){  
                printf("i%d = %x\n", i, curve_data[i]);
            }
            alt_dma_rxchan_close (rx);
            usleep(1000000);
        }
    }
    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?