led驱动程序 led控制卡驱动程序


#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<asm/uaccess.h>#include<asm/atomic.h>#include<asm/unistd.h>
#define DEVICE_NAME "myled" //设备名#define DEVICE_MAJOR 212 //主设备号static int led_major=DEVICE_MAJOR; //?????????
#define LED1 S3C2410_GPB5#define LE D2 S3C2410_GPB6#define LED3 S3C2410_GPB7#define LED4 S3C2410_GPB8
#define LED1_out S3C2410_GPB5_OUTP#define LED2_out S3C2410_GPB6_OUTP#define LED3_out S3C2410_GPB7_OUTP#define LED4_out S3C2410_GPB8_OUTP
struct s3c2440_led_dev{struct cdev cdev;};
static struct s3c2440_led_dev dev;
static int s3c2440_led_open(struct inode *inode,struct file*filp){printk("It's OPEN!n");return 0;}
static int s3c2440_led_release(struct inode *inode,struct file*filp){return 0;}
static int s3c2440_led_ioctl(struct inode *inode,struct file*filp,unsigned int cmd,unsigned long arg){unsigned int status;status=cmd<<5;s3c2410_gpio_setpin(LED1,(cmd&1));s3c2410_gpio_setpin(LED2,(cmd&2)>>1);s3c2410_gpio_setpin(LED3,(cmd&4)>>2);s3c2410_gpio_setpin(LED4,(cmd&8)>>3);
return 0;}
static const struct file_operations s3c2440_led_fops={.owner=THIS_MODULE,.ioctl=s3c2440_led_ioctl,.open=s3c2440_led_open,.release=s3c2440_led_release,};
static void led_setup_cdev(void){int err,devno=MKDEV(led_major,0); //构造设备号cdev_init(&dev.cdev,&s3c2440_led_fops);//初始化cdev设备,调用cdev_init()函数,将设备结构体cdev与邋file_operators指针相关联dev.cdev.owner=THIS_MODULE; //使驱动程序属于该模块dev.cdev.ops=&s3c2440_led_fops;//制定s3c2440_led_fops为字符设备的文件操作函数指针err=cdev_add(&dev.cdev,devno,1);//将cdev注册到系统中if(err){printk(KERN_NOTICE "Error in cdev_add");}}
static int s3c2440_led_init(void){int result;dev_t devno=MKDEV(led_major,0); //构造设备号if(led_major)//如果不为0,则静态申请{result=register_chrdev_region(devno,1,"DEVICE_NAME");}else//否则动态申请{result=alloc_chrdev_region(&devno,0,1,"DEVICE_NAME");led_major=MAJOR(devno);}if(result<0){return result;}//配置 LED 对应的端口为输出并且初始化s3c2410_gpio_cfgpin(LED1, LED1_out); s3c2410_gpio_setpin(LED1, 0);s3c2410_gpio_cfgpin(LED2, LED2_out); s3c2410_gpio_setpin(LED2, 0);s3c2410_gpio_cfgpin(LED3, LED3_out); s3c2410_gpio_setpin(LED3, 0);s3c2410_gpio_cfgpin(LED4, LED4_out); s3c2410_gpio_setpin(LED4, 0);
led_setup_cdev();printk(DEVICE_NAME " initializadn");return 0;}
static void s3c2440_led_exit(void){cdev_del(&dev.cdev); //注销cdevunregister_chrdev_region(MKDEV(led_major,0),1); //释放设备号}
module_init(s3c2440_led_init);module_exit(s3c2440_led_exit);MODULE_LICENSE("GPL");//设备许可

测试用的应用程序#include<stdio.h>#include<stdlib.h>#include<unistd.h>#include "sys/types.h"#include "sys/ioctl.h"#include "stdlib.h"#include "termios.h"#include "sys/stat.h"#include "fcntl.h"#include "sys/time.h"
int main(void){int fd,i,j;unsigned int led_status=0;fd=open("/dev/myled",O_RDWR);if(fd<0){perror("open device led failed!");exit(1);}while(1){printf("please enter 1-15 to contral the four led:");scanf("%d",&led_status);for(i=0;i<10;i++){for(j=0;j<100;j++){ioctl(fd,led_status);}}}close(fd);return 0;}

  

爱华网本文地址 » http://www.413yy.cn/a/25101015/244133.html

更多阅读

显卡驱动如何更新 精 如何更新显卡驱动程序

显卡驱动如何更新 精——简介这里介绍几个常用的显卡驱动更新的方法。显卡驱动如何更新 精——工具/原料PC 电脑可能互连网连接显卡驱动如何更新 精——方法一、通过显卡官方网站下载最新驱动显卡驱动如何更新 精 1、这里以下载

如何解决用户安装不上打印机驱动程序 安装打印机驱动程序

如何解决用户安装不上打印机驱动程序——简介打印机是非常常用的办公软件,有时候打印机驱动程序安装不上。这里教大家如何解决用户安装不上打印机驱动程序。如何解决用户安装不上打印机驱动程序——工具/原料电脑如何解决用户安装

声明:《led驱动程序 led控制卡驱动程序》为网友薄荷蓝少年分享!如侵犯到您的合法权益请联系我们删除