?? hamaro_srbin.c
字號:
/* hamaro_srbin.c */
/*+++ *******************************************************************\
*
* Abstract:
*
* Hamaro Scan-the-sky symbol rate binning implementation.
*
* Created: 11/22/2005
*
*
* Copyright and Disclaimer:
*
* ---------------------------------------------------------------
* This software is provided "AS IS" without warranty of any kind,
* either expressed or implied, including but not limited to the
* implied warranties of noninfringement, merchantability and/or
* fitness for a particular purpose.
* ---------------------------------------------------------------
*
* Author: Amar Puttur
*
* Module Revision Id:
*
* $Header:hamaro_srbin.c, 1, 11/22/2005 10:56:00 AM, Amar Puttur$
*
* Copyright (c) 2005 Conexant Systems, Inc.
* All rights reserved.
*
\******************************************************************* ---*/
#include <stdlib.h> /* ANSI Standard */
#include <time.h>
#include "hamaro_sts.h"
#if HAMARO_SCAN_THE_SKY
#include "hamaro_srbin.h"
#include "hamaro_fsm.h"
#if HAMARO_WIN_DEBUG
#define STSDBG_WR_INT_LN(str, val) (WINDBG_WriteIntegerLn((char*)(str), val))
#define STSDBG_WR_INT(str, val) (WINDBG_WriteInteger((char*)(str), val))
#define STSDBG_WR_HEX(str, val) (WINDBG_WriteHex((char*)(str), val))
#define STSDBG_WR_UNSIGNED_LN(str, val) (WINDBG_WriteUnsignedLn((char*)(str), val))
#define STSDBG_WR_UNSIGNED(str, val) (WINDBG_WriteUnsigned((char*)(str), val))
#define STSDBG_WR_STR(str, nl) (WINDBG_WriteString((char*)(str), nl))
#define STSDBG_WR_ELAPSED_TIME() (WINDBG_FileWriteDuration())
#define STSDBG_START_TIMER() (WINDBG_SetTimer()) /* used for time measurements */
#else // HAMARO_WIN_DEBUG
#define STSDBG_WR_INT_LN(str, val) /* Expands to nothing */
#define STSDBG_WR_INT(str, val) /* Expands to nothing */
#define STSDBG_WR_UNSIGNED_LN(str, val) /* Expands to nothing */
#define STSDBG_WR_UNSIGNED(str, val) /* Expands to nothing */
#define STSDBG_WR_STR(str, nl) /* Expands to nothing */
#define STSDBG_WR_ELAPSED_TIME() /* Expands to nothing */
#define STSDBG_START_TIMER() /* Expands to nothing */
#endif /* HAMARO_WIN_DEBUG */
#define REORDER_SYMBOL_RATE_NUMBER (100)
static u_int16 reorder_symbol_rate_table[REORDER_SYMBOL_RATE_NUMBER];
static u_int16 reorder_symbol_rate_count = 0;
static const u_int16 known_symbol_rate_table[] =
{43000,42990,41530,41518,41250,40700,35500,33483,32550,30800,30005,30000,
29900,29500,29300,29270,29265,29000,
28860,28850,28800,28700,28340,28200,28125,28117,28100,28066,28063,28000,27903,27690,27682,
27500,27490,27250,27000,26865,26850,26687,26670,26666,26600,26470,26079,26000,
25844,25776,25770,25766,25600,25582,25330,25000,24800,24000,23150,22425,22000,
21600,21500,21300,21200,21096,21000,20600,20500,20400,20250,20000,19850,
19835,19600,19565,19531,19530,19500,18000,17500,17363,16500,15552,14900,13650,13347,
13340,13333,13240,13236,12857,12850,12500,12300,12118,12000,11852, 11850, 11840,
11230,11000,10850,10125,10000,9766,9760,9400,9333,8932,8800,8678,8400,
8382,8333,8100,7997,7820,7730,7500,7438,7405,7400,7272,7234,7140,
7030,6980,6930,6928,6897,6876,6813,6700,6670,6666,
6664,6624,6600,6527,6512,6510,6507,6500,6311,6250,6200,
6110,6015,6000,5998,5990,5966,5949,5936,5926,5925,5924,
5875,5789,5786,5740,5730,5700,5660,5632,5630,5610,
5555,5460,5400,5386,5360,5275,5200,5100,5064,5062,5000,
4991,4960,4800,4778,4774,4760,4687,4685,4613,4540,4450,4420,4418,
4400,4355,4340,4300,4295,4289,4288,4285,4284,4283,
4275,4224,4200,4208,4203,4199,4167,4152,4100,4000,3977,3702,
3700,3680,3679,3677,3620,3615,3571,3570,3475,3424,
3400,3366,3360,3358,3355,3333,3331,3308,3300,3290,
3260,3255,3254,3250,3200,3185,3184,3120,3100,3075,3037,
3033,3000,2998,2977,2940,2910,2902,2900,2893,2892,
2848,2821,2803,2770,2734,2650,2625,2600,2592,2551,2500,
2401,2400,2313,2221,2206,2170,2169,2168,2165,2000,
1724,1627,1500,1498,1239,1229
};
static u_int8 SrbinHighFlag = 0;
static u_int8 SrbinLowFlag = 0;
static const u_int16 known_symbol_rate_num = sizeof(known_symbol_rate_table)/2;
//static int aagc_th;
extern unsigned long sts_fsm_coding;
FSM sr_bin_fsm = {&sts_fsm_coding, 0x0F000000, 0, 0, 0, 0};
static void SRBIN_ChangeChannel(unsigned long nominal_symbol_rate_hz);
/*****************************************************************************/
/* SYMBOL RATE BINNING FSM */
/*****************************************************************************/
/* Function prototypes */
/* Symbol rate binning: Reset state */
static void SRBIN_ResetEnter();
static void SRBIN_Reset();
static BOOL SRBIN_Reset2NextChannelCriterion();
static STATE* SRBIN_Reset2NextChannel();
/* Symbol rate binning: Next channel state */
static void SRBIN_NextChannelEnter();
static BOOL SRBIN_NextChannel2NextBinCriterion();
static STATE* SRBIN_NextChannel2NextBin();
static BOOL SRBIN_NextChannel2CleanupCriterion();
static STATE* SRBIN_NextChannel2Cleanup();
/* Symbol rate binning: Next bin state */
static void SRBIN_NextBinEnter();
static void SRBIN_NextBin();
static BOOL SRBIN_NextBin2LockTestCriterion();
static STATE* SRBIN_NextBin2LockTest();
static BOOL SRBIN_NextBin2NextChannelCriterion();
static STATE* SRBIN_NextBin2NextChannel();
static BOOL SRBIN_NextBin2CleanupCriterion();
static STATE* SRBIN_NextBin2Cleanup();
/* Symbol rate binning: Lock Test state */
static void SRBIN_LockTestEnter();
static void SRBIN_LockTest();
static BOOL SRBIN_LockTest2NextChannelCriterion();
static STATE* SRBIN_LockTest2NextChannel();
static void SRBIN_CleanupEnter();
static BOOL SRBIN_Cleanup2ReadyCriterion();
static STATE* SRBIN_Cleanup2Ready();
/* Symbol rate binning: Ready state */
static void SRBIN_ReadyEnter();
/* State tables */
STATE sr_bin_reset_state = /* SR_BIN FSM, RESET state */
{
SRBIN_ResetEnter, /* Entry task */
{
{SRBIN_Reset2NextChannelCriterion, SRBIN_Reset2NextChannel}, /* Criterion1 and Exit task */
{0,0} /* End of Criterion/Exit task */
},
SRBIN_Reset, /* Regular/Routine task */
0, /* No counter */
SRBIN_RESET_STATE /* state code */
};
STATE sr_bin_next_channel_state = /* SR_BIN FSM, NEXT CHANNEL state */
{
SRBIN_NextChannelEnter, /* Entry task */
{
{SRBIN_NextChannel2NextBinCriterion, SRBIN_NextChannel2NextBin}, /* Criterion1 and Exit task */
{SRBIN_NextChannel2CleanupCriterion, SRBIN_NextChannel2Cleanup},
{0,0} /* End of Criterion/Exit task */
},
0, /* Regular/Routine task */
0, /* No counter */
SRBIN_NEXT_CHANNEL_STATE /* state code */
};
STATE sr_bin_next_bin_state = /* SR_BIN FSM, NEXT BIN state */
{
SRBIN_NextBinEnter, /* Entry task */
{
{SRBIN_NextBin2LockTestCriterion, SRBIN_NextBin2LockTest},
{SRBIN_NextBin2NextChannelCriterion, SRBIN_NextBin2NextChannel},
{SRBIN_NextBin2CleanupCriterion, SRBIN_NextBin2Cleanup},
{0,0} /* No Criterion/Exit task */
},
SRBIN_NextBin, /* Regular task */
0,
SRBIN_NEXT_BIN_STATE
};
STATE sr_bin_lock_test_state = /* SR_BIN FSM, LOCK TEST state */
{
SRBIN_LockTestEnter, /* Entry task */
{
{SRBIN_LockTest2NextChannelCriterion, SRBIN_LockTest2NextChannel},
{0,0} /* No Criterion/Exit task */
},
SRBIN_LockTest, /* Regular task */
0,
SRBIN_LOCK_TEST_STATE
};
STATE sr_bin_cleanup_state = /* SR_BIN FSM, CLEANUP state */
{
SRBIN_CleanupEnter, /* Entry task */
{
{SRBIN_Cleanup2ReadyCriterion, SRBIN_Cleanup2Ready},
{0,0} /* End of Criterion/Exit task */
},
0, /* Regular/Routine task */
0, /* No counter */
SRBIN_CLEANUP_STATE /* state code */
};
STATE sr_bin_ready_state = /* SR_BIN FSM, READY state */
{
SRBIN_ReadyEnter, /* Entry task */
{
{0,0} /* End of Criterion/Exit task */
},
0, /* Regular/Routine task */
0, /* No counter */
SRBIN_READY_STATE /* state code */
};
/*****************************************************************************/
void
SRBIN_DumpChannelList(char* function_name, char format )
{
unsigned short max_ch = STS_GetMaxChannels();
HAMARO_STS_CHANNEL_INFO ch_info;
unsigned short loop;
char lock;
if (function_name == 0)
{
return;
}
STSDBG_WR_STR("---------------------", True);
STSDBG_WR_STR(function_name, True);
if( format )
{
for (loop = 0; loop < max_ch; loop++)
{
STS_GetChannel(loop, &ch_info);
STSDBG_WR_UNSIGNED_LN("SRBIN FSM::CF_Estimate(Hz) = ", ch_info.carrier_freq_hz);
STSDBG_WR_UNSIGNED_LN("SRBIN FSM::SR_Estimate(Hz) = ", ch_info.symbol_rate_hz);
STSDBG_WR_UNSIGNED_LN("SRBIN FSM::CR_Estimate(Hz) = ", ch_info.code_rate);
if (ch_info.good_channel == True)
{
STSDBG_WR_STR("SRBIN FSM::Good/Bad_Estimate = Good", True);
}
else
{
STSDBG_WR_STR("SRBIN FSM::Good/Bad_Estimate = Bad", True);
}
}
}
else
{
for (loop = 0; loop < max_ch; loop++)
{
STS_GetChannel(loop, &ch_info);
STSDBG_WR_UNSIGNED_LN("STS FSM::CF_Final(Hz) = ", ch_info.carrier_freq_hz);
STSDBG_WR_UNSIGNED_LN("STS FSM::SR_Final(Hz) = ", ch_info.symbol_rate_hz);
STSDBG_WR_UNSIGNED_LN("STS FSM::CR_FinalR(Hz) = ", ch_info.code_rate);
if (ch_info.good_channel == True)
{
STSDBG_WR_STR("STS FSM::Good/Bad_Final = Good", True);
}
else
{
STSDBG_WR_STR("STS FSM::Good/Bad_Final = Bad", True);
}
}
}
//added by sunbey, for test only
STSDBG_WR_STR("GET TP",True);
for (loop = 0; loop < max_ch; loop++)
{
STS_GetChannel(loop, &ch_info);
if(ch_info.good_channel == True)
{
lock = 1;
}
else
{
lock = 0;
}
//trace("CF,SR,AAGC,LOCK, = %d,%d,%d,%d\r\n", ch_info.carrier_freq_hz/1000, ch_info.symbol_rate_hz/1000,ch_info.aagc,lock);
STSDBG_WR_UNSIGNED("CF,SR,AAGC,LOCK, = ",ch_info.carrier_freq_hz/1000);
STSDBG_WR_UNSIGNED(",",ch_info.symbol_rate_hz/1000);
STSDBG_WR_INT(",",ch_info.aagc);
STSDBG_WR_INT_LN(",",lock);
}
STSDBG_WR_STR("---------------------", True);
}
/*****************************************************************************/
/* SRBIN_Start() */
/* Main FSM function */
/*****************************************************************************/
static unsigned long btl_bin_size;
static unsigned short max_channels;
static unsigned short channel_index;
static BOOL more_channels = False;
static unsigned long max_dmd_lock_detect_time=0;
void
SRBIN_Start(FSM *fsm)
{
STSDBG_WR_ELAPSED_TIME();
fsm->p_curr = &sr_bin_reset_state;
btl_bin_size = 0;
max_channels = STS_GetMaxChannels();
if (max_channels == 0)
{
more_channels = False;
}
else
{
more_channels = True;
}
#if 0
/* Get the max AAGC of the candidate TPs */
aagc_th = SRBIN_GetMaxCandidateAAGC();
STSDBG_WR_INT_LN("[MAX AAGC] = ",aagc_th);
if( aagc_th > 30 )
{
aagc_th = aagc_th*100 / SRBIN_AAGC_TH_MARGIN;
}
else
{
aagc_th = 30;
}
STSDBG_WR_INT_LN("[AAGC TH] = ",aagc_th);
#endif
max_dmd_lock_detect_time = 0;
STS_ProgramAFC(SRBIN_ACQ_AFC_EXPIRATION_WINDOW);
STS_BTLAccumClearSelect(SRBIN_BTL_NO_RESET_WHEN_REACQUIRE);
STSDBG_WR_UNSIGNED_LN("STS_ProgramAFC() = ", SRBIN_ACQ_AFC_EXPIRATION_WINDOW);
}
/* Symbol rate binning: Reset state */
static unsigned long btl_bin_size_ppm;
static unsigned long btl_max_one_side_ppm;
static unsigned long btl_bin_size_hz;
static unsigned long nom_sym_rate_hz;
//static unsigned long sym_rate_bound;
static long sym_rate_bound;
unsigned short
STS_GetCurrentChannelIndex()
{
return channel_index;
}
static void
SRBIN_ResetEnter()
{
btl_bin_size_ppm = SRBIN_BTL_BIN_SIZE_PPM;
btl_max_one_side_ppm = SRBIN_BTL_MAX_ONE_SIDE_PPM;
channel_index = 0;
STSDBG_WR_UNSIGNED_LN("btl_bin_size_ppm = ", btl_bin_size_ppm);
STSDBG_WR_UNSIGNED_LN("btl_max_one_side_ppm = ", btl_max_one_side_ppm);
SRBIN_DumpChannelList("SRBIN_ResetEnter",1);
/* Set BTL BandWideth value here */
HAMARO_RegisterWrite(hamaro_nim_list.nim[0],CX2430X_BTLBW,3, HAMARO_DEMOD_I2C_IO);
}
static void
SRBIN_Reset()
{
/* do nothing */
}
static BOOL
SRBIN_Reset2NextChannelCriterion()
{
return (True);
}
static STATE*
SRBIN_Reset2NextChannel()
{
DBG_CHECK_FSM_LIMITS(&sr_bin_next_channel_state);
return &sr_bin_next_channel_state;
}
/* Symbol rate binning: Next channel state */
static unsigned char try_next_channel = 1;
static short bin_timeout_msec = SRBIN_BIN_TIMEOUT_MSEC;
static HAMARO_STS_CHANNEL_INFO channel_info;
static HAMARO_CHANOBJ chan_obj;
static BOOL lock_achieved = False;
static void
SRBIN_NextChannelEnter()
{
//HAMARO_LNBPOL *lnbpol;
HAMARO_STS_CHANNEL_INFO temp_ch_info;
int temp_fr1,temp_fr2;
int i;
nom_sym_rate_hz = 0;
sym_rate_bound = 0;
btl_bin_size_hz = 0;
lock_achieved = False;
try_next_channel = 0;
STSDBG_WR_UNSIGNED_LN("channel_index = ", channel_index);
STSDBG_WR_UNSIGNED_LN("max_channels = ", max_channels);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -