广州品牌网站建设,百度搜索广告怎么收费,重庆商城网站制作报价,做振动盘的企业网站1.练习课上代码
2.把设备树信息解析相关函数按照自己的理解发布CSDN
3.复习中断相关内核 IO多路复用---epoll 核心内容#xff1a;一棵树一个链表三个方法 epoll会将要监听的事件文件描述符添加到内核里一颗红黑树上#xff0c;当有事件发生#xff0c;epoll会调用回调函数…1.练习课上代码
2.把设备树信息解析相关函数按照自己的理解发布CSDN
3.复习中断相关内核 IO多路复用---epoll 核心内容一棵树一个链表三个方法 epoll会将要监听的事件文件描述符添加到内核里一颗红黑树上当有事件发生epoll会调用回调函数将发生事件的文件描述符添加到存放的链表中程序中只需要判断这个表是否为空即可知道是否有事件发生然后针对表中的文件描述符进行IO操作即可。 一棵电路板上CPU、总线、设备组成的树 dtb文件会在内存中一直存在着不会被内核或者应用程序占用我们需要使用的时候可以直接使用dtb文件。dtb文件的内容会被解析生成多个device_node然后这些device_node构成一棵树, 根节点为: of_root 1.双亲表示法 2.孩子表示法 3.孩子兄弟表示法 自动换行 #include sys/epoll.h 1. int epoll_create(int size) 功能创建一个epoll建立红黑树 2. int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) 功能epoll的操作函数 3.int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout); 功能阻塞等待事件就绪 stdio.h sys/types.h sys/stat.h sys/wait.h fcntl.h sys/select.h sys/time.h sys/epoll.h unistd.h stdlib.h string.h #includestdio.h #include sys/types.h #include sys/stat.h #include sys/wait.h #include fcntl.h #include sys/select.h #include sys/time.h #include sys/epoll.h #include unistd.h #include stdlib.h #includestring.h stdio.h是stand input output的缩写意思是标准输入输出头文件。凡是用到标准输入输出函数就要调用该头文件。 查看stdio.h目录下包含哪些函数主要有文件访问、二进制输入/输出、格式化和非格式化输入/输出、文件定位、错误处理、文件操作等。 具体打开自己的VS安装目录找到include文件夹打开include夹下面的stdio.h文件即可查看 常用标准输入输出函数 scanf() 从屏幕格式输入 printf() 格式输出到屏幕 getchar() 从屏幕得到一个字符 putchar() 字符输出到屏幕 gets() 从屏幕得到一个字符串 puts() 字符串输出到屏幕 fscanf() 从磁盘格式输入 fprintf() 格式输出到磁盘 fgetc() 从磁盘得到一个字符 fputc() 字符输出到磁盘 fgets() 从磁盘得到一个字符串 fputs() 字符串输出到磁盘 #号是预处理语句表明在编译之前预先进行处理。 .h是header file的缩写表面这是一个头文件。 include是文件包含命令后面跟着引号或者尖括号意思是将引号或尖括号内指定的文件包含到本程序中成为本程序的一部分而包含的文件通常是由系统提供的。 区分引号或者尖括号尖括号编译程序会先到标准函数库中找文件引号编译程序会先从当前目录中找文件。 #include sys/types.h 基本系统数据类型 是Unix/Linux系统的基本系统数据类型的头文件含有size_ttime_tpid_t等类型。 NAME sys/types.h - data typesSYNOPSIS (简要说明) #include sys/types.hDESCRIPTION 描述 The sys/types.h header shall include definitions for at least the following types: 以下类型 blkcnt_t Used for file block counts. blksize_t Used for block sizes. clock_t Used for system times in clock ticks or CLOCKS_PER_SEC; see time.h . clockid_t Used for clock ID type in the clock and timer functions. dev_t Used for device IDs. fsblkcnt_t Used for file system block counts. fsfilcnt_t Used for file system file counts. gid_t Used for group IDs. id_t Used as a general identifier; can be used to contain at least a pid_t, uid_t, or gid_t. ino_t Used for file serial numbers. key_t Used for XSI interprocess communication. mode_t Used for some file attributes. nlink_t Used for link counts. off_t Used for file sizes. pid_t Used for process IDs and process group IDs. size_t Used for sizes of objects. ssize_t Used for a count of bytes or an error indication. suseconds_t Used for time in microseconds. time_t Used for time in seconds. timer_t Used for timer ID returned by timer_create(). trace_attr_t Used to identify a trace stream attributes object. trace_event_id_t Used to identify a trace event type. trace_event_set_t Used to identify a trace event type set. trace_id_t Used to identify a trace stream. uid_t Used for user IDs. useconds_t Used for time in microseconds. All of the types shall be defined as arithmetic types of an appropriate length, with the following exceptions: key_t Additionally: * mode_t shall be an integer type. * nlink_t, uid_t, gid_t, and id_t shall be integer types. * blkcnt_t and off_t shall be signed integer types. * fsblkcnt_t, fsfilcnt_t, and ino_t shall be defined as unsigned integer types. * size_t shall be an unsigned integer type. * blksize_t, pid_t, and ssize_t shall be signed integer types. * time_t and clock_t shall be integer or real-floating types. dts 设备树源文件 dtc 设备树编译 dtb 二进制设备树镜像 dtsi 功能类似设备树文件的头文件 流程为 dts dtb device_node platform_device 什么是设备树 (1)设备树(dt:device tree)是linux内核采用的参数表示和传递技术在系统引导启动阶段进行设备初始化的时候将设备树中描述的硬件信息传递给操作系统 (2)dts(device tree source)设备树源文件描述设备信息的 (3)dtc(device tree compiler)设备树编译/反编译/调试工具 (4)dtb(device tree binary)二进制设备树镜像 (5)dtsi(device tree source include):功能类似设备树文件的头文件可以被dts文件通过include引用dtsi文件一般是描述共性部分设备树的加载流程 dts文件经过dtc工具编译为dtb内核加载并解析dtb文件最终获得设备树的信息 在dts文件中在根节点中有一个compatible属性该属性的值是一系列的字符串比如compatible “samsungsmdk2440”“samsung,smdk2410,samsungsmdk24xx”;该属性就是告诉内核要选择什么样的machine_desc因为machine_desc结构体中有一个dt_compat成员该成员表示machine_desc支持哪些单板所以内核会把compatible中的字符串与dt_compat进行依次比较。 一、dts产生原因DTS即Device Tree Source 设备树源码, DeviceTree是一种描述硬件的数据结构它起源于OpenFirmware (OF)。
它替代arch/arm/plat-xxx和arch/arm/mach-xxx中的板级spec代码便于code管理。 本质上Device Tree改变了原来用hardcode方式将HW配置信息嵌入到内核代码的方法改用bootloader传递一些参数。 如果我们认为kernel是一个black box那么其输入参数应该包括 a.识别platform的信息 b. runtime的配置参数 c.设备的拓扑结构以及特性 对于嵌入式系统在系统启动阶段bootloader会加载内核并将控制权转交给内核此外还需要把上述的三个参数信息传递给kernel以便kernel可以有较大的灵活性。在linux kernel中Device Tree的设计目标就是如此。 2.1 dts加载过程 如果要使用Device Tree首先用户要了解自己的硬件配置和系统运行参数并把这些信息组织成Device Tree source file。通过DTCDevice Tree Compiler可以将这些适合人类阅读的Device Tree source file变成适合机器处理的Device Tree binary file有一个更好听的名字DTBdevice tree blob。在系统启动的时候boot program例如firmware、bootloader可以将保存在flash中的DTB copy到内存当然也可以通过其他方式例如可以通过bootloader的交互式命令加载DTB或者firmware可以探测到device的信息组织成DTB保存在内存中并把DTB的起始地址传递给client program例如OS kernelbootloader或者其他特殊功能的程序。对于计算机系统computer system一般是firmware-bootloader-OS对于嵌入式系统一般是bootloader-OS。 2.2 dts描述信息 Device Tree由一系列被命名的结点node和属性property组成而结点本身可包含子结点。所谓属性其实就是成对出现的name和value。在Device Tree中可描述的信息包括原先这些信息大多被hard code到kernel中 CPU的数量和类别 内存基地址和大小 总线和桥 外设连接 中断控制器和中断使用情况 GPIO控制器和GPIO使用情况 Clock控制器和Clock使用情况 一棵电路板上CPU、总线、设备组成的树 .dts文件是一种ASCII 文本格式的Device Tree描述此文本格式非常人性化适合人类的阅读习惯。基本上在ARM Linux在一个.dts文件对应一个ARM的machine一般放置在内核的arch/arm/boot/dts/目录。由于一个SoC可能对应多个machine一个SoC可以对应多个产品和电路板势必这些.dts文件需包含许多共同的部分Linux内核为了简化把SoC公用的部分或者多个machine共同的部分一般提炼为.dtsi类似于C语言的头文件。其他的machine对应的.dts就include这个.dtsi。 dtb文件会在内存中一直存在着不会被内核或者应用程序占用我们需要使用的时候可以直接使用dtb文件。dtb文件的内容会被解析生成多个device_node然后这些device_node构成一棵树, 根节点为: of_root 设备树中的每一个节点都会被转换为device_node结构体 那么多的device_node哪些会被转化为platform_device呢 根节点下的子节点且该子节点必须包含compatible属性 如果一个节点的compatile属性含有这些特殊的值(“simple-bus”,“simple-mfd”,“isa”,“arm,amba-bus”)之一那么它的子结点(需含compatile属性)也可以转换为platform_device。 内核提供了一些API来直接获取设备树中对应的属性。如 of_property_read_u32_index获取设备树中某个属性的值of_property_read_string获取设备树中某个属性的字符串的值of_get_address获取设备树中的某个节点的地址信息头文件 a. 处理DTBof_fdt.h // dtb文件的相关操作函数, 我们一般用不到, 因为dtb文件在内核中已经被转换为device_node树(它更易于使用) b. 处理device_nodeof.h // 提供设备树的一般处理函数, 比如 of_property_read_u32(读取某个属性的u32值), of_get_child_count (获取某个 device_node的子节点数)of_address.h // 地址相关的函数, 比如 of_get_address(获得reg属性中的addr, size值)of_match_device(从matches数组中取出与 当前设备最匹配的一项)of_dma.h // 设备树中DMA相关属性的函数of_gpio.h // GPIO相关的函数of_graph.h // GPU相关驱动中用到的函数, 从设备树中获得GPU信息of_iommu.h // 很少用到of_irq.h // 中断相关的函数of_mdio.h // MDIO (Ethernet PHY) APIof_net.h // OF helpers for network devices.of_pci.h // PCI相关函数of_pdt.h // 很少用到of_reserved_mem.h // reserved_mem的相关函数 c. 处理 platform_deviceof_platform.h // 把device_node转换为platform_device时用到的函数, // 比如of_device_alloc(根据device_node分配设置platform_device), // of_find_device_by_node (根据device_node查找到platform_device), // of_platform_bus_probe (处理device_node及它的子节点)of_device.h // 设备相关的函数, 比如 of_match_device