/* ------------------------------------------------------------------------*/
/* Project:       20051 DRIVER                                             */
/* Filename:      FEM.H                                                    */
/* Description:   set up memory and definitions for FEM.C	           */
/* Version:       1.5                                                      */
/* Author:        MK;JF  		                                   */
/* History:       Original 09/15/92                                        */
/*		  							   */
/* ------------------------------------------------------------------------*/
#include <stdio.h>
#include <io51.h>
#include "arc51.h"


void main(void);
void scan_net();
int  cmd_rec();
void setup_pckt();
int  mem_dump();
void readback();
void copy_code(void);
void node_wake();
void test_fun();
void gen_cs(int x);  
void ERROR(int type);
void SERROR();
void  testsend(int x);
int time_out(int x);


/* data buffers located at 0x5ff8 - to acommodate the incomming packets */
#define HOPDATA ((USIGN8 *)0x015ff8)
#define GUF     ((int *)0x0107f0)

#define LOC_HOPDATA 0x5ff8
#define  FPROG    0x3800
#define  PGB      0xfeff


/* packet header information stored in this structure*/
typedef struct CMD_WORD 
{
  USIGN8        cmd;
  USIGN8        node;
  USIGN8        devtype;
  USIGN8        grpcmd;
  unsigned int  dlen;
  USIGN8        error;
}  CMD_WORD;

CMD_WORD   pckt;

#define         PUB             1
/*    packet header  locations*/
#define         CMD             1
#define         DEVTYPE         2
#define         GRPCMD          3
#define         DLEN            6
#define         ERR             4



/* command words */
#define         NEW_CODE        0x01
#define         RESET_SW        0x02
#define         RESPOND         0x03
#define		ECHO		0x04
#define		TOKEN_OFF	0x05
#define		TOKEN_ON	0x06
#define		NET_MAP 	0x07
#define		FEM_VER 	0x08


/* define  abs function locations and variables */
void  *FNP;
code int UFUN    = 0x4000;       /*location for user function*/
code int SWRESET = 0x0000;    /*software reset   set PC = 0x0000*/
code int EPROG   = 0x3800;    /*EEPROM PROGRAMING ROUTINE*/
void (*fblock)();

#define SW_RESET     {FNP = &SWRESET; fblock = FNP; (*fblock) ();}
#define PRG_ROM     {FNP = &EPROG; fblock = FNP; (*fblock) ();}
#define USR_FUNC     {FNP = &UFUN; fblock = FNP; (*fblock) ();}






