无法使用outb()调用点亮键盘LED

时间:2013-11-13 12:25:50

标签: c linux-device-driver device-driver hardware-port

我试图通过以下程序点亮Linux中的键盘LED(在互联网上找到它)但似乎没有任何事情发生。我错过了什么吗?

/* sample.c: very simple example of port I/O
 *
 * This code does nothing useful, just a port write, a pause,
 * and a port read. Compile with `gcc -O2 -o example example.c',
 * and run as root with `./example'.
 */

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

#define BASEPORT 0x0060 /* lp1 */

int main()
{
        /* Get access to the ports */
        if (ioperm(BASEPORT, 3, 1)) {perror("ioperm"); exit(1);}

        /* Set the data signals (D0-7) of the port to all low (0) */
        outb(0xED, BASEPORT);

        /* Sleep for a while (100 ms) */
        usleep(1000);
        printf("\n here ");
        outb(0x07, BASEPORT);
        usleep(1000);

        /* We don't need the ports anymore */
        if (ioperm(BASEPORT, 3, 0)) {perror("ioperm"); exit(1);}
    exit(0);
}

0 个答案:

没有答案