/******************************************************************\

   IOEDGL_N.C

   BL11xx/Little Giant with multiple I/O Expansion board

   Always run exp_init_n () first to initialize the PPI.

   int exp_init_n (int node, int ppia, int ppib, int ppicl, int ppicu, int def);

   node may be 0-3 or -1.

   To set mode of PPI ports use 0 to specify as output.  
   Use -1 to specify as inputs.

   def specifies whether to save the node as the default.
   Use 1 to set the default to the specified mode, 0 to not save.

   Digital I/O is accomplished by reading and writing to the 
   appropriate I/O registers.  Place a jumper between two of the
   J8 pins and observe change in output.

   Three other functions support faster access to multiple IOE boards.

   int get_na (int node, struct node_addr *na);
   int set_def_na (int node);
   int get_def_na (struct node_addr *na);

   get_na loads the structure pointed to by na with the addresses of the
   specified node.  Returns -1 if an invalid node is specified.

   set_def_na loads the default set of addresses with the addresses of the
   specified node.  Returns -1 if an invalid node is specified.

   get_def_na loads the structure pointed to by na with the addresses saved
   as the default addresses.  If a default set has not been loaded the
   default will be loaded with Fx0xH.  Returns the node number for the 
   default address set.

   The node address structure is declared as follows:

struct node_addr
{
   int ppicn;            PPI control register 
   int ppida;            PPI A data 
   int ppidb;            PPI B data 
   int ppidc;            PPI C data 
   int pal;              PWM enable (out) PIN (in) 
   int pol;              Polarity for PWM
   int rdttl;            TTL input
   int num;              node number
};
   
\******************************************************************/

struct node_addr na;                /* declare a node address structure */

main()
{
   long i;

   set_def_na (3);                  /* set default node address */
   get_def_na (&na);                /* load the default address set */

   exp_init_n (3, -1,-1,-1,-1, 0);  /* PPI all inputs, don't change default */

   while(1)
   {
   	hitwd();
      printf("PPIDA inputs=%x\n",inport(na.ppida));
      printf("PPIDB inputs=%x\n",inport(na.ppidb));
      printf("PPIDC inputs=%x\n",inport(na.ppidc)); /* opto isolated inputs */
      printf("U1 inputs=%x\n",inport(na.rdttl));   /* ttl inputs */

      for (i = 20000L;--i;) hitwd();               /* pause */
   }
}

/***************************************** End of IOEDGL_N.C ************/
