摘要: 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 阅读(313) 评论(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 阅读(506) 评论(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 阅读(534) 评论(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 阅读(740) 评论(1) 推荐(1) 编辑
摘要: 阅读全文
posted @ 2012-05-16 15:49 ITMelody 阅读(376) 评论(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 阅读(612) 评论(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 阅读(688) 评论(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 阅读(443) 评论(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 阅读(373) 评论(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 阅读(1058) 评论(0) 推荐(0) 编辑