日期:2014-05-16  浏览次数:20597 次

初学驱动,遇到一点问题
下面是测试程序,在调用open之后,就看不到printf函数的输出了,也就是说能看到输出的Before   open,却看不到After   open!,其他好像都正常,请大虾帮忙分析下啊!
#include   <stdio.h>
#include   <string.h>
#include   <malloc.h>
#include   <sys/types.h>
#include   <sys/stat.h>
#include   <sys/ioctl.h>
#include   <fcntl.h>
#include   <unistd.h>
#include   <signal.h>
#include   <fcntl.h>


int   main(void)
{
  int   i=10,fd;
  rgdata=0xffffffff;
  printf( "Before   open\n ");
  if((fd=open( "/dev/leddrv ",O_RDWR))==-1)   {
    printf( "open   error\n ");
    exit(1);
  }
  printf( "After   open!\n ");
  while(i--)   {
    rgdata=~rgdata;
    sleep(1);
  }
  close(fd);
  return   0;
}


------解决方案--------------------
其他好像都正常......这是什么意思?
既然下面都没输出了,你怎么知道正常呢?
------解决方案--------------------
能不能打印出错误信息?

用root权限试试看!!

------解决方案--------------------
那就从printk开始 找原因, 进行调试啊。
------解决方案--------------------
建议这样用printk, printk( "%s\n ", "fdsa ");
还有,希望你能把驱动源码发上来看一下。
------解决方案--------------------
static struct file_operations led_fops=
{
open :(void (*))led_open,
};

里struct module *owner;这个域不能省吧

记得以前这个地方填错了,出过错

你的系统没有down掉,你 已经很幸运了