Linux驱动设计——字符杂项设备
杂项设备
struct miscdevice{
int minor; //杂项设备的此设备号(如果设置为MISC_DYNAMIC_MINOR,表示系统自动分配未使用的minor)
const char *name;
const stuct file_operations *fops;//驱动主题函数入口指针
struct list_head list;
struct device *parent;
struct device *this device;
const char *nodename;(在/dev下面创建的设备驱动节点)
mode_t mode;
};
#include <linux/miscdevice.h>
#include <linux/delay.h>
#include <asm/irq.h>
#include <mach/regs-gpio.h>
#include <mach/hardware.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/fs.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/moduleparam.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include <linux/ioctl.h>
#include <linux/cdev.h>
#include <linux/string.h>
#include <linux/list.h>
#include <linux/pci.h>
#include <linux/gpio.h>
#include <asm/uaccess.h>
#include <asm/atomic.h>
#include <asm/unistd.h> #define DEVICE_NAME "leds" #define IOCTL_LED_ON 1
#define IOCTL_LED_OFF 0 static unsigned long led_table [] =
{
S3C2410_GPB(),
S3C2410_GPB(),
S3C2410_GPB(),
S3C2410_GPB(),
}; static unsigned int led_cfg_table [] =
{
S3C2410_GPIO_OUTPUT,
S3C2410_GPIO_OUTPUT,
S3C2410_GPIO_OUTPUT,
S3C2410_GPIO_OUTPUT,
}; static int gt2440_leds_ioctl(
// struct inode *inode,
struct file *file,
unsigned int cmd,
unsigned long arg)
{
if (arg > )
{
return -EINVAL;
} switch(cmd)
{
case IOCTL_LED_ON:
// 设置指定引脚的输出电平为0
s3c2410_gpio_setpin(led_table[arg], );
return ; case IOCTL_LED_OFF:
// 设置指定引脚的输出电平为1
s3c2410_gpio_setpin(led_table[arg], );
return ; default:
return -EINVAL;
}
} static struct file_operations dev_fops = {
.owner = THIS_MODULE,
.unlocked_ioctl = gt2440_leds_ioctl,
}; static struct miscdevice misc = {
.minor = MISC_DYNAMIC_MINOR,
.name = DEVICE_NAME,
.fops = &dev_fops,
}; static int __init dev_init(void)
{
int ret; int i;
for (i = ; i < ; i++)
{
s3c2410_gpio_cfgpin(led_table[i], led_cfg_table[i]);
s3c2410_gpio_setpin(led_table[i], );
} ret = misc_register(&misc); printk (DEVICE_NAME" initialized\n"); return ret;
} static void __exit dev_exit(void)
{
misc_deregister(&misc);
} module_init(dev_init);
module_exit(dev_exit); MODULE_LICENSE("GPL");
MODULE_AUTHOR("www.e-online.cc");
MODULE_DESCRIPTION("LEDS control for GT2440 Board");
Linux驱动设计——字符杂项设备的更多相关文章
- Linux驱动设计——字符设备驱动(一)
Linux字符设别驱动结构 cdev结构体 struct cdev { struct kobject kobj; struct module *owner; const struct file_ope ...
- linux驱动初探之杂项设备(控制两个GPIO口)
关键字:linux驱动.杂项设备.GPIO 此驱动程序控制了外接的两个二极管,二极管是低电平有效. 上一篇博客中已经介绍了linux驱动程序的编写流程,这篇博客算是前一篇的提高篇,也是下一篇博客(JN ...
- Linux驱动设计—— 中断与时钟
中断和时钟技术可以提升驱动程序的效率 中断 中断在Linux中的实现 通常情况下,一个驱动程序只需要申请中断,并添加中断处理函数就可以了,中断的到达和中断函数的调用都是内核实现框架完成的.所以程序员只 ...
- Linux 驱动框架---cdev字符设备驱动和misc杂项设备驱动
字符设备 Linux中设备常见分类是字符设备,块设备.网络设备,其中字符设备也是Linux驱动中最常用的设备类型.因此开发Linux设备驱动肯定是要先学习一下字符设备的抽象的.在内核中使用struct ...
- 手把手教Linux驱动3-之字符设备架构详解,有这篇就够了
一.Linux设备分类 Linux系统为了管理方便,将设备分成三种基本类型: 字符设备 块设备 网络设备 字符设备: 字符(char)设备是个能够像字节流(类似文件)一样被访问的设备,由字符设备驱动程 ...
- 【Linux驱动】字符设备驱动
一.linux系统将设备分为3类:字符设备.块设备.网络设备.使用驱动程序: 1.字符设备:是指只能一个字节一个字节读写的设备,不能随机读取设备内存中的某一数据,读取数据需要按照先后数据.字符设备是面 ...
- linux驱动开发之块设备学习笔记
我的博客主要用来存放我的学习笔记,如有侵权,请与我练习,我会立刻删除.学习参考:http://www.cnblogs.com/yuanfang/archive/2010/12/24/1916231.h ...
- 迅为4412开发板Linux驱动教程——总线_设备_驱动注册流程详解
本文转自:http://www.topeetboard.com 视频下载地址: 驱动注册:http://pan.baidu.com/s/1i34HcDB 设备注册:http://pan.baidu.c ...
- 迅为4412开发板Linux驱动教程——总线_设备_驱动注冊流程具体解释
视频下载地址: 驱动注冊:http://pan.baidu.com/s/1i34HcDB 设备注冊:http://pan.baidu.com/s/1kTlGkcR 总线_设备_驱动注冊流程具体解释 • ...
随机推荐
- SharePoint 2013 开发——CSOM概要
博客地址:http://blog.csdn.net/FoxDave 本篇对客户端API做一个大致地了解. 看一下各个类别主要API之间的对应关系表. 假设我们对Server API已经有了足够地了 ...
- LOGISTIC REGRESSION
In logistic regression we learn a family of functions
- JVM-class文件完全解析-魔数
魔数(Magic Number) 魔数和Class文件的版本. 一个文件能否被Java虚拟机接受,不是通过文件的扩展名来进行识别的,而是通过魔数来进行识别.这主要是基于安全方面的考虑,因为文件的扩展名 ...
- hdu4597 区间dp
//Accepted 1784 KB 78 ms //区间dp //dp[l1][r1][l2][r2] 表示a数列从l1到r1,b数列从l2到r2能得到的最大分值 // #include <c ...
- Mysql5.0以下 手工注入
order by 20 www. .com/product/introduction.php?id=-65 UNION SELECT user(),2 www. .com/product/introd ...
- 使用开源工具MonoDevelop开发GTK#图形界面
转自:http://developer.51cto.com/art/201011/235040.htm Mono一直到现在的2.8已经完全可以胜任一些比较小的项目了,但相关的开发文档与教程一直比较匮乏 ...
- (转)phoneGap-Android开发环境搭建
(原)http://www.cnblogs.com/shawn-xie/archive/2012/08/15/2638480.html phoneGap-Android开发环境搭建 一.安装 在安 ...
- Packages
Packages are a way of structuring Python's module namespace by using "dotted module names" ...
- Training little cats_矩阵快速幂
Description Facer's pet cat just gave birth to a brood of little cats. Having considered the health ...
- const char* <----- > string
(1) const char* <----- string const char* const_txt_path=txt_path.c_str(); (2) string ...