GPIO简单驱动测试程序出错: BUG: soft lockup - CPU#0 stuck for 61s!

parmalat570907 2012-04-09 01:30:29
我编了一个简单的GPIO驱动程序,运行测试程序,出现如下错误,不知道如何确定原因,怎么修改,望大家指导,多谢!

root@am3517-evm:~/all_driver/CCD/ccd_test# ./ccd_test1
####CAIJI test device open####3
BUG: soft lockup - CPU#0 stuck for 61s! [ccd_test1:1498]
Modules linked in: ccd

Pid: 1498, comm: ccd_test1
CPU: 0 Not tainted (2.6.31-rc7-omap1-06331-g757f531 #1)
PC is at __delay+0x0/0xc
LR is at caiji_rd+0x30/0x3c [ccd]
pc : [<c016d940>] lr : [<bf000040>] psr: 20000013
sp : cd8f7f58 ip : 00000017 fp : be850c94
r10: 00000000 r9 : cd8f6000 r8 : 00001000
r7 : 00001000 r6 : cd8f7f80 r5 : be84fc84 r4 : cfa9d500
r3 : 00000003 r2 : 00000770 r1 : ff3fffff r0 : 000000cf
Flags: nzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user
Control: 10c5387d Table: 8fa34019 DAC: 00000015
BUG: soft lockup - CPU#0 stuck for 61s! [ccd_test1:1498]
Modules linked in: ccd
...全文
902 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zaochenhai 2012-09-12
  • 打赏
  • 举报
回复
你的内核版本太低了吧
timerlist 回调函数不能占用太长时间。
parmalat570907 2012-04-09
  • 打赏
  • 举报
回复
谢谢大家,我改一下再试试
parmalat570907 2012-04-09
  • 打赏
  • 举报
回复
哦,循环变量写错了,再试试去,谢谢了
parmalat570907 2012-04-09
  • 打赏
  • 举报
回复
我把while(1)去掉,也是不行,是不是哪里还有别的错误呢
deep_pro 2012-04-09
  • 打赏
  • 举报
回复
你的caiji_rd 写成死循环了 不会结束
falloutmx 2012-04-09
  • 打赏
  • 举报
回复
for(k=0;i<6;k++)
for(k=0;i<3;k++)
你确定你就是想这么做的?

还有,你驱动里的while(1) 循环是死循环。
parmalat570907 2012-04-09
  • 打赏
  • 举报
回复
驱动程序:

/**********************************************************
caiji driver
pxa270-ads7818
module
**********************************************************/

#include <linux/version.h>
#include <linux/fs.h>
#include <linux/delay.h>
#include <linux/poll.h>
//#include <asm/hardware.h>
#include <asm/uaccess.h> /* get_user,copy_to_user */
#include <linux/miscdevice.h>
#include <linux/string.h>
#include <linux/sched.h>
#include <linux/fcntl.h>
#include <linux/interrupt.h>
#include <linux/ptrace.h>
#include <linux/ioport.h>
#include <linux/in.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/string.h>
#include <linux/init.h>
#include <asm/bitops.h>
#include <linux/errno.h>
#include <linux/wait.h>


#include <linux/gpio.h>


#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/clk.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <asm/io.h>
#include <mach/dmtimer.h>
#include <linux/types.h>




#define DEVICE_NAME "cz_caiji"

#define CAIJI_MAGIC 'K'
#define SET_INTEGRAL1 _IOW(CAIJI_MAGIC, 1, unsigned int)
#define SET_INTEGRAL2 _IOW(CAIJI_MAGIC, 1, unsigned int)


static volatile unsigned int delay_time = 0;
unsigned short int get_ad(void);
static struct omap_dm_timer *timer_ptr9,*timer_ptr10;

void InitGPIO(void)
{

/*ROG,CLK*/
gpio_request(118,"p");//ROG
gpio_request(119, "q");//CLK


}



static ssize_t caiji_rd(struct file *file, char *buffer, size_t count, loff_t * offset)
{
unsigned short int *dbuf;
int i,j,k;

dbuf=kmalloc(2048*sizeof(unsigned short int), GFP_KERNEL);


while(1)

{

// step 1
gpio_direction_output(118, 1);//ROG
gpio_direction_output(119, 1);//CLK

for(k=0;i<3;k++)
{
udelay(1);
}

// step 2
gpio_direction_output(118, 0);
gpio_direction_output(119, 1);

for(k=0;i<6;k++)
{
udelay(1);
}

// step 3
gpio_direction_output(118, 1);
gpio_direction_output(119, 1);//////////to the end

for(k=0;i<3;k++)
{
udelay(1);
}

// step 4
gpio_direction_output(119, 0);
udelay(1); ////////////////////////1/4 CLK , MIN:udelay(2)
//shp();//start GPT9 high first
udelay(1);

gpio_direction_output(119, 1);
udelay(1);
//shd();//start GPT10 high first
udelay(1);

// step 5
for(i=0;i<33;i++)
{
gpio_direction_output(119, 0);
udelay(2);
gpio_direction_output(119, 1);
udelay(2);
}

// step 6
//for(j=0;j<2048+delay_time;j++) //plus integral time
for(j=0;j<2048;j++)
{
gpio_direction_output(119, 0);
gpio_direction_output(88, 1);

dbuf[j]=5;

udelay(2);

gpio_direction_output(119, 1);
gpio_direction_output(88, 0);
udelay(2);
}

// step 7
for(i=0;i<7;i++)
{
gpio_direction_output(119, 0);
udelay(2);
gpio_direction_output(119, 1);
udelay(2);
}

//step 8
//omap_dm_timer_free(timer_ptr9);
//omap_dm_timer_free(timer_ptr10);

//buffer undefined but the application program define it
copy_to_user(buffer, (char*)dbuf, 4096);
kfree(dbuf);



}

return 0;
}

/*
static int caiji_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
{
unsigned int data=0;

if (copy_from_user(&data, (unsigned int *)arg, sizeof(unsigned int)))
return -EFAULT;

switch(cmd)
{
case SET_INTEGRAL1:
delay_time = data;

#ifdef TEST_DEBUG
printk(KERN_INFO "delay_time is %d", delay_time);
#endif
break;

case SET_INTEGRAL2:
delay_time = data;

#ifdef TEST_DEBUG
printk(KERN_INFO "delay_time is %d", delay_time);
#endif
break;

default:
return -EINVAL;


}

return 0;

}

*/
static int caiji_open(struct inode *inode, struct file *filp)
{
//MOD_INC_USE_COUNT;
return 0;
}

static int caiji_release(struct inode *inode, struct file *filp)
{
//MOD_DEC_USE_COUNT;
return 0;
}

static struct file_operations cz_fops = {
open: caiji_open,
read: caiji_rd,
//ioctl: caiji_ioctl,
release: caiji_release,
owner: THIS_MODULE,
};


static int __init caiji_init(void)
{
int ret;
ret = register_chrdev(252, DEVICE_NAME , &cz_fops);

if (ret < 0)
{
printk(DEVICE_NAME " can't get major number\n");
return ret;
}

InitGPIO();

printk(DEVICE_NAME " initialized\n");
return 0;
}

static void __exit caiji_exit(void)
{
unregister_chrdev(252, DEVICE_NAME);
printk(DEVICE_NAME " uninitialized\n");
}


MODULE_AUTHOR("LiuZhuo, <czliuzhuo@emails.bjut.edu.cn>");
MODULE_LICENSE("Dual BSD/GPL");
MODULE_DESCRIPTION("Caiji Device Driver");

module_init(caiji_init);
module_exit(caiji_exit);



测试程序:


/************************************************
Be sure the Major Num 252 not be used
Implement: mknod "/dev/caiji" c 252 1
Be sure the file "/dev/caiji" exist in the filesystem


test: ccd data read,integrel time
*************************************************/
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <termio.h>
#include <fcntl.h>
//include <linux/kernel.h>

#define CAIJI_DEV "/dev/caiji"
int fd;
#define CAIJI_MAGIC 'K'
#define SET_INTEGRAL1 _IOW(CAIJI_MAGIC, 1, unsigned int)
#define SET_INTEGRAL2 _IOW(CAIJI_MAGIC, 1, unsigned int)

int main(int argc, char **argv)
{



//get data
unsigned short int buffer[2048];
int nread;
int i;
FILE *nwrite;

fd = open(CAIJI_DEV, O_RDWR);
if(fd < 0)
{
printf("####CAIJI test device open failed####%d \r\n",fd);
return (-1);
}
printf("####CAIJI test device open####%d \n",fd);


nread= read(fd, buffer, 4096);

if(nread==-1)
{
printf("###A read error###\n",nread);
}

nwrite = fopen("/tmp/data.xls","a+");
for(i=0;i<2048;i++)
{
fprintf(nwrite, "%d\n", (buffer[i]));
}

close(fd);
printf("####CAIJI test device closed####%d \n",fd);


return(0);
}
parmalat570907 2012-04-09
  • 打赏
  • 举报
回复
驱动程序:

/**********************************************************
caiji driver
pxa270-ads7818
module
**********************************************************/

#include <linux/version.h>
#include <linux/fs.h>
#include <linux/delay.h>
#include <linux/poll.h>
//#include <asm/hardware.h>
#include <asm/uaccess.h> /* get_user,copy_to_user */
#include <linux/miscdevice.h>
#include <linux/string.h>
#include <linux/sched.h>
#include <linux/fcntl.h>
#include <linux/interrupt.h>
#include <linux/ptrace.h>
#include <linux/ioport.h>
#include <linux/in.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/string.h>
#include <linux/init.h>
#include <asm/bitops.h>
#include <linux/errno.h>
#include <linux/wait.h>


#include <linux/gpio.h>


#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/clk.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <asm/io.h>
#include <mach/dmtimer.h>
#include <linux/types.h>




#define DEVICE_NAME "cz_caiji"

#define CAIJI_MAGIC 'K'
#define SET_INTEGRAL1 _IOW(CAIJI_MAGIC, 1, unsigned int)
#define SET_INTEGRAL2 _IOW(CAIJI_MAGIC, 1, unsigned int)


static volatile unsigned int delay_time = 0;
unsigned short int get_ad(void);
static struct omap_dm_timer *timer_ptr9,*timer_ptr10;

void InitGPIO(void)
{

/*ROG,CLK*/
gpio_request(118,"p");//ROG
gpio_request(119, "q");//CLK


}



static ssize_t caiji_rd(struct file *file, char *buffer, size_t count, loff_t * offset)
{
unsigned short int *dbuf;
int i,j,k;

dbuf=kmalloc(2048*sizeof(unsigned short int), GFP_KERNEL);


while(1)

{

// step 1
gpio_direction_output(118, 1);//ROG
gpio_direction_output(119, 1);//CLK

for(k=0;i<3;k++)
{
udelay(1);
}

// step 2
gpio_direction_output(118, 0);
gpio_direction_output(119, 1);

for(k=0;i<6;k++)
{
udelay(1);
}

// step 3
gpio_direction_output(118, 1);
gpio_direction_output(119, 1);//////////to the end

for(k=0;i<3;k++)
{
udelay(1);
}

// step 4
gpio_direction_output(119, 0);
udelay(1); ////////////////////////1/4 CLK , MIN:udelay(2)
//shp();//start GPT9 high first
udelay(1);

gpio_direction_output(119, 1);
udelay(1);
//shd();//start GPT10 high first
udelay(1);

// step 5
for(i=0;i<33;i++)
{
gpio_direction_output(119, 0);
udelay(2);
gpio_direction_output(119, 1);
udelay(2);
}

// step 6
//for(j=0;j<2048+delay_time;j++) //plus integral time
for(j=0;j<2048;j++)
{
gpio_direction_output(119, 0);
gpio_direction_output(88, 1);

dbuf[j]=5;

udelay(2);

gpio_direction_output(119, 1);
gpio_direction_output(88, 0);
udelay(2);
}

// step 7
for(i=0;i<7;i++)
{
gpio_direction_output(119, 0);
udelay(2);
gpio_direction_output(119, 1);
udelay(2);
}

//step 8
//omap_dm_timer_free(timer_ptr9);
//omap_dm_timer_free(timer_ptr10);

//buffer undefined but the application program define it
copy_to_user(buffer, (char*)dbuf, 4096);
kfree(dbuf);



}

return 0;
}

/*
static int caiji_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
{
unsigned int data=0;

if (copy_from_user(&data, (unsigned int *)arg, sizeof(unsigned int)))
return -EFAULT;

switch(cmd)
{
case SET_INTEGRAL1:
delay_time = data;

#ifdef TEST_DEBUG
printk(KERN_INFO "delay_time is %d", delay_time);
#endif
break;

case SET_INTEGRAL2:
delay_time = data;

#ifdef TEST_DEBUG
printk(KERN_INFO "delay_time is %d", delay_time);
#endif
break;

default:
return -EINVAL;


}

return 0;

}

*/
static int caiji_open(struct inode *inode, struct file *filp)
{
//MOD_INC_USE_COUNT;
return 0;
}

static int caiji_release(struct inode *inode, struct file *filp)
{
//MOD_DEC_USE_COUNT;
return 0;
}

static struct file_operations cz_fops = {
open: caiji_open,
read: caiji_rd,
//ioctl: caiji_ioctl,
release: caiji_release,
owner: THIS_MODULE,
};


static int __init caiji_init(void)
{
int ret;
ret = register_chrdev(252, DEVICE_NAME , &cz_fops);

if (ret < 0)
{
printk(DEVICE_NAME " can't get major number\n");
return ret;
}

InitGPIO();

printk(DEVICE_NAME " initialized\n");
return 0;
}

static void __exit caiji_exit(void)
{
unregister_chrdev(252, DEVICE_NAME);
printk(DEVICE_NAME " uninitialized\n");
}


MODULE_AUTHOR("LiuZhuo, <czliuzhuo@emails.bjut.edu.cn>");
MODULE_LICENSE("Dual BSD/GPL");
MODULE_DESCRIPTION("Caiji Device Driver");

module_init(caiji_init);
module_exit(caiji_exit);



测试程序:


/************************************************
Be sure the Major Num 252 not be used
Implement: mknod "/dev/caiji" c 252 1
Be sure the file "/dev/caiji" exist in the filesystem


test: ccd data read,integrel time
*************************************************/
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <termio.h>
#include <fcntl.h>
//include <linux/kernel.h>

#define CAIJI_DEV "/dev/caiji"
int fd;
#define CAIJI_MAGIC 'K'
#define SET_INTEGRAL1 _IOW(CAIJI_MAGIC, 1, unsigned int)
#define SET_INTEGRAL2 _IOW(CAIJI_MAGIC, 1, unsigned int)

int main(int argc, char **argv)
{



//get data
unsigned short int buffer[2048];
int nread;
int i;
FILE *nwrite;

fd = open(CAIJI_DEV, O_RDWR);
if(fd < 0)
{
printf("####CAIJI test device open failed####%d \r\n",fd);
return (-1);
}
printf("####CAIJI test device open####%d \n",fd);


nread= read(fd, buffer, 4096);

if(nread==-1)
{
printf("###A read error###\n",nread);
}

nwrite = fopen("/tmp/data.xls","a+");
for(i=0;i<2048;i++)
{
fprintf(nwrite, "%d\n", (buffer[i]));
}

close(fd);
printf("####CAIJI test device closed####%d \n",fd);


return(0);
}
deep_pro 2012-04-09
  • 打赏
  • 举报
回复
粘你的代码 应该是你犯了一个严重的错误 例如中断服务里睡眠了才有这样的问题

4,436

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧