[PARPORT] Problems writing a device driver

From: Paulo Dantas (phdantas@h8.ita.br)
Date: Wed Nov 28 2001 - 20:25:22 EST

  • Next message: Tim Waugh: "Re: [PARPORT] Problems writing a device driver"

    Hi,
    I'm trying to write a device driver under Linux to access an EKG device on the parallel port. It's my first attempt to program for Linux. Here is my problem: The first test code I've written doesn't succeed. It compiles but when I try to insert the module, a message appears saying that doesn't identify the kernel version the module was compiled for. When I compile without the optimization -O2 parameter it doesn´t recognize some kenel functions, like ioperm(), usleep() etc.My kernel version is 2.2. I run the Conectiva Linux 6.0.What changes should I make to make it work?The code is transcribed after.Thanks a lot,Paulo Henrique DantasSao Paulo - SP - Brazil
    /*Primeira versao do driver de leitura da porta paralelaData: 13/09/2001Paulo Henrique de Holanda Dantas*/#include <linux/kernel.h>#include <linux/version.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <asm/io.h>#define _NO_VERSION_#define BASE 0x378 /* endereco base LPT1 *//* Definição das variaveis globais */char kernel_version [] = UTS_RELEASE;int aux;int canal;int pulso;int eoczero;int eocum;int amostra;/* Inicializar o modulo*/int init_module(){/* Permissao de acesso as portas */ioperm(BASE, 3, 1);/*Especificacao do endereco do canal */aux = inb(BASE+2);canal = aux & 249; /* Zera os bits A1 e A0, escolhendo o canal 1 */outb(canal,BASE+2);/* Pulso START - Inicio da conversao */aux = inb(BASE+2);pulso = aux & 254; /* Zera o bit de START, iniciando o pulso */outb(pulso,BASE+2);pulso = pulso | 1; /* Seta em 1 o bit de START, gerando o pulso */outb(pulso,BASE+2);/* Monitorar o EOC - Fim da conversao */do{aux = inb(BASE+1);eoczero = aux & 64;}while(eoczero = 64); /* Espera EOC ir a zero */do{aux = inb(BASE+1);eocum = aux & 64;}while(eocum = 0); /* Espera EOC ir a zero *//* Habilitar o CHIP SELECT */aux = inb(BASE+2);aux = aux | 32; /* Fazer o bit de CHIP SELECT igual a 1 */outb(aux,BASE+2);/* Capturar a amostra */amostra = inb(BASE);/* Desabilitar o CHIP SELECT */aux = inb(BASE+2);aux = aux & 223; /* Fazer o bit de CHIP SELECT igual a 0 */outb(aux,BASE+2);printk("Driver de leitura da PP instalado\n");return 0;}/* Cleanup - desfazer o que o init_module fez */int cleanup_module(){/* Retirar a permissao de acesso às portas */ioperm(BASE, 3, 0);printk("Driver de leitura da PP removido\n");return 0;exit(0);}

    -- To unsubscribe, send mail to: linux-parport-request@torque.net --
    -- with the single word "unsubscribe" in the body of the message. --



    This archive was generated by hypermail 2b29 : Thu Nov 29 2001 - 09:43:13 EST