/*
   CLDEMOR.C

   Little Giant, Tiny Giant, Protocol Switch

   Program to demonstrate the use of the high speed parallel protocol.
   Retrieves the time from the target system and displays it on a PC.
   
   Run with CLDEMO.C compiled and loaded onto the PC.
   
   See Applications Note #100 (Tech Note #106) for information on the
   high speed parallel protocol.

   NOTE: documentation may indicate the CLINK_NBUFS and clink_bufptrs,
         these are actually NBUFS and bufptrs.
*/

// The default configuration uses the Protocol Switch PIOA

// #define USELG 1  // uncomment for the Little Giant (BL11xx)
// #define USETG 1  // uncomment for the Tiny Giant

#define NBUFS 4

struct tm ttt;    // time of day 
int buf0[NBUFS] = {8, 2, 2, sizeof (ttt)};
int buf1[2];     // holds pctimeout and timeout 
char buf2[2];    // flag for get time and date 

char *bufptrs [NBUFS] = {buf0, buf1, buf2, &ttt};

long counters;
#use prport.lib

#define ZEROWAIT 1

main()
{
   setwaits(0,0);       // set I/O and memory waitstates to zero 

   piolatch();          // make sure you get PIO interrupts 

   doreti();            // do a reti to prevent resetting the 
                        // IUS latch on 2 peripheral devices 

   clink_init();        // intialize the HS parallel protocol 

   counters=0;
   EI();
   
   while(1)
   {
      if( buf2[0] )     // check for request for the time 
      { 
         tm_rd(&ttt);   // get the time 
         buf2[0]=0;     // and flag it 
      }

      runwatch();
      hitwd();
   }
}
