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表单和工作流 - Nintex篇(五)
博客地址 http://blog.csdn.net/foxdave 接上篇点击打开链接 本篇我们应用Nintex来创建一个简单的工作流. 首先创建一个自定义列表,用于存放请假数据用,我们就叫做Leav ...
- Android常见控件— — —TextView
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android=&qu ...
- Ubuntu 升级VisualBox后无法启动 Kernel driver not installed (rc=-1908)
VisualBox之所以在Linux上比传统的VMware快得多,关键一点就是它和Linux内核的结合比较紧密,这也是开源的优点. 不过Linux内核更新很频繁,每次更新内核后启动VirtualBox ...
- Hello Qt
版本:Qt 5.5.1 Windows 参考: C++ GUI Programming with Qt 4 Second Edition 1. 打开 Qt Creator,File -> New ...
- 夜黑风高的夜晚用SQL语句做了一些想做的事·······
IT这条漫漫长路注定是孤独的,陪伴我们的只有那些不知冷暖的代码语句和被手指敲打的磨掉了键上的标识的键盘. 之所以可以继续坚持下去,是因为心中有一份永不熄灭的激情. 成功的路上让我们为自己带盐 ...
- android:windowSoftInputMode及其他部分属性用法
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 今天我们来讲讲android:windoSoftInputMode的用法,许多同学会为软键盘的弹出. ...
- 2、C#基础整理(运算符、数据类型与转换、var关键字)
·运算符 数学运算符:+ - * / % 比较运算符:< > = <= >= != 返回bool值 逻辑运算符:&&并且.||或者,两者运行 ...
- HDU 4927
http://acm.hdu.edu.cn/showproblem.php?pid=4927 直接模拟会超时,要在纸上写写推公式 A[n]*C(0,n-1) - A[n-1]*C(1,n-1) + ...
- 直接用bat命令对Inno Setup的脚本文件.iss进行编译
直接用bat命令对Inno Setup的脚本文件.iss进行编译 2010-06-17 15:17 qjn0059 | 浏览 2163 次 编程语言外语学习 分享到: 2010-06-29 11: ...
- Python 读书系列
1. 原文<A byte of Python> 翻译版:<<简明Python教程>> 2. Python:核心编程