📄 port.c
字号:
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include "../../include/directio.h"
static int fd = -1;
int port_init()
{
fd=open("/dev/directio",O_NONBLOCK,0);
if(fd<0)
{
printf("Can't open directio device\n");
return -1;
}
return 0;
}
unsigned char port_inb(unsigned int port)
{
struct port_data data;
data.cmd = CMD_PORT;
data.startaddr = port;
data.nums = 1;
data.opts = PORT_BYTE;
ioctl(fd, IOCTL_GET_MSG, &data);
return data.value;
}
unsigned short port_inw(unsigned int port)
{
struct port_data data;
data.cmd = CMD_PORT;
data.startaddr = port;
data.nums = 2;
data.opts = PORT_HWORD;
ioctl(fd, IOCTL_GET_MSG, &data);
return data.value;
}
unsigned int port_inl(unsigned int port)
{
struct port_data data;
data.cmd = CMD_PORT;
data.startaddr = port;
data.nums = 4;
data.opts = PORT_WORD;
ioctl(fd, IOCTL_GET_MSG, &data);
return data.value;
}
int port_outb(unsigned int port, unsigned char value)
{
struct port_data data;
data.cmd = CMD_PORT;
data.startaddr = port;
data.nums = 1;
data.opts = PORT_BYTE;
data.value = value;
ioctl(fd, IOCTL_SET_MSG, &data);
}
int port_outw(unsigned int port, unsigned short value)
{
struct port_data data;
data.cmd = CMD_PORT;
data.startaddr = port;
data.nums = 2;
data.opts = PORT_HWORD;
data.value = value;
ioctl(fd, IOCTL_SET_MSG, &data);
}
int port_outl(unsigned int port, unsigned int value)
{
struct port_data data;
data.cmd = CMD_PORT;
data.startaddr = port;
data.nums = 4;
data.opts = PORT_WORD;
data.value = value;
ioctl(fd, IOCTL_SET_MSG, &data);
}
void port_uninit()
{
if(fd >= 0)
close(fd);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -