Untitled
unknown
plain_text
a month ago
1.3 kB
6
Indexable
#include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <sys/mman.h> #include <unistd.h> #include <errno.h> #include <string.h> int main() { int fd; void *buffer; const char test_string[] = "Hello from DMA buffer!"; char read_buffer[64]; // Open the DMA buffer device fd = open("/dev/udmabuf0", O_RDWR); if (fd < 0) { printf("Failed to open /dev/udmabuf0: %s\n", strerror(errno)); return 1; } // Map the buffer into user space buffer = mmap(NULL, 4194304, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (buffer == MAP_FAILED) { printf("Failed to mmap: %s\n", strerror(errno)); close(fd); return 1; } // Write test string to buffer memcpy(buffer, test_string, strlen(test_string) + 1); // Read back from buffer memcpy(read_buffer, buffer, strlen(test_string) + 1); printf("Written to DMA buffer: %s\n", test_string); printf("Read from DMA buffer: %s\n", read_buffer); // Compare if (strcmp(test_string, read_buffer) == 0) { printf("Test PASSED - Data matches!\n"); } else { printf("Test FAILED - Data mismatch!\n"); } // Cleanup munmap(buffer, 4194304); close(fd); return 0; }
Editor is loading...
Leave a Comment