Chinaunix首页 | 论坛 | 博客
  • 博客访问: 402854
  • 博文数量: 62
  • 博客积分: 1483
  • 博客等级: 上尉
  • 技术积分: 779
  • 用 户 组: 普通用户
  • 注册时间: 2009-02-24 12:25
文章分类

全部博文(62)

文章存档

2012年(2)

2011年(6)

2010年(6)

2009年(48)

我的朋友

分类: LINUX

2009-09-17 19:19:47

必须用root用户才能使用并口。su。
1
在init里加了下面的语句发现
printk(KERN_INFO "0x378:after ioremap is 0x%x",short_base);
[ 1632.343385] 0x378:after ioremap is 0x378
端口映射前后,居然是一样的,以后看看代码是怎么实现的?
2
echo -e '\377'>/dev/parport
echo -e '\0'>  /dev/parport
分别是全亮和全灭。
学到了些变化:
INIT_WORK(&short_wq, (void (*)(void *)) short_do_tasklet);
现在是两个参数了。
3
#include
#include
里面的东西有一些变换,比如initerrup.h里的预定义。
什么SA_什么的都没有了,要用最新的。以后在说呵呵。
4
即使是rmmod所有的使用并口的模块后,short模块也不能正常使用,更不用说测试应用程序了,后来,干脆把/lib/modules/2.6.31/kernel/drivers/parport/
目录移动到别处,这样重启的时候就会因为找不到parport而加载不了他了,呵呵,虽然很暴力,但是,启动后,加载short模块就正常了,不清楚原因,可能在ubuntu的并口驱动里有蹊跷吧。
5
下面是我的测试程序
#include
#include
#include
#include
#include

int main(void)
{
    int i,j,fd,count=0;
    fd = open("/dev/parport", O_RDWR);
    if (fd < 0) {
        perror("open device /dev/gm");
        exit(1);
    }

    unsigned char index[1] = {1};
    while(1){
        index[0] = 1;    /*最低位先亮*/
        do {
            write(fd,index,1);
            usleep(100000);
            }
        while(index[0] <<= 1);
        index[0] = 1 << (sizeof(index)*8 - 1);  /*然后是最高位*/
        do {
            write(fd,index,1);
            usleep(100000);
            }
        while(index[0] >>= 1);
    }

    return 0;
}
阅读(1661) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~