提供一个dma_buffer c语言 demo
时间: 2023-03-14 13:11:12 浏览: 126
DMA传送的C语言实现
4星 · 用户满意度95%
我可以提供以下 C 语言 dma_buffer 示例程序:#include <stdio.h>
#include <sys/ioctl.h>
#include <linux/dma-buf.h>int main()
{
int dma_fd;
int ret;
struct dma_buf_export_info info;
void *buffer; //open a dma buffer
dma_fd = open("/dev/dma_buf", O_RDWR);
if (dma_fd < 0) {
perror("open error");
return -1;
} //export a dma buffer
info.size = 0x1000;
info.flags = 0;
buffer = (void *)mmap(NULL, info.size, PROT_READ | PROT_WRITE, MAP_PRIVATE, dma_fd, 0);
ret = ioctl(dma_fd, DMA_BUF_IOCTL_EXPORT, &info);
if (ret < 0) {
perror("ioctl error");
return -1;
} //do something with the dma buffer
printf("dma_fd = %d\n", dma_fd); //close the dma buffer
munmap(buffer, info.size);
close(dma_fd); return 0;
}
阅读全文