Current location - Education and Training Encyclopedia - Graduation thesis - Who can help me write a paper on "Driver Design and Implementation of Embedded linux Operating System"? Have extra points
Who can help me write a paper on "Driver Design and Implementation of Embedded linux Operating System"? Have extra points
Such a problem cannot be solved by an article. Find a book to read by yourself.

Design and Implementation of Device Driver for Embedded Linux Operating System

Tamia Liu Qu Xiaoping

(School of Information Science and Technology, Jiujiang University, Jiujiang, Jiangxi 332005)

This paper mainly expounds the concept of embedded Linux device driver, summarizes the characteristics of embedded Linux device driver, and probes into embedded Linux device driver.

This paper introduces the specific development process and key codes of the driver, and summarizes the leading ideas of the driver development of embedded Linux devices.

Keywords: embedded system; Linux device driver; core

Computing technology and automation

Design and Implementation of Embedded Linux Device Driver

Xiao Quping, Tamia Liu

(School of Information Technology, Jiujiang University, Jiujiang, Jiangxi 332005)

Keywords: embedded system; Linux device driver; core

Embedded systems are widely used in consumer electronics, automobiles, electronics, micro-control and wireless communication.

Information, digital products, network equipment, security systems and other fields. More and more companies and research institutions.

Research institutions, universities and individuals began to study embedded systems and embed them.

System design will be a research hotspot for a long time to come.

Overview of 1 Linux device drivers

Embedded Linux can be applied to a variety of hardware platforms, and the kernel is efficient and stable.

Open source code, rich software, perfect network communication and file management mechanism, etc.

Sex has become a research hotspot in the field of embedded systems. Embedded Linux system

The kernel provides a protection mechanism, and processes in user space generally cannot directly access the hardware.

Pieces. To develop embedded systems, a lot of work is to write drivers for various devices.

Program, unless the system does not use the operating system. Linux device driver

Kernel source code accounts for a large proportion, from 2.0, 2.2 to 2.4 versions of the kernel, source code generation.

The length of code is increasing day by day, in fact, the main reason is the increase of device drivers.

Device driver plays an extremely important role in Linux kernel, and it is internal.

The core is used to control the physical equipment. In addition to CPU, memory

And several other parts, all equipment control operations must be carried out by

Code related to the controlled device (i.e. driver). The kernel must include

A driver corresponding to each external device in the system. Otherwise, the device will not be able to

It works normally under Linux. This is how the driver is developed into a Linux kernel.

The reason for the main job. As can be seen from the code distribution of the kernel source code, the device driver source code.

The code accounts for at least half of the kernel source code, which can better explain the operation of the device driver.

The significance and value of the system.

2 embedded Linux device driver development

2. 1 Working principle of device driver

There are three main types of device files under Linux operating system: block devices,

Character devices and network devices. This classification method can control different input/output.

Device drivers are independent of other operating system software. Character devices and blocks

The main difference between devices is that when sending a read/write request to a character device, the actual hardware

I/O is usually followed by. On the other hand, block devices use a block of system memory as a buffer.

If the user process's request for the device can meet the user's requirements, it will return the request.

Data; Otherwise, the request function will be called to perform the actual I/O operation. network equipment

You can access data through BSD windows sockets. All embedded Linux device drivers

Sequence has some * * * features that are common to all types of drivers. operating system

The support provided by the system to drivers is also roughly the same. These functions include: (1) read/write.

Almost all devices have inputs and outputs. Each driver is responsible for this device.

Other parts of the operating system do not need to know the specific read/write operation of the device.

How the write operation is completed is blocked by the driver. Operating system settings

The read-write interface is well defined, and the specific function is completed by the driver. At the start of the driver

At initialization, it is necessary to register the read/write function with the operating system. (2)

Interrupt plays an important role in modern computer structure, and the operating system must

Provides the driver with the ability to respond to interrupts. In general, please pay attention to the interrupt handler.

Volume into the system, the operating system calls the driver to handle after the hardware is interrupted.

Program. Linux supports interrupt sharing, that is, multiple devices share an interrupt. (3) Clock

When implementing drivers, clocks are used in many places, such as in some protocols.

Timeout processing, hardware polling without interruption mechanism, etc. The operating system should be a driver.

Sequence provides a timing mechanism, which is usually used when the registration is called back after a predetermined time.

Clock function.

There is not much difference between embedded Linux system driver development and ordinary Linux.

Don't. Due to the diversity of hardware, embedded devices are the default kernel version.

It is impossible to include all drivers. It can be on the hardware manufacturer or the Internet.

Go find the driver. If you can't find it, you can follow a driver similar to hardware.

Rewrite. The general process of realizing an embedded Linux device driver is as follows: (1) Fixed.

The primary device number and secondary device number can also be obtained dynamically; (2) Realize the functions of driver initialization and clearing.

No.,if the driver adopts module mode, it is necessary to realize the module initialization and clearing functions.

Number; (3) Design the file operation to be realized and define the structure of the file operation; (4) Reality

Now the required file operation calls, such as reading, writing, etc. (5) realizing the service interruption function,

And request irq to register with the kernel; (6) Compile the driver into kernel or module.

Block, loaded with insmod command; (7) Generate the equipment node file.

Compared with ordinary files, the operation of device files is much more complicated and impossible to be simple.

It is implemented by reading, writing and llseek. All other types of operations may

It is executed by calling ioctl through VFS, so it only needs to be implemented in the driver.

Now ioctl function, and add the corresponding case to it. Distinguish by cmd

Operation, passing parameters and results through arg.

2.2 Device driver development process

2.2. 1 device driver interface

Structure file _ operation IOdriver_fops=

{read: 1Odriver_read,

Write: IOdriver_write,

};

Key file operation structure in the driver interface of character device;

& ltLinux/fs . h & gt; The definition of is as follows:

Structure file _ operation {

Structure module * owner;

loft_t(*llseek)(struct file*,loff_t,int);

45

ssize_t(*read)(struct file*、char*、size_t、loft _ t);

ssize_t(*write)(struct file*,const char*,size_t, 1 off _ t *);

int(readdir struct inode*、struct file*、void*、fill dir _ t);

int(*select)(struct inode*,struct file*,int,select table *);

int(*ioct 1)(struct inode*、struct file*、unsigned int、unsigned int);

int(*mmap)(struct inode*、struct file*、struct VM _ area _ struct *);

int( *open)(struct inode*,struct file *);

Void(*release) (structure inode*, structure file *);

Int(*fsync) (structure inode*, structure file *);

};

2.2.2 Registration and cancellation module

2.2.2. 1 equipment registration module

Static int_nit IOdriver_init(void)

{ int ret=0:

Ret=register_chrdv(MAJOR_NUM, "IOdriver", & iodine Derive.

If (return)

{printk (kern _ alert "iDriver registration failed!" ) }

other

{printk (kern _ alert "iDriver registered successfully!" ) }

Return to ret

}

2.2.2.2 equipment logout module

Static int_exit IOdriver_exit(void)

{ int ret = 0;

ret=unregister_chrdv(MAJOR_NUM," io driver ");

If (return)

{printk(KERN_AL ERT"IOdriver logout failed! " ); }

other

{printk(KERN_AL ERT"IOdriver logout succeeded! ''); }

Return to ret

}

2.2.3 concrete realization of basic entry point equipment functions

2.2.3. 1 device reading module

Static ssize _ t iodriver _ read (struct file * file, char*buf, size_t len,

loft_t*off)

{ if(_ _copy_to_user(bur,& ampIOdriver_var,sizeof(int)))

{ retum _ EFAULT}

retum sizeof(int);

}

2.2.3.2 device write module

Static ssize _ t iodriver _ write (struct file * file, const char*buf, size _ t

len,loff_t*off)

{ if(_ _ copy _ from _ user(& amp; IOdriver_var,buf,sizeof(int)))

{ retum _ _ EFAULT}

retum sizeof(int);

}

2.2.4 Module Initialization and Module Exit Macros

module _ init(io driver _ init);

Module _ exit (iodriver _ exit);

3 the process of compiling the device driver into the kernel

The steps to compile the driver into the kernel are as follows:

(1) copy IOdriver.c to Linux-2.4.20-8/drivers/char and repair it.

Change the config.in file in this directory, which is the configuration script of each module.

Define the modules to be configured and how to configure them in this file, so that when adding

After the IO configuration is completed, the configuration options of this module will appear when the kernel is configured.

(2) Modify the Makefile in the current directory and put it in the Makefile of each module.

Include the submodules contained in this module, and include IO in the char device.

Device, you must tell Makefile to compile iDriver And contains the compiled iDriver.

C file, so that the kernel will link to this module when it links.

(3) Reconfigure the kernel, select the IO module to execute the command make menuconfig,

Enter the kernel configuration menu.

(4) recompile the kernel and update the kernel of the embedded target system.

(5) create a device file, restart the Linux of the embedded target system, and enter

Directory /proc, check the device files that list the current system.

Some character devices and block devices, including device numbers and device names, are listed in characters.

The last device to be migrated is: 254 IOdriver, that is, the id driver device.

Has been correctly loaded into the kernel.

(6) Add a device file node, and execute the following command to add a device file node.

The device name created here is used to access the corresponding device in the application. if

For character devices, the device number type is represented by C, and the block device is represented by B; primary device

Number is the device number of IOdriver in /proc/devices, because this device only has.

One, so the number of auxiliary equipment is 0. If there are other equipment of this type, it is once.

1, 2, 3 and so on.

5 concluding remarks

Device driver is the interface between operating system kernel and machine hardware. inside

The kernel uses the interface of the driver to initialize and release the device. In this system,

Data is transmitted between the kernel and the hardware, and errors in devices are always detected and handled. it

It is the most basic part of the operating system, so it is very important to be familiar with the writing of drivers.

Yes