/*-------------------------------------------------------------------- * C LANGUAGE SAMPLE 0 * * Sample program for the Watchdog Serial Interface card * demonstrating register level programming. * * Last Modification : 21 November 1994. *------------------------------------------------------------------*/ #include #include #include #include #include #define _10secLo 0xCA #define _10secHi 0x08 unsigned base; unsigned AskForBaseAddress(unsigned int OldOne) { char msg[81]; unsigned int NewOne=0; window(5,5,75,19); textcolor(WHITE); textbackground(BLUE); clrscr(); window(10,7,70,17); cprintf("\n\n\nPlease enter the Base Address for your card (in hex)\n\r" "or press ENTER for %X.\n\r" ">",OldOne); msg[0]=5; cgets(msg); sscanf(msg+2,"%x",&NewOne); textcolor(LIGHTGRAY); textbackground(BLACK); window(1,1,80,24); clrscr(); return ((NewOne>=0x100)&&(NewOne<=0x3f0)) ? NewOne : OldOne; } /* end of AskForBaseAddress */ void intro(void) { clrscr(); puts("Sample "); puts("\n"); puts("This sample program simulates the Watchdog timer in action."); puts("The program sets the Watchdog timer to provide a 10 second"); puts("fault monitoring polling interval. If a key is not pressed"); puts("within that interval, the Watchdog will alert the system"); puts("that a failure has occured."); puts("\n"); puts("\n"); puts("\n"); puts("\n"); puts("Please press ENTER to set base address."); getch(); clrscr(); base = AskForBaseAddress(0x350); clrscr(); printf("Address entered was %X hexidecimal.\n", base); printf("Is this the correct address for your configuration? (Y/n)"); while(!kbhit()); if (toupper(getch()) == 'N') { printf("\n\nPlease restart program and enter correct address.\n"); exit(1); } } /* end of intro */ void main(void) { int secs1, secs2; int count; intro(); clrscr(); puts("The Watchdog is on patrol!"); puts("\n"); puts("Press any key to issue the 'all clear' message and"); puts("reset the Watchdog timer, or wait ten seconds for "); puts("time out and error response."); puts("\n"); outportb(base+3, 0xB0); /* Select Watchdog counter */ outportb(base+2, _10secLo); /* Set counter LSB */ outportb(base+2, _10secHi); /* Set counter MSB */ secs2 = ((_10secHi << 8) + _10secLo) / 225; /* Init seconds count */ delay(50); do { if (kbhit()) /* then reset Watchdog */ { getch(); /* Clear keyboard buffer */ printf(" 'All clear!' -- Watchdog reset.\n"); delay(100); sound(1200); delay(50); nosound(); delay(100); sound(1200); delay(50); nosound(); delay(200); outportb(base+3, 0xB0); /* Select the Watchdog counter */ outportb(base+2, _10secLo); /* Load a 10 second countdown */ outportb(base+2, _10secHi); secs2 = ((_10secHi << 8) + _10secLo) / 225; delay(50); } /* of if keyboard hit */ outportb(base+3, 0x40); /* Latch current timer count */ count = inportb(base+2); /* Read counter LSB/MSB */ count = count + (inportb(base+2) << 8); secs1 = (count / 255) + 1; /* Convert to seconds */ if (secs1 < secs2) { secs2 = secs1; /* if new secs < prev secs */ printf("%d ", secs1); /* Display new seconds */ sound(720); /* Sound a clock tick */ delay(20); nosound(); } /* end if secs */ } while (count >= 0); /* Time's up! */ puts("\n"); puts("\n"); puts(" WOOF!!"); /* Issue Watchdog warning */ sound(1200); delay(400); nosound(); puts("\n"); puts(" Had this been an actual emergency, Watchdog"); puts(" would have taken appropriate fail-safe action."); } /* end of main */