内核空间程序代码:
static int retries = 5;
static int timeout = 1000;
static int state = 0; // the leds configuration
#define SCROLL_LOCK (1 << 0)
#define NUM_LOCK (1 << 1)
#define CAPS_LOCK (1 << 2)
static void setAllLedsOn()
{
state = SCROLL_LOCK | NUM_LOCK | CAPS_LOCK;
outb(0xed, 0x60); // tell the keyboard we want to set the leds configuration
udelay(timeout);
while (retries != 0 && inb(0x60) != 0xfa) { // wait for the keyboard controller
retries--;
udelay(timeout);
}
if (retries != 0) { //check is keyboard is ready to accept command
outb(state, 0x60);
}
}
用户空间程序代码:
#include <stdio.h>
#include <sys/io.h>
int main()
{
int ret;
ret = ioperm(0x60, 0xf, 1);
if (ret < 0) {
perror("ioperm");
return 1;
}
while (inb(0x64) & 0x2);
outb(0xed, 0x60);
while (inb(0x64) & 0x2);
outb(0x07, 0x60);
ioperm(0x60, 0xf, 0);
return 0;
}