05 2012 档案

摘要:lcd驱动设计实现流程图:驱动代码实现:lcd.c#include <linux/module.h>#include <linux/kernel.h>#include <linux/errno.h>#include <linux/string.h>#include <linux/mm.h>#include <linux/slab.h>#include <linux/delay.h>#include <linux/fb.h>#include <linux/init.h>#include & 阅读全文
posted @ 2012-05-27 10:49 ITMelody 阅读(623) 评论(0) 推荐(0)
摘要:总线设备驱动模型关系图:驱动程序总线设备驱动模型代码编写步骤:device、driver、app led驱动实例:device代码实现:led_drv.c#include <linux/module.h>#include <linux/version.h>#include <linux/init.h>#include <linux/kernel.h>#include <linux/types.h>#include <linux/interrupt.h>#include <linux/list.h>#includ 阅读全文
posted @ 2012-05-23 11:27 ITMelody 阅读(700) 评论(0) 推荐(0)
摘要:编写输入子系统的驱动程序步骤:驱动程序代码实现:buttons.c/* 参考drivers\input\keyboard\gpio_keys.c */#include <linux/module.h>#include <linux/version.h>#include <linux/init.h>#include <linux/fs.h>#include <linux/interrupt.h>#include <linux/irq.h>#include <linux/sched.h>#include <l 阅读全文
posted @ 2012-05-22 16:06 ITMelody 阅读(573) 评论(0) 推荐(0)
摘要:输入子系统由驱动层、输入子系统核心、事件处理层三部分组成,个输入事件,如鼠标移动、键盘按下等通过Driver->Inputcore->Event handler->userspace的顺序到达用户控件的应用程序。驱动层:将底层的硬件输入转化为统一事件形式,想输入核心(Input Core)汇报。输入子系统核心:承上启下。为驱动层提供输入设备注册与操作接口,如:input_register_device;通知事件处理层对事件进行处理;在/Proc下产生相应的设备信息事件处理层:主要是和用户空间交互。(Linux中在用户空间将所有的设备都当初文件来处理,由于在一般的驱动程序中都有 阅读全文
posted @ 2012-05-22 11:25 ITMelody 阅读(1450) 评论(0) 推荐(1)
摘要:实现原理图:驱动程序实现:buttons.c#include <linux/module.h>#include <linux/kernel.h>#include <linux/fs.h>#include <linux/init.h>#include <linux/delay.h>#include <linux/irq.h>#include <asm/uaccess.h>#include <asm/irq.h>#include <asm/io.h>#include <asm/arch 阅读全文
posted @ 2012-05-20 11:33 ITMelody 阅读(429) 评论(0) 推荐(1)
摘要:1.原子操作:原子操作指的是在执行过程中不会被别的代码路径所中断的操作。常用的原子操作函数举例:crucial_code// 定义初始化原子变量atomic_t *v = ATOMIC_INIT(1);// 读取并返回原子变量的值atomic_read(atomic_t *v);// 原子变量加1atomic_int(atomic_t *v);// 原子变量减1atomic_dec(atomic_t *v);//原子变量减1并测试其值是否为0 , 若是则函数返回true, 否则返回 falseint atomic_dec_and_test(*v);2.信号量:crucial_code// 定义 阅读全文
posted @ 2012-05-19 12:53 ITMelody 阅读(322) 评论(0) 推荐(0)
摘要:实现原理图:异步通信关键代码:crucial_codeAPP:signal(SIGIO, my_signal_fun);fcntl(fd, F_SETOWN, getpid());int Oflags = fcntl(fd, F_GETFL);fcntl(fd, F_SETFL, Oflags | FASYNC);DRIVE:static struct fasync_struct *button_fasync;static struct file_operations second_drv_fops = { .fasync = fifth_drv_fasync,}static int f... 阅读全文
posted @ 2012-05-18 21:00 ITMelody 阅读(520) 评论(0) 推荐(0)
摘要:poll函数 poll函数起源于SVR3,最初局限于流设备。SVR4取消了这种限制,允许poll工作在任何描述字上。poll提供的功能与select类似,不过在处理流设备时,它能够提供额外的信息。 1.#include <poll.h> 2.int poll(struct pollfd *fdarray, unsigned long nfds, int timeout); 3.返回:就绪描述字的个数,0-超时,-1-出错 第一个参数是指向一个结构数组第一个元素的指针。每个数组元素都是一个pollfd结构,用于指定测试某个给定描述字fd的条件。 struct poll... 阅读全文
posted @ 2012-05-18 15:04 ITMelody 阅读(558) 评论(0) 推荐(0)
摘要:内核:request_irq(riq, handle, irqflags, devname, devid); 的实现过程中断驱动及应用程序设计整体思路:驱动程序代码实现过程:third_drv.c#include <linux/module.h>#include <linux/kernel.h>#include <linux/fs.h>#include <linux/init.h>#include <linux/delay.h>#include <linux/irq.h>#include <asm/uaccess.h 阅读全文
posted @ 2012-05-17 08:03 ITMelody 阅读(760) 评论(1) 推荐(1)
摘要: 阅读全文
posted @ 2012-05-16 15:49 ITMelody 阅读(389) 评论(0) 推荐(0)
摘要:原理图:驱动程序代码:second_drv.c#include <linux/module.h>#include <linux/kernel.h>#include <linux/fs.h>#include <linux/init.h>#include <linux/delay.h>#include <asm/uaccess.h>#include <asm/irq.h>#include <asm/io.h>#include <asm/arch/regs-gpio.h>#include &l 阅读全文
posted @ 2012-05-16 15:31 ITMelody 阅读(623) 评论(1) 推荐(0)
摘要:原理图:驱动程序代码:myleds.c#include <linux/module.h>#include <linux/kernel.h>#include <linux/fs.h>#include <linux/init.h>#include <linux/delay.h>#include <asm/uaccess.h>#include <asm/irq.h>#include <asm/io.h>#include <asm/arch/regs-gpio.h>#include <as 阅读全文
posted @ 2012-05-16 10:52 ITMelody 阅读(715) 评论(0) 推荐(0)
摘要:原理图:驱动程序代码实现:first_drv.c#include <linux/module.h>#include <linux/kernel.h>#include <linux/fs.h>#include <linux/init.h>#include <linux/delay.h>#include <asm/uaccess.h>#include <asm/irq.h>#include <asm/io.h>#include <asm/arch/regs-gpio.h>#include & 阅读全文
posted @ 2012-05-15 23:25 ITMelody 阅读(460) 评论(0) 推荐(0)
摘要:最近看了一下Linux Poll 机制的实现,看了韦老师的分析文档,总结如下:int poll(struct pollfd *fds,nfds_t nfds, int timeout);总的来说,Poll机制会判断fds中的文件是否可读,如果可读则会立即返回,返回的值就是可读fd的数量,如果不可读,那么就进程就会休眠timeout这么长的时间,然后再来判断是否有文件可读,如果有,返回fd的数量,如果没有,则返回0. 在内核中大致上实现过程:当应用程序调用poll函数的时候,会调用到系统调用sys_poll函数,该函数最终调用do_poll函数,do_poll函数中有一个死循 环,在里面又会利用 阅读全文
posted @ 2012-05-13 23:58 ITMelody 阅读(394) 评论(0) 推荐(0)
摘要:request_irq的作用是申请使用IRQ并注册中断处理程序。request_irq()函数的原型如下:/* kernel/irq/manage.c */int request_irq(unsigned int irq, irqreturn_t (*handler)(int, void *, struct pt_regs *), unsigned long irqflags, const char *devname, void *dev_id );我们知道,当使用内核共享中断时,request_irq必须要提供dev_id参数,并且dev_id的值必须唯一。那么这里提供唯一的dev_... 阅读全文
posted @ 2012-05-12 09:58 ITMelody 阅读(1140) 评论(0) 推荐(0)