Android Deep Explore (Vol. 1) HAL and Driver development reading experience 8

Source: Internet
Author: User

PWM Buzzer Driver

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 sufficient for compiling A.C into A.O, and when the A.O and B.O are linked 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, you can use the B.h file to define functions in B.C, and then include B.h files in A.C. You can omit the extern keyword for some c/+ + compilers. However, in order to be more general, it is recommended to add extern.

If you are writing a Linux driver that is logically correct, it can be loaded and unloaded normally, but in some cases, some programs may have unusual conditions. The Linux driver may not uninstall properly.

For Linux drivers with partial exception conditions forcibly unloaded:

Scenario 1: Initialization function crashes

The key to this situation is that the value of the reference counter is inconsistent with the reference. In fact, the reference does not exist, so you only need to clear the current Linux Driver module reference counter 0. The following two functions can be used to modify a reference counter.

static inline int try_module_get (struct module *module)

extern void Module_put (struct module *module)

Scenario 2: The Unload function is blocked

The problem with this situation is the Unload function, so just replace the original unload function with an empty unload function.

In either case, an unavoidable problem is to get a pointer to the module struct that represents the Linux driver module to unload. Because the struct module represents information about the Linux driver.

cat/proc/kallsyms | grep _this_module | grep bad_driver1

The principle of the buzzer drive:

Drive Key Code:

Android Deep Explore (Vol. 1) HAL and Driver development reading experience 8

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.