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