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;
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);
};
以下是我用来测试驱动的应用程序:
#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);