// test_dma_wd.c
// test_dma with drivers
// 2017/12/14 by marsee
//
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include <sys/mman.h>
#include <fcntl.h>
#include "xdma_pow2.h"
int main(){
int fd1, fd2;
XDma_pow2 xdma_ap;
int Xdma_status;
volatile unsigned int *cma_buffer;
char attr[1024];
unsigned long phys_addr;
int i;
// Initialize the Device
Xdma_status = XDma_pow2_Initialize(&xdma_ap, "dma_pow2");
if (Xdma_status != XST_SUCCESS){
fprintf(stderr, "Could not Initialize XDma_pow2\n");
return(-1);
}
// udmabuf0
fd1 = open("/dev/udmabuf0", O_RDWR); // frame_buffer, The chache is enabled.
if (fd1 == -1){
fprintf(stderr, "/dev/udmabuf0 open error\n");
exit(-1);
}
cma_buffer = (volatile unsigned *)mmap(NULL, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, fd1, 0);
if (!cma_buffer){
fprintf(stderr, "cma_buffer mmap error\n");
exit(-1);
}
// phys_addr of udmabuf0
fd2 = open("/sys/class/udmabuf/udmabuf0/phys_addr", O_RDONLY);
if (fd2 == -1){
fprintf(stderr, "/sys/class/udmabuf/udmabuf0/phys_addr open error\n");
exit(-1);
}
read(fd2, attr, 1024);
sscanf(attr, "%lx", &phys_addr);
close(fd2);
printf("phys_addr = %x\n", (int)phys_addr);
XDma_pow2_Set_in_r(&xdma_ap, phys_addr);
XDma_pow2_Set_out_r(&xdma_ap, phys_addr+sizeof(int)*10);
for(i=0; i<10; i++)
cma_buffer[i] = i;
XDma_pow2_Start(&xdma_ap);
while(!XDma_pow2_IsDone(&xdma_ap)) ;
printf("in[] = ");
for(i=0; i<10; i++)
printf("%2d ", cma_buffer[i]);
printf("\n");
printf("out[] = ");
for(i=10; i<20; i++)
printf("%2d ", cma_buffer[i]);
printf("\n");
munmap((void *)cma_buffer, 0x10000);
close(fd1);
return(0);
}
# Makefile(test_dma_wd.c)
# Referred to http://www.ie.u-ryukyu.ac.jp/~e085739/c.makefile.tuts.html
PROGRAM = test_dma_wd
OBJS = test_dma_wd.o xdma_pow2.o xdma_pow2_linux.o
CC = gcc
CFLAGS = -Wall -O2
.SUFFIXES: .c .o
.PHONY: all
all: test_dma_wd
test_dma_wd: $(OBJS)
$(CC) -Wall -o $@ $(OBJS)
.c.o:
$(CC) $(CFLAGS) -c $<
.PHONY: clean
clean:
$(RM) $(PROGRAM) $(OBJS)
日 | 月 | 火 | 水 | 木 | 金 | 土 |
---|---|---|---|---|---|---|
- | - | - | - | - | 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 | - | - | - | - | - | - |