Andriod Deep Exploration of-hal and Driver Development Chapter Seventh reading notes

Source: Internet
Author: User

Creating LED-driven device files

1th Step: Initialize the Cdev with the Cdev_init function

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

3rd Step: Use the Cdev_add function to add the character device to the character device array in the kernel

4th step: 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 the Device_destroy, Class_destroy, and Unregister_chrdev_region methods in turn

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 LEDs via 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 LED is 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.

Andriod Deep Exploration of-hal and Driver Development Chapter Seventh reading notes

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.