/*
	z104wdog.c

	This program demonstrates watch dog reset monitoring at the start of a
	program. It also blinks the LED at different rates depending on branching
	within the program.
*/

#use "default.h"

#if (BOARD_TYPE!=Z104ISA)
#fatal "This program only runs on the Z104 or ZISA boards."
#endif

main()
{
   unsigned int i;

   if(wderror())            // if a watchdog error was encountered
   {
      printf("A watchdog error has occured.\n");
      printf("Reset the board to reset the watchdog.\n");

         while(1)
         {
            hitwd();
            outport(LED, 1);
            for(i = 0; i < 5000; i++);  // delay
            hitwd();
            outport(LED, 0);
            for(i = 0; i < 5000; i++);
         }
   }
   
    // If a watch dog reset has not happened, toggle the led at a different 
    // rate. Also the following loop does not hit the watch dog. Enable the
    // watchdog by jumpering JP3 and see a watch dog reset happen.

   printf("Waiting for watchdog time out, jumper JP3.\n");
   printf("Recompile and run program if a watchdog has timed out.\n");

   while(1)                
   {                         
      for(i = 0; i < 20000; i++);      // delay
      outport(LED, 1);                 // turn on the LED
      for(i = 0; i < 20000; i++);      // delay
      outport(LED, 0);                 // turn off the LED
   }
}
