资源简介
OK6410 linux混杂设备驱动LED程序,使用3.0.1内核编译,还有驱动源码、Makefile和测试程序
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include “led.h“
#define DEVICE_NAME “LED“
static int led_open(struct inode *inodestruct file *filp)
{
unsigned int tmp;
tmp = readl(S3C64XX_GPMCON);
tmp = (tmp & ~(0xFFFFU)) | (0x1111U);
writel(tmpS3C64XX_GPMCON);
tmp = readl(S3C64XX_GPMDAT);
tmp |= (0xFU);
writel(tmpS3C64XX_GPMDAT);
printk(“configure led init\n“);
return 0;
}
static ssize_t led_read(struct file *filpchar __user *bufsize_t countloff_t *f_pos)
{
unsigned int tmp;
tmp = readl(S3C64XX_GPMDAT);
if(copy_to_user(buf&tmp1))
{
printk(“led read copy to user fail\n“);
return -EFAULT;;
}
return 0;
}
static ssize_t led_write(struct file *filpconst char __user *bufsize_t countloff_t *f_pos)
{
char wbuf[10]; //防止传递下来数据过多
unsigned int tmp;
copy_from_user(wbufbufcount);
wbuf[0] = wbuf[0]&0xFU;
tmp = readl(S3C64XX_GPMDAT);
tmp = (tmp & ~(0xFU)) | (~wbuf[0]);
writel(tmpS3C64XX_GPMDAT);
return count;
}
static int led_release(struct inode *inodestruct file *filp)
{
printk(“#########led module release########\n“);
return 0;
}
static long led_ioctl (struct file *filp unsigned int cmd unsigned long arg)
{
int err = 0;
unsigned int tmp = 0;
int count = 0;
/* 检测命令的有效性 */
if (_IOC_TYPE(cmd) != LED_IOC_MAGIC)
return -EINVAL;
if (_IOC_NR(cmd) > LED_IOC_MAXNR)
return -EINVAL;
/* 根据命令类型,检测参数空间是否可以访问 */
if (_IOC_DIR(cmd) & _IOC_READ)
err = !access_ok(VERIFY_WRITE (void *)arg _IOC_SIZE(cmd));
else if (_IOC_DIR(cmd) & _IOC_WRITE)
err = !access_ok(VERIFY_READ (void *)arg _IOC_SIZE(cmd));
if (err)
return -EFAULT;
switch(cmd)
{
case LED_LEFT:
for(count = 1;count<32;)
{
if(count<16)
{
tmp = readl(S3C64XX_GPMDAT);
tmp = (tmp & ~(0xFU)) | (~count);
writel(tmpS3C64XX_GPMDAT);
}
else
{
tmp = readl(S3C64XX_GPMDAT);
tmp = (tmp & ~(0xFU));
writel(tmpS3C64XX_GPMDAT);
}
msleep(200);
count = count * 2;
}
break;
case LED_RIGHT:
for(count = 8;count!=0;)
{
tmp = readl(S3C64XX_GPMDAT);
tmp = (tmp & ~(0xFU)) | (~count);
writel(tmpS3C64XX_GPMDAT);
msleep(200);
count = count / 2;
}
break;
case LED_COUNT:
for(count = 0;count<16;)
{
tmp = readl(S3C64XX_GPMDAT);
tmp = (tmp & ~(0xFU)) | (~count);
writel(tmpS3C64XX_GPMDAT);
msleep(200);
count++;
}
break;
default:
return -EINVAL;
}
return 0;
}
struct file_operations led_fops = {
.owner = THIS_MODULE
.open = led_open
.wri
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3725 2012-08-20 23:09 led\led.c
文件 295 2012-08-20 22:45 led\led.h
文件 76637 2012-08-20 23:09 led\led.ko
文件 5985 2012-08-20 23:09 led\test
文件 762 2012-08-20 23:09 led\test.c
目录 0 2012-08-21 12:08 led
----------- --------- ---------- ----- ----
87404 6
- 上一篇:STC单片机读取AT24C02程序
- 下一篇:run_program.sh
相关资源
- stc12单片驱动DHT11温湿度传感器
- win7蓝牙万能驱动
- Linux RS485 通信代码
- Linux系统下dhcp源码
- 利用驱动来实现极速屏幕传输的代码
- altera DE0开发板驱动程序完美解决无法
- LED8N收银客户显示屏幕开发
- iic_slaver.rar
- ft232r usb uart 驱动
- win7精简版APM驱动添加
- arm开发板上摄像头抓图源代码(v4l通
- OLED0.91模组12832 IIC全套显示函数字符显
- Bluez5.50 arm交叉编译脚本亲测成功
- LED文字滚屏程序 labview
- TLC5615 STM32驱动程序
- IIC Linux 应用层的两种操作方式
- nmon工具linux性能32位的
- AT1846S驱动或RD1846S
- EliteIV v2.40.0.1 drivers
- linux网络设备驱动
- S5PV210按键控制LED
- ads1246驱动程序
- Linux Wi-Fi open source drivers-mac80211 ath9k
- Linux Device Driver 中文版第三版
- RS422串口C驱动源代码
- 89C2051+DS1302+74HC595+8位LED数码管的电子
- 理发师问题Linux,c
- linux下cp2101/2102驱动
- PSoC单片机读秒带LED灯全零闪烁功能时
- GrandDog宏狗驱动
评论
共有 条评论