《Linux Device Drivers》第十一章 核心数据类型——note
- 基本介绍
- 因为Linux多平台特性,不管是哪一个重要驱动力应该是便携
- 与内核代码相关的核心问题应该是访问的同时是数据项的已知长度。能力和利用不同的处理器
- 内核使用的数据类型主要分为三类
- 类似int这种标准C语言类型
- 类似u32这种有确定大小的类型
- 像pid_t这种用于特定内核对象的类型
- 本章将讨论在什么情况下使用这三种类型以及怎样使用
- 使用标准C语言类型
- 当我们须要“两个字节的填充符”或者“用四个字节字符串表示的某个东西”时。我们不能使用标准类型,由于在不同的体系架构上。普通C语言的数据类型所占空间在大小并不同样
- 内核中的普通内存地址一般是unsigned long。在当前Linux支持的全部平台上,指针和long整形的大小总是同样的
- C99标准定义了intptr_t和uintptr_t类型,它们是可以保存指针值的整形变量
- 为数据项分配确定的空间大小
- <asm/types.h>
- <linux/types.h>
- u8, s8
- u16, s16
- u32, s32
- u64, s64
- 假设一个用户空间程序须要使用这些类型,它能够在名字前加上两个下划线作为前缀
- __u8
- __u32
- 使用新编译器的系统将支持C99标准类型,如uint8_t和uint32_t
- 接口特定的类型
- 内核中最经常使用的数据类型由它们自己的typedef声明。这样能够防止出现不论什么移植性问题
- “接口特定(interface-specific)”是指由某个库定义的一种数据类型,以便为某个特定的数据结构提供接口
- 完整的_t类型在<linux/types.h>中定义
- _t数据项的主要问题是在我们须要打印它们的时候,不太easy选择正确的printk或者printf的输出格式
- 其它有关移植的问题
- 一个通用的原则是要避免使用显式的常量值
- 时间间隔
- 使用jiffies计算时间间隔的时候,应该用HZ来衡量
- 页大小
- 内存页的大小是PAGE_SIZE字节
- PAGE_SHIFT
- <asm/page.h>
- getpagesize库函数
- get_order函数
- 字节序
- <asm/byteorder.h>
- __BIG_ENDIAN
- __LITTLE_ENDIAN
- u32 cpu_to_le32 (u32);
- u32 le32_to_cpu(u32);
- be64_to_cpu
- le16_to_cpus
- cpu_to_le32p
- <asm/byteorder.h>
- 数据对齐
- <asm/unaligned.h>
- get_unaligned(ptr);
- put_unaligned(val, ptr);
- <asm/unaligned.h>
- 指针和错误值
- 很多内核接口通过把错误值编码到一个指针值中来返回错误信息
- <linux/err.h>
- void *ERR_PTR(long error);
- long IS_ERR(const void *ptr);
- long PTR_ERR(const void *ptr);
- 链表
- <linux/list.h>
- struct list_head
- struct list_head *next, *prev;
- INIT_LIST_HEAD(&list);
- LIST_HEAD(list);
- list_add(struct list_head *new, struct list_head *head);
- list_add_tail(struct list_head *new, struct list_head *head);
- list_del(struct list_head *entry);
- list_del_init(struct list_head *entry);
- list_move(struct list_head *entry, struct list_head *head);
- list_move_tail(struct list_head *entry, struct list_head *head);
- list_empty(struct list_head *head);
- list_splice(struct list_head *list, struct list_head *head);
- list_entry(struct list_head *ptr, type_of_struct, field_name);
- list_for_each(struct list_head *cursor, struct list_head *list)
- list_for_each_prev(struct list_head *cursor, struct list_head *list)
- list_for_each_safe(struct list_head *cursor, struct list_head *next, struct list_head *list)
- list_for_each_entry(type *cursor, struct list_head *list, member)
- list_for_each_entry_safe(type *cursor, type *next, struct list_head *list, member)
- struct list_head
- <linux/list.h>
版权声明:本文博客原创文章,博客,未经同意,不得转载。
《Linux Device Drivers》第十一章 核心数据类型——note的更多相关文章
- 《Linux Device Drivers》第八章 分配内存——note
本章主要介绍Linux内核的内存管理. kmalloc函数的内幕 不正确所获取的内存空间清零 分配的区域在物理内存中也是连续的 flags參数 <linux/slab.h> <lin ...
- 《Linux Device Drivers》第十四章 Linux 设备型号
基本介绍 2.6内核设备模型来提供的抽象叙述性描述的一般系统的结构,为了支持各种不同的任务 电源管理和系统关机 用户空间与通信 热插拔设备 设备类型 kobject.kset和子系统 kobject是 ...
- 《Linux Device Drivers》第十二章 PCI司机——note
一个简短的引论 它给这一章总线架构的高级概述 集中访问讨论Peripheral Component Interconnect(PCI,外围组件互连)外设内核函数 PCI公交车是最好的支持的内核总线 本 ...
- 《Linux Device Drivers》 第十七章 网络驱动程序——note
基本介绍 第三类是标准的网络接口Linux设备,本章介绍的内核,其余的交互网络接口描述 网络接口,必须使用特定的内核数据结构本身注册,与外部分组交换数据线打电话时准备 经常使用的文件上的网络接口操作是 ...
- 《Linux Device Drivers》第十五章 内存映射和DMA——note
简单介绍 很多类型的驱动程序编程都须要了解一些虚拟内存子系统怎样工作的知识 当遇到更为复杂.性能要求更为苛刻的子系统时,本章所讨论的内容迟早都要用到 本章的内容分成三个部分 讲述mmap系统调用的实现 ...
- 《Linux Device Drivers》第十六章 块设备驱动程序——note
基本介绍 块设备驱动程序通过主传动固定大小数据的随机访问设备 Linux核心Visual块设备作为基本设备和不同的字符设备类型 Linux块设备驱动程序接口,使块设备最大限度地发挥其效用.一个问题 一 ...
- 《Linux Device Drivers》第十八章 TTY驱动程序——note
简单介绍 tty设备的名称是从过去的电传打字机缩写而来,最初是指连接到Unix系统上的物理或虚拟终端 Linux tty驱动程序的核心紧挨在标准字符设备驱动层之下,并提供了一系列的功能,作为接口被终端 ...
- 《Linux Device Drivers》第十章 中断处理——note
概述:系统要及时的感知硬件的状态,通常有两种方式:一种是轮询.一种是通过响应硬件中断.前者会浪费处理器的时间,而后者不会. 准备并口 在没有节设定产生中断之前,并口是不会产生中断的 并口的标准规定设置 ...
- linux device drivers ch03
ch03.字符设备驱动程序 编写驱动程序的第一步就是定义驱动程序为用户程序提供的能力(机制).接下来以scull(“Simple Character Utility for Loading Local ...
随机推荐
- Android Studio SVN使用和VisualSVN-Server配置(图解)
转载请标明出处: http://blog.csdn.net/zq2114522/article/details/51078544: 本文出自:[梁大盛的博客] Android Studio SVN使用 ...
- oracle 之 COMMENT 分类: H2_ORACLE 2014-04-24 15:30 386人阅读 评论(0) 收藏
http://blog.csdn.net/liguihan88/article/details/3002403 无疑注释现在都被大家接受和认可,在大家编程用的IDE中都提供或有第三方插件来支持提取注释 ...
- Java并发包探秘 (一) ConcurrentLinkedQueue
本文是Java并发包探秘的第一篇,旨在介绍一下Java并发容器中用的一些思路和技巧,帮助大家更好的理解Java并发容器,让我们更好的使用并发容器打造更高效的程序.本人能力有限,错误难免.希望及时指出. ...
- 嵌入式linux串口通信自发自收测试程序
/*串口自收自发程序主函数*/#include"uart_api.h"int main(){ int fd; char buff[BUFFER_SIZE]; char buff2 ...
- [Angular] Enable router tracing
To enable router tracing is really simple: RouterModule.forRoot(ROUTES, { enableTracing: true }) Whe ...
- js动态获取地址栏后的参数
原文链接:https://blog.csdn.net/qq_37936542/article/details/78866651 需求:js动态的获取地址栏后面的参数 js代码: alert(GetQu ...
- js如何使用正则表达式验证电话号码(可选区号)和邮箱?(分步骤)
js如何使用正则表达式验证电话号码(可选区号)和邮箱?(分步骤) 一.总结 js进阶正则表达式16电话号码和邮箱正则(分类解决邮箱验证)(分组加?解决电话号码区号选择问题)([\w\.-]中括号解决邮 ...
- Procedural graphics architectures and techniques
BACKGROUND The evolution of graphics rendering technology has led to the development of procedural t ...
- wpf SnapsToDevicePixels
原文:wpf SnapsToDevicePixels 可以在您的根元素上将此属性设为 true,以在整个 UI 上启用像素对齐呈现. 对于运行在大于 96 每英寸点数 (dpi) 的设备,像素对 ...
- Lua转让C功能
在上一篇文章中(C调用lua函数)中.讲述了怎样用c语言调用lua函数,通常,A语言能调用B语言,反过来也是成立的.正如Java 与c语言之间使用JNI来互调.Lua与C也能够互调. 当lua调用c函 ...