Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

448 lines
11 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Philips Semiconductors-CSU 1999
  4. // All rights are reserved. Reproduction in whole or in part is prohibited
  5. // without the written consent of the copyright owner.
  6. //
  7. // Philips reserves the right to make changes without notice at any time.
  8. // Philips makes no warranty, expressed, implied or statutory, including but
  9. // not limited to any implied warranty of merchantibility or fitness for any
  10. // particular purpose, or that the use will not infringe any third party
  11. // patent, copyright or trademark. Philips must not be liable for any loss
  12. // or damage arising from its use.
  13. //
  14. // VSB1.CPP
  15. // Class CVSB1Demod Implementation
  16. //////////////////////////////////////////////////////////////////////////////
  17. #include "philtune.h"
  18. #include "vsb1.h"
  19. //VSB Initialization sequence
  20. UCHAR VsbInitArray[17]=
  21. {
  22. 0x00, //0
  23. 0x00, //1
  24. 0x04, //2
  25. 0x00, //3
  26. 0x02, //4
  27. 0x80, //5
  28. 0x00, //6
  29. 0xca, //7
  30. 0x74, //8
  31. 0x00, //9
  32. 0x00, //a
  33. 0x00, //b
  34. 0xfc, //c
  35. 0x96, //d
  36. 0x66, //e
  37. 0x55, //f
  38. 0x5f //10
  39. };
  40. /*
  41. * CVSB1Demod()
  42. * Input :
  43. * Output: TRUE - if initialization data can be written to I2C
  44. * FALSE - if there is an I2C error
  45. * Description: CVSB2Demod Constructor.
  46. */
  47. CVSB1Demod::CVSB1Demod(CI2CScript *p_I2CScript, BoardInfoType *p_BoardInfo, NTSTATUS *p_Status)
  48. :CVSBDemod(p_I2CScript, p_BoardInfo, p_Status)
  49. {
  50. Initialize();
  51. }
  52. /*
  53. * ~CVSB1Demod()
  54. * Input :
  55. * Output:
  56. * Description: CVSB1Demod Destructor.
  57. */
  58. CVSB1Demod::~CVSB1Demod()
  59. {
  60. }
  61. #if 0
  62. /*
  63. * operator new
  64. * Purpose: CVSB1Demod class overrides operator new.
  65. *
  66. * Inputs : UINT uiSize : size of the object to be placed
  67. *
  68. * Outputs: PVOID : pointer of the CVSB1Demod class object
  69. * Author : MM
  70. */
  71. PVOID CVSB1Demod::operator new(UINT uiSize)
  72. {
  73. if (uiSize != sizeof(CVSB1Demod))
  74. {
  75. _DbgPrintF( DEBUGLVL_ERROR,("CVSB1Demod: operator new() fails\n"));
  76. return(NULL);
  77. }
  78. return (AllocateFixedMemory(uiSize));
  79. }
  80. /*
  81. * operator delete
  82. * Purpose: CVSB1Demod class overrides operator delete
  83. *
  84. * Inputs : PVOID p_Buffer : pointer to object being deleted
  85. *
  86. * Outputs:
  87. * Author : MM
  88. */
  89. void CVSB1Demod::operator delete(PVOID p_Object)
  90. {
  91. if(p_Object != NULL)
  92. FreeFixedMemory(p_Object);
  93. _DbgPrintF( DEBUGLVL_VERBOSE,("CVSB1Demod: operator delete() succeeds\n"));
  94. }
  95. #endif
  96. /*
  97. * Initialize()
  98. * Input :
  99. * Output: TRUE - if initialization data can be written to I2C
  100. * FALSE - if there is an I2C error
  101. * Description: Initialize.
  102. */
  103. BOOL CVSB1Demod::Initialize()
  104. {
  105. m_uiMaxControlRegisterAddress = VSB1_CONTROL_SIZE - 1;
  106. m_uiMaxStatusRegisterAddress = VSB1_STATUS_SIZE - 1;
  107. return (InitVSB());
  108. }
  109. /*
  110. * InitVSB()
  111. * Input :
  112. * Output: TRUE - if initialization data can be written to I2C
  113. * FALSE - if there is an I2C error
  114. * Description: Initialize the VSB chip with default values.
  115. */
  116. BOOL CVSB1Demod::InitVSB()
  117. {
  118. MemoryCopy(m_ucControlReg, VsbInitArray, sizeof(VsbInitArray));
  119. // Write I2C sequence to chip
  120. if(Write(VsbInitArray, sizeof VsbInitArray, 0) == WDMMINI_NOERROR)
  121. {
  122. _DbgPrintF( DEBUGLVL_TERSE,("CVSB1Demod: Demodulator Init PASSED !!! ------------ \n"));
  123. return TRUE;
  124. }
  125. else
  126. {
  127. _DbgPrintF( DEBUGLVL_TERSE,("CVSB1Demod: Demodulator Init FAILED !!! ------------ \n"));
  128. return FALSE;
  129. }
  130. }
  131. /*
  132. * GetStatus()
  133. * Input : PVsbStatusType p_Status : pointer to Status structure
  134. * Output: TRUE - if status can be read from I2C
  135. * FALSE - if there is an I2C error
  136. * Description: Get chip status. The status is stored in m_8VSBStatus
  137. */
  138. BOOL CVSB1Demod::GetStatus(PVsbStatusType p_Status)
  139. {
  140. UCHAR ucStatus[VSB1_STATUS_SIZE];
  141. if(Read(ucStatus, sizeof(ucStatus), 0) != WDMMINI_NOERROR)
  142. return FALSE;
  143. p_Status->bFrontEndLock = (ucStatus[0] & 0x4) >> 2;
  144. p_Status->ucState = ucStatus[0] & 0x3;
  145. p_Status->bEqualizerLock = ((ucStatus[0] & 0x7) == 0x7) ? 1 : 0;
  146. p_Status->uiMse = ((UINT(ucStatus[1]) << 8) & 0xff00) |
  147. (UINT(ucStatus[2]) & 0xff);
  148. p_Status->ucCarrierOffset = UCHAR(ucStatus[3]) & 0xff;
  149. // Not implemented in VSB1
  150. p_Status->uiSegmentErrorRate = 0;
  151. // _DbgPrintF( DEBUGLVL_TERSE,("CVSB1Demod::GetStatus: %x %x %x %x\n", ucStatus[0], ucStatus[1], ucStatus[2], ucStatus[3]));
  152. return TRUE;
  153. }
  154. /*
  155. * EnableCoefficients()
  156. * Input: UCHAR ucEnable
  157. * Output :
  158. * Description: Set the enable coefficients register
  159. */
  160. BOOL CVSB1Demod::EnableCoefficients(UCHAR ucEnable)
  161. {
  162. // Nothing is done in VSB1 as no register has to be set for reading
  163. // coefficients
  164. _DbgPrintF( DEBUGLVL_VERBOSE,("CVSB1Demod::EnableCoefficients()\n"));
  165. return TRUE;
  166. }
  167. /*
  168. * DisableCoefficients()
  169. * Input:
  170. * Output :
  171. * Description: Disable coefficient Read/Write
  172. */
  173. BOOL CVSB1Demod::DisableCoefficients()
  174. {
  175. // Nothing is done in VSB1 as no register has to be set for reading
  176. // coefficients
  177. _DbgPrintF( DEBUGLVL_VERBOSE,("CVSB1Demod::DisableCoefficients()\n"));
  178. return TRUE;
  179. }
  180. /*
  181. * ResetHangCounter()
  182. * Input:
  183. * Output :
  184. * Description: Reset Hang Counters
  185. */
  186. void CVSB1Demod::ResetHangCounter()
  187. {
  188. // Initialize parameters
  189. m_uiHangCounter = 0;
  190. m_uiPrevMseValue = 0xffff;
  191. }
  192. /*
  193. * CheckHang()
  194. * Input:
  195. * Output :
  196. * Description: Check VSB chip Hang
  197. */
  198. BOOL CVSB1Demod::CheckHang()
  199. {
  200. VsbStatusType VSBStatus;
  201. BOOL bReset;
  202. // Read status register and MSE
  203. if(!GetStatus(&VSBStatus))
  204. return TRUE; // Chip is not in HANG, hence returning TRUE
  205. // _DbgPrintF( DEBUGLVL_VERBOSE,("CPhilipsWDMTuner::TimerRoutine(): Prev MSE = %x Curent MSE = %x\n",
  206. // *p_uiMseValue, VSBStatusItem.Mse));
  207. bReset = TRUE;
  208. if (VSBStatus.ucState == 0x1)
  209. {
  210. // Check Hang
  211. if(m_uiPrevMseValue == VSBStatus.uiMse)// Is VSB State = 1 and mse = previous mse
  212. {
  213. bReset = FALSE;
  214. _DbgPrintF( DEBUGLVL_VERBOSE,("CVSB1Demod::TimerRoutine(): Increment HC \n"));
  215. // Is the hang counter count > 800ms ( hang counter
  216. // = 8 as interrupt occurs every 100 ms)
  217. if(++(m_uiHangCounter) > 8)
  218. {
  219. m_uiHangCounter = 0; // Reset Hang Counter
  220. _DbgPrintF( DEBUGLVL_VERBOSE,("CVSB1Demod::TimerRoutine(): Chip Hang. Resetting\n"));
  221. SoftwareReset(VSB_GENERAL_RESET);
  222. return TRUE ;
  223. }
  224. }
  225. }
  226. if (bReset == TRUE)
  227. {
  228. // Reset the Hang counter if the the chip is not in
  229. // State 1 as the chip hangs only in State 1
  230. m_uiHangCounter = 0;
  231. // Save current MSE
  232. m_uiPrevMseValue = VSBStatus.uiMse;
  233. // _DbgPrintF( DEBUGLVL_VERBOSE,("CPhilipsWDMTuner::TimerRoutine(): Prev MSE = %x \n",
  234. // m_PrevMseValue));
  235. }
  236. return FALSE;
  237. }
  238. /*
  239. * CoeffIDToAddress()
  240. * Input: UINT uiID - ID
  241. * UINT *p_uiAddress - The address pointer
  242. * Output : TRUE: If ID can be translated
  243. * FALSE: IF ID does not exist
  244. * Description: Translate coefficient ID to address
  245. */
  246. BOOL CVSB1Demod::CoeffIDToAddress(UINT uiID, UINT *p_uiAddress,
  247. UINT uiRegisterType)
  248. {
  249. _DbgPrintF( DEBUGLVL_VERBOSE,("CVSB1Demod::CoeffIDToAddress()\n"));
  250. switch(uiID)
  251. {
  252. case EQUALIZER_ID:
  253. if(uiRegisterType == WRITE_REGISTERS)
  254. *p_uiAddress = VSB1_CTRL_REG_EQUALIZER_COEFF;
  255. else
  256. *p_uiAddress = VSB1_STATUS_REG_EQUALIZER_COEFF;
  257. break;
  258. default:
  259. *p_uiAddress = 0;
  260. return FALSE;
  261. }
  262. return TRUE;
  263. }
  264. /*
  265. * SetOutputMode()
  266. * Input:
  267. * Output :
  268. * Description: Set The output mode (Normal/Diagnostic/Bypass)
  269. */
  270. BOOL CVSB1Demod::SetOutputMode(UINT uiOutputMode)
  271. {
  272. RegisterType Control;
  273. UCHAR ucOutput;
  274. UCHAR ucMask;
  275. ucOutput = m_ucControlReg[VSB1_REG_OUTPUT] & VSB1_TS_OUT_MODE_MASK;
  276. if(uiOutputMode == VSB_OUTPUT_MODE_NORMAL)
  277. {}
  278. else if(uiOutputMode == VSB_OUTPUT_MODE_DIAGNOSTIC)
  279. ucOutput |= 0x80;
  280. else if(uiOutputMode == VSB_OUTPUT_MODE_BYPASS)
  281. ucOutput |= 0x40;
  282. else
  283. return FALSE;
  284. Control.uiAddress = VSB1_REG_OUTPUT;
  285. Control.uiLength = 1;
  286. Control.p_ucBuffer = &ucOutput;
  287. // Reset chip
  288. if(SetControlRegister(&Control, 1) != WDMMINI_NOERROR)
  289. return FALSE;
  290. return TRUE;
  291. }
  292. /*
  293. * GetOutputMode()
  294. * Input:
  295. * Output :
  296. * Description: Get The output mode (Normal/Diagnostic/Bypass)
  297. */
  298. BOOL CVSB1Demod::GetOutputMode(UINT *p_uiOutputMode)
  299. {
  300. RegisterType Control;
  301. UCHAR ucOutput;
  302. UCHAR ucMask;
  303. ucOutput = m_ucControlReg[VSB1_REG_OUTPUT] & (~VSB1_TS_OUT_MODE_MASK);
  304. if(ucOutput == 0)
  305. *p_uiOutputMode = VSB_OUTPUT_MODE_NORMAL;
  306. else if(ucOutput == 0x40)
  307. *p_uiOutputMode = VSB_OUTPUT_MODE_BYPASS;
  308. else
  309. *p_uiOutputMode = VSB_OUTPUT_MODE_DIAGNOSTIC;
  310. return TRUE;
  311. }
  312. /*
  313. * SetDiagMode()
  314. * Input: ULONG ulMode - Diagnostic mode(enumeration VSBDIAGTYPE)
  315. * Output :
  316. * Description: Set The diag mode
  317. */
  318. BOOL CVSB1Demod::SetDiagMode(VSBDIAGTYPE ulMode)
  319. {
  320. RegisterType Control;
  321. UCHAR ucOutput;
  322. UCHAR ucMask;
  323. ucOutput = m_ucControlReg[VSB1_REG_OUTPUT] & VSB1_DIAG_MODE_MASK;
  324. if((((LONG)ulMode >= EQUALIZER_OUT) && (ulMode <= TRELLIS_DEC_DIAG_OUT)) ||
  325. ((ulMode >= TRELLIS_DEC_OUT) && (ulMode <= REED_SOLOMON_DIAG_OUT)))
  326. {
  327. Control.uiAddress = VSB1_REG_OUTPUT;
  328. Control.uiLength = 1;
  329. Control.p_ucBuffer = &ucOutput;
  330. // Send Diag type to chip
  331. if(SetControlRegister(&Control, 1) != WDMMINI_NOERROR)
  332. return FALSE;
  333. return TRUE;
  334. }
  335. else
  336. return FALSE;
  337. }
  338. /*
  339. * GetDiagMode()
  340. * Input: ULONG *p_ulMode - pointer to diagnostic mode
  341. * Output : Diagnostic mode (enumeration VSBDIAGTYPE)
  342. * Description: Get The Diag mode
  343. */
  344. BOOL CVSB1Demod::GetDiagMode(ULONG *p_ulMode)
  345. {
  346. RegisterType Control;
  347. UCHAR ucOutput;
  348. UCHAR ucMask;
  349. *p_ulMode = (UINT)(m_ucControlReg[VSB1_REG_OUTPUT]) & (~VSB1_DIAG_MODE_MASK);
  350. return TRUE;
  351. }
  352. /*
  353. * GetDiagSpeed()
  354. * Input: ULONG ulType - Diagnostic type
  355. * Output : Diagnostic speed
  356. * Description: Get The Diagnostic data speed
  357. */
  358. ULONG CVSB1Demod::GetDiagSpeed(ULONG ulType)
  359. {
  360. RegisterType Control;
  361. UCHAR ucOutput;
  362. UCHAR ucMask;
  363. ULONG ulSpeed;
  364. ucOutput = m_ucControlReg[VSB1_REG_OUTPUT] & (~VSB1_TS_OUT_MODE_MASK);
  365. switch(ulType)
  366. {
  367. case EQUALIZER_OUT:
  368. case CR_ERROR:
  369. case TR_ERROR:
  370. case EQUALIZER_IN:
  371. case TRELLIS_DEC_DIAG_OUT:
  372. ulSpeed = TENPOINT76MHZ;
  373. break;
  374. case TRELLIS_DEC_OUT:
  375. case REED_SOLOMON_DIAG_OUT:
  376. ulSpeed = TWOPOINT69MHZ;
  377. break;
  378. default:
  379. ulSpeed = 0;
  380. break;
  381. }
  382. return ulSpeed;
  383. }