source: svn/newcon3bcm2_21bu/magnum/portinginterface/vbi/7552/bvbi.c @ 66

Last change on this file since 66 was 66, checked in by megakiss, 11 years ago

키패드 기능 연결

전원키 누르고 리모콘 누르면 학습
CH+ 간격 1초 증가 MAX:15
CH- 간격 1초 감소 MIN :1

  • Property svn:executable set to *
File size: 28.2 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2011, 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: bvbi.c $
11 * $brcm_Revision: Hydra_Software_Devel/5 $
12 * $brcm_Date: 2/17/11 6:31p $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/portinginterface/vbi/7400/bvbi.c $
19 *
20 * Hydra_Software_Devel/5   2/17/11 6:31p jtna
21 * SW7420-1456: update BCHP_PWR pm code
22 *
23 * Hydra_Software_Devel/4   2/14/11 5:02p darnstein
24 * SW7420-1456: Merge BVBI work to main branch: power management.
25 *
26 * Hydra_Software_Devel/SW7420-1456/2   2/3/11 6:16p jtna
27 * SW7420-1456: add VDC_656 output to power management
28 *
29 * Hydra_Software_Devel/SW7420-1456/1   2/2/11 8:07p jtna
30 * SW7420-1456: initial work on VDC/VBI power management
31 *
32 * Hydra_Software_Devel/3   6/30/09 5:51p darnstein
33 * PR56342: support for 7550 chipset.
34 *
35 * Hydra_Software_Devel/2   12/3/08 7:55p darnstein
36 * PR45819: New, more modular form of most BVBI source files.
37 *
38 * Hydra_Software_Devel/103   9/15/08 8:57p darnstein
39 * PR46356: VPS decoder software in BVBI is ready for test.
40 *
41 * Hydra_Software_Devel/102   9/12/08 1:24p darnstein
42 * PR46112: Implement variant of CGMS-B (output) defined in CEA-805-D.
43 *
44 * Hydra_Software_Devel/101   9/8/08 1:52p darnstein
45 * PR40709: support for CGMS-B.
46 *
47 * Hydra_Software_Devel/100   9/4/08 7:16a vobadm
48 * PR 44539:
49 *
50 * Hydra_Software_Devel/bdvd_v2.0/1   8/29/08 8:01a fbasso
51 * PR 10340: 7601 build
52 *
53 * Hydra_Software_Devel/98   7/30/08 8:39p darnstein
54 * PR43926,PR43413: Workaround for TTD addressing error in hardware.
55 * Decodes at most one line of teletext per video field. Will not
56 * corrrupt memory if input signal actually contains more teletext.
57 *
58 * Hydra_Software_Devel/97   6/30/08 4:56p darnstein
59 * PR41267: Silence a Coverity complaint with a big hammer.
60 *
61 * Hydra_Software_Devel/96   6/26/08 6:04p darnstein
62 * PR39493: Remove extraneous line of code.
63 *
64 * Hydra_Software_Devel/95   5/28/08 5:41p darnstein
65 * PR43083: deallocate SCTE data when destroying a field handle.
66 *
67 * Hydra_Software_Devel/94   5/28/08 5:35p darnstein
68 * PR23220: Some implementation of Gemstar decoding was missing.
69 *
70 * Hydra_Software_Devel/93   5/19/08 2:35p darnstein
71 * PR42717,PR42733,PR42734: Fix Coverity warnings.
72 *
73 * Hydra_Software_Devel/92   5/13/08 2:08p darnstein
74 * PR34584: Port over changes from 7401 dedicated branch. Allow user to
75 * choose bit shift direction for teletext encoding.
76 *
77 * Hydra_Software_Devel/91   4/30/08 3:41p darnstein
78 * PR38956: fix problem: CGMSB not available on 7405 (and many other
79 * chipsets).
80 *
81 * Hydra_Software_Devel/90   4/28/08 7:49p darnstein
82 * PR38956: CGMS-B encoding ready for bring-up. Need accurate register
83 * settings for tuning.
84 *
85 * Hydra_Software_Devel/89   4/14/08 8:10p darnstein
86 * PR41309: Put in a 6-bit preamble in BVBI_WSS2CGMS(). I don't think that
87 * is enough though.
88 *
89 * Hydra_Software_Devel/88   4/9/08 8:02p darnstein
90 * PR37064: In previous checkin, I made a mistake in porting over from
91 * dedicated 7401 branch.
92 *
93 * Hydra_Software_Devel/87   4/8/08 6:13p darnstein
94 * PR37064: This is the same 15-lines-of-teletext problem that was solved
95 * (worked-around, actually) on the dedicated 7401 ClearCase branch.
96 *
97 * Hydra_Software_Devel/86   4/4/08 3:07p darnstein
98 * PR41359: port PR36108 to main branch. Use CGMSAE core to produce
99 * WSS/576P waveform.
100 *
101 * Hydra_Software_Devel/85   3/14/08 3:18p darnstein
102 * PR23220: Gemstar decoding almost works. Cannot process video line 11
103 * for some reason.
104 *
105 * Hydra_Software_Devel/84   3/11/08 6:49p darnstein
106 * PR23220: Fill in some missing Gemstar decoder logic.
107 *
108 * Hydra_Software_Devel/83   11/1/07 12:51p darnstein
109 * PR30411: Fix some logic errors involving multi-line closed caption vs
110 * classic closed caption.
111 *
112 * Hydra_Software_Devel/82   10/15/07 11:33a pntruong
113 * PR 35037, PR 35038, PR 35039: Fixed linux build errors.
114 *
115 * Hydra_Software_Devel/81   10/12/07 11:15a syang
116 * PR 35037, PR 35038, PR 35039:  init eStatus
117 *
118 * Hydra_Software_Devel/80   10/12/07 10:58a syang
119 * PR 35037, PR 35038, PR 35039: clean up
120 *
121 * Hydra_Software_Devel/79   10/11/07 6:15p syang
122 * PR 35037, PR 35038 , PR 35039: coverity (resouce_leak) fix
123 *
124 * Hydra_Software_Devel/78   9/11/07 6:03p darnstein
125 * PR25708: Fix ClearCase merge errors. More to come.
126 *
127 * Hydra_Software_Devel/77   9/11/07 5:12p darnstein
128 * PR25708: First release of SCTE encoder software.
129 *
130 * Hydra_Software_Devel/76   6/8/07 6:30p darnstein
131 * PR31804: Deallocate bulky memory in BVBI_Field_Destroy().
132 *
133 * Hydra_Software_Devel/75   6/6/07 12:47p darnstein
134 * PR30411: multi-line closed caption encoding is ready for test.
135 *
136 * Hydra_Software_Devel/74   2/27/07 11:52a darnstein
137 * PR25990: Fix up programming of ANCI656 core, for 7400-B0 chipset.
138 *
139 * Hydra_Software_Devel/73   2/14/07 6:12p darnstein
140 * PR27721: Release resources from BVBI_Decode_Create() when it fails
141 * halfway through.
142 *
143 * Hydra_Software_Devel/72   1/17/07 5:31p darnstein
144 * PR26464: correctly handle teletext output to multiple VECs
145 *
146 * Hydra_Software_Devel/71   12/14/06 7:16p darnstein
147 * PR25990: Can compile for BCM97400-B0 now.
148 *
149 * Hydra_Software_Devel/70   11/13/06 3:07p darnstein
150 * PR23247: Serial output of teletext is ready for testing.
151 *
152 * Hydra_Software_Devel/69   11/8/06 5:13p darnstein
153 * PR23247: Serial output of teletext is partially supported now.
154 *
155 * Hydra_Software_Devel/68   9/26/06 7:37p darnstein
156 * PR24573: The BVBI porting interface module now compiles for the 7440
157 * chipset. Correct operation has not been verified.
158 *
159 * Hydra_Software_Devel/67   9/13/06 6:33p darnstein
160 * PR21688: Can now compile for 97118-A0 chipset. Correct operation is not
161 * guaranteed.
162 *
163 * Hydra_Software_Devel/66   8/18/06 6:50p darnstein
164 * PR23178: basic compile on 93563 is possible.
165 *
166 * Hydra_Software_Devel/65   5/26/06 1:20p darnstein
167 * PR21710: A field handle can be dequeued for encoding at any one of
168 * three times: top field, bottom field, or FRAME. FRAME is the new
169 * choice. The field handles themselves continue to be defined as top
170 * field, bottom field, or both. The new logic is when a field handle is
171 * dequeued at time FRAME, it is always encoded immediately. The rest of
172 * the logic is the same: a "top" field handle is only dequeued and
173 * encoded at "top field" time, same for bottoms. When setting up field
174 * interrupt callbacks, for progressive video output, the argument
175 * BAVC_Polarity_eFrame should be used now.
176 *
177 * Hydra_Software_Devel/70   11/13/06 3:07p darnstein
178 * PR23247: Serial output of teletext is ready for testing.
179 *
180 * Hydra_Software_Devel/69   11/8/06 5:13p darnstein
181 * PR23247: Serial output of teletext is partially supported now.
182 *
183 * Hydra_Software_Devel/68   9/26/06 7:37p darnstein
184 * PR24573: The BVBI porting interface module now compiles for the 7440
185 * chipset. Correct operation has not been verified.
186 *
187 * Hydra_Software_Devel/67   9/13/06 6:33p darnstein
188 * PR21688: Can now compile for 97118-A0 chipset. Correct operation is not
189 * guaranteed.
190 *
191 * Hydra_Software_Devel/66   8/18/06 6:50p darnstein
192 * PR23178: basic compile on 93563 is possible.
193 *
194 * Hydra_Software_Devel/65   5/26/06 1:20p darnstein
195 * PR21710: A field handle can be dequeued for encoding at any one of
196 * three times: top field, bottom field, or FRAME. FRAME is the new
197 * choice. The field handles themselves continue to be defined as top
198 * field, bottom field, or both. The new logic is when a field handle is
199 * dequeued at time FRAME, it is always encoded immediately. The rest of
200 * the logic is the same: a "top" field handle is only dequeued and
201 * encoded at "top field" time, same for bottoms. When setting up field
202 * interrupt callbacks, for progressive video output, the argument
203 * BAVC_Polarity_eFrame should be used now.
204 *
205 * Hydra_Software_Devel/64   4/12/06 1:56p darnstein
206 * PR18010: Add ANCI656_PRIM_ANCI656_CNTRL setting to the PR18010
207 * backwards compatibility option.
208 *
209 * Hydra_Software_Devel/63   4/11/06 7:26p darnstein
210 * PR20429: first cut at AMOL encoder software.
211 *
212 * Hydra_Software_Devel/62   3/20/06 1:08p darnstein
213 * PR19719: After changing BCHP_VBI_ENC_PRIM_Control (indirectly), poll
214 * register until it has really changed. This enforces the one transition
215 * that is critical to this PR: when disabling a VBI encoder core, the
216 * appropriate bit in BCHP_VBI_ENC_PRIM_Control must be zeroed before the
217 * individual VBI core is disabled.
218 *
219 * Hydra_Software_Devel/61   3/3/06 12:49p darnstein
220 * PR18331: When BVBI_Decode_ApplyChanges() fails, roll back hardware
221 * state completely. The state was random before this fix.
222 *
223 * Hydra_Software_Devel/60   3/2/06 4:58p darnstein
224 * PR18331: When BVBI_Encode_ApplyChanges() fails, roll back hardware
225 * state completely. The state was random before this fix.
226 *
227 * Hydra_Software_Devel/59   2/3/06 1:28p darnstein
228 * PR19428: Add #ifdef's to support the 7400 chip.
229 *
230 * Hydra_Software_Devel/58   1/18/06 2:19p darnstein
231 * PR19133: Fix two problems that were preventing VPS output.
232 *
233 * Hydra_Software_Devel/57   12/21/05 5:14p darnstein
234 * PR18341: Swap bytes of the teletext "line mask" DRAM entry on little-
235 * endian systems.
236 *
237 * Hydra_Software_Devel/56   12/5/05 7:29p darnstein
238 * PR18010: Implement work-around for the bad line number, together with
239 * an exception for customers that now depend on the bad line number.
240 *
241 * Hydra_Software_Devel/55   11/14/05 7:15p darnstein
242 * PR17732: Change the way the bottom field base video line number is
243 * expressed.
244 *
245 * Hydra_Software_Devel/54   10/21/05 7:10p darnstein
246 * PR17732: Gemstar encoder can output a waveform, but I can't make it
247 * change yet.
248 *
249 * Hydra_Software_Devel/53   10/20/05 4:16p darnstein
250 * PR17732: Fix a silly coding error.
251 *
252 * Hydra_Software_Devel/52   10/20/05 1:56p darnstein
253 * PR17732: Gemstar features not ready yet. However, the build for 97038
254 * is not broken.
255 *
256 * Hydra_Software_Devel/51   9/23/05 2:46p darnstein
257 * PR13750: Proper use of BERR_TRACE and BERR_CODEs.
258 *
259 * Hydra_Software_Devel/50   9/19/05 2:56p darnstein
260 * PR17151: Check for chip name where needed. Also, convert to new scheme
261 * for testing chip revisions (BCHP_VER).
262 *
263 * Hydra_Software_Devel/49   8/22/05 8:10p darnstein
264 * PR16057: To support many different chips, use private #defines that
265 * specify number of VECs, VDECs, and (separately) pass-through VECs.
266 *
267 * Hydra_Software_Devel/48   7/7/05 3:34p darnstein
268 * PR 16008: The default settings struct for BVBI_Open() now allows the
269 * user to choose a buffer size for capturing ancillary data packets in
270 * incoming ITU-R 656 digital video.
271 *
272 * Hydra_Software_Devel/47   7/6/05 5:54p darnstein
273 * PR 16008: Input of closed caption data in SAA7113 ancillary data
274 * packets of ITU-R 656 digital video has been confirmed. SAA7114 input
275 * almost certainly needs some debugging though.
276 *
277 * Hydra_Software_Devel/46   6/15/05 5:05p darnstein
278 * PR 14487: Put in runtime checking for workaround for hardware PR 13583.
279 *
280 * Hydra_Software_Devel/45   5/18/05 5:47p darnstein
281 * PR 11440: Progress towards ITU-R 656 input of VBI data.
282 *
283 * Hydra_Software_Devel/44   4/14/05 12:00p darnstein
284 * PR 14720: For each reference to BCHP_REV_B[01], add a BCHP_REV_B2.
285 * Still untested.
286 *
287 * Hydra_Software_Devel/43   3/18/05 5:12p darnstein
288 * PR 14518: allow CGMS and WSS output to be persistent.
289 *
290 * Hydra_Software_Devel/42   3/18/05 4:12p darnstein
291 * PR 14472: BVBI_Encode_Create() errors out right away if caller attempts
292 * to open on secondary VEC, on a BCM3560 chip.
293 *
294 * Hydra_Software_Devel/41   3/9/05 3:44p darnstein
295 * PR 11440: fix errors involving ITU-R 656 input and output.
296 *
297 * Hydra_Software_Devel/40   2/15/05 1:20p darnstein
298 * PR 14118: Use function argument as required (twice). Bug discovered at
299 * the source by Perrier.
300 *
301 * Hydra_Software_Devel/39   12/13/04 7:44p darnstein
302 * PR 13516: Do not turn closed caption encoder off just because there is
303 * no data immediately ready for output.
304 *
305 * Hydra_Software_Devel/38   7/22/04 12:44p darnstein
306 * PR 9080: change names of BVBI GetDisplayFormat functions to
307 * GetVideoFormat.  This change should have been made in the revision
308 * Hydra_Software_Devel/32 on 4/2/04.
309 *
310 * Hydra_Software_Devel/37   7/16/04 7:06p darnstein
311 * PR 9080: merge in 656 input and output work. Some testing and debugging
312 * remains to be done.
313 *
314 * Hydra_Software_Devel/I656/5   7/16/04 6:22p darnstein
315 * Don't de-initialize IN656 core.  It may hang the memory bus!
316 *
317 * Hydra_Software_Devel/I656/4   7/15/04 8:15p darnstein
318 * Don't initialize IN656 core.  It may hang the memory bus!
319 *
320 * Hydra_Software_Devel/I656/3   7/15/04 5:51p darnstein
321 * Allow choice of sdid field in ancillary data packets written out.
322 *
323 * Hydra_Software_Devel/I656/2   7/8/04 7:44p darnstein
324 * ITU-R 656 decoding of VBI seems to be ready for bring up.  Expect bugs.
325 *
326 * Hydra_Software_Devel/I656/1   6/28/04 1:10p darnstein
327 * 656 output is ready for testing.
328 *
329 * Hydra_Software_Devel/36   6/17/04 6:19p darnstein
330 * PR 11443: Get rid of a kludge that was only needed in revision -A0 of
331 * the hardware.
332 *
333 * Hydra_Software_Devel/35   6/17/04 5:54p darnstein
334 * PR 9080: Do a better job of handling the fact that WSS and VPS only
335 * occur on top field.
336 *
337 * Hydra_Software_Devel/34   5/6/04 6:16p darnstein
338 * PR 9080: choose video line for interrupt, even if no VBI data is to be
339 * processed. Useful for testing.
340 *
341 * Hydra_Software_Devel/33   4/29/04 3:31p darnstein
342 * PR 9080: do video format check before programming VPS core.
343 *
344 * Hydra_Software_Devel/32   4/2/04 2:12p darnstein
345 * PR 9080: change names of BVBI SetDisplayFormat functions to
346 * SetVideoFormat. This change prevents wastage of VS cycles.
347 *
348 * Hydra_Software_Devel/31   3/26/04 1:44p darnstein
349 * PR 8543: Work around for "teletext lines in use" hardware bug.
350 *
351 * Hydra_Software_Devel/30   3/18/04 11:03a darnstein
352 * PR 9080: program the VD_TOP_vd_interrupt register to get decoding ISR
353 * at the correct moment.
354 *
355 * Hydra_Software_Devel/29   3/12/04 5:51p darnstein
356 * PR 9080: Teletext for NTSC is working, with a kludge for an A0 hardware
357 * flaw.  There is a lot of debug code that will be removed later.
358 *
359 * Hydra_Software_Devel/28   3/4/04 4:23p darnstein
360 * PR 9080: Fix some logic errors concerning activation of VBI.  Add some
361 * functionality needed by progressive video formats.
362 *
363 * Hydra_Software_Devel/27   2/27/04 6:13p darnstein
364 * PR 9080: Fix misuse of BDBG_ASSERT macro.  Add checks for valid video
365 * format.
366 *
367 * Hydra_Software_Devel/26   2/26/04 3:13p darnstein
368 * PR 9906: When doing CRC computation in software, cache last computation
369 * for reuse, to save CPU cycles.
370 *
371 * Hydra_Software_Devel/25   2/6/04 11:48a darnstein
372 * PR 9080: Better handle VBI decoding errors.
373 *
374 * Hydra_Software_Devel/24   2/3/04 4:42p darnstein
375 * PR 9080: fix logic errors in handling decoding errors. A few other
376 * minor fixes.
377 *
378 * Hydra_Software_Devel/23   1/27/04 6:22p darnstein
379 * PR 9080: Don't check for overrun errors on encoding.  It is only
380 * possible for closed caption encoding, anyway.
381 *
382 * Hydra_Software_Devel/22   1/23/04 4:08p darnstein
383 * PR 9080: Routines used in (pseudo) ISRs have no critical sections.
384 *
385 * Hydra_Software_Devel/21   1/20/04 1:20p darnstein
386 * PR 9338: Don't fiddle with VBI_ENC_xxx_Control registers.  The VDC
387 * module owns them now.
388 *
389 * Hydra_Software_Devel/20   1/15/04 4:23p darnstein
390 * PR 9080: Many fixes.  Closed caption encoding seems to work now.
391 *
392 * Hydra_Software_Devel/19   12/22/03 5:18p darnstein
393 * PR 9080: fix a stupid bug.
394 *
395 * Hydra_Software_Devel/18   12/19/03 5:20p darnstein
396 * PR 9080: adapt to changed BAVC enum for field polarity.
397 *
398 * Hydra_Software_Devel/17   12/19/03 5:04p darnstein
399 * PR 9080: many changes. Still not working.
400 *
401 * Hydra_Software_Devel/16   10/17/03 3:38p darnstein
402 * VBI encoding can be disabled for one field time.
403 *
404 * Hydra_Software_Devel/15   10/16/03 4:27p darnstein
405 * Use revised #define BAVC_SourceId_eVdec0.
406 *
407 * Hydra_Software_Devel/14   10/16/03 1:21p darnstein
408 * Fix usage of BDBG_ENTER(), BDBG_LEAVE().
409 *
410 * Hydra_Software_Devel/13   10/14/03 11:26a darnstein
411 * Change polarity to polarityMask in BVBI_P_Field_Handle.
412 *
413 * Hydra_Software_Devel/12   10/9/03 4:00p darnstein
414 * Change name of several API functions to indicate that they may be
415 * called from an ISR.  Add polarity attribute to BVBI_Field_Handle and
416 * use it in the API.  Fix some typing errors.
417 *
418 * Hydra_Software_Devel/11   10/9/03 1:17p darnstein
419 * Add "use count" attribute to BVBI_Field_Handle.  Not for general use!
420 *
421 * Hydra_Software_Devel/10   10/2/03 2:25p darnstein
422 * Remove improper use of BERR_TRACE.
423 * Put in some missing BDBG_LEAVE statements.
424 *
425 * Hydra_Software_Devel/9   10/1/03 10:54a darnstein
426 * Take out some debug code that caused problems in nightly build.
427 *
428 * Hydra_Software_Devel/8   9/25/03 5:37p darnstein
429 * Fix simple typo for BDBG_ASSERT
430 *
431 * Hydra_Software_Devel/7   9/25/03 4:48p darnstein
432 * BVBI module is mostly complete. The only things that I know are missing
433 * are the critical sections, 656 support, macrovision support, and LOTS
434 * OF TESTING.
435 *
436 * Hydra_Software_Devel/6   9/12/03 6:50p darnstein
437 * Done except for VPS, teletext, critical sections, and (lots of)
438 * testing.
439 *
440 * Hydra_Software_Devel/5   9/10/03 5:20p darnstein
441 * Change API according to agreement with Jason (yesterday).  Add
442 * documentation of function return values.  More documentation is needed
443 * though.
444 *
445 * Hydra_Software_Devel/4   9/9/03 7:53p darnstein
446 * I think all API functions have been implemented, though some with
447 * stubs.
448 *
449 * Hydra_Software_Devel/3   9/2/03 8:08p darnstein
450 * Still not ready for use.
451 *
452 * Hydra_Software_Devel/2   8/29/03 6:47p darnstein
453 * Implementation of the most general parts of the VBI API.
454 *
455 * Hydra_Software_Devel/1   8/28/03 11:35a darnstein
456 * Implementation of the most general parts of the VBI API.
457 *
458 ***************************************************************************/
459
460#include "bstd.h"                /* standard types */
461#include "bdbg.h"                /* Dbglib */
462#include "bkni.h"                /* malloc */
463#include "bvbi.h"                /* VBI processing, this module. */
464#include "bvbi_priv.h"           /* VBI internal data structures */
465
466#ifdef BCHP_PWR_SUPPORT
467#include "bchp_pwr.h"
468#endif
469
470BDBG_MODULE(BVBI);
471
472/***************************************************************************
473* Private data items
474***************************************************************************/
475
476static const BVBI_Settings s_DefaultSettings =
477{
478        24576,                                          /* in656bufferSize    */
479        false                       /* tteShiftDirMsb2Lsb */
480};
481
482static const BVBI_XSER_Settings s_XSER_DefaultSettings =
483{
484        BVBI_TTserialDataContent_DataMagFrmRun,    /* xsSerialDataContent */
485        BVBI_TTserialDataSync_EAV,                 /* ttSerialDataSync */
486        27                                         /* iTTserialDataSyncDelay */
487};
488/* TODO: determine sensible defaults (above) from our customers. */
489
490/***************************************************************************
491* Implementation of "BVBI_" API functions
492***************************************************************************/
493
494/***************************************************************************
495 *
496 */
497BERR_Code BVBI_GetDefaultSettings(  BVBI_Settings *pSettings )
498{
499        BDBG_ENTER(BVBI_GetDefaultSettings);
500
501        if (!pSettings)
502        {
503                BDBG_ERR(("Invalid parameter\n"));
504                return BERR_TRACE(BERR_INVALID_PARAMETER);
505        }
506
507        *pSettings = s_DefaultSettings;
508
509        BDBG_LEAVE(BVBI_GetDefaultSettings);
510
511        return BERR_SUCCESS;
512}
513
514
515/***************************************************************************
516 *
517 */
518BERR_Code BVBI_Open
519        ( BVBI_Handle           *pVbiHandle,
520          BCHP_Handle            hChip,
521          BREG_Handle            hRegister,
522          BMEM_Handle            hMemory,
523          const BVBI_Settings           *pDefSettings )
524{
525        int type;
526        BERR_Code eErr;
527        BVBI_P_Handle *pVbi = NULL;
528        const BVBI_Settings* settings =
529                (pDefSettings ? pDefSettings : &s_DefaultSettings);
530
531        BDBG_ENTER(BVBI_Open);
532
533        if((!pVbiHandle) ||
534           (!hChip) ||
535           (!hRegister) ||
536           (!hMemory))
537        {
538                BDBG_ERR(("Invalid parameter\n"));
539                eErr = BERR_TRACE(BERR_INVALID_PARAMETER);
540                goto BVBI_Open_Done;
541        }
542
543        /* Alloc the main VBI context. */
544        pVbi = (BVBI_P_Handle*)(BKNI_Malloc(sizeof(BVBI_P_Handle)));
545
546        if(!pVbi)
547        {
548                eErr = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
549                goto BVBI_Open_Done;
550        }
551
552        /* Clear out the context and set defaults. */
553        BKNI_Memset((void*)pVbi, 0x0, sizeof(BVBI_P_Handle));
554
555        /* Initialize magic number to the size of the struct */
556        pVbi->ulBlackMagic = sizeof(BVBI_P_Handle);
557
558        /* Store the hChip, hRegister, hMemory, and hRdc for later use. */
559        pVbi->hChip = hChip;
560        pVbi->hReg  = hRegister;
561        pVbi->hMem  = hMemory;
562
563        /* Store other settings from user */
564        pVbi->in656bufferSize = settings->in656bufferSize;
565        pVbi->tteShiftDirMsb2Lsb = settings->tteShiftDirMsb2Lsb;
566
567        /* Initialize empty lists of decode and encode contexts */
568        BLST_D_INIT(&pVbi->decode_contexts);
569        BLST_D_INIT(&pVbi->encode_contexts);
570
571        /* Initialize freelists for bulky data */
572        BVBI_P_LCOP_INITFREELIST (&pVbi->ttFreelist);
573
574        /* Clear out list of "in use" VEC cores */
575        for (type = 0 ; type < BVBI_P_EncCoreType_eLAST ; ++type)
576        {
577                pVbi->vecHwCoreMask[type] = 0x0;
578                pVbi->vecHwCoreMask_656[type] = 0x0;
579        }
580
581#ifdef BCHP_PWR_RESOURCE_VDC_VEC
582        BCHP_PWR_AcquireResource(pVbi->hChip, BCHP_PWR_RESOURCE_VDC_VEC);
583#endif
584#ifdef BCHP_PWR_RESOURCE_VDC_656_OUT
585        BCHP_PWR_AcquireResource(pVbi->hChip, BCHP_PWR_RESOURCE_VDC_656_OUT);
586#endif
587
588        /* Bang on the hardware until it makes a nice sound */
589        if ((eErr = BERR_TRACE (BVBI_P_CC_Init (pVbi))) != BERR_SUCCESS)
590        {
591                goto BVBI_Open_Done;
592        }
593        if ((eErr = BERR_TRACE (BVBI_P_CGMS_Init (pVbi))) != BERR_SUCCESS)
594        {
595                goto BVBI_Open_Done;
596        }
597        if ((eErr = BERR_TRACE (BVBI_P_WSS_Init (pVbi))) != BERR_SUCCESS)
598        {
599                goto BVBI_Open_Done;
600        }
601        if ((eErr = BERR_TRACE (BVBI_P_VPS_Init (pVbi))) != BERR_SUCCESS)
602        {
603                goto BVBI_Open_Done;
604        }
605        if ((eErr = BERR_TRACE (BVBI_P_TT_Init (pVbi))) != BERR_SUCCESS)
606        {
607                goto BVBI_Open_Done;
608        }
609#if (BVBI_P_NUM_GSE > 0)
610        if ((eErr = BERR_TRACE (BVBI_P_GS_Init (pVbi))) != BERR_SUCCESS)
611        {
612                goto BVBI_Open_Done;
613        }
614#endif
615#if (BVBI_P_NUM_AMOLE > 0)
616        if ((eErr = BERR_TRACE (BVBI_P_AMOL_Init (pVbi))) != BERR_SUCCESS)
617        {
618                goto BVBI_Open_Done;
619        }
620#endif
621#if (BVBI_P_NUM_SCTEE > 0) 
622        if ((eErr = BERR_TRACE (BVBI_P_SCTE_Init (pVbi))) != BERR_SUCCESS)
623        {
624                goto BVBI_Open_Done;
625        }
626#endif
627        if ((eErr = BERR_TRACE (BVBI_P_VE_Init (pVbi))) != BERR_SUCCESS)
628        {
629                goto BVBI_Open_Done;
630        }
631#if (BVBI_P_HAS_XSER_TT)
632        if ((eErr = BERR_TRACE (
633                BVBI_P_ITU656_Init (pVbi->hReg, BVBI_P_GetDefaultXserSettings())))
634                != BERR_SUCCESS)
635        {
636                goto BVBI_Open_Done;
637        }
638#endif
639#if (BVBI_P_NUM_ANCI656_656 > 0)
640        if ((eErr = BERR_TRACE (BVBI_P_A656_Init (pVbi))) != BERR_SUCCESS)
641        {
642                goto BVBI_Open_Done;
643        }
644#endif
645#if (BVBI_P_NUM_IN656 > 0)
646        if ((eErr = BERR_TRACE (BVBI_P_IN656_Init (pVbi))) != BERR_SUCCESS)
647        {
648                goto BVBI_Open_Done;
649        }
650#endif
651
652        /* All done. now return the new fresh context to user. */
653        *pVbiHandle = (BVBI_Handle)pVbi;
654
655  BVBI_Open_Done:
656
657        BDBG_LEAVE(BVBI_Open);
658
659        if ((BERR_SUCCESS != eErr) && (NULL != pVbi)) {
660                /* release power if open fails */
661#ifdef BCHP_PWR_RESOURCE_VDC_656_OUT
662                BCHP_PWR_ReleaseResource(pVbi->hChip, BCHP_PWR_RESOURCE_VDC_656_OUT);
663#endif
664#ifdef BCHP_PWR_RESOURCE_VDC_VEC
665                BCHP_PWR_ReleaseResource(pVbi->hChip, BCHP_PWR_RESOURCE_VDC_VEC);
666#endif
667                BKNI_Free((void*)pVbi);
668        }
669
670        return eErr;
671}
672
673
674/***************************************************************************
675 *
676 */
677void  BVBI_Close ( BVBI_Handle vbiHandle )
678{
679        BVBI_P_Handle *pVbi;
680        BERR_Code eErr;
681
682        BDBG_ENTER(BVBI_Close);
683
684        /* check parameters */
685        BVBI_P_GET_CONTEXT(vbiHandle, pVbi);
686        BDBG_ASSERT (pVbi != NULL);
687
688        /* Refuse service if user left any decoder objects open */
689        BDBG_ASSERT (NULL == BLST_D_FIRST (&pVbi->decode_contexts));
690
691        /* Refuse service if user left any encoder objects open */
692        BDBG_ASSERT (NULL == BLST_D_FIRST (&pVbi->encode_contexts));
693
694        /* Close the individual cores.  These same functions were used in
695           BVBI_Open(). */
696        eErr = BERR_TRACE (BVBI_P_CC_Init   (pVbi));
697        BDBG_ASSERT (eErr == BERR_SUCCESS);
698        eErr = BERR_TRACE (BVBI_P_CGMS_Init (pVbi));
699        BDBG_ASSERT (eErr == BERR_SUCCESS);
700        eErr = BERR_TRACE (BVBI_P_WSS_Init  (pVbi));
701        BDBG_ASSERT (eErr == BERR_SUCCESS);
702        eErr = BERR_TRACE (BVBI_P_TT_Init   (pVbi));
703        BDBG_ASSERT (eErr == BERR_SUCCESS);
704        eErr = BERR_TRACE (BVBI_P_VPS_Init  (pVbi));
705        BDBG_ASSERT (eErr == BERR_SUCCESS);
706#if (BVBI_P_NUM_GSE > 0)
707        eErr = BERR_TRACE (BVBI_P_GS_Init  (pVbi));
708        BDBG_ASSERT (eErr == BERR_SUCCESS);
709#endif
710#if (BVBI_P_NUM_AMOLE > 0)
711        eErr = BERR_TRACE (BVBI_P_AMOL_Init  (pVbi));
712        BDBG_ASSERT (eErr == BERR_SUCCESS);
713#endif
714#if (BVBI_P_NUM_SCTEE > 0) 
715        eErr = BERR_TRACE (BVBI_P_SCTE_Init  (pVbi));
716        BDBG_ASSERT (eErr == BERR_SUCCESS);
717#endif
718        eErr = BERR_TRACE (BVBI_P_VE_Init   (pVbi));
719        BDBG_ASSERT (eErr == BERR_SUCCESS);
720#if (BVBI_P_HAS_XSER_TT)
721        eErr =
722                BERR_TRACE (
723                        BVBI_P_ITU656_Init (pVbi->hReg, BVBI_P_GetDefaultXserSettings()));
724        BDBG_ASSERT (eErr == BERR_SUCCESS);
725#endif
726#if (BVBI_P_NUM_ANCI656_656 > 0)
727        eErr = BERR_TRACE (BVBI_P_A656_Init (pVbi));
728        BDBG_ASSERT (eErr == BERR_SUCCESS);
729#endif
730#if (BVBI_P_NUM_IN656 > 0)
731        eErr = BERR_TRACE (BVBI_P_IN656_Init(pVbi));
732        BDBG_ASSERT (eErr == BERR_SUCCESS);
733#endif
734
735        /* The handle is invalid */
736        pVbi->ulBlackMagic = 0;
737
738        /* Sanity check for bulky storage */
739        BDBG_ASSERT (pVbi->ttFreelist.l_co == 0x0);
740
741#ifdef BCHP_PWR_RESOURCE_VDC_656_OUT
742        BCHP_PWR_ReleaseResource(pVbi->hChip, BCHP_PWR_RESOURCE_VDC_656_OUT); 
743#endif
744#ifdef BCHP_PWR_RESOURCE_VDC_VEC
745        BCHP_PWR_ReleaseResource(pVbi->hChip, BCHP_PWR_RESOURCE_VDC_VEC);
746#endif
747
748        /* Release context in system memory */
749        BKNI_Free((void*)pVbi);
750
751        BDBG_LEAVE(BVBI_Close);
752}
753
754/***************************************************************************
755 *
756 */
757BERR_Code BVBI_Standby
758        ( BVBI_Handle hVbi,
759          BVBI_StandbySettings *pSettings )
760{
761        BVBI_P_Handle *pVbi;
762        BSTD_UNUSED(pSettings); /* unused for now */
763
764        BVBI_P_GET_CONTEXT(hVbi, pVbi);
765        BDBG_ASSERT (pVbi != NULL);
766
767        /* TODO: if BVBI is in use and there are clocks that need to be kept powered,
768           we should short-circuit and return an error. for now, no such check is deemed necessary */
769        if (0) {
770                BDBG_ERR(("Cannot enter standby due to ( ) in use"));
771                return BERR_UNKNOWN;
772        }
773
774#ifdef BCHP_PWR_RESOURCE_VDC_656_OUT
775        BCHP_PWR_ReleaseResource(pVbi->hChip, BCHP_PWR_RESOURCE_VDC_656_OUT);
776#endif
777#ifdef BCHP_PWR_RESOURCE_VDC_VEC
778        BCHP_PWR_ReleaseResource(pVbi->hChip, BCHP_PWR_RESOURCE_VDC_VEC);
779#endif
780        return BERR_SUCCESS;
781}
782
783/***************************************************************************
784 *
785 */
786BERR_Code BVBI_Resume (BVBI_Handle hVbi)
787{
788        BVBI_P_Handle *pVbi;
789
790        BVBI_P_GET_CONTEXT(hVbi, pVbi);
791        BDBG_ASSERT (pVbi != NULL);
792
793#ifdef BCHP_PWR_RESOURCE_VDC_VEC
794        BCHP_PWR_AcquireResource(pVbi->hChip, BCHP_PWR_RESOURCE_VDC_VEC);
795#endif
796#ifdef BCHP_PWR_RESOURCE_VDC_656_OUT
797        BCHP_PWR_AcquireResource(pVbi->hChip, BCHP_PWR_RESOURCE_VDC_656_OUT);
798#endif
799        return BERR_SUCCESS;
800}
801
802/***************************************************************************
803 * VBI private (top level) functions
804 ***************************************************************************/
805
806const BVBI_XSER_Settings* BVBI_P_GetDefaultXserSettings (void)
807{
808        return &s_XSER_DefaultSettings;
809}
810
811/***************************************************************************
812 *
813 */
814uint32_t BVBI_P_LEBE_SWAP (uint32_t ulDatum)
815{
816        uint8_t temp;
817        union {
818                uint8_t b[4];
819                uint32_t l;
820        } scratch;
821
822        scratch.l = ulDatum;
823        P_SWAP (scratch.b[0], scratch.b[3], temp);
824        P_SWAP (scratch.b[1], scratch.b[2], temp);
825
826        return scratch.l;
827}
828
829
830/***************************************************************************
831 *
832 */
833uint32_t BVBI_WSS2CGMS (uint16_t wssData)
834{
835        int iBit;
836        uint32_t cgmsData;
837
838        /* Insert the 6 bit preamble */
839        cgmsData = 0x3E;
840
841        /* Left justify the user's data */
842        wssData <<= 3;
843
844        /* Slide in the user's data */
845        for (iBit = 0 ; iBit < 13 ; ++iBit)
846        {
847                cgmsData <<= 2;
848
849                /* Process input data MSb first */
850                if (wssData & (uint16_t)(0x8000))
851                {
852                        /* 1 bits get encoded as 10 */
853                        cgmsData |= 0x2;
854                }
855                else
856                {
857                        /* 0 bits get encoded as 01 */
858                        cgmsData |= 0x1;
859                }
860
861                /* Next bit please */
862                wssData <<= 1;
863        }
864
865        return cgmsData;
866}
867
868/* End of File */
Note: See TracBrowser for help on using the repository browser.