
Linux驱动开发
gwKismit
不要想太多,只要有一点灵感就赶紧行动吧,没有什么失败是不可承受的,没有什么成功是一触而就的!
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
驱动模板
#include #include #include #include #include MODULE_LICENSE("GPL"); //声明本驱动遵循GPL协议 /*加载模块*/ static int XXX_init() { return 0; } /*卸载模块*/ static void XXX_exit() {原创 2016-04-11 21:45:20 · 381 阅读 · 0 评论 -
中断分层
一。中断部分 1.中断申请函数 request_irq int request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags, const char *name, void *dev) 输入参数:中断号 中断处理函数 中断类型 设备名字 返回给中断处理函数的设备号 成功返回0 失败返回错误代码原创 2016-07-21 17:15:09 · 368 阅读 · 0 评论 -
定时器timer
1.定义一个timer,定时器中断函数fun struct timer_list timer; void fun(); 2.先初始化timer init_timer(&timer); then 对timer的相关参数赋值: timer.function = fun; timer.expires = jiffies + TIMER_DELAY; 3.注册定时器 ad转载 2016-07-21 17:14:13 · 392 阅读 · 0 评论 -
设备驱动模型:总线bus_type 设备device 驱动driver
一.总线 bus_type 数据结构 struct bus_type{ const char *name; //总线类型的名称 struct bus_attribute *bus_attrs; struct device_attribute *dev_atrrs; struct driver_attribute *drv_attrs; int (*match) (stru原创 2016-07-14 16:13:34 · 1147 阅读 · 0 评论 -
中断与时钟机制
一.中断 IRQ 中断安装与释放 1.申请中断线 int request_irq(unsigned int irq,irq_handler_t handler,unsigned long irqflags,const char *devname,void *dev_id) 中断号 中断处理函数 中断触发方式 设备名称 共用中断信号线时使用到(一般设备为NULL) 一般在init函数中设置原创 2016-07-13 17:21:24 · 583 阅读 · 0 评论 -
printk 消息打印级别
KERN_EMERG 紧急消息,常常是那些崩溃前的消息 KERN_ALTER 需要立即动作的情形 KERN_CRIT 严重情况,常常与严重的硬件或者软件失效有关 KERN_ERR 报告错误使用,常用于报告硬件故障 KERN_WARNING 有问题的警告,这些情况自己不会引起系统的严重问题 KERN_NOTICE 正常情况,警告一些安全情况原创 2016-07-13 17:20:26 · 358 阅读 · 0 评论 -
阻塞和非阻塞
1. 非阻塞non-block --select int select(int nfds,fd_set *readfds,fd_set *writefds,fd_set *exceptfds,struct timeval *timeout) 参数:最大fd 可读 可写 异常 超时 超时参数:秒 微妙 struct timeval { long tv_sec; long tv原创 2016-07-13 17:19:03 · 457 阅读 · 0 评论 -
完成量:线程同步
作用:一个线程发送信号通知另一个线程开始执行某个任务 #include struct completion{ unsigned int done; wait_queue_head_t wait; } done 0:等待 >0:可执行 wait 等待队列 定义和初始化完成量 定义 struct completion com; 初始化init原创 2016-07-13 17:16:52 · 325 阅读 · 0 评论 -
锁机制:自旋锁spinlock和信号量semaphore
作用:避免竞争 一. 自旋锁 使用步骤: 1.定义自旋锁 spinklock_t lock; 2.初始化自旋锁 spin_lock_init(&lock); 3.获得自旋锁 spin_lock(&lock); 4.释放自旋锁 spin_unlock(&lock); spin_lock [如果获得lock则立即返回,否则将自旋在那里直到其他线程释放] 临界资源原创 2016-07-13 17:15:39 · 1739 阅读 · 0 评论 -
file_operation
struct file_operations ***_ops={ .owner = THIS_MODULE, .llseek = ***_llseek, .read = ***_read, .write = ***_write, .ioctl = ***_ioctl, .open = ***_open, .release = ***_release, }原创 2016-07-13 17:13:37 · 271 阅读 · 0 评论 -
platform_driver平台设备驱动模型
一。平台设备 platform_device 结构 struct platform_device { const char * name; /*平台设备的名字,与驱动的名字对应*/ int id; /*一般为-1*/ struct device dev; /*设备结构,platform_device 派生于device*/ u32 num_resources; /*设备使用的资原创 2016-07-21 17:16:23 · 545 阅读 · 0 评论