Andriod Deep Exploration of-hal and Driver development Seventh Chapter reading notes and a little experience

Source: Internet
Author: User

Creating LED -driven device files

Step 1 : Initialize the cdev with the cdev_init function

Step 2 : Specify the device number. Assign directly in code or dynamically

Step 3 : Use the cdev_add function to add a character device to a character device array in the kernel

Step 4 : Create a struct class using the class_create Macro

5th Step: Create a device file using the Device_create function

Uninstalling LED -driven device files

You need to call Device_destroy,Class_destroy , and unregister_chrdev_region in turn Method

void Device_destroy (struct class *class, dev_t devt)

void Class_destroy (struct class *cls)

void Unregister_chrdev_region (dev_t from, unsigned count)

Control LED

LED drivers can control LEDs in two different ways:

1. control The LEDsvia a string.

2. Control the LEDs with the I/O command .

To control LEDs, use both of these methods. the LED driver must receive the corresponding data. If the LEDis controlled by a string. you need to use the File_operations.write function. If the LEDs are controlled through the I/O command , you need to use the file_operations.ioctl function.

Porting Linux Drivers is a very important one. is to modify the Linux driver source code, you should try not to modify the Linux driver interface.

This chapter focuses on LED drivers, a Linux driver that really deals with hardware. Although the LED driver is not complicated, it only controls a few LEDs, but the LED driver already includes all the necessary parts of the Linux drive. A complete Linux driver consists of two parts: internal processing and hardware interaction. The internal processing mainly refers to the Linux driver loading, unloading, and device file-related action processing (read and write device files, send I/O commands to the device file), as well as business logic. The porting of Linux drivers on different platforms is also handled in these two parts.

My blog address: http://home.cnblogs.com/u/jie617530/

Andriod Deep Exploration of-hal and Driver development Seventh Chapter reading notes and a little experience

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.