source: svn/newcon3bcm2_21bu/magnum/syslib/synclib/7552/bsynclib_priv.c

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 6.2 KB
Line 
1/***************************************************************************
2*     Copyright (c) 2004-2009, Broadcom Corporation
3*     All Rights Reserved
4*     Confidential Property of Broadcom Corporation
5*
6*  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7*  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8*  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9*
10* $brcm_Workfile: bsynclib_priv.c $
11* $brcm_Revision: Hydra_Software_Devel/5 $
12* $brcm_Date: 12/10/09 9:18p $
13*
14* Revision History:
15*
16* $brcm_Log: /magnum/syslib/synclib/noarch/bsynclib_priv.c $
17*
18* Hydra_Software_Devel/5   12/10/09 9:18p bandrews
19* SW7401-3634: adding PWC (now JTI) support to synclib
20*
21* Hydra_Software_Devel/4   8/4/09 4:56p bandrews
22* PR52812: added improved rmd for dmv2
23*
24* Hydra_Software_Devel/3   2/25/09 7:52p bandrews
25* PR52514: needed another const
26*
27* Hydra_Software_Devel/2   10/15/08 2:50p bandrews
28* PR47923: Added support for 24 Hz units
29*
30* Hydra_Software_Devel/1   3/24/08 3:09p bandrews
31* PR40865: Fixed
32*
33* Hydra_Software_Devel/7   2/27/08 8:33p bandrews
34* PR37951: Fixed units conversion
35*
36* Hydra_Software_Devel/6   2/27/08 2:57p bandrews
37* PR37951: Fixed problem decrementing vsync count from VDC when the count
38* is already zero
39*
40* Hydra_Software_Devel/5   2/26/08 10:21p bandrews
41* PR37951: Fixed units.  Implemented static rate mismatch detection.
42*
43* Hydra_Software_Devel/4   2/25/08 9:33p bandrews
44* PR37951: Fixed various bugs
45*
46* Hydra_Software_Devel/3   2/22/08 8:28p bandrews
47* PR37951: Fixed bug in units conversion
48*
49* Hydra_Software_Devel/2   2/20/08 10:03p bandrews
50* PR37951: Updated based on feedback from usage
51*
52* Hydra_Software_Devel/1   1/3/08 6:02p bandrews
53* PR37951: Updated based on initial feedback
54*
55* Hydra_Software_Devel/1   12/12/07 2:53p bandrews
56* PR37951: Initial check-in
57***************************************************************************/
58
59#include "bstd.h"
60#include "bsynclib.h"
61#include "bsynclib_priv.h"
62
63BDBG_MODULE(synclib);
64
65bool BSYNClib_P_Enabled(BSYNClib_Handle hSync)
66{
67        bool bEnabled = false;
68       
69        BDBG_ENTER(BSYNClib_P_Enabled);
70
71        BDBG_ASSERT(hSync);
72
73        bEnabled = hSync->sSettings.bEnabled;
74       
75        BDBG_LEAVE(BSYNClib_P_Enabled);
76        return bEnabled;
77}
78
79static unsigned int BSYNClib_P_Gcd_isr(unsigned int a, unsigned int b)
80{
81        unsigned int t;
82       
83        while (b != 0)
84        {
85                t = b;
86                b = a % b;
87                a = t;
88        }
89
90        return a;
91}
92
93int BSYNClib_P_ConvertSigned(int iValue, BSYNClib_Units eFromUnits, BSYNClib_Units eToUnits)
94{
95        int iResult;
96       
97        BDBG_ENTER(BSYNClib_P_ConvertSigned);
98
99        BKNI_EnterCriticalSection();
100        iResult = BSYNClib_P_ConvertSigned_isr(iValue, eFromUnits, eToUnits);
101        BKNI_LeaveCriticalSection();
102
103        BDBG_LEAVE(BSYNClib_P_ConvertSigned);
104
105        return iResult;
106}
107
108int BSYNClib_P_ConvertSigned_isr(int iValue, BSYNClib_Units eFromUnits, BSYNClib_Units eToUnits)
109{
110        int iResult;
111        unsigned int uiResult;
112        unsigned int uiValue;
113        bool neg;
114
115        if (iValue < 0)
116        {
117                neg = true;
118                uiValue = (unsigned)-iValue;
119        }
120        else
121        {
122                neg = false;
123                uiValue = (unsigned)iValue;
124        }
125       
126        BDBG_ENTER(BSYNClib_P_ConvertSigned_isr);
127
128        uiResult = BSYNClib_P_Convert_isr(uiValue, eFromUnits, eToUnits);
129
130        BDBG_LEAVE(BSYNClib_P_ConvertSigned_isr);
131
132        iResult = (signed)uiResult;
133
134        if (neg)
135        {
136                iResult = -iResult;
137        }
138
139        return iResult;
140}
141
142unsigned int BSYNClib_P_Convert(unsigned int uiValue, BSYNClib_Units eFromUnits, BSYNClib_Units eToUnits)
143{
144        unsigned int uiResult;
145       
146        BDBG_ENTER(BSYNClib_P_Convert);
147
148        BKNI_EnterCriticalSection();
149        uiResult = BSYNClib_P_Convert_isr(uiValue, eFromUnits, eToUnits);
150        BKNI_LeaveCriticalSection();
151
152        BDBG_LEAVE(BSYNClib_P_Convert);
153
154        return uiResult;
155}
156
157unsigned int BSYNClib_P_Convert_isr(unsigned int uiValue, BSYNClib_Units eFromUnits, BSYNClib_Units eToUnits)
158{
159        unsigned int uiResult = 0;
160        unsigned int uiMultiplier = 1;
161        unsigned int uiDivisor = 1;
162        unsigned int uiMDGcd;
163        unsigned int uiVDGcd;
164       
165        BDBG_ENTER(BSYNClib_P_Convert_isr);
166
167        uiResult = uiValue;
168       
169        if (eFromUnits == eToUnits)
170        {
171                goto end;
172        }
173
174        if (eFromUnits != BSYNClib_Units_e27MhzTicks && eToUnits != BSYNClib_Units_e27MhzTicks)
175        {
176                BDBG_WRN(("Unsupported conversion (%s to %s).  Conversion only supported from 27 MHz ticks to x or from x to 27 MHz ticks", BSYNClib_P_UnitsStrings[eFromUnits], BSYNClib_P_UnitsStrings[eToUnits]));
177                goto end;
178        }
179
180        if (eFromUnits == BSYNClib_Units_eMilliseconds)
181        {
182                uiDivisor = 1000;
183        }
184        else if (eFromUnits == BSYNClib_Units_e24HzVsyncs)
185        {
186                uiDivisor = 24;
187        }
188        else if (eFromUnits == BSYNClib_Units_e50HzVsyncs)
189        {
190                uiDivisor = 50;
191        }
192        else if (eFromUnits == BSYNClib_Units_e60HzVsyncs)
193        {
194                uiDivisor = 60;
195        }
196        else if (eFromUnits == BSYNClib_Units_e45KhzTicks)
197        {
198                uiDivisor = 45000;
199        }
200        else if (eFromUnits == BSYNClib_Units_e90KhzTicks)
201        {
202                uiDivisor = 90000;
203        }
204        else if (eFromUnits == BSYNClib_Units_e27MhzTicks)
205        {
206                uiDivisor = 27000000;
207        }
208       
209        if (eToUnits == BSYNClib_Units_eMilliseconds)
210        {
211                uiMultiplier = 1000;
212        }
213        else if (eToUnits == BSYNClib_Units_e24HzVsyncs)
214        {
215                uiMultiplier = 24;
216        }
217        else if (eToUnits == BSYNClib_Units_e50HzVsyncs)
218        {
219                uiMultiplier = 50;
220        }
221        else if (eToUnits == BSYNClib_Units_e60HzVsyncs)
222        {
223                uiMultiplier = 60;
224        }
225        else if (eToUnits == BSYNClib_Units_e45KhzTicks)
226        {
227                uiMultiplier = 45000;
228        }
229        else if (eToUnits == BSYNClib_Units_e90KhzTicks)
230        {
231                uiMultiplier = 90000;
232        }
233        else if (eToUnits == BSYNClib_Units_e27MhzTicks)
234        {
235                uiMultiplier = 27000000;
236        }
237
238        uiMDGcd = BSYNClib_P_Gcd_isr(uiMultiplier, uiDivisor);
239        if (uiValue > 0)
240        {
241                uiVDGcd = BSYNClib_P_Gcd_isr(uiValue, uiDivisor);
242        }
243        else
244        {
245                uiVDGcd = 1;
246        }
247
248        if (uiMDGcd > 1 && uiVDGcd > 1)
249        {
250                if (uiMDGcd > uiVDGcd)
251                {
252                        uiMultiplier /= uiMDGcd;
253                        uiDivisor /= uiMDGcd;
254                }
255                else
256                {
257                        uiValue /= uiVDGcd;
258                        uiDivisor /= uiVDGcd;
259                }
260
261        }
262        else if (uiMDGcd > 1)
263        {
264                uiMultiplier /= uiMDGcd;
265                uiDivisor /= uiMDGcd;
266        }
267        else if (uiVDGcd > 1)
268        {
269                uiValue /= uiVDGcd;
270                uiDivisor /= uiVDGcd;
271        }
272
273        uiResult = uiValue * uiMultiplier / uiDivisor;
274
275        if (uiValue * uiMultiplier % uiDivisor > uiDivisor / 2)
276        {
277                uiResult++;
278        }
279
280end:
281
282        BDBG_LEAVE(BSYNClib_P_Convert_isr);
283        return uiResult;
284}
285
286#if BDBG_DEBUG_BUILD
287const char * const BSYNClib_P_UnitsStrings[] =
288{
289        "ms",
290        "24 Hz vsyncs",
291        "50 Hz vsyncs",
292        "60 Hz vsyncs",
293        "45 KHz ticks",
294        "90 KHz ticks",
295        "27 MHz ticks",
296        "<enum terminator>",
297        NULL
298};
299#endif
300
Note: See TracBrowser for help on using the repository browser.