/* this is the DSP320C30 main program */

#define EXTERN
#include        "define.h"

#include        "coeff.h"       /* clutter filter coefficients */

float PX,PY;

/* this initializes everything and starts the interrupt routine */
main()
   {
   int          i;
   float        *g;
   
   *LOCALCTRL  = 0x103C0000;
   *GLOBALCTRL = 0x0F3BC000;
   asm("        LDHI  8000H,AR1");
   asm("        LDPE AR1,IVTP");
   asm("        LDPE AR1,TVTP"); 
   asm("        LDI 800H,ST"); 
   asm("        LDI 0,DIE"); 
   asm("        LDI 0,IIE");

   
   /* put a pattern on the LED's */
   LEDCLR(0x3F);        /* clear all LED's */   
   
   LEDSET(ALIVE);       /* set the ALIVE bit */   

   /* clear the FIFO */
   *FIFOCLR = 0;
   
   /* set up the coefficient array */
   for(g=COEFF,i=0; i<20; i++)  *g++ = coeff[i]; 
   
   /* give an initial guess for the reciprical of the gate0 amplitude */
   *G0invmag = 1.0 / (0x1800000 * *Pulsewidth); 
   
   /* initialize the general purpose values */
   /* frequency of the doppler offset remover */
   PX = *Sp1 = *Sp3 = 1.0;
   PY = *Sp2 = *Sp4 = 0.0;
   
   /* this is regular old ABP data arrangment */
   *Dataformat = 0;

   /* set up the double buffer pointers */
   bufpointer[0] = Buffer0;
   bufpointer[1] = Buffer1;
   tsptr[0] = TSPTR0;
   tsptr[1] = TSPTR1;
   /* *Flag = 0; */		/* stick with the given number */
   
   /* initialize the lag memory (I and Q) */
   g = LAGBUF; 
   for(i=0; i<2 * *Gates; i++)   *g++ = 0.0; 
   
   /* initialize the clutter filter memory (8 parms per gate) */
   g = DELAY_PTR; 
   for(i=0; i<8 * *Gates; i++)   *g++ = 0.0; 
   
   hitcount = 0;        /* hitcount is used by pulsep */

   *Numdiscrim = *Dendiscrim = 0.0;

   asm("        LDI 176,IIF");    /* IIOF1 is level triggered */
   
   *DSPRDY = ASSERT;  /* signal PC that DSP is ready for pulses */

   /* go into idle state */
    asm("        IDLE");
   }

