随笔分类 -  技术剖析

摘要:nor flash 驱动程序设计流程:nor flash 驱动程序内核识别分析:analysis codeNOR FLASH识别过程:do_map_probe("cfi_probe", s3c_nor_map); drv = get_mtd_chip_driver(name) ret = drv->probe(map); // cfi_probe.c cfi_probe mtd_do_chip_probe(map, &cfi_chip_probe); cfi = genprobe_ident... 阅读全文
posted @ 2012-06-10 16:52 ITMelody 阅读(626) 评论(0) 推荐(1)
摘要:nand flash 驱动内核实现分析过程:analysis codes3c2410_nand_inithws3c2410_nand_init_chipnand_scan // drivers/mtd/nand/nand_base.c 根据nand_chip的底层操作函数识别NAND FLASH,构造mtd_info nand_scan_ident nand_set_defaults if (!chip->select_chip) chip->select_chip = nand_select_chip; // 默认值不... 阅读全文
posted @ 2012-06-10 08:47 ITMelody 阅读(530) 评论(0) 推荐(0)
摘要:程序设计实现过程:块设备内核实现分析过程:analysis code分析ll_rw_block for (i = 0; i < nr; i++) { struct buffer_head *bh = bhs[i]; submit_bh(rw, bh); struct bio *bio; // 使用bh来构造bio (block input/output) submit_bio(rw, bio); // 通用的构造请求: 使用bio来构造请求... 阅读全文
posted @ 2012-06-04 23:13 ITMelody 阅读(434) 评论(0) 推荐(0)
摘要:usb驱动程序设计实现步骤:usb总线驱动内核代码分析过程:analysis codehub_irq kick_khubd hub_thread hub_events hub_port_connect_change udev = usb_alloc_dev(hdev, hdev->bus, port1); dev->dev.bus = &usb_bus_type; ... 阅读全文
posted @ 2012-06-03 21:57 ITMelody 阅读(963) 评论(0) 推荐(0)
摘要:触摸屏响应过程:触摸屏程序代码实现:s3c_ts.c#include <linux/errno.h>#include <linux/kernel.h>#include <linux/module.h>#include <linux/slab.h>#include <linux/input.h>#include <linux/init.h>#include <linux/serio.h>#include <linux/delay.h>#include <linux/platform_device 阅读全文
posted @ 2012-06-03 10:41 ITMelody 阅读(662) 评论(0) 推荐(0)
摘要: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 阅读(699) 评论(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 阅读(1446) 评论(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 阅读(428) 评论(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 阅读(519) 评论(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 阅读(557) 评论(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 阅读(388) 评论(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 阅读(714) 评论(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 阅读(459) 评论(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 阅读(1137) 评论(0) 推荐(0)