Use of character device drivers

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.