随笔分类 -  linux字符设备驱动

字符设备驱动中cdev与inode、file_operations的关系
摘要:一、cdev与inode 二、cdev与file_operations 阅读全文

posted @ 2013-10-12 10:42 熊猫酒仙是也 阅读(1535) 评论(0) 推荐(0)

支持异步通知的globalfifo平台设备驱动程序及其测试代码
摘要:驱动:#include #include #include #include #include //内存管理头文件,含有页面大小定义和一些页面释放函数原型#include #include #include #include //I/O头文件,以宏的嵌入汇编程序形式定义对I/O端口操作的函数。#include //系统头文件,定义了设置或修改描述符/中断门等的嵌入式汇编宏。#include //包含了copy_to_user、copy_from_user等内核访问用户进程内存地址的函数定义#include //包含了kcalloc、kzalloc内存分配函数的定义。#include //--- 阅读全文

posted @ 2013-09-17 16:52 熊猫酒仙是也 阅读(590) 评论(0) 推荐(0)

使用内核定时器的second字符设备驱动及测试代码
摘要:驱动:#include #include #include #include #include #include #include //cdev#include //udev#include //schedule#include //copy_to_user#include //kmalloc()#define DEVICE_NAME "second_drv"static int second_major=0;/*主设备号*/struct class *second_class;/*second设备结构体*/static struct second_dev{ struct 阅读全文

posted @ 2013-09-05 13:43 熊猫酒仙是也 阅读(349) 评论(0) 推荐(0)

用内核定时器来实现的按键驱动代码分析以及测试代码
摘要:驱动代码:#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //udevstruct class *key_class;static int key_major = 0;struct key_desc_t { int p... 阅读全文

posted @ 2013-09-03 21:55 熊猫酒仙是也 阅读(419) 评论(0) 推荐(0)

基于等待队列及poll机制的按键驱动代码分析和测试代码
摘要:按键驱动分析:#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include #include struct class *key_class;//udev机制自动创建文件结点#define USING_TASKLET//struct timespec start_time;//struct tim 阅读全文

posted @ 2013-09-02 17:03 熊猫酒仙是也 阅读(539) 评论(0) 推荐(0)

支持阻塞操作和轮询操作的globalfifo设备驱动代码分析以及测试代码
摘要:#include #include #include #include #include #include #include #include #include #include #include #include #include //-------------class_create,device_create------#include /*用udev机制自动添加设备节点*/struct class *globalfifo_class;#define GLOBALFIFO_SIZE 0x1000 /*全局内存最大4K字节*/#define MEM_CLEAR 0x1 /*清... 阅读全文

posted @ 2013-08-29 20:43 熊猫酒仙是也 阅读(580) 评论(0) 推荐(0)

虚拟内存设备驱动memdev及实例代码
摘要:驱动:#include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef MEMDEV_MAJOR#define MEMDEV_MAJOR 0 /*预设的mem的主设备号*/#endif#ifndef MEMDEV_NR_DEVS#define MEMDEV_NR_DEVS 2 /*设备数*/#endif#ifndef MEMDEV_SIZE#define MEMDEV_SIZE 4096#endif#d... 阅读全文

posted @ 2013-08-27 09:42 熊猫酒仙是也 阅读(831) 评论(0) 推荐(0)

Linux下实现流水灯等功能的LED驱动代码及测试实例
摘要:驱动代码:#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //-------------class_create,device_create------#include /*用udev机制自动添加设备节点*/struct class *led_class;static int led_major = 0; ... 阅读全文

posted @ 2013-08-26 15:25 熊猫酒仙是也 阅读(4715) 评论(0) 推荐(0)

Linux下简易蜂鸣器驱动代码及测试实例
摘要:驱动代码:#include #include #include #include #include #include #include #include #include #define DEVICE_NAME "beep3"#define BEEP_MAGIC 'k'#define BEEP_START_CMD _IO (BEEP_MAGIC, 1)#define BEEP_STOP_CMD _IO (BEEP_MAGIC, 2)static void beep3_stop(void) { printk("in the beep3_stop!!\ 阅读全文

posted @ 2013-08-25 20:43 熊猫酒仙是也 阅读(1664) 评论(0) 推荐(0)

Linux下18b20温度传感器驱动代码及测试实例
摘要:驱动代码:#include #include #include #include #include #include #include #include #include #define DEVICE_NAME "TEM0"#define TEM_SHOW_CODE 0x01//static struct cdev cdev;struct class *tem_class;//static dev_t devno;//static int major = 243;//可以用int alloc_chrdev_region(dev_... 阅读全文

posted @ 2013-08-25 15:32 熊猫酒仙是也 阅读(1375) 评论(0) 推荐(0)

LED字符设备驱动实例及测试代码
摘要:驱动代码如下:#include //内核头文件#include //__init等#include //模块加载的头文件#include //file_operations#include //错误状态常数#include //size_t,ssize_t等//--------------cdev----------------#include //-------------class_create,device_create------#include //--------------GPIO-----------------#include #include #include //---- 阅读全文

posted @ 2013-08-25 15:27 熊猫酒仙是也 阅读(984) 评论(0) 推荐(0)

Linux下GPIO驱动(五) ----misc_register();
摘要://struct miscdevice { int minor; const char *name; const struct file_operations *fops; struct list_head list; struct device *parent; struct device *this_device; const char *nodename; mode_t mode;}; int misc_register(struct miscdevice * misc);//注册为杂项设备 int misc_deregister(str... 阅读全文

posted @ 2013-08-24 16:23 熊猫酒仙是也 阅读(2133) 评论(0) 推荐(0)

Linux下GPIO驱动(四) ----gpio_request();gpio_free();
摘要://gpio_request申请gpio口int gpio_request(unsigned gpio, const char *label){ struct gpio_desc *desc; struct gpio_chip *chip; int status = -EINVAL; unsigned long flags; spin_lock_irqsave(&gpio_lock, flags); // gpio_lock是自旋锁,上锁,保存FLAG在flags变量 if (!gpio_is_valid(gp... 阅读全文

posted @ 2013-08-24 15:57 熊猫酒仙是也 阅读(16526) 评论(0) 推荐(0)

Linux下GPIO驱动(三) ----gpio_desc()的分析
摘要:上篇最后提出的疑问是结构体gpio_chip中的成员函数set等是怎么实现的,在回答之前先介绍下gpio_desc这个结构体。 如上图所示,右上方部分为GPIO驱动对其它驱动提供的GPIO操作接口,其对应的右下方部分为GPIO硬件操作接口,也就是说对外提供的接口最终会一一对应的对硬件GPIO进行操作。再来看左边部分,左上方部分为一全局数组,记录各个GPIO的描述符,即对应左下方的gpio_desc结构体,其中gpio_chip指向硬件层的GPIO,flags为一标志位,用来指示当前GPIO是否已经占用,当用gpio_request申请GPIO资源时,flags位就会置位,当调用gpio_fre 阅读全文

posted @ 2013-08-24 15:46 熊猫酒仙是也 阅读(13634) 评论(0) 推荐(1)

Linux下GPIO驱动(二) ----s3c_gpio_cfgpin();gpio_set_value();
摘要:首先来看s3c_gpio_cfgpin();int s3c_gpio_cfgpin(unsigned int pin, unsigned int config){ struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);//得到对应GPIO结构体首指针,里面包含了该GPIO的各种参数 unsigned long flags; int offset; int ret; if (!chip) return -EINVAL; offset = pin - chip->chip.base; s3... 阅读全文

posted @ 2013-08-24 14:55 熊猫酒仙是也 阅读(7019) 评论(0) 推荐(0)

Linux下GPIO驱动(一) ----一个简单的LED驱动
摘要:/******************************* * *杂项设备驱动:miscdevice *majior=10; * * *****************************/#include #include #include #include #include //#include //#include //kcalloc,kzalloc等内存分配函数//---------ioctl------------#include //---------misc_register----#include //----------cdev--------------#incl 阅读全文

posted @ 2013-08-24 13:52 熊猫酒仙是也 阅读(7543) 评论(0) 推荐(0)

导航