a0ff20c67e84001d1a01f088cc7cc1e3

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

TXT
30
字号
#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");
        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, (void*)curve_data, 10, NULL, NULL) < 0){
            printf ("Error: failed to post receive request\n");
        }
        int i;
        for(i=0; i<=1023; i++){  
            printf("i%d = %x\n", i, curve_data[i]);
        }
        alt_dma_rxchan_close (rx);
    return 0;
}

⌨️ 快捷键说明

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