Leaked source code of windows server 2003
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.

86 lines
2.5 KiB

  1. // $Header: G:/SwDev/WDM/Video/bt848/rcs/Tuner.cpp 1.8 1998/05/07 15:24:56 tomz Exp $
  2. extern "C" {
  3. #include <strmini.h>
  4. #include <wdm.h>
  5. #include <windef.h>
  6. }
  7. #include "device.h"
  8. #define PICTURE_INTERMEDIATE_FREQUENCY 45750000L
  9. const BAND_LOW = 55250000; // 55.25 MHz
  10. const BAND_LOWMID = 160000000; // 160.00 MHz
  11. const BAND_MIDHI = 454000000; // 454.00 MHz
  12. const BAND_HI = 801250000; // 801.25 MHz
  13. int PsDevice::GetPllOffset( PULONG busy, ULONG &lastFreq )
  14. {
  15. lastFreq = LastFreq_;
  16. BYTE status = 0;
  17. I2CHWRead( TunerInfo.TunerI2CAddress, &status );
  18. DebugOut((1, "Tuner - status(%x)\n", status));
  19. if ( status & 0x40 ) {
  20. *busy = false;
  21. switch ( status & 0x07 ) {
  22. case 0: // carrier sensed, need to lower frequency
  23. DebugOut((1, "Tuner: -2 (carrier sensed, need to lower frequency)\n"));
  24. return -2;
  25. case 1: // carrier sensed, need to lower frequency
  26. DebugOut((1, "Tuner: -1 (carrier sensed, need to lower frequency)\n"));
  27. return -1;
  28. case 2: // carrier sensed, we are on correct frequency
  29. DebugOut((1, "Tuner: 0 (carrier sensed, we are on correct frequency)\n"));
  30. return 0;
  31. case 3: // carrier sensed, need to raise frequency
  32. DebugOut((1, "Tuner: 1 (carrier sensed, need to raise frequency)\n"));
  33. return 1;
  34. case 4: // carrier not sensed
  35. default:
  36. DebugOut((1, "Tuner: 2 (carrier not sensed)\n"));
  37. return 2;
  38. } // switch
  39. }
  40. DebugOut((1, "Tuner: busy - return 0\n"));
  41. *busy = true;
  42. return 0;
  43. }
  44. void PsDevice::SetChannel( long lFreq )
  45. {
  46. // Set the video carrier frequency
  47. // by controlling the programmable divider
  48. //
  49. // N = (16 * (FreqRF + FreqIntermediate)) / 1e6
  50. //
  51. LastFreq_ = lFreq;
  52. LONGLONG lTemp = lFreq;
  53. WORD wCtrl=0;
  54. lTemp = (lTemp + PICTURE_INTERMEDIATE_FREQUENCY) * 16;
  55. lTemp /= 1000000;
  56. // Set the band register
  57. if ( lFreq >= BAND_LOW && lFreq <= BAND_LOWMID )
  58. {
  59. wCtrl = TunerInfo.TunerBandCtrlLow;
  60. }
  61. else if ( lFreq > BAND_LOWMID && lFreq <= BAND_MIDHI )
  62. {
  63. wCtrl = TunerInfo.TunerBandCtrlMid;
  64. }
  65. else if ( lFreq > BAND_MIDHI && lFreq <= BAND_HI)
  66. {
  67. wCtrl = TunerInfo.TunerBandCtrlHigh;
  68. }
  69. // write HIWORD to I2C
  70. I2CHWWrite3( TunerInfo.TunerI2CAddress, HIBYTE( WORD( lTemp ) ), LOBYTE( WORD( lTemp ) ) );
  71. // write LOWORD to I2C
  72. I2CHWWrite3( TunerInfo.TunerI2CAddress, HIBYTE( wCtrl ), LOBYTE( wCtrl ) );
  73. }