国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

小小的led驅動和測試程序

2019-11-06 09:23:46
字體:
來源:轉載
供稿:網友

使用的板子為gec210的板子

#include <linux/kernel.h>

#include <linux/module.h>#include <linux/init.h>#include <linux/device.h>#include <linux/cdev.h>#include <linux/fs.h>#include <mach/gpio.h>#include <mach/regs-gpio.h>#include <plat/gpio-cfg.h>#include <linux/delay.h>

#include <linux/io.h>

#define LEDCON 0xe0200280  //led控制寄存器的物理地址#define LEDDAT 0xe0200284  //led數據寄存器的物理地址#define LED_MAGIC 'm'#define LED_ON _IO(LED_MAGIC,0)#define LED_OFF _IO(LED_MAGIC,1)unsigned int *led_config;unsigned int *led_data;struct cdev cdev;dev_t devno;#define DRIVER_NAME "my_led_driver"struct class *my_class;static int led_open(struct inode *inode,struct file *file){led_config=ioremap(LEDCON,4);writel(0x00001111,led_config);led_data=ioremap(LEDDAT,4);return 0;}static int led_close(struct inode *inode,struct file *file){iounmap(led_config);iounmap(led_data);return 0;}long led_ioctl (struct file *file, unsigned int cmd, unsigned long arg){switch(cmd){case LED_ON:writel(0x00,led_data);break;case LED_OFF:writel(0x0f,led_data);break;default:return -EINVAL;}return 0;}static struct file_Operations led_fops ={.owner = THIS_MODULE,.open = led_open,.release = led_close,.unlocked_ioctl =led_ioctl,};static int led_init(void){cdev_init(&cdev,&led_fops);alloc_chrdev_region(&devno, 0 , 1 , "myled");cdev_add(&cdev, devno, 1);my_class = class_create(THIS_MODULE, "led_class");if(IS_ERR(my_class)){PRintk("Err: failed in creating class./n");return -1;}device_create(my_class, NULL, devno,NULL,"led_driver");return 0;}static void led_exit(void){device_destroy(my_class,devno);class_destroy(my_class);cdev_del(&cdev);unregister_chrdev_region(devno,1);}module_init(led_init);module_exit(led_exit);MODULE_LICENSE("GPL");

MODULE_AUTHOR("EIGHT&FIVE");

測試程序如下

#include<stdio.h>#include<sys/ioctl.h>#include<sys/types.h>#include<sys/stat.h>#include<fcntl.h>#define LED_MAGIC 'm'#define LED_ON _IO(LED_MAGIC,0)#define LED_OFF _IO(LED_MAGIC,1)int main(int argv,char **argc){int fd,i;fd=open("/dev/led_driver",0x666);while(1){scanf("%d",&i);switch(i){case 1 :ioctl(fd,LED_ON,NULL);break;case 2:ioctl(fd,LED_OFF,NULL);break;default:break;}}close(fd);return 0;}

測試已成功。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 梧州市| 河间市| 三穗县| 楚雄市| 宕昌县| 渝中区| 石楼县| 沧州市| 枣强县| 浦东新区| 大港区| 页游| 嘉义市| 来凤县| 孟村| 清水县| 三原县| 宜川县| 大关县| 鄄城县| 彩票| 永川市| SHOW| 晋中市| 宿州市| 昌宁县| 阜阳市| 嘉禾县| 托克托县| 策勒县| 贡山| 武隆县| 寿光市| 东宁县| 阳高县| 开远市| 阿瓦提县| 余庆县| 肥乡县| 安平县| 莫力|