// DMP_pow2_test.c
// 2023/03/13 by marsee
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/mman.h>
void main(){
int uio4_fd;
volatile int32_t *dma_pow2;
volatile int32_t *data;
int fd_udmabuf0;
u_int32_t fd_paddr;
unsigned char attr[1024];
unsigned long phys_addr;
// uio4, DMP_pow2
if((uio4_fd = open("/dev/uio4", O_RDWR)) == -1) {
printf("Can not open /dev/uio4\n");
exit(1);
}
dma_pow2 = (volatile int32_t*)mmap(NULL, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, uio4_fd, 0);
// udmabuf0
fd_udmabuf0 = open("/dev/udmabuf0", O_RDWR | O_SYNC); // frame_buffer, The chache is disabled.
if (fd_udmabuf0 == -1){
fprintf(stderr, "/dev/udmabuf0 open errorn");
exit(-1);
}
// phys_addr of udmabuf0
fd_paddr = open("/sys/class/u-dma-buf/udmabuf0/phys_addr", O_RDONLY);
if (fd_paddr == -1){
fprintf(stderr, "/sys/class/u-dma-buf/udmabuf0/phys_addr open errorn");
exit(-1);
}
read(fd_paddr, (void *)attr, 1024);
sscanf((const char *)attr, "%lx", &phys_addr);
close(fd_paddr);
printf("phys_addr = %x\n", (unsigned int)phys_addr);
data = (volatile int32_t *)mmap(NULL, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, fd_udmabuf0, 0);
if (data == MAP_FAILED){
fprintf(stderr, "data mmap error\n");
exit(-1);
}
// data Initialization
for(int i=0; i<10; i++){
data[i] = i;
}
// DMP_pow2 start
while((dma_pow2[0] & 4) == 0) ; // wait ap_idle
dma_pow2[6] = phys_addr; // in_r
dma_pow2[8] = phys_addr + 10 * sizeof(int32_t); // out_r
dma_pow2[0] = 1; // ap_start
while((dma_pow2[0] & 2) == 0) ; // wait ap_done
for(int i=0; i<10; i++){
printf("in = %d, out = %d\n", data[i], data[i+10]);
}
}
日 | 月 | 火 | 水 | 木 | 金 | 土 |
---|---|---|---|---|---|---|
- | - | - | - | 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 | - |