Seventh Reading notes

Source: Internet
Author: User

The implementation principle of LED driver:

The Linux kernel provides several functions that interact with I/O memory, and the kernel management module for Linux is responsible for the data in the I/O memory and hardware.

Every hardware that connects to Linux has a mapped address in memory, and the LEDs on the board have their first address.

Steps to create a device file:

The first step uses the Cdev_init function to initialize the Cdev

The second step specifies the device number

The third step uses the Cdev_add function to add the character device to the character device array in the kernel

Fourth step create a struct class using the Class_create macro

The fifth step is to create a device file using the Device_create function.

LED drivers can control LEDs in two ways:

(1) control led via string

(2) led control via LED

Here are a few things to keep in mind when writing code:

(1) The status of 4 LEDs (light and off) is stored with a char array of length 4,

(2) If the written string length is less than equal to 4, write these strings directly if the string length is greater than four write the first 4 characters.

(3) Since the prior mem array has been zeroed, if the length of the written string is less than 4, then the equivalent of the subsequent character is 0.

(4) It is better to read the current value of the Gpmdat register before Gpmdat register to write the data, and to retain the value unrelated to this operation by bitwise AND, bit or etc.

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.