主题 : 自己写了一个控制IO端口的驱动~~可是在运行应用程序时出现如下错误!!!求大侠帮忙!! 复制链接 | 浏览器收藏 | 打印
大家互相帮忙一下可以吗?请大家互相帮忙一下啊!
级别: 新手上路
UID: 27546
精华: 0
发帖: 40
金钱: 210 两
威望: 42 点
综合积分: 80 分
注册时间: 2010-08-27
最后登录: 2013-09-17
楼主  发表于: 2011-03-10 14:19

 自己写了一个控制IO端口的驱动~~可是在运行应用程序时出现如下错误!!!求大侠帮忙!!

[root@FriendlyARM /]# ./led 1 0
Unable to handle kernel paging request at virtual address 7afffff4
pgd = c3b20000
[7afffff4] *pgd=00000000
Internal error: Oops: 5 [#1]
last sysfs file: /sys/devices/virtual/misc/dynamo/dev
Modules linked in: dynamo
CPU: 0    Not tainted  (2.6.32.2-FriendlyARM #1)
PC is at s3c2410_gpio_setpin+0x24/0x44
LR is at sbc2440_dynamos_ioctl+0x34/0x40 [dynamo]
pc : [<c0039e34>]    lr : [<bf000034>]    psr: 80000093
sp : c3ad3ebc  ip : c3ad3ed0  fp : c3ad3ecc
r10: 00000000  r9 : c3ad2000  r8 : c0030088
r7 : 00000003  r6 : 00000000  r5 : 00000000  r4 : c3b13380
r3 : 80000013  r2 : 7afffff0  r1 : 00000001  r0 : fffffff1
Flags: Nzcv  IRQs off  FIQs on  Mode SVC_32  ISA ARM  Segment user
Control: c000717f  Table: 33b20000  DAC: 00000015
Process led (pid: 723, stack limit = 0xc3ad2270)
Stack: (0xc3ad3ebc to 0xc3ad4000)
3ea0:                                                                c3b13380
3ec0: c3ad3edc c3ad3ed0 bf000034 c0039e20 c3ad3efc c3ad3ee0 c00a7a2c bf000010
3ee0: 00000001 00000001 00000000 00000003 c3ad3f7c c3ad3f00 c00a7ce8 c00a79c8
3f00: c002f1e0 c0036ba0 00000000 c3adef38 00000001 08100877 c3acc780 00000001
3f20: 00000000 c3b13380 c3a9af04 00000000 c3ad3f64 c3ad3f40 c00afb7c c3b00000
3f40: 00000003 ffffff9c 00000000 00000000 c3ad2000 c3b13380 00000001 00000000
3f60: 00000003 c0030088 c3ad2000 00000000 c3ad3fa4 c3ad3f80 c00a8290 c00a7c8c
3f80: 00000005 00000000 000086cc 00000000 0000849c 00000036 00000000 c3ad3fa8
3fa0: c002fee0 c00a8260 000086cc 00000000 00000003 00000000 00000001 00000001
3fc0: 000086cc 00000000 0000849c 00000036 00000000 00000000 40025000 be8a3d44
3fe0: 00000000 be8a3d28 00008698 400e4cac 60000010 00000003 33cc33cc 33cc33cc
Backtrace:
[<c0039e10>] (s3c2410_gpio_setpin+0x0/0x44) from [<bf000034>] (sbc2440_dynamos_i
octl+0x34/0x40 [dynamo])
r4:c3b13380
[<bf000000>] (sbc2440_dynamos_ioctl+0x0/0x40 [dynamo]) from [<c00a7a2c>] (vfs_io
ctl+0x74/0x7c)
[<c00a79b8>] (vfs_ioctl+0x0/0x7c) from [<c00a7ce8>] (do_vfs_ioctl+0x6c/0x5d4)
r7:00000003 r6:00000000 r5:00000001 r4:00000001
[<c00a7c7c>] (do_vfs_ioctl+0x0/0x5d4) from [<c00a8290>] (sys_ioctl+0x40/0x68)
[<c00a8250>] (sys_ioctl+0x0/0x68) from [<c002fee0>] (ret_fast_syscall+0x0/0x28)
r7:00000036 r6:0000849c r5:00000000 r4:000086cc
Code: e121f002 e3c0201f e1a020a2 e28224fb (e592c004)
---[ end trace 693773a0693773a0 ]---
Segmentation fault
[root@FriendlyARM /]#




驱动程序
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#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 <linux/gpio.h>
#include <asm/uaccess.h>
#include <asm/atomic.h>
#include <asm/unistd.h>

#define MISC_DYNAMIC_DYNAMO    71
#define DEVICE_NAME "dynamo"

static unsigned long dynamo_table [] = {  

    S3C2410_GPG(0),
    S3C2410_GPG(3),
};


static unsigned int dynamo_cfg_table [] = {
    S3C2410_GPIO_OUTPUT,
    S3C2410_GPIO_OUTPUT,
};


static int sbc2440_dynamos_ioctl(
    struct inode *inode,
    struct file *file,
    unsigned int cmd,  

    unsigned long arg)  

{    
    
    switch(cmd) {  
    
    case 0:    

    case 1:    

        if (arg > 2) {    

            return -EINVAL;    

        }
        s3c2410_gpio_setpin(dynamo_cfg_table[arg], !cmd);
        
        return 0;
    default:
        return -EINVAL;    

    }
}


static struct file_operations dev_fops = {
    .owner    =    THIS_MODULE,    
    .ioctl    =    sbc2440_dynamos_ioctl,  

};

static struct miscdevice misc = {
    .minor = MISC_DYNAMIC_DYNAMO,
    
    .name = DEVICE_NAME,  

    .fops = &dev_fops,    

};


static int __init dev_init(void)
{
    int ret;

    int i;
    
    for (i = 0; i < 2; i++) {    

        s3c2410_gpio_cfgpin(dynamo_table, dynamo_cfg_table);
        s3c2410_gpio_setpin(dynamo_table, 0);
    }


    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_LICENSE("GPL");
MODULE_AUTHOR("FriendlyARM YUMMEN");



测试程序!!!!!



#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/select.h>
#include <sys/time.h>
#include <string.h>

static int led_fd;
static int type = 1;
static int period = 1;


static void push_leds(void)
{

    switch(type)
    {
    case 0:
        {
            
            ioctl(led_fd, 1, 0);
            ioctl(led_fd, 0, 1);
            
        }
        break;
    case 1:
        {
            
            ioctl(led_fd, 0, 0);
            ioctl(led_fd, 1, 1);
            
        }
        break;
    default:
        {
            ioctl(led_fd, 0, 0);
            ioctl(led_fd, 0, 1);
            
        }
    }
}


int main(void)
{
    int led_control_pipe;
    int null_writer_fd; // for read endpoint not blocking when control process exit


    led_fd = open("/dev/dynamo", 0);
    if (led_fd < 0)
    {
        led_fd = open("/dev/dynamo", 0);
    }
    if (led_fd < 0)
    {
        perror("open device dynamo");
        exit(1);
    }
    unlink("/tmp/led-control");
    mkfifo("/tmp/led-control", 0666);

    led_control_pipe = open("/tmp/led-control", O_RDONLY | O_NONBLOCK);
    if (led_control_pipe < 0)
    {
        perror("open control pipe for read");
        exit(1);
    }
    
    null_writer_fd = open("/tmp/led-control", O_WRONLY | O_NONBLOCK);
    if (null_writer_fd < 0)
    {
        perror("open control pipe for write");
        exit(1);
    }

    for (;;)
    {
        fd_set rds;

        int ret;

        FD_ZERO(&rds);
        FD_SET(led_control_pipe, &rds);

        ret = select(led_control_pipe + 1, &rds, NULL, NULL, NULL);
        if (ret < 0)
        {
            perror("select");
            exit(1);
        }
        if (ret == 0)
        {
            push_leds();
        }
        else if (FD_ISSET(led_control_pipe, &rds))
         {
            static char buffer[200];
            for (;;)
            {
                char c;
                int len = strlen(buffer);
                if (len >= sizeof buffer - 1)
                {
                    memset(buffer, 0, sizeof buffer);
                    break;
                }
                if (read(led_control_pipe, &c, 1) != 1)
                {
                    break;
                }
                if (c == '\r')
                {
                    continue;
                }
                if (c == '\n')
                {
                    int tmp_type;
                    double tmp_period;
                    if (sscanf(buffer,"%d%lf", &tmp_type, &tmp_period) == 2)
                    {
                        type = tmp_type;
                        period = tmp_period;
                    }
                    fprintf(stderr, "type is %d, period is %d\n", type, period);
                    memset(buffer, 0, sizeof buffer);
                    break;
                }
                buffer[len] = c;
            }
        }
    }

    close(led_fd);
    return 0;
}

希望有人可以帮助我啊!!!!!!!!!!!!新手求助!!!!!!!!!!!!!!!!!!!!!!!!
大家互相帮忙一下可以吗?请大家互相帮忙一下啊!
级别: 新手上路
UID: 27546
精华: 0
发帖: 40
金钱: 210 两
威望: 42 点
综合积分: 80 分
注册时间: 2010-08-27
最后登录: 2013-09-17
1楼  发表于: 2011-03-10 14:21
        
大家互相帮忙一下可以吗?请大家互相帮忙一下啊!
级别: 新手上路
UID: 27546
精华: 0
发帖: 40
金钱: 210 两
威望: 42 点
综合积分: 80 分
注册时间: 2010-08-27
最后登录: 2013-09-17
2楼  发表于: 2011-03-10 16:32
        
大家互相帮忙一下可以吗?请大家互相帮忙一下啊!
级别: 新手上路
UID: 27546
精华: 0
发帖: 40
金钱: 210 两
威望: 42 点
综合积分: 80 分
注册时间: 2010-08-27
最后登录: 2013-09-17
3楼  发表于: 2011-03-21 10:06
     问题解决了~~~~~~~~~~
级别: 新手上路
UID: 38048
精华: 0
发帖: 6
金钱: 45 两
威望: 9 点
综合积分: 12 分
注册时间: 2011-02-20
最后登录: 2011-04-27
4楼  发表于: 2011-04-17 21:33

 回 3楼(weiqifa0) 的帖子

那个oops的问题怎么解决的啊?求楼主给指点啊