Frage

I am trying to understand the following code:

#include<stdio.h>
#include<stdlib.h>
#include<sys/io.h>

#define baseport 0x378

int main()
{
    int b;
    if(ioperm(baseport,3,1))
    {
        perror("ioperm");
        exit(1);
    }
    outb(0,baseport);

    usleep(1000000);
    printf("\n the status: %x,\n",inb(baseport));

    if (ioperm(baseport,3,0)) {perror("ioperm"); exit(1);}

    exit(0);
}

The output is 0xff, 255 in decimal, whether I write on Port 1 or Port 0 (using outb()). I cannot understand why it is 255 when I am writing 0 to it.

War es hilfreich?

Lösung

The result of doing inb(0x378) is hardware-dependent. Some chips return the value you have written previously with outb, and some other chips just return garbage. In any case, it is not the port to read bytes from a potentially connected device.

Andere Tipps

first see, how the port can behave, as input or output or both!!!.. if it can be configured as both .. you have to set to respective mode then only you can expect the right behaviour ..

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top