夺宝电子|JDB夺宝电子游戏,官网,官方网站,官方网址

 

联系我们

联系我们

中山市勤龙输送设备科技有限公司

联系人:黄先生 手机:13420032999

邮箱: qinlong@zgqinlong.com

电话: 0760-22586708

传真: 0760-22586709

地址:广东省中山市小榄镇小榄大道北47号之二

您现在的位置:首页> 技术专题 技术专题

一个字符设备驱动--点亮和熄灭一个LED设备

时间:2013/6/10 0:00:00     关键字:

在mini2440开发板上(CPU是s3c2440)开发字符设备驱动完成一个led灯的亮灭。

1. 环境

硬件环境:

Host:X86PC

Target:友善之臂mini2440开发板

软件环境:

Host:VMware虚拟机下的redhat linux 9.0(完全安装)

Target:arm-linux kernel:linux-2.6.13

Crosstool: arm-linux-gcc-3.3.2

2. 完成过程

⑴驱动程序文件--mini2440_one_led.c,其具体内容如下:

#define DEVICE_NAME "lsq_led"

#define LED_MAJOR 250

#define GPB5_ON 1

#define GPB5_OFF 2

static int mini2440_led_ioctl(

struct inode *inode,

struct file *file,

unsigned int cmd,

unsigned long arg)

{

if (cmd==GPB5_ON) {

//printk("ioctl LEDON successfully\n");

s3c2410_gpio_setpin(S3C2410_GPB5, 0);

return 0;

}

if (cmd==GPB5_OFF) {

//printk("ioctl LEDOFF successfully\n");

s3c2410_gpio_setpin(S3C2410_GPB5, 1);

return 0;

}

printk("ioctl error \n");

return -EFAULT;

}

static struct file_operations mini2440_led_fops = {

.owner = THIS_MODULE,

.ioctl = mini2440_led_ioctl,

};

static int __init mini2440_led_init(void)

{

int ret;

ret = register_chrdev(LED_MAJOR, DEVICE_NAME, &mini2440_led_fops);

if (ret < 0) {

printk(DEVICE_NAME " can''''''''''''''''''''''''''''''''t register major number\n");

return ret;

}

devfs_mk_cdev(MKDEV(LED_MAJOR, 0), S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP, DEVICE_NAME);

s3c2410_gpio_cfgpin(S3C2410_GPB5, S3C2410_GPB5_OUTP);

s3c2410_gpio_setpin(S3C2410_GPB5, 1);

printk(DEVICE_NAME " initialized\n");

return 0;

}

static void __exit mini2440_led_exit(void){

devfs_remove(DEVICE_NAME);

unregister_chrdev(LED_MAJOR, DEVICE_NAME);

}

module_init(mini2440_led_init);

module_exit(mini2440_led_exit);

应用程序文件—文件名led.c,其内容如下:

#define GPB5_ON 1

#define GPB5_OFF 2

int main(void)

{

//int k;

int dev_fd;

int retval;

dev_fd = open("/dev/lsq_led",O_RDWR | O_NONBLOCK);

if ( dev_fd == -1) {

printf("Can''t open file /dev/lsq_led\n");

exit(-1);

}

printf ("\n/dev/lsq_led opened successfully, fd=%d\n",dev_fd);

wlile(1)

{

retval=ioctl(dev_fd,GPB5_ON,0);

if(retval==-1){

perror("ioctl LEDON error\n");

exit(-1);

}

sleep(1);

retval=ioctl(dev_fd,GPB5_OFF,0);

if(retval==-1){

perror("ioctl LEDOFF error\n");

exit(-1);

}

sleep(1);

}

close(dev_fd);

}

⑶ 编译应用程序led.c的Makefile,其内容如下:

all: led

led:

arm-linux-gcc -o led led.c

clean:

@rm -vf mini2440led *.o *~

⑷ 使内核撑持和编译驱动程序mini2440_one_led.c,需在相应的目录下增加如下内容(自己的习气,当然这一步是可选的):

kernel...../drivers/char/

Makefile

obj-$(CONFIG_MINI2440_ONE_LED) += mini2440_one_led.o

Kconfig

config MINI2440_ONE_LED

tristate "mini2440 one LED Driver"

depends on ARCH_S3C2440

help

mini2440 User led, use GPB5.

   【上一篇:LED市场设备的分析和发展     下一篇:LED日光灯老化线的产品用途! 】    【返回】  

更多

全国服务热线

0760-22586708

Sitemap

AG百家乐| 最正规的老虎机平台| 真人娱乐在线|