Code reuse for 1.linux drives (with standard C programs): Static and dynamic reuse
2. If the Linux driver wants to use a third-party source code, it will have to compile multiple source code files and eventually build the. ko file or compile it into the Linux kernel
3. Using the FUN.C function in MAIN.C by using the extern keyword, use the functions in the product.c file by including the Product.h file
4. These two macros are used to identify the Linux driver initialization function (MAIN_INIT) and the Linux drive unload function, which are not required to use _init and _exit, but using them will improve the efficiency of the Linux drive. Because these two macros are actually compiled instructions
5. The most critical step is to write the makefile file code as follows
# Makefile obj-m: =multi_file_driver.o multi_file_driver-y:=main.c fun.c Product
6. There is a Build,sh script file in the Multi_file_driver directory that compiles and tests the examples in this section.
7. To uninstall the two Linux drivers in the reverse order, to uninstall Symboi_consumer before uninstalling Symbol_producer,
Enter # Lsmod|grep symbol to see the dependency between Symbol_prod ' UCE Cottage and Symbol_consumer.
The 8.depmod command is used to analyze dependencies between Linux modules, a feature that is useful for having complex dependencies between multiple Linux modules. After you have analyzed 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 based on the Linux module dependencies generated by the Depmod command. It is not necessary to load the Linux modules in the same way as with the Insmod command.
You first need to use the following command to generate Symbol_producer and Symbol_consumer dependencies.
#depmod/root/drivers/ch08/driver_shared/export_symbol/symbol_consumer.ko
/root/drivers/ch08/driver_shared/export_symbol/symbol_producer.ko
9. Forcibly uninstall Linux drivers
(1) Initialization function crash: Due to the initialization function of the Linux driver module (the function specified by the MODULE_INIT macro) crashes, the initialization function fails to return normally.
The key to this situation is that the value of the reference counter is inconsistent with the reference.
Adds 1 to the reference counter of the Linux driver that the module points to, returns 1 successfully, and 0 fails
static inline int try_module_get (struct module *module)
Subtract 1 from the reference counter of the Linux driver that the module points to
Externvoid module_put (struct module *module)
(2) The Unload function is blocked: When uninstalling the Linux driver using the Rmmod command, the system invokes the Unload function (the function specified by the MODU Le_exit macro), and the Linux driver is unloaded only if the Unload function is successfully returned to the elbow. If the Unload function is blocked (possibly a dead loop, The Rmmod command will also be blocked. That is, the code to uninstall the Linux driver module will never be executed. Simply replace the original unload function with an empty unload function.
Since the address of the module struct is in kernel space, it is only possible to write Linux drivers to unload another Linux driver.
10. Buzzer is also called PWM (pulse width modulation), the basic principle is to control the buzzer by pulse to open and stop. PWM uses port F's Gpfcon register for control. The macro corresponding to the register in the Linux kernel is S3c64xx_gpfcon, which represents the virtual address of the Gpfcon Register register. The Gpfcon only uses up to two bits (30 and 31 bits) to control the PWM, and when the maximum two bits is 10 o'clock, the PWM is switched on. Stop the PWM for 00 o'clock. So you only need to set different values for the Gpfcon register by using the IOWRITE32 function.
11. Test Buzzer Driver:
First enter the/root/drivers/ioct1 directory, execute the build.sh script file to compile and upload the Ioct1 file.
Open pwm:#./ioctl/dev/pwm_dev 1 0
Stop pwm:#./ioctl/dev/pwm_dev 0 0
Eighth Chapter buzzer Driver