威望0
积分7976
贡献0
在线时间763 小时
UID1
注册时间2021-4-14
最后登录2024-11-24
管理员
- UID
- 1
- 威望
- 0
- 积分
- 7976
- 贡献
- 0
- 注册时间
- 2021-4-14
- 最后登录
- 2024-11-24
- 在线时间
- 763 小时
|
[mw_shl_code=cpp,true]/*
*
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/io.h>
#define lPort 0x2E
#define cData 0x2F
#define message(args...) fprintf(stdout, args)
void init_wdt_timer();
void wdt_active(int timeout);
void wdt_disable(void);
int main(int argc, char **argv)
{
int timeout;
if (argc == 1)
{
timeout = 5;
}
else
{
timeout = atoi(argv[1]);
if (timeout < 3)
{
timeout = 3;
}
else if (timeout > 60)
{
timeout = 60;
}
}
//message("Starting Watchdog, %d secs timeout\n", timeout);
//I/O端口访问
if (ioperm(0, 0x3ff, 1) < 0)
{
//端口可读写
if (iopl(3) < 0)
{
message("iopl fail\n");
return 0;
}
}
message("Starting Watchdog, %d secs timeout\n", timeout);
init_wdt_timer();
//每隔一秒钟重置看门狗时间,达到喂狗效果
while (1)
{
wdt_active(timeout);
message("set watch dog timeout value: %d secs\n", timeout);
sleep(1);
}
}
void init_wdt_timer()
{
unsigned int temp = 0;
outb(0x87, lPort);
outb(0x01, lPort);
outb(0x55, lPort);
outb(0x55, lPort);
outb(0x07, lPort);
outb(0x07, cData);
outb(0x72, lPort);
temp = inb(cData);
temp = temp | 0xC0;
outb(temp, cData);
}
void wdt_active(int timeout)
{
outb(0x73, lPort);
outb(timeout, cData);
}
void wdt_disable(void)
{
unsigned int temp = 0;
outb(0x87, lPort);
outb(0x01, lPort);
outb(0x55, lPort);
outb(0x55, lPort);
outb(0x07, lPort);
outb(0x07, cData);
outb(0x72, lPort);
temp = inb(cData);
temp = temp & 0xBF;
outb(temp, cData);
outb(0x73, lPort);
outb(0x00, cData);
}[/mw_shl_code] |
|