int main(int argc, char *argv[]) { const int LENGTH = 1025; int i; uint32_t *src; uint32_t *dst; if (xdma_init() < 0) { exit(EXIT_FAILURE); } dst = (uint32_t *) xdma_alloc(LENGTH, sizeof(uint32_t)); src = (uint32_t *) xdma_alloc(LENGTH, sizeof(uint32_t)); // fill src with a value for (i = 0; i < LENGTH; i++) { src[i] = 'B'; } src[LENGTH - 1] = '\n'; // fill dst with a value for (i = 0; i < LENGTH; i++) { dst[i] = 'A'; } dst[LENGTH - 1] = '\n'; printf("test: dst buffer before transmit:\n"); for (i = 0; i < 10; i++) { printf("%d\t", dst[i]); } printf("\n"); if (0 < xdma_num_of_devices()) { xdma_perform_transaction(0, XDMA_WAIT_NONE, src, LENGTH, dst, LENGTH); } printf("test: dst buffer after transmit:\n"); for (i = 0; i < 10; i++) { printf("%d\t", dst[i]); } printf("\n"); xdma_exit(); return 0; }
int xdma_init(void) { int i; struct xdma_chan_cfg dst_config; struct xdma_chan_cfg src_config; /* Open the char device file. */ fd = open(FILEPATH, O_RDWR | O_CREAT | O_TRUNC, (mode_t) 0600); if (fd == -1) { perror("Error opening file for writing"); return EXIT_FAILURE; } /* mmap the file to get access to the DMA memory area. */ map = mmap(0, FILESIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (map == MAP_FAILED) { close(fd); perror("Error mmapping the file"); return EXIT_FAILURE; } xdma_alloc_reset(); num_of_devices = xdma_num_of_devices(); if (num_of_devices <= 0) { perror("Error no DMA devices found"); return EXIT_FAILURE; } for (i = 0; i < MAX_DEVICES; i++) { xdma_devices[i].tx_chan = (u32) NULL; xdma_devices[i].tx_cmp = (u32) NULL; xdma_devices[i].rx_chan = (u32) NULL; xdma_devices[i].rx_cmp = (u32) NULL; xdma_devices[i].device_id = i; if (i < num_of_devices) { if (ioctl(fd, XDMA_GET_DEV_INFO, &xdma_devices[i]) < 0) { perror("Error ioctl getting device info"); return EXIT_FAILURE; } dst_config.chan = xdma_devices[i].rx_chan; dst_config.dir = XDMA_DEV_TO_MEM; dst_config.coalesc = 1; dst_config.delay = 0; dst_config.reset = 0; if (ioctl(fd, XDMA_DEVICE_CONTROL, &dst_config) < 0) { perror("Error ioctl config dst (rx) chan"); return EXIT_FAILURE; } src_config.chan = xdma_devices[i].tx_chan; src_config.dir = XDMA_MEM_TO_DEV; src_config.coalesc = 1; src_config.delay = 0; src_config.reset = 0; if (ioctl(fd, XDMA_DEVICE_CONTROL, &src_config) < 0) { perror("Error ioctl config src (tx) chan"); return EXIT_FAILURE; } } } return EXIT_SUCCESS; }