1. Compiling and installing the driver
In Linux systems, drivers are usually encoded using the kernel module's program structure, so compiling and installing a driver is essentially compiling and installing a kernel module.
Put the file memdev.c makefile into the virtual machine, make get the. ko file
CP. KO Rootfs
Start the Development Board
Insmod *.ko
2. Create a Device file
With character device files, the application can use the appropriate character device driver to control the character device. How to create a character device file:
A. Using the Mkmod command
mknod/dev/file name C main device number (associate driver and device file) secondary device number
Mknod/dev/memdev0 C 253 0
B. Using functions to create in a drive
Application-"Through the file name-" character device file-"through the main device number-" device driver
Main device number Cat Proc/device contains the main device number for different devices.
MEMDEV.C simulates a device, imports data into an array, or outputs a data from an array.
3. Accessing the device
Vim WRITE_MEM.C
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main ()
{
int FD =0;//
int src = 2013;
Fd=open ("/dev/memdev0", O_RDWR);//Opens the file in a readable and writable manner, and returns an FD when opened.
Write (fd,&src,sizeof (int)); writes data to the file, writes FD First, and then writes the data, the size of the data.
Close (FD);
}
ARM-LINUX-GCC Write_mem.c-o Write_mem-g
An error occurred and a header file could not be included.
Use of character device drivers