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

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

imx6q led燈驅動及測試代碼ioctl(自動創建設備文件v2)

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

微笑驅動層代碼微笑

/*************************************************************************	> File Name: led_drv.c	> Author: XXDK	> Email: v.manstein@QQ.com 	> Created Time: Sun 26 Feb 2017 04:28:00 AM PST ************************************************************************/#include<linux/init.h>#include<linux/module.h>#include<asm/gpio.h>#include<mach/iomux-mx6q.h>#include<linux/cdev.h>#include<linux/fs.h>#include<linux/device.h>#define SABRESD_GPIO_LED4	IMX_GPIO_NR(3, 21)#define SABRESD_GPIO_LED5	IMX_GPIO_NR(3, 22)#define SABRESD_GPIO_LED6   IMX_GPIO_NR(3, 23)#define LED_ON	1#define LED_OFF 0struct led_resource {	int gpio;	char *name;	int data;};static struct cdev led_cdev;static dev_t led_dev_id;static struct class *cls;static struct led_resource led_res[] = {	[0] = {		.gpio = SABRESD_GPIO_LED4,		.name = "xxdk_led4",	},	[1] = {		.gpio = SABRESD_GPIO_LED5,		.name = "xxdk_led5",	},	[2] = {		.gpio = SABRESD_GPIO_LED6,		.name = "xxdk_led6",	}};static int led_open(struct inode* ip, 		struct file* fp){	int i;	PRintk("%s/n", __func__);		for(i=0; i<ARRAY_SIZE(led_res); i++) {		gpio_set_value(led_res[i].gpio, 1);	}	return 0;}static int led_close(struct inode* ip, 		struct file* fp){	int i;	printk("%s/n", __func__);	for(i=0; i<ARRAY_SIZE(led_res); i++) {		gpio_set_value(led_res[i].gpio, 0);	}	return 0;}static struct file_Operations led_fops = {	.owner = THIS_MODULE,	.open = led_open,	.release = led_close };static int led_init(void){	int i;	alloc_chrdev_region(&led_dev_id, 0, 1, "led@xxdk");	cdev_init(&led_cdev, &led_fops);	cdev_add(&led_cdev, led_dev_id, 1);	for(i=0; i<ARRAY_SIZE(led_res); i++) {		gpio_request(led_res[i].gpio, led_res[i].name);		gpio_direction_output(led_res[i].gpio, 0);	}	cls = class_create(THIS_MODULE, "xxdk");	device_create(cls, NULL, led_dev_id, NULL, "led@xxdk");	return 0;}static void led_exit(void){	int i;	cdev_del(&led_cdev);	unregister_chrdev_region(led_dev_id, 1);	for(i=0; i<ARRAY_SIZE(led_res); i++) {		gpio_set_value(led_res[i].gpio, 0);		gpio_free(led_res[i].gpio);	}		device_destroy(cls, led_dev_id);	class_destroy(cls);}module_init(led_init);module_exit(led_exit);MODULE_LICENSE("GPL");吐舌頭應用層代碼吐舌頭

/*************************************************************************	> File Name: led_test.c	> Author: XXDK	> Email: v.manstein@qq.com 	> Created Time: Sun 26 Feb 2017 05:22:08 AM PST ************************************************************************/#include<stdio.h>#include<sys/stat.h>#include<sys/types.h>#include<fcntl.h>int main(void){	int fd;	fd = open("/dev/led@xxdk", O_RDWR);	if(fd < 0) {		printf("open led device failed!/n");		return -1;	}	sleep(3);	close(fd);	return 0;}偷笑編譯腳本偷笑

#Makefilifneq ($(KERNELRELEASE),)	obj-m += led_drv.oelse	KERNEL_DIR = /opt/EmbedSky/TQIMX6/TQ_COREC/linux_IMX6_CoreC_3.0.35_for_Linuxall:	PWD=$(shell pwd)	$(MAKE) -C $(KERNEL_DIR) M=$(PWD)clean:	rm -rf .*.cmd *.o *.mod.c *.ko *.tmp_versions module* Module*endif


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 汨罗市| 嵊泗县| 镇平县| 寿光市| 荣昌县| 昭苏县| 抚宁县| 巩义市| 渑池县| 酒泉市| 肃南| 祁门县| 开封县| 永福县| 岗巴县| 吴忠市| 富平县| 黄大仙区| 大宁县| 盐山县| 阿拉善左旗| 高要市| 河津市| 朝阳县| 墨玉县| 当雄县| 怀集县| 囊谦县| 吉林省| 焦作市| 无为县| 姚安县| 巨鹿县| 盐边县| 宕昌县| 宣城市| 渝北区| 灵石县| 教育| 石首市| 六安市|