/* **********************************************************************
 * *                                                                    *
 * *  DEFINITIONS INCLUDE FILE FOR DSP RELATED DEFINITIONS              *
 * *                                                                    *
 * **********************************************************************
 * File: libs/dsp/dsp_def.h
 *
 *                     COPYRIGHT (c) 2000, 2004  BY
 *          SIGMET INCORPORATED, WESTFORD MASSACHUSETTS, U.S.A.
 * 
 * THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
 * ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
 * INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
 * COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
 * OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
 * TRANSFERED.
 */

/* Include requirements:
 *  sigtypes.h
 *  dsp_lib.h
 */
#ifdef DSP_ALLOCATE
#define EXTERN
#else
#define EXTERN extern
#endif

/* ============== Digital Signal Processor Parameters ======================== 
 *
 * The timeout time for reads and writes in seconds.  Note, do not
 * lower below 6 seconds because of the time it takes for the DSP to
 * recover from a reset.
 */

/* SCSI Interface parameters for generic scsi class driver
 */
#define GK_IBM_IOCMD (2)

#define GK_SCSI_INQUIRY   0x12	/* SCSI Inquiry Op Code (7.2.5) */
#define GK_SCSI_RECEIVE   0x08	/* SCSI Processor RECEIVE Command (11.2.1) */
#define GK_SCSI_SEND      0x0A	/* SCSI Processor SEND Command (11.2.2)*/
#define GK_SCSI_MODESENSE 0x1A	/* SCSI Mode Sense(6) (7.2.10) */

#ifndef DSP_INFO_DRIVER

/* Array holding simulation state
 */
EXTERN UINT2 lsimu_c;
      
/* Array holding unfolding code
 */
EXTERN UINT2 iunfold_c;
      
/* Here is an explaination of how the lSoprmValid_c, lgparm_valid_c,
 * lpw_setting_valid_c, etc variables are set.  They are all cleared
 * at the same time when: a) dsp_open_for_io is called. b) When new
 * rom code is loaded. c) When features checking seems to indicate an
 * error.  lSoprmValid_c is set when the SOPRM array is written to the
 * DSP. lgparm_valid_c is set whenever the GPARM is read.
 * lpw_setting_valid_c is set whenever the PW/PRF command is written.
 */

/* This holds the current operational parameter configuration.  There
 * are several different driver routines which modify and write out
 * this array.
 */
EXTERN struct opprm soprm_c ;
EXTERN UINT2 lSoprmValid_c;  /* Above array contains valid data */
    
/* This is a command array, used for temporary storage, shared between
 * the driver subroutines.
 */
EXTERN UINT2 icmd_c[40];

/* This common array is used for temporary storage for reading the DSP
 * operating parameters.
 */
EXTERN struct gparm gparm_c ;
EXTERN UINT2 lgparm_valid_c ;

/* Indicates that we have set the dsp pulse width or polarization
 * since powering up.
 */
EXTERN UINT2 lpw_setting_valid_c;
EXTERN UINT2 lpol_setting_valid_c;

/* We will use compression with data going to the socket interface.
 */
EXTERN UINT1 lServerCompressed_c;

/* To improve efficiency of the TTY chat modes, the following buffer
 * holds read-ahead chat and plot data from the signal processor.  The
 * buffer will be filled using DspReadAvail(), which is more efficient
 * for the single word TTY characters, but is less efficient for the
 * long plot data arrays.  Thus, increasing the buffer size beyond a
 * certain point may actually reduce the performance.
 */
#define TTYREADAHEAD  20
EXTERN UINT2 iTTYBuf_c[ TTYREADAHEAD ] ;
EXTERN SINT4 iTTYCount_c, iTTYPtr_c ;

#endif  /* #ifndef DSP_INFO_DRIVER */

#define DSP_VERSION( GPARM ) \
  ( ((GPARM)->irev_ser >> 12) + (((GPARM)->irev_ser & 0x0E00) >> 5) )

#define DSP_MINOREV( GPARM ) ( ((GPARM)->intflt >> 4) & 0xF )


struct dsp_info
{
  UINT4 itype;
  UINT4 interface;
  UINT4 idsplu;        /* Channel number for I/O */
  SINT4 iPwRadiateOffWait;
  SINT4 ipw_wait;

  UINT4 iopen ;
#define DSP_OPEN        1
#define DSP_OPEN_FOR_IO 2

  SINT4 iMaskSpacing[4];	/* Range mask spacing in cm */
  SINT4 iaqclock ;		/* Acquisition clock in Hz */

  struct dsp_data_mask DataMask;  /* Mask of available data types */
  UINT4 iProcFlags ;		/* Various processor switches */
#define DSP_PFLG_DUAL_RCV    0x01    /*  System has 2 receivers */
#define DSP_PFLG_PHASE0      0x04    /*  bit 0 of phase code choices */
#define DSP_PFLG_PHASE1      0x08    /*  bit 1 of phase code choices */
#define DSP_PFLG_MUSER1      0x10    /*  Major mode User1 available */
#define DSP_PFLG_MUSER2      0x20    /*  Major mode User2 available */
#define DSP_PFLG_MUSER3      0x40    /*  Major mode User3 available */
#define DSP_PFLG_MUSER4      0x80    /*  Major mode User4 available */
  SINT4 iWidthCount;            /* Number of pulse widths available */
  SINT4 iPWidths[4];            /* Actual widths of each PW */
};

#ifndef DSP_INFO_DRIVER
/* Actual array holding the information
 */
EXTERN Dsp dsp_c;

/* Copy of setup information, not to be referenced by information only
 * routines.
 */
EXTERN struct dsp_manual_setup dspdrv_setup_c;
#endif  /* #ifndef DSP_INFO_DRIVER */

/* Maximum length of a SCSI I/O transfer is generally around 32K
 * bytes, except on LINUX where we make it smaller because the driver
 * requires a copy to a separate consolidated I/O array.
 */
#ifdef LINUX
#define SCSI_MAX_IOLEN  4000
#else
#define SCSI_MAX_IOLEN 32000
#endif

/* Flag indicating whether I/O transfer alignment must be done from
 * multiples of 4-byte addresses.  An error signal will be generated
 * on platforms for which it matters, otherwise the unaligned transfer
 * will simply work okay.
 */
#ifdef IRIX
#define CHECK_IO_ALIGNMENT (1)
#else
#define CHECK_IO_ALIGNMENT (0)
#endif

/* ==================================================
 * Function prototypes for routines local to the driver
 */
MESSAGE DspOpenSocket           /* File: OpenSocket.c */
( Dsp *pDsp_a );
  
int ReadSocket             /* File: OpenSocket.c */
( int iSocket_a,
  char *pData_a,        /* Data goes here */
  SINT4 iMaxSize_a,     /* Size of data buffer goes here */
  MESSAGE *pStatus_a    /* Detailed status returned here */
  );

UINT2 idsp_prt( Dsp *dsp_a, UINT2 iprf_a ) ;

MESSAGE dspr_pram_internal	/* File: dspr_subs.c */
( Dsp *dsp_a ) ;

MESSAGE dspw_polarization       /* File: dspw_subs.c */
( Dsp *dsp_a,
  UINT2 iPolarization_a );

MESSAGE dspw_prf		/* File: dspw_subs.c */
( Dsp *dsp_a,
  FLT4  fPrf_a,
  UINT2 ipwcode_a );

#ifdef HPUX
#ifdef DSP_SCSI_INCLUDED
MESSAGE hpux_scsi_status( struct sctl_io *sctl );
#endif
#endif

#ifdef IRIX
#ifdef DSP_SCSI_INCLUDED
MESSAGE irix_scsi_status( struct dsreq *ds );
#endif
#endif

#ifdef LINUX
#ifdef DSP_SCSI_INCLUDED
MESSAGE linux_scsi_command
( int fd_a, void *pbuf_a, SINT4 buflen_a, UINT2 lread_a, UINT1 cdb_a[6] ) ;
#endif
#endif

#undef EXTERN
