⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frame_sync.lst

📁 Realtek 公司的RTD2523A芯片原厂source code,没有被修改过的。
💻 LST
📖 第 1 页 / 共 2 页
字号:
 232   1          if (Data[0])
 233   1          {
 234   2              //Fine-tune DCLK offset 
 235   2              if (TestSync((Data[0] & 0x02) ? (usDelta - 1) : (usDelta + 1)))     return 2;
 236   2      
 237   2              if (Data[0] & 0x03)     return 1;   //Frame sync fail!
 238   2          }
C51 COMPILER V6.20c  FRAME_SYNC                                                            04/15/2004 12:59:05 PAGE 5   

 239   1      
 240   1      #endif
 241   1      
 242   1          return 0;
 243   1      
 244   1      #else   //If define non-zero FIX_LAST_DHT ....
               
                  //Read the last line information , read back data equal to half last line length
                  RTDRead(LAST_LINE_H_2C, 1, N_INC);
                  usMax_Last_Line = (unsigned int)(Data[0] & 0xf8) << 2;
              
                  RTDRead(LAST_LINE_L_26, 1, N_INC);
                  usMax_Last_Line = usMax_Last_Line + (Data[0] / 8);
              
                  //Read the last line information when frequency offset set one more step
                  RTDSetByte(DCLK_OFFSET_LSB_9A, (unsigned char)(usDelta + 1));
                  RTDSetBit(DCLK_OFFSET_MSB_9B, 0xf0, (unsigned char)(((usDelta + 1) >> 8) & 0x0f) | 0x20);
              
                  Wait_For_Event(EVENT_IVS);
                  Wait_For_Event(EVENT_IVS);
              
                  RTDRead(LAST_LINE_H_2C, 1, N_INC);
                  usMin_Last_Line = (unsigned int)(Data[0] & 0xf8) << 2;
              
                  RTDRead(LAST_LINE_L_26, 1, N_INC);
                  usMin_Last_Line = usMin_Last_Line + (Data[0] / 8);
              
                  // Calculate the difference of last line when increase one offset step
                  if (usMin_Last_Line < usMax_Last_Line)
                      usMin_Last_Line = usMax_Last_Line - usMin_Last_Line;
                  else
                      usMin_Last_Line = (usDH_Total / 2) - usMin_Last_Line + usMax_Last_Line;
                  
                  if (FIX_LAST_DHT > usMax_Last_Line)
                  {
                      if ((FIX_LAST_DHT - usMax_Last_Line) > (usDH_Total / 4)) 
                      {
                          //Decreasing DCLK frequency to decrease last line length
                          Data[0] = (unsigned int)(usMax_Last_Line + (usDH_Total / 2) - FIX_LAST_DHT) / usMin_Last_Line;
                          usDelta = usDelta + Data[0];
                      }
                      else
                      {   
                          //Increasing DCLK frequency to increase last line length
                          Data[0] = (unsigned int)(FIX_LAST_DHT - usMax_Last_Line) / usMin_Last_Line; 
                          usDelta = usDelta - (Data[0] + 1);
                      }
                  }
                  else
                  {
                      if ((usMax_Last_Line - FIX_LAST_DHT) > (usDH_Total / 4))
                      {
                          //Increasing DCLK frequency to increase last line length
                          Data[0] = (unsigned int)(FIX_LAST_DHT + (usDH_Total / 2) - usMax_Last_Line) / usMin_Last_Line;
                          usDelta = usDelta - (Data[0] + 1);
                      }
                      else
                      {
                          //Decreasing DCLK frequency to decrease last line length
                          Data[0] = (usMax_Last_Line - FIX_LAST_DHT) / usMin_Last_Line; 
                          usDelta = usDelta + Data[0];
                      }
C51 COMPILER V6.20c  FRAME_SYNC                                                            04/15/2004 12:59:05 PAGE 6   

                  }
              
              
                  if (usDelta != usBuffer)
                  {
                      if (TestSync(usDelta))  return 2;
              
                      if (Data[0])
                      {
                          // Last-line length fine-tune failed !! 
                          // We cannot reach desired last-line length with safe frame-sync margin.
                          // So we restore original setting and abort changing last-line length.
              
                          usDelta = usBuffer;
                          
                          if (TestSync(usDelta))     return 2;
                      }
                      else
                      {
                          // Continue fine-tuning last-line length ....
              
                          if (TestSync(usDelta + 4))  return 2;
              
                          usDelta     = Data[0] ? usDelta - 2 : usDelta + 2;
                          usBuffer    = usDelta;
              
                          if (TestSync(usDelta))  return 2;
                      }
                  }
              
                  // Read the last line information , read back data equal to half last line length
                  RTDRead(LAST_LINE_H_2C, 1, N_INC);
                  usMax_Last_Line = (unsigned int)(Data[0] & 0xf8) << 2;
              
                  RTDRead(LAST_LINE_L_26, 1, N_INC);
                  usMax_Last_Line = usMax_Last_Line + (Data[0] / 8);
              
                  // Set desired last-line length
                  RTDSetByte(FX_LST_LEN_L_59,(unsigned char)(usMax_Last_Line << 1));
                  RTDSetBit(FX_LST_LEN_H_5A,0xe8,(unsigned char)((usMax_Last_Line >> 7) & 0x07));
              
                  //Measure result of last 16 line of DVTotal, including the un-complete last line
                  RTDRead(DV_ACT_END_34, 2, Y_INC);
                  Data[2] = Data[1] & 0x07;
                  Data[3] = Data[0];
              
                  Data[4] = Data[1] >> 4;
              
                  // Get Output_Active Height
                  ((unsigned int *)Data)[1]   = ((unsigned int *)Data)[1] - DV_ACT_STA_POS;
              
                  // Original Idea :
                  // DVTotal  = Output_Active_Line * (Input_Total_Line / Input_Active_Line) 
                  ((unsigned int *)Data)[0]   = (unsigned long)usVsync * ((unsigned int *)Data)[1] / usIPV_ACT_LEN;
              
                  ((unsigned int *)Data)[1]   = (((unsigned int *)Data)[0] & 0xfff0) | Data[4];
              
                  if (((unsigned int *)Data)[1] > (((unsigned int *)Data)[0] + 4))
                      ((unsigned int *)Data)[1]   -= 0x10;
                  else if (((unsigned int *)Data)[1] < (((unsigned int *)Data)[0] - 4))
                      ((unsigned int *)Data)[1]   += 0x10;
              
C51 COMPILER V6.20c  FRAME_SYNC                                                            04/15/2004 12:59:05 PAGE 7   

                  RTDSetByte(FIX_DVTOTAL_LSB_97, Data[3]);
                  RTDSetByte(FIX_DVTOTAL_MSB_98, Data[2]);
              
                  RTDSetBit(SPREAD_SPECTRUM_99, 0xfc, 0x02);  //Frequency Synthesis select N = 3
                  RTDSetBit(DCLK_OFFSET_MSB_9B, 0xff, 0x20);
              
                  // Issac :
                  // In order to synthesis fixed last-line length,
                  // we have to increase DCLK offset frequency by one step.
                  usBuffer    = usBuffer - 1;
              
              #if (SPREAD_SPECTRUM) 
              
                  //Enable the spread spectrum function
                  RTDSetBit(SPREAD_SPECTRUM_99, 0x0f, (DCLK_SPREAD_RANGE << 4));
                  RTDSetBit(DCLK_OFFSET_MSB_9B,0xff,0x20);
              
                  usBuffer    = usBuffer + DCLK_OFFSET[DCLK_SPREAD_RANGE];
              
              #endif
              
                  if (TestSync(usBuffer))     return 2;
              
                  if (Data[0] & 0x03)
                  {
                      //Fine-tune DCLK offset 
                      if (TestSync((Data[0] & 0x02) ? (usBuffer - 1) : (usBuffer + 1)))     return 2;
              
                      return Data[0] ? 1 : 0;
                  }
                  else
                  {
                      // Enable the Fixed DVTOTAL & Last Line Lenghth Fucntion
                      // only when everything is OK.
              
                      
                      // Issac :
                      // To enable fixed last-line length function may cause OSD bouncing, 
                      // so I decide to disable this function in frame-sync forever.
                      // However, this function must be 1 in free-run mode
              
                      //RTDSetBit(FX_LST_LEN_H_5A, 0xff, 0x10);
                      
                  }
              
                  return 0;
              
              #endif
 411   1      }
 412          
 413          
 414          void Adjust_I_Code(void)
 415          {
 416   1          // Calculate the IHF in KHz
 417   1          ((unsigned int *)Data)[0] = (unsigned int)RTD_XTAL / usHsync; //Input Horizontal Frequency
 418   1      
 419   1          //Formula : I_Correction = CE * 2 * Fav(215634) * 100 / IHF / 2^(I_Code - 34)
 420   1          //          I_Code = 14; I_Code[13] = 0;
 421   1      /*
 422   1          ucI_Code    = 14;
 423   1          Data[2]     = ((unsigned long)ucCE_Value * 43126800 / (unsigned long)((unsigned int*)Data)[0]) >> 20;
 424   1          Data[3]     = I_Correction ? I_Correction : (ucPE_Level ? (Correct_Amount - ucP_Corr) : ((ucP_Corr >> 
C51 COMPILER V6.20c  FRAME_SYNC                                                            04/15/2004 12:59:05 PAGE 8   

             -2) + 10));
 425   1      */
 426   1          ucI_Code    = 14;
 427   1          Data[2]     = ((unsigned long)ucCE_Value * BEST_FAV_FREQ * 200 / (unsigned long)((unsigned int*)Data)[
             -0]) >> 20;
 428   1          Data[3]     = I_Correction ? I_Correction : (ucPE_Level ? (Correct_Amount - ucP_Corr) : ((ucP_Corr >> 
             -2) + 10));
 429   1      
 430   1      
 431   1          while(1)
 432   1          {
 433   2              if (Data[2] > Data[3])
 434   2              {
 435   3                  Data[2]     = Data[2] >> 1;
 436   3                  ucI_Code    = ucI_Code - 1;
 437   3      
 438   3                  if (Data[2] <= Data[3])     break;
 439   3              }
 440   2              else
 441   2              {
 442   3                  if ((Data[2] << 1) > Data[3])   break;
 443   3                  
 444   3                  Data[2]     = Data[2] << 1;
 445   3                  ucI_Code    = ucI_Code + 1;
 446   3              }
 447   2          }
 448   1      
 449   1          // Judge if I_Code[13] set to 1 will more close to 155
 450   1          if ((unsigned char)((unsigned int)Data[2] * 3 / 2) <= Data[3])
 451   1          {
 452   2              ucI_Code |= 0x80;
 453   2          }
 454   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    946    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----       7
   IDATA SIZE       =      2    ----
   BIT SIZE         =      1    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -