Eighth Chapter buzzer Driver

Source: Internet
Author: User

Main look: Linux driver code reuse

    1. Compilation is a Linu x driver consisting of multiple files

For complex Linux drivers, it is necessary to use multiple source code files to store different function codes, which facilitates code categorization and management.

When compiling multiple source code files in the C or C + + language, if A.C uses the functions in the B.C file, you need to use extern to pre-define the functions in B.C in the A.c file, and extern is to tell the compiler the function name, the number of arguments, the parameter type, and the return value type. This information is compiled into A.O for A.C. It's enough. When you link A.O and b.o to an executable file or library, the compiler then looks for a specific implementation of the function in B.O, that is, extern only works in the compile phase.

In addition, if the Linux driver has only 1 source code files in makefile, the value of the OBJ-M variable can be the same as the source code file. For example, the source code file is MAIN.C, and the value of Obj-m is MAIN.O. If the Linux driver contains multiple files now, you need to use module-y C or MODULE-OBJS to specify the destination file. You cannot specify only the referenced target file.

After compiling makefile-----à input su builed.sh-----àdmesg.

2.Linux Driver Module dependencies (export symbols)

(1) Code reuse is divided into two types: static and dynamic. The approach described above is static reuse of code, which is a code-level reuse that compiles the code that needs to be reused and the user who uses the code, eventually generating an executable file or library (. Ko,. So, and so on).

Another way of sharing code: module dependencies, also known as export symbols. If you can only use a sentence to explain how to use the export symbols to implement the code, this sentence is "in one drive module using another driver module in the exported symbols (constants, variables, functions, etc.)"

(2) You can use the following two macros to export a function in Linux driver.

Export_symbol (symbol name)

EXPORT_SYMBOL_GPL (symbol name) "EXPORT_SYMBOL_GPL is only used in Linux driver modules with GPL protocol"

(3) Enter the following command to view the Symbol_producer-driven exported symbols from the/proc/kallsyms file.

cat/proc/kallsyms I grep symbol_producer

Note: Before you install Symbol_consumer, you need to install Symbol_producer, which is the reverse of the order of two Linux drivers to uninstall. You need to uninstall Symboi_consumer before uninstalling Symbol_producer.

Enter the following command to see the dependency between Symbol_prodoucer and Symbol_consumer: Lsmod I grep symbo1.

(4) Depmod and Modprobe commands. Where the Depmod command is used to analyze dependencies between Linux modules, this feature is useful for having complex dependencies between multiple Linux modules. After analyzing the dependencies of the Linux modules using Depmod, you can use the modprobe command to load the Linux modules. The modprobe command loads the Linux modules entirely according to the Linux module dependencies generated by the Depmod command, and does not need to load the Linux modules in the same way as with the Insmod command.

Eighth buzzer driver

Related Article

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.