这个驱动就是想测试一下LED,控制四个LED灯的亮和灭。程序可以编译,驱动模块也能正常加载,用户程序也能运行。就是LED灯没有反映。LED灯是好的,因为启动开发板的时候,灯是会亮的。不知道问题出在哪?我自己觉得有点疑问:就是不确定四个LED灯,是不是就是对应GPIO_F7,G0,G1,G8,我找不到这个板子的硬件连接图,是从内核文件smdk.c中看到的。
希望大家能帮我看看,最好是用过JXARM9-2410板子的,非常感谢。
以下是我的驱动程序:
/* leddriver.c - Create an input/output character device
my first driver --xuyongle 20090319 */
#include
#include
#include
#include /* for -EBUSY */
#include /* for verify_area */
#include /* for module_init */
#include /* for get_user and put_user */
#include
#include
#include
#define LED_MAJOR 214
#define DEVICE_NAME "myled"
static devfs_handle_t devfs_handle;
static unsigned long led_table[]=
{
GPIO_F7,
GPIO_G0,
GPIO_G1,
GPIO_G8,
};
static int leds_ioctl(
struct inode *inode,
struct file *file,
unsigned int ioctl_num,/* The number of the ioctl */
unsigned long ioctl_param) /* The parameter to it */
{
switch(ioctl_num){
case 0: { write_gpio_bit(led_table[ioctl_param],1); printk("led off\n");break;}
case 1: { write_gpio_bit(led_table[ioctl_param],0); printk("led on\n"); break;}
default: return 0;
}
}
static int leds_open(struct inode *inode,struct file *file)
{
MOD_INC_USE_COUNT;
printk("Open successful\n");
return 0;
}
static int leds_close(struct inode *inode,struct file *file)
{
MOD_DEC_USE_COUNT;
printk("Close successful\n");
return 0;
}
static struct file_operations fops = {
.owner = THIS_MODULE,
.open = leds_open,
.release = leds_close,
.ioctl = leds_ioctl,
};
static int __init leds_init( void )
{
int ret_val;
int i;
ret_val = register_chrdev(LED_MAJOR, DEVICE_NAME, &fops);
if (ret_val < 0) {
printk ("%s failed with %d\n",
"Sorry, registering the character device ", ret_val);
return ret_val;
}
else printk("register successfully!-xyl");
devfs_handle=devfs_register(NULL, DEVICE_NAME, DEVFS_FL_DEFAULT, LED_MAJOR, 0, S_IFCHR|S_IRUSR|S_IWUSR, &fops, NULL);
for(i=0;i<4;i++)
{
set_gpio_ctrl(GPIO_MODE_OUT|GPIO_PULLUP_DIS|led_table);
write_gpio_bit(led_table,1);
}
printk ("%s 3The major device number is %d.\n","Registeration is a success", LED_MAJOR); printk ("you'll have to create a device file. \n");
printk ("We suggest you use:\n");
printk ("mknod %s c %d 0\n", DEVICE_NAME,LED_MAJOR);
return 0;
};
static void __exit leds_exit(void)
{
int ret;
ret = unregister_chrdev(LED_MAJOR, DEVICE_NAME);
if (ret < 0)
printk("Error in module_unregister_chrdev: %d\n", ret);
else printk("unregister is successful");
devfs_unregister(devfs_handle);
};
module_init(leds_init);
module_exit(leds_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Cvtech Co., Ltd ");
MODULE_DESCRIPTION("LED char driver");
以下是我用来测试驱动的应用程序:
#include
#include
#include
#include
#include
/*input format:ledtest 1 1or0*/
int main(int argc,char **argv)
{
int number; //select led1 to led4
int ledonoff;//led on or off
int fd=-1;
sscanf(argv[1],"%d",&ledonoff);
sscanf(argv[2],"%d",&number);
fd=open("/dev/myled",0);
if(fd<0)
{
perror("open device myled");
exit(1);
}
ioctl(fd,ledonoff,number);
sleep(5);
close(fd);
return 0;
}