/* * heatbeats.c -- sends heartbeats (pulses) over a serial port with RTS and DTR * This Program needs to be restarted (= killed and new started) within MAXUPTIME Seconds; otherwise the watchdogs resets! * 2001 */ #include #include /* or asm/io.h; for inb, ioperm, iopl ... */ #include /* atoi */ #include // getuid() #include // EPERM #include // time #define MAXUPTIME 1000000 // default 1 Ms : 1 1/2 Weeks int main(int argc, char **argv) { const int udelay = 2000000; // 2 s delay const unsigned int sbase=0x2f8; // 0x2f8 usually for the second serial port, 0x3f8 for first, 0x3E8 for third, 0x2E8 for fouth unsigned char s0=0, s1=1, sregister=0; // status register values of the serial port int starttime=0; // starttime if (geteuid()!=0) { printf("\a\n\nError: $EUID==%d!=0 (you are not a superuser).\n\n",getuid()); exit (-EPERM); } starttime = time(NULL); iopl(3); /* unlimited I/O access permission, nessesary above the 0x3ff limit e. g. at 0x9800=38912 */ nice(19); /* be nice ;-) */ sregister = inb(sbase+4); s0 = sregister & 0xfc; // clear RTS and DTR s1 = sregister | 0x03; // set RTS and DTR while ( time(NULL) - starttime < MAXUPTIME ) // while system is running and uptimelimit is not reached { outb(s0,sbase+4); // first part of the heartbeat usleep(udelay); // sleep outb(s1,sbase+4); // second part of the heartbeat usleep(udelay); // sleep } iopl(0); /* no I/O permission */ exit(-1); /* never happen within uptime */ }