ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

Johannes 《Linux内核模块与设备驱动开发:编写Linux驱动程序》 (14-19)设备树相关

Johannes 《Linux内核模块与设备驱动开发:编写Linux驱动程序》 (14-19)设备树相关 视频https://www.bilibili.com/video/BV18SE26cEjn?vd_source92b7efa4daa5bb4fdcdc9f2db97c307bp14lesson13后面的视频是说设备树和misc 设备感觉设备树讲的不太好没有基础的估计完全看不懂而且这个系列没有说中断DMASPIUARTIIC等也没说网络设备和块设备值得称道的是源码例子非常浅显。设备树lesson14 说了下设备树基本概念。linux 官方解释了设备树的三大目的Linux and the Devicetree — The Linux Kernel documentationLinux uses DT data for three major purposes:platform identification,runtime configuration, anddevice population.也就是定义识别设备/总线读取设备树配置设备生成设备信息。我的理解是设备树是描述硬件状态的一个文件它的语法类似json需要更多了解下设备树语法。一般官方会给出一个设备树模板自己根据情况修改。比如之前给zynq的linux 写个system_user.dtsi,要写个mcp2518fd的设备树xilinx 官方 内核提供了设备树模板文件microchip,mcp251xfd.yamlexamples: - | #include dt-bindings/gpio/gpio.h #include dt-bindings/interrupt-controller/irq.h spi { #address-cells 1; #size-cells 0; can0 { compatible microchip,mcp251xfd; reg 0; clocks can0_osc; pinctrl-names default; pinctrl-0 can0_pins; spi-max-frequency 20000000; interrupts-extended gpio 13 IRQ_TYPE_LEVEL_LOW; microchip,rx-int-gpios gpio 27 GPIO_ACTIVE_LOW; vdd-supply reg5v0; xceiver-supply reg5v0; }; };这个设备树有头文件 dt-bindings/gpio/gpio.hdt-bindings/interrupt-controller/irq.h所以自己写的时候要加进去zynq 里面基本可以不考虑pin_ctrl因为vivado里面配置zynq的时候已经给spi总线设置好了IO口各种属性了。然后写zynq system_user.dtsi 是overlay的lesson15解释了overlay),所以这个SPI调用的时候SPI总线节点需要给它加上号根据硬件原理图就是SPI1然后例子里面的can0_osc 这个需要自己写个对应的根节点。所以我就先参考官方的例子Device Tree Tips - AMD Adaptive Computing Wiki - Confluence给晶振clock 说明写好一个clocks对应的晶振osc:osc: oscillator { //节点osc,别名 oscillatorcompatible fixed-clock; //这个看厂家我找的zynq的选择是 fixed-clock#clock-cells 0;clock-frequency 40000000; //晶振频率40MHZclock-output-names osc;};然后spi总线SPI1里面调用这个osc, clocks osc;最后设备MCP2518FD的设备树自己写了如下spi1{#address-cells 1;#size-cells 0;status okay;canfd0{compatible microchip,mcp2518fd;reg 0;clocks osc;spi-max-frequency 20000000;interrupt-parent gpio0;interrupts-extended gpio0 62 IRQ_TYPE_LEVEL_LOW;microchip,rx-int gpio0 61 GPIO_ACTIVE_LOW;};};同时内核进行相应的裁减操作这样驱动读取设备树文件dtsi就知道SPI总线用的是40Mhz的时钟晶振spi 的sclk 20MHZ,中断用的是哪个IO口。总而言之PCB 软件用画原理图来表明这个设备的情况设备树是通过语言的方式描叙硬件的状态。具体设备树怎么写一般下载内核后在DOCUMENT下面查找各个内核的设备树照说明写。要自己写驱动写好设备树之后让自己的驱动读取它来工作可以看看视频lesson17,lesson18了解。视频里面的代码那些都不放了。感觉大同小异。看视频和git,了解即可。搜索看到Johannes还有个UP传送了另一个系列的他的linux 内核视频系列 ://www.bilibilhttps://www.bilibili.com/video/BV1CNJc64Esv/?vd_source92b7efa4daa5bb4fdcdc9f2db97c307b内容挺丰富的1. Simple Kernel Module2. Device Numbers and Device Files3. Create device file in driver and callbacks4. GPIO Driver5. Text LCD Driver6. PWM Module7. Temperature Sensor (I2C)8. Timer in Linux Kernel Modules9. High Resolution Timer in Linux Kernel Modules10. Accessing SPI with a Linux Kernel Module (BMP280 sensor again)11. Using a GPIO Interrupt in a Linux Kernel Module12. Using Parameters in a Linux Kernel Module13. IOCTL in a Linux Kernel Module14. Threads in a Linux Kernel Module15. Sending a signal from a Linux Kernel Module to an userspace application16. The poll callback17. Waitqueues in a Linux Kernel Module18. Create procfs entries from a Linux Kernel Module19. Create sysfs entries from a Linux Kernel Module20. Parse the device tree from a Linux Kernel Module to get the deivce properties of a specific device21. Device Tree GPIO Driver22. Device Tree Driver for I2C Device23. Dynamical memory management in a Linux Kernel module24. Serial (UART) Driver25. Industrial IO compatible driver for an ATMEGA I2C ADC26. Device Tree SPI Driver (IIO compatible driver for Atmega SPI ADC)27. Misc Device28. Mutex for exclusive access to shared resource29. Completions for synchronisation30. Direct Memory Access (DMA) memcopy example31. Accessing files form a Linux Driver32. The mmap callback33. Linked Lists34. Registering device numbers, read and write callback in character devices Take 235. Private Data in struct file36. I2C Device Driver without Device Tree37. Sysfs Class38. Kernel Log levelsgit 上面有程序资源B站评论区有。
返回列表