📄 frame_sync.lst
字号:
C51 COMPILER V7.06 FRAME_SYNC 11/21/2005 13:47:25 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE FRAME_SYNC
OBJECT MODULE PLACED IN .\Output\Frame_Sync.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Code\Frame_Sync.c OPTIMIZE(9,SPEED) BROWSE DEBUG OBJECTEXTEND CODE SYMBOLS
-PRINT(.\Output\Frame_Sync.lst) PREPRINT(.\Output\Frame_Sync.i) OBJECT(.\Output\Frame_Sync.obj)
stmt level source
1 #define __FRAMESYNC__
2
3 #include "Header\Frame_Sync.h"
4 #include "Header\Lcd_func.h"
5 #include "Header\Access.h"
6 #include "Header\Main_def.h"
7 #include "Header\Config.h"
8 #include "Header\Lcd_main.h"
9 #include "Header\LCD_OSD.h"
10
11
12
13 /////////////////////////
14 // Frame-Sync Detector //
15 /////////////////////////
16 bit Frame_Sync_Detector(void)
17 {
18 1 if (bPower_Status && bStable && MODE_NOSIGNAL != ucMode_Curr && MODE_NOSUPPORT != ucMode_Curr)
19 1 {
20 2 if (bFrameSync)
21 2 {
22 3 RTDRead(STATUS1_1F, 1, N_INC);
23 3 ucStatus |= (Data[0] >> 6);
24 3
25 3 if(Data[0])
26 3 RTDSetByte(STATUS1_1F,0x00);
27 3
28 3 if (Data[0] & 0xc0)
29 3 {
30 4 ucSyncErrorCnt += 1;
31 4 #if (RTDDEBUG)
if (0xff > ucDebug) ucDebug ++;
#endif
34 4 }
35 3
36 3 //#if (DISP_BIT == DISP_18BIT)
37 3 // else if (Data[0] & 0x04)
38 3 // {
39 3 // bDitherToggle = !bDitherToggle;
40 3
41 3 // if (bDitherToggle)
42 3 // {
43 3 // bDitherTable = !bDitherTable;
44 3 // WriteDither(bDitherTable ? DITHER_1 : DITHER_2);
45 3 // }
46 3 // }
47 3 //#endif
48 3
49 3 }
50 2
51 2 if (SYNC_FAIL_TIMES >= ucSyncErrorCnt)
52 2 {
53 3 RTDRead(STATUS0_01, 1, N_INC);
54 3 ucStatus |= (Data[0] & 0xfc);
C51 COMPILER V7.06 FRAME_SYNC 11/21/2005 13:47:25 PAGE 2
55 3
56 3
57 3 if(Data[0])
58 3 RTDSetByte(STATUS0_01,0x00); //if some event happened, write once to clear status
59 3
60 3 if (Data[0] & 0x60) ucSyncErrorCnt += (SYNC_FAIL_TIMES + 1);
61 3
62 3 if (SOURCE_VGA == (stGUD1.INPUT_SOURCE & 0x07))
63 3 {
64 4 if (Data[0] & 0x80)
65 4 {
66 5 ucSyncErrorCnt += 1;
67 5 #if (RTDDEBUG)
if (0xff > ucDebug) ucDebug ++;
#endif
70 5 }
71 4 else
72 4 {
73 5
74 5 #if(TUNE_APLL)
75 5
76 5 RTDSetBit(DV_TOTAL_STATUS_3D, 0x7f, 0x20); //Enable PE Max Measurement
77 5 Delay_Xms(1);
78 5 RTDRead(DV_TOTAL_STATUS_3D, 1, N_INC);
79 5 ucPE_Max = Data[0] & 0x1f;
80 5 if((ucPE_Max > 0x10) && (ucPE_Level == 0))
81 5 {
82 6 ucPE_Level = 1;
83 6 Adjust_I_Code();
84 6 if((ucI_Code & 0x80) == 0x80)
85 6 RTDSetBit(I_CODE_MB_CA,0xdf,0x20); //Set the I_Code[13] to 1;
86 6 else
87 6 RTDSetBit(I_CODE_MB_CA,0xdf,0x00); //Set the I_Code[13] to 0;
88 6
89 6 ucI_Code = ucI_Code & 0x7f;
90 6 RTDSetByte(I_CODE_LB_C9,0x1c | ((ucI_Code & 0x07) << 5));
91 6 RTDSetBit(I_CODE_MB_CA,0xfc,0x04 | ((ucI_Code & 0x18) >> 3));
92 6
93 6 RTDSetBit(DV_TOTAL_STATUS_3D, 0xdf, 0x00);//Disable PE Max Measurement
94 6 RTDSetByte(DV_TOTAL_STATUS_3D,0x40); //clear PE Max value
95 6 ucPE_Max = 0;
96 6 }
97 5
98 5 #endif
99 5 }
100 4 }
101 3 }
102 2
103 2 if (SYNC_FAIL_TIMES < ucSyncErrorCnt)
104 2 {
105 3 Reset_Mode();
106 3
107 3 Set_Task(STATE_MODECHANGE); // Notify Task State Machine
108 3
109 3 bNotify_Timer0_Int = 0;
110 3
111 3 return _TRUE;
112 3 //continue; // leave current iteration.
113 3 }
114 2
115 2 if (bNotify_Timer0_Int && MODE_DETECT_FREQ == ucModeCnt)
116 2 {
C51 COMPILER V7.06 FRAME_SYNC 11/21/2005 13:47:25 PAGE 3
117 3 if (ucSyncErrorCnt) ucSyncErrorCnt -= 1;
118 3
119 3 }
120 2 }
121 1 return _FALSE;
122 1 }
123
124 /////////////////////////////////////////////////////////////////////////////////
125 // FrameSync fine-tune routines
126 /////////////////////////////////////////////////////////////////////////////////
127 void AbortSync(void)
128 {
129 1 Data[0] = 5;
130 1 Data[1] = Y_INC;
131 1 Data[2] = DH_TOTAL_22;
132 1 Data[3] = (unsigned char)usDH_Total;
133 1 Data[4] = (unsigned char)(usDH_Total >> 8);
134 1 Data[5] = 0;
135 1 RTDWrite(Data);
136 1
137 1 RTDSetBit(DV_TOTAL_H_2E, 0x07, 0x00);
138 1 }
139
140 unsigned char TestSync(unsigned int offset) // 0 - Success; Otherwise - Fail
141 {
142 1
143 1 RTDSetByte(DCLK_OFFSET_LSB_9A,(unsigned char)offset);
144 1 RTDSetBit(DCLK_OFFSET_MSB_9B,0xf0,(unsigned char)((offset >> 8) & 0x0f) | 0x20);
145 1
146 1 //RTDSetBit(DV_TOTAL_H_2E, 0x07, fine & 0xf8);
147 1
148 1 Wait_For_Event(EVENT_DVS); // Wait for Frame End
149 1 //Delay_Xms(10);
150 1
151 1 RTDSetByte(STATUS0_01,0x00);
152 1
153 1 Wait_For_Event(EVENT_DVS); // Wait for Frame End
154 1
155 1 //RTDSetByte(STATUS0_01,0x00);////
156 1 /*
157 1 if (SOURCE_VGA != (stGUD1.INPUT_SOURCE & 0x07))
158 1 {
159 1 Wait_For_Event(EVENT_DVS); // Wait for Frame End
160 1 }
161 1 */
162 1 Wait_For_Event(EVENT_DVS); // Wait for Frame End
163 1
164 1 //RTDSetByte(STATUS0_01,0x00);////
165 1 //Delay_Xms(10);
166 1
167 1 RTDRead(STATUS0_01, 1, N_INC); // Get status
168 1
169 1
170 1 if(Data[0])
171 1 RTDSetByte(STATUS0_01,0x00);
172 1
173 1
174 1 if (Data[0] & 0x60) // Mode Changed
175 1 {
176 2 AbortSync();
177 2 return 1;
178 2 }
C51 COMPILER V7.06 FRAME_SYNC 11/21/2005 13:47:25 PAGE 4
179 1
180 1 Data[0] &= 0x03;
181 1
182 1 return 0; // Success
183 1 }
184
185
186
187 //Returned value
188 // 0 : Succeed(Frame-sync settings returned in Data[3] and Data[4])
189 // 1 : Fail
190 // 2 : Abort
191 #define Offset_Step 32//16 //This value should better larger then 16
192 unsigned char Frame_Sync(void)
193 {
194 1 unsigned int idata usBuffer,usDelta;
195 1 unsigned char idata ucFine,ucTemp=0;
196 1
197 1 #if(FIX_LAST_DHT)
unsigned int idata usMax_Last_Line,usMin_Last_Line;
#endif
200 1
201 1
202 1
203 1 RTDRead(DCLK_OFFSET_LSB_9A , 2, Y_INC);
204 1 Data[2] = Data[1] & 0x0f;
205 1 Data[3] = Data[0];
206 1 usBuffer = ((unsigned int*)Data)[1];//get the DCLK offset
207 1 //usDelta = ((unsigned int*)Data)[1];//get the DCLK offset
208 1 usDelta = usBuffer;
209 1 // ucFine = 0;
210 1
211 1 if(((stGUD1.INPUT_SOURCE & 0x07) == SOURCE_VGA) || ((stGUD1.INPUT_SOURCE & 0x07) == SOURCE_DVI))
212 1 {
213 2
214 2 //while(usDelta < Offset_Step * 14)
215 2 while(usBuffer < (1228 + 14 * Offset_Step))
216 2 //while(usBuffer < (1228 + 24 * Offset_Step)) //eric 0729 issue: dvi flash
217 2 {
218 3 RTDRead(DPLL_M_D1,2,Y_INC);
219 3 RTDSetByte(DPLL_M_D1,Data[0]+1);
220 3 RTDSetByte(DPLL_N_D2,Data[1]);
221 3 // Forster :
222 3 // if the DCLK offset too small, then set the M_Code = M_Code + 1
223 3 // And reculculate the offset
224 3 // Original formula:
225 3 // 24.576M * M/N - 24.576M*M/N/2^15*old_offset = 24.576M*(M+1)/N - 24.576M*(M+1)/N/2^15*new_offset
226 3 // => new_offset = (2^15 + M*old_offset) / (M+1);
227 3 usBuffer = (unsigned int)((unsigned long)(32768 + (unsigned long)(Data[0] + 2) * usBuffer)/(unsigned l
-ong)(Data[0] + 3));
228 3 //usBuffer = (32768 + (Data[0] + 2) * usDelta)/(Data[0] + 3);
229 3 usDelta = usBuffer;
230 3
231 3 }
232 2
233 2
234 2 /* //Below spend more code size
235 2 ((unsigned int*)Data)[1] = 1228 + 14 * Offset_Step;
236 2
237 2 if(usBuffer < ((unsigned int*)Data)[1])
238 2 {
239 2 RTDRead(DPLL_M_D1,1,N_INC);
C51 COMPILER V7.06 FRAME_SYNC 11/21/2005 13:47:25 PAGE 5
240 2
241 2 ucFine =(unsigned char)((unsigned long)(Data[0] + 2) * (((unsigned int*)Data)[1] - usBuffer)/(unsigned
- long)(32768 - ((unsigned int*)Data)[1]));
242 2
243 2 usBuffer = (unsigned int)(((unsigned long)32768 * (ucFine + 1) + (unsigned long)(Data[0] + 2) * usBuff
-er)/(unsigned long)(Data[0] + 2 + (ucFine + 1)));
244 2
245 2 RTDSetByte(DPLL_M_D1,Data[0] + ucFine + 1);
246 2 RTDSetBit(DPLL_N_D2,0xf8,USER_MODE_NCODE - 2);
247 2 }
248 2
249 2 usDelta = usBuffer;
250 2 */
251 2 usDelta -= 128; //Clk offset fine-tune
252 2 }
253 1
254 1 usBuffer = usDelta;
255 1
256 1
257 1 for(ucFine =0;ucFine < 14;ucFine++)
258 1 {
259 2 if (TestSync(usDelta)) return 2;
260 2
261 2 if(Data[0] & 0x03)
262 2 {
263 3 usDelta = (Data[0] & 0x02) ? usDelta - Offset_Step : usDelta + Offset_Step;
264 3 ucTemp += 1;
265 3 }
266 2 else if((Data[0] & 0x03) == 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -