我使用的是国嵌的LED驱动程序:
#include <linux/miscdevice.h>
#include <linux/delay.h>
#include <asm/irq.h>
#include <mach/regs-gpio.h>
#include <mach/hardware.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/fs.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/moduleparam.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include <linux/ioctl.h>
#include <linux/cdev.h>
#include <linux/string.h>
#include <linux/list.h>
#include <linux/pci.h>
#include <asm/uaccess.h>
#include <asm/atomic.h>
#include <asm/unistd.h>
#include <asm/io.h>
#include <asm/system.h>
#include <asm/uaccess.h>
#include "memdev.h"
#define DEVICE_NAME "leds"
static unsigned long led_table [] = {
S3C2410_GPB5,
S3C2410_GPB6,
S3C2410_GPB7,
S3C2410_GPB8,
};
static unsigned int led_cfg_table [] = {
S3C2410_GPB5_OUTP,
S3C2410_GPB6_OUTP,
S3C2410_GPB7_OUTP,
S3C2410_GPB8_OUTP,
};
static int sbc2440_leds_ioctl(
struct inode *inode,
struct file *file,
unsigned int cmd,
unsigned long arg)/*arg是灯号*/
{
int i = 0;
/* 检测命令的有效性 */
if (_IOC_TYPE(cmd) != MEMDEV_IOC_MAGIC)
return -EINVAL;
if (_IOC_NR(cmd) > MEMDEV_IOC_MAXNR)
return -EINVAL;
/* 根据命令,执行相应的操作 */
switch(cmd) {
case MEMDEV_IOCOFF:
/*灯全灭*/
cmd = 1;
for(i=0; i<4; i++)
s3c2410_gpio_setpin(led_table, cmd);
return 0;
case MEMDEV_IOCON:
/*灯全亮*/
for(i=0; i<4; i++)
s3c2410_gpio_setpin(led_table, !cmd);
return 0;
default:
return -EINVAL;
}
}
/*文件操作结构体*/
static struct file_operations dev_fops = {
.owner = THIS_MODULE,
.ioctl = sbc2440_leds_ioctl,
};
static struct miscdevice misc = {
.minor = MISC_DYNAMIC_MINOR,/*在内核中为255,如果你不知道哪些被用了,使用它,内核为你分配*/
.name = DEVICE_NAME,
.fops = &dev_fops,
};
static int __init dev_init(void)
{
int ret;
int i;
/*设置GPIO控制寄存器,GPIO设置为输出模式,默认下灯全灭*/
for (i = 0; i < 4; i++) {
s3c2410_gpio_cfgpin(led_table, led_cfg_table);/*板级支持包实现的:/arch/arm*/
s3c2410_gpio_setpin(led_table, 1);/*设置相应GPIO口的值*/
}
/*注册混杂型字符设备驱动*/
ret = misc_register(&misc);
printk (DEVICE_NAME"\tinitialized\n");
return ret;
}
static void __exit dev_exit(void)
{
/*注销混杂型字符设备驱动*/
misc_deregister(&misc);
}
module_init(dev_init);
module_exit(dev_exit);
MODULE_AUTHOR("David Xie");
MODULE_LICENSE("GPL");
make的时候错误提示为:
[root@localhost 5-3-2]# make
make -C /root/Desktop/kernel/linux-2.6.38 M=/mnt/hgfs/share/guoqian2/5-3-2 modules ARCH=arm CROSS_COMPILE=arm-linux-
make[1]: Entering directory `/root/Desktop/kernel/linux-2.6.38'
CC [M] /mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.o
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:33:2: error: 'S3C2410_GPB5' undeclared here (not in a function)
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:34:2: error: 'S3C2410_GPB6' undeclared here (not in a function)
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:35:2: error: 'S3C2410_GPB7' undeclared here (not in a function)
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:36:2: error: 'S3C2410_GPB8' undeclared here (not in a function)
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:40:2: error: 'S3C2410_GPB5_OUTP' undeclared here (not in a function)
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:40:2: error: initializer element is not constant
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:40:2: error: (near initialization for 'led_cfg_table[0]')
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:41:2: error: 'S3C2410_GPB6_OUTP' undeclared here (not in a function)
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:41:2: error: initializer element is not constant
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:41:2: error: (near initialization for 'led_cfg_table[1]')
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:42:2: error: 'S3C2410_GPB7_OUTP' undeclared here (not in a function)
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:42:2: error: initializer element is not constant
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:42:2: error: (near initialization for 'led_cfg_table[2]')
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:43:2: error: 'S3C2410_GPB8_OUTP' undeclared here (not in a function)
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:43:2: error: initializer element is not constant
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:43:2: error: (near initialization for 'led_cfg_table[3]')
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c: In function 'sbc2440_leds_ioctl':
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:65:4: error: implicit declaration of function 's3c2410_gpio_setpin'
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c: At top level:
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:80:2: error: unknown field 'ioctl' specified in initializer
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:80:2: warning: initialization from incompatible pointer type
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c: In function 'dev_init':
/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.c:96:3: error: implicit declaration of function 's3c2410_gpio_cfgpin'
make[2]: *** [/mnt/hgfs/share/guoqian2/5-3-2/mini2440_leds_misc.o] Error 1
make[1]: *** [_module_/mnt/hgfs/share/guoqian2/5-3-2] Error 2
make[1]: Leaving directory `/root/Desktop/kernel/linux-2.6.38'
make: *** [all] Error 2
我的内核版本是2.6.38.
我觉得应该是是头文件的问题:
我用souce insight查了一下,'S3C2410_GPB5、6、7、8以及'S3C2410_GPB5_OUTP在内核中的arch/arm/mach-s3c2410/include/mach/regs-gpio.h头文件中定义。
s3c2410_gpio_setpin在内核中的头文件arch/arm/mach-s3c2410/include/mach/hardware.h中定义。
不知道怎么回事,请大家帮帮忙啊!