/* **********************************************************************
 * *                                                                    *
 * *              Burst/AFC Thread Private Definitions                  *
 * *                                                                    *
 * **********************************************************************
 * File: rda/rvp8main/core/burst_def.h
 *
 *                        COPYRIGHT (c) 2001  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.
 */
#ifdef BURST_DEF_ALLOCATE
  #define XM
#else
  #define XM extern
#endif

#define BURSTPACEMS   40	/* Requested period (ms) for burst analysis */
XM FLT4 fBurstPeriodMS_c ;	/*   and actual rate being achieved. */
#define BURSTPACEHZ (1000 / BURSTPACEMS)

XM pthread_mutex_t burstAnalysisMutex_c ;

/* If no CPI's have been processed recently within this maximum time
 * in miliseconds, then we can make adjustments freely to burst and
 * AFC parameters.  This trys to minimize interference to the data
 * that we really care about.
 */
#define BURSTIDLEDATAMS 1500	/* No data processing ==> okay to adjust */

XM FLT4 fBurstDC_c ;		/* Mean DC level and average power in the */
XM FLT4 fBurstPow_c ;		/*   complete window of burst samples. */

XM UINT1 lBurstOkay_c ;		/* Burst pulse is presently ok */
XM UINT1 lBurstSettled_c ;	/* Burst pulse averaging parameters are ok */
XM UINT4 iBtimeNoBurst_c ;	/* Last time that burst was missing */

XM FLT4 fBurstFreq_c ;		/* Measured burst frequency (MHz) */

XM FLT4 fBurstExp_c ;		/* Exponential averaging multiplier */
XM FLT4 fBurstExp2_c ;		/*   (and a slightly longer version) */

XM FLT8 fBurstLag0_c ;		/* Burst pulse R(zero) autocorrelation */
XM FLT8 fBurstLag1_c ;		/* Burst pulse R(one) autocorrelation */

XM FLT8 fBurst4LagX_c ;		/* Burst pulse 4-lag autocorrel 'X' term */
XM FLT8 fBurst4LagY_c ;		/* Burst pulse 4-lag autocorrel 'Y' term */

XM FLT4 fBurstCosMag_c ;	/* Correction terms for the magnitude and */
XM FLT4 fBurstCosOff_c ;	/*   angle of the cosine freq estimator */

struct afcdrx {			/* Dual-receiver AFC information */
  FLT4 pwrnow ;			/*   Instantaneous power */
  FLT4 pwravg ;			/*   Running average of power */
  FLT4 pwrmax ;			/*   Maximum (full scale input) power */
  FLT4 firtab[DIMIMPLENGTH] ;	/*   FIR Coefficients */
} ;
XM struct afcdrx afcdrx_pri_c ;  /* Primary and secondary info structures */
XM struct afcdrx afcdrx_sec_c ;  /*   for dual-receiver AFC tracking. */

XM FLT4 fBurstMom_c ;		/* Index of power weighted center of mass in */
XM FLT4 fBurstMomVar_c ;	/*   complete window, and mean variation */

XM FLT4 fAFCTargetFreq_c ;	/* Frequency that servo is aiming for */
XM UINT1 lAFCInner_c ;		/* AFC locked in inner hysteresis zone */

XM UINT1 lAFCEnab_c ;		/* AFC is enabled */
XM UINT1 lMFCEnab_c ;		/* MFC is enabled (Manual-Frequency-Control) */

XM SINT4 iAFCLevel_c ;		/* 32-Bit AFC value [-100%,+100%] */
XM SINT4 iAFCUserFmt_c ;	/* AFC level translated to user's format */

XM SINT4 iAFCTestValue_c ;	/* AFC Bit Test Mode value */
XM SINT4 iAFCTestFlags_c ;	/* AFC Bit Test Mode flags */
#define AFCTEST_ENAB 0x01	/*   Bit 0: Test mode enabled */
#define AFCTEST_WALK 0x02	/*   Bit 1: Automatic walking bit */
#define AFCTEST_PINS 0x04	/*   Bit 2: Bits refer to pin numbers */

/* ------------------- burst_api.c -------------------
 */
void killBurstFlagsPreLocked( void ) ;

/* -------------------- burst_track.c --------------------
 */
void burstTrack( void ) ;
