
/*********************************************************************/
/*                                                                   */
/*     Low Level Port : EtherNet Network Interface                   */
/*                                                                   */
/*      Version 0.1                      vom 28. November 1996       */
/*                                                                   */
/*********************************************************************/


#include <tos.h>
#include <stdio.h>
#include <string.h>

#include "sting\transprt.h"
#include "sting\port.h"


#define  M_YEAR    16
#define  M_MONTH   11
#define  M_DAY     28


long           get_stik_cookie (void);
int16          install (void);
int16          check_hardware (void);
void    cdecl  my_send (PORT *port);
void    cdecl  my_receive (PORT *port);
int16   cdecl  my_set_state (PORT *port, int16 state);


DRV_LIST  *stik_drivers;
TPL       *tpl;
STX       *stx;
PORT      my_port   = {  "EtherNet", L_SER_BUS, FALSE, 0L, 0xffffffffUL, 0xffffffffUL,
                         1500, 1500, 0, NULL, 0, NULL, NULL, NULL   };
DRIVER    my_driver = {  my_set_state, my_send, my_receive, "EtherNet", "00.01",
                         (M_YEAR << 9) | (M_MONTH << 5) | M_DAY, "Unknown Programmer",
                         NULL   };
char      fault[] = "ETHER.STX : STiK extension module. Only to be started by STiK !";



void  main (argc, argv)

int   argc;
char  *argv[];

{
   if (argc != 2) {
        puts (fault);   return;
      }
   if (strcmp (argv[1], "STiK_Load") != 0) {
        puts (fault);   return;
      }

   if (! check_hardware())   return;

   stik_drivers = (DRV_LIST *) Supexec (get_stik_cookie);

   if (stik_drivers == 0L)   return;

   if (strcmp (stik_drivers->magic, MAGIC) != 0)
        return;

   tpl = (TPL *) (*stik_drivers->get_dftab) (TRANSPORT_DRIVER);
   stx = (STX *) (*stik_drivers->get_dftab) (MODULE_DRIVER);

   if (tpl != (TPL *) NULL && stx != (STX *) NULL) {
        if (install())
             Ptermres (_PgmSize, 0);
      }
 }


long  get_stik_cookie()

{
   long  *work;

   for (work = * (long **) 0x5a0L; *work != 0L; work += 2)
        if (*work == 'STiK')
             return (*++work);

   return (0L);
 }


int16  install()

{
   PORT    *ports;
   DRIVER  *driver;

   query_chains ((void **) & ports, (void **) & driver, NULL);
   my_port.driver = & my_driver;

   while (ports->next)
        ports = ports->next;

   ports->next = & my_port;

   while (driver->next)
        driver = driver->next;

   driver->next = & my_driver;

   return (TRUE);
 }


int16  check_hardware()

{
   return (TRUE);
 }


void  cdecl  my_send (port)

PORT  *port;

{
   if (port != & my_port)   return;
 }


void  cdecl  my_receive (port)

PORT  *port;

{
   if (port != & my_port)   return;
 }


int16  cdecl  my_set_state (port, state)

PORT   *port;
int16  state;

{
   if (port != & my_port)   return (FALSE);

   return (TRUE);
 }
