| 我想问一下我写了一个led驱动程序,程序编译和测试程序编译都对,也将驱动注册成功到内核了,目标是能控制led灯全灭和全亮,但是我发现tq2440的led灯只要板子电源开启了,就会按照一定的规律闪动,我想是不是因为文件系统有一个程序是只要系统打开就会一直执行,然后所以我的操作优先级不够高,所以led灯不能受我的控制,求解释啊,谢谢大家 这是驱动程序
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/fs.h>
 #include <linux/init.h>
 #include <linux/delay.h>
 #include <linux/irq.h>
 #include <linux/device.h>
 #include <asm/uaccess.h>
 #include <asm/irq.h>
 #include <asm/io.h>
 #include <linux/poll.h>
 
 static int major;
 
 /*定义class结构体*/
 static struct class *first_led_class;
 
 /*定义一个class_device结构体*/
 
 /*此定义也是可以的:static struct class_device *first_led_device;*/
 static struct class_device *first_led_device;
 
 
 volatile unsigned long *GPBCON = NULL;
 volatile unsigned long *GPBDAT = NULL;
 
 static int first_led_open (struct inode *inode, struct file *file)
 {
 *GPBCON &= ~((3<<10)|(3<<12)|(3<<14)|(3<<16));
 *GPBCON |= (1<<10)|(1<<12)|(1<<14)|(1<<16);
 return 0;
 }
 static ssize_t first_led_write(struct file *file,
 
 const char __user *user_buffer, size_t count, loff_t * loff)
 {
 int ret;
 
 /*从用户空间得到数据*/
 copy_from_user(&ret,user_buffer,count);
 if(0 == ret)
 
 /*点亮led*/
 *GPBDAT &=  ~((1<<5)|(1<<6)|(1<<7)|(1<<8));
 else
 
 /*熄灭led*/
 
 *GPBDAT |= ((1<<5)|(1<<6)|(1<<7)|(1<<8));
 return count;
 }
 
 /*定义一个file_operations结构体*/
 static struct file_operations first_led_fops = {
 .owner = THIS_MODULE,
 .open  = first_led_open,
 .write = first_led_write,
 };
 
 /*入口函数*/
 static int first_led_init(void){
 
 /*注册,主设备的位置为0,代表自动分配主设备号*/
 major = register_chrdev(0,"first_dev_led",&first_led_fops);
 
 /*创建一个类,可在/sys/class目录下查看到*/
 first_led_class = class_create(THIS_MODULE,"fisrst_led_class");
 
 /*类下创建一个设备,可在/sys/class/fisrst_led_class目录下查看到*/
 first_led_device = device_create(first_led_class,NULL,
 MKDEV(major,0),NULL,"first_led");
 
 /*地址映射*/
 GPBCON = (volatile int *)ioremap(0x56000010,16);
 GPBDAT = GPBCON + 1;
 
 return 0;
 }
 static void first_led_exit(void){
 
 /*注销*/
 unregister_chrdev(major,"first_dev_led");
 
 /*注销设备*/
 device_unregister(first_led_device);
 
 /*销毁类*/
 class_destroy(first_led_class);
 
 /*注销虚拟地址的映射*/
 iounmap(GPBCON);
 }
 MODULE_LICENSE("GPL");
 module_init(first_led_init);
 module_exit(first_led_exit);
 这是测试程序
 //usage< file on | off >
 
 #include<unistd.h>
 
 #include<fcntl.h>
 #include<stdio.h>
 int main(int argc,char **argv){
 int fd;
 int val=1;
 fd=open("/dev/first_led",O_RDWR);
 if(fd<0)
 printf("can't open!\n");
 if(argc != 2)
 
 {
 printf("usage:\n");
 printf("first_devdritest <on|off>\n");
 return 0;
 }
 if(strcmp(argv[1],"on")==0)
 val=0;
 else
 val=1;
 write(fd,&val,4);
 return 0;
 }
 |