打印

我的第一个实验pgio驱动,就是通常点亮led的那个,居然有问题

[复制链接]
5003|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
oiu|  楼主 | 2008-1-24 18:28 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
gpiodrv.c 代码如下:
#include <linux/config.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/iobuf.h>
#include <linux/kernel.h>
#include <linux/major.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <linux/vmalloc.h>
#define IOPORT_MAJOR 220
#define GPFCON (*(volatile unsigned *)0x56000050)  
#define GPFDAT (*(volatile unsigned *)0x56000054)
#define GPFUP  (*(volatile unsigned *)0x56000058)
int gpio_open(struct inode *, struct file*);
int gpio_release(struct inode*, struct file*);
int gpio_ctl_ioctl(struct inode *, struct file*, unsigned int, unsigned long);
static struct file_operations gpio_ctl_fops = {
    ioctl :    gpio_ctl_ioctl,
    open  : gpio_open,
    release : gpio_release,
};
#define LED1_ON()    (GPFDAT &= ~0X10)
#define LED1_OFF()    (GPFDAT |= 0X10)
#define LED2_ON()    (GPFDAT &= ~0X20)
#define LED2_OFF()    (GPFDAT |= 0X20)
#define LED3_ON()    (GPFDAT &= ~0X40)
#define LED3_OFF()    (GPFDAT |= 0X40)
#define LED4_ON()    (GPFDAT &= ~0X80)
#define LED4_OFF()    (GPFDAT |= 0X80)
static int LedStatus;
void LedSet(int led)
{
   LedStatus = led;
   if(LedStatus & 0x01)
    LED1_ON();
   else
    LED1_OFF();
}

void LedDisp(void)
{
    udelay(0x500000);
    LedSet(0x02);
    udelay(0x500000);
    LedSet(0x01);

}

static int __init gpio_init(void)
{   int err = 0;
      printk("gpio inint\n");
      err = register_chrdev(IOPORT_MAJOR, "gpio", &gpio_ctl_fops);
       if(err)
         {
                printk("fail to register\n");
                return -1;
         }
        printk("success to register  \n");
        return 0;
}
int gpio_open(struct inode* inode, struct file* fllp)
{
    GPFCON = 0X5500;
    GPFUP = 0XFF;
    printk("open gpio devices\n");
    return 0;
}
int gpio_release(struct inode *inode, struct file* fillp)
{
    printk("release this device\n");
    return 0;
}
int gpio_ctl_ioctl(struct inode *inode, struct file *flip,unsigned \ 
              int command, unsigned long arg)
{
    int err =0;
    if(command == 1)
        {
            while(arg--)
                {
                   LedDisp();
                   printk("......");
                 }
            printk("\n");
            return 0;
         }
    return err;
}

 module_init(gpio_init);
 module_exit(gpio_release);

我的编译方法是:arm-linux-gcc -O2 -DMODULE -D__KERNEL__ -c gpiodrv.c
提示如下:
gpiodrv.c: In function `__cleanup_module_inline':
gpiodrv.c:113: warning: return from incompatible pointer type

请问哪里出了问题,我看了半天也没看出问题出来,谢谢高手指教。

相关帖子

沙发
Iamstudent| | 2008-1-25 10:26 | 只看该作者

113行是哪行啊?楼主还要别人给您一行行的数

使用特权

评论回复
板凳
oiu|  楼主 | 2008-1-25 17:28 | 只看该作者

谢谢大侠,现在终于调通了,

原来要加入 __exit 这样,不过现在生成的文件不能安装,insmod 的时候,提示有如下问题:
No module found in object
insmod: cannot insert `gpiodrv.o': Invalid module format (-1): Exec format error
,还在努力中....

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

oiu

28

主题

81

帖子

0

粉丝