国产探花免费观看_亚洲丰满少妇自慰呻吟_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;}

測試已成功。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 郴州市| 修水县| 枣强县| 洞头县| 三河市| 阜宁县| 玉门市| 崇明县| 瑞金市| 烟台市| 高邮市| 建昌县| 罗山县| 东至县| 蒲城县| 旬阳县| 邻水| 云霄县| 秦皇岛市| 监利县| 扬中市| 湛江市| 盐津县| 黄骅市| 崇文区| 临江市| 沾化县| 天台县| 洪泽县| 廊坊市| 酉阳| 城市| 永德县| 绥化市| 娱乐| 高安市| 海原县| 达拉特旗| 安岳县| 封丘县| 蚌埠市|