Normal through the file system access to the value of Ain serial port, you can use Fread and other file IO read/sys/bus/iio/devices/iio:device0/in_voltage*_raw content.
But this requires high frequency access to the ADC is very inefficient, the data needs to be copied from the disk to the kernel process space, and then copied to the user process space, consuming unnecessary resources.
This problem can be solved by memory innuendo, Mmap can realize the data copy of disk data to user main memory, so as to achieve high efficiency of user space drive.
Under Linux You can view the/dev/mem file, which can be considered a mirror of physical memory and can be used to access physical memory.
Under Beaglebone Black, access to the GPIO,ADC data can be accessed by accessing the/DEV/MEM. Mmap Establish a mapping relationship example:
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <stdint.h> #include <sys/mman.h> #include <fcntl.h> #define MMAP_OFFSET (0x44c00000) #define Mmap_siz
E (0x481aefff-mmap_offset) static volatile uint32_t *map;
static char mapped = FALSE; int Init_mmap () { if (!mapped) { int fd; &NBSP ;
FD = open ("/dev/mem", O_RDWR); if (FD = 1) { perror ("U
Nable to Open/dev/mem ");
exit (exit_failure); } map = (uint32_t*) mmap (NULL, mmap_size, Prot_read |
Prot_write, map_shared, FD, Mmap_offset); if (map = = map_failed) {
Close (FD); &NBSP
Perror ("Unable to Map/dev/mem");
exit (exit_failure);
} mapped = TRUE;
} return mapped; }
The current implementation code is based on a project on GitHub to make modifications. Interested can refer to here: Https://github.com/alban-rochel/pixbox-controls/tree/master/service