source: svn/trunk/newcon3bcm2_21bu/magnum/portinginterface/vbi/7552/bvbi_tt.c

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 15.9 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-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: bvbi_tt.c $
11 * $brcm_Revision: Hydra_Software_Devel/5 $
12 * $brcm_Date: 12/21/09 7:06p $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/portinginterface/vbi/7400/bvbi_tt.c $
19 *
20 * Hydra_Software_Devel/5   12/21/09 7:06p darnstein
21 * SW7550-120: Add support for SECAM variants.
22 *
23 * Hydra_Software_Devel/4   6/24/09 5:39p darnstein
24 * PR56342: BVBI compiles for 7550 chipset now.
25 *
26 * Hydra_Software_Devel/3   1/20/09 12:12p darnstein
27 * PR51074: For the problem with 15 lines or more teletext (output), apply
28 * the same software workaround that was used on 7401-C0. Note that this
29 * workaround itself causes problems for some chipsets, such as 3563-C0.
30 * So the workaround is controlled by an #ifdef.
31 *
32 * Hydra_Software_Devel/2   12/3/08 7:57p darnstein
33 * PR45819: New, more modular form of most BVBI source files.
34 *
35 * Hydra_Software_Devel/30   7/30/08 8:39p darnstein
36 * PR43926,PR43413: Workaround for TTD addressing error in hardware.
37 * Decodes at most one line of teletext per video field. Will not
38 * corrrupt memory if input signal actually contains more teletext.
39 *
40 * Hydra_Software_Devel/29   7/30/08 5:41p darnstein
41 * PR43926: A basic solution to the memory addressing problem is in place.
42 * It can decode one line of teletext. If more teletext is present, then
43 * memory corruption will occur. This danger will be eliminated next.
44 *
45 * Hydra_Software_Devel/28   4/25/08 2:36p darnstein
46 * PR37064: Do not do byte-swapping on line masks. It was wrong.
47 *
48 * Hydra_Software_Devel/27   4/8/08 6:14p darnstein
49 * PR37064: This is the same 15-lines-of-teletext problem that was solved
50 * (worked-around, actually) on the dedicated 7401 ClearCase branch.
51 *
52 * Hydra_Software_Devel/26   1/21/08 3:29p darnstein
53 * PR38858: fix up test for insufficient memory (to store teletext data).
54 *
55 * Hydra_Software_Devel/25   7/26/07 2:43p darnstein
56 * PR33057: when allocating space for teletext data, initialize its line
57 * mask to "empty" state. This will prevent display of random teletext in
58 * Settop API applications.
59 *
60 * Hydra_Software_Devel/24   1/17/07 5:32p darnstein
61 * PR26464: correctly handle teletext output to multiple VECs
62 *
63 * Hydra_Software_Devel/23   1/2/07 4:21p darnstein
64 * PR26872: Mechanically add SECAM to all cases where PAL formats are
65 * accepted.
66 *
67 * Hydra_Software_Devel/22   12/14/06 7:18p darnstein
68 * PR25990: Can compile for BCM97400-B0 now.
69 *
70 * Hydra_Software_Devel/21   8/31/06 2:09p darnstein
71 * PR23869: clean up the handling of multiple VECs and VDECs.
72 *
73 * Hydra_Software_Devel/20   7/24/06 4:45p darnstein
74 * PR22720: Implement the software workaround: duplicate the first framing
75 * code byte.
76 *
77 * Hydra_Software_Devel/19   1/4/06 12:57p rjlewis
78 * PR18341: fixed typo.
79 *
80 * Hydra_Software_Devel/18   12/21/05 5:15p darnstein
81 * PR18341: Swap bytes of the teletext "line mask" DRAM entry on little-
82 * endian systems.
83 *
84 * Hydra_Software_Devel/17   9/23/05 2:47p darnstein
85 * PR13750: Proper use of BERR_TRACE and BERR_CODEs.
86 *
87 * Hydra_Software_Devel/16   8/22/05 8:11p darnstein
88 * PR16057: To support many different chips, use private #defines that
89 * specify number of VECs, VDECs, and (separately) pass-through VECs.
90 *
91 * Hydra_Software_Devel/15   3/17/05 7:35p darnstein
92 * PR 14472: Eliminate references to secondary VEC if chip is 3560.
93 *
94 * Hydra_Software_Devel/I656/1   6/28/04 1:10p darnstein
95 * 656 output is ready for testing.
96 *
97 * Hydra_Software_Devel/13   4/6/04 4:13p darnstein
98 * PR 9080: fix a stupid memory leak.
99 *
100 * Hydra_Software_Devel/12   4/2/04 6:42p darnstein
101 * PR 9080: Allow NTSC-J video format.
102 *
103 * Hydra_Software_Devel/11   3/26/04 1:46p darnstein
104 * PR 9080: commented out some debug code.
105 *
106 * Hydra_Software_Devel/10   3/12/04 5:52p darnstein
107 * PR 9080: Teletext for NTSC is working, with a kludge for an A0 hardware
108 * flaw.  There is a lot of debug code that will be removed later.
109 *
110 * Hydra_Software_Devel/9   3/4/04 4:28p darnstein
111 * PR 9080: Improve allocation of teletext private data.  Partial
112 * implementation of teletext.
113 *
114 * Hydra_Software_Devel/8   2/6/04 11:49a darnstein
115 * PR 9080: better handle VBI decoding errors.
116 *
117 * Hydra_Software_Devel/7   2/3/04 4:42p darnstein
118 * PR 9080: fix logic errors in handling decoding errors. A few other
119 * minor fixes.
120 *
121 * Hydra_Software_Devel/6   10/17/03 6:04p darnstein
122 * Define a user-friendly data structure for holding teletext data.
123 *
124 * Hydra_Software_Devel/5   10/16/03 1:21p darnstein
125 * Fix usage of BDBG_ENTER(), BDBG_LEAVE().
126 *
127 * Hydra_Software_Devel/4   10/9/03 3:57p darnstein
128 * Change name of several API functions to indicate that they may be
129 * called from an ISR.
130 *
131 * Hydra_Software_Devel/3   9/25/03 4:48p darnstein
132 * BVBI module is mostly complete. The only things that I know are missing
133 * are the critical sections, 656 support, macrovision support, and LOTS
134 * OF TESTING.
135 *
136 * Hydra_Software_Devel/2   9/9/03 7:53p darnstein
137 * I think all API functions have been implemented, though some with
138 * stubs.
139 *
140 * Hydra_Software_Devel/1   9/9/03 4:00p darnstein
141 * Teletext specific code to support VBI processing.
142 *
143 ***************************************************************************/
144
145#include "bstd.h"                /* standard types */
146#include "bdbg.h"                /* Dbglib */
147#include "bvbi.h"                /* VBI processing, this module. */
148#include "bvbi_priv.h"           /* VBI internal data structures */
149
150BDBG_MODULE(BVBI);
151
152
153/***************************************************************************
154* Forward declarations of static (private) functions
155***************************************************************************/
156
157
158/***************************************************************************
159* Implementation of "BVBI_" API functions
160***************************************************************************/
161
162
163/***************************************************************************
164 *
165 */
166BERR_Code BVBI_Field_GetTTData_isr ( 
167        BVBI_Field_Handle fieldHandle, 
168        int                    nLines,
169        BVBI_TT_Line *        ttLines
170)
171{
172        uint8_t *pData;
173        uint32_t lineMask;
174        int      iLine;
175        int      iChar;
176        BVBI_P_Field_Handle* pVbi_Fld;
177        BVBI_P_TTData* pTTData;
178        BERR_Code eErr = BERR_SUCCESS;
179
180        BDBG_ENTER(BVBI_Field_GetTTData_isr);
181
182        /* check parameters */
183        BVBI_P_GET_FIELD_CONTEXT(fieldHandle, pVbi_Fld);
184        if((!pVbi_Fld) || (!ttLines))
185        {
186                return BERR_TRACE(BERR_INVALID_PARAMETER);
187        }
188
189        /* Verify that data is present on this field handle */
190        if (!(pVbi_Fld->ulWhichPresent & BVBI_P_SELECT_TT))
191                return (BVBI_ERR_FIELD_NODATA);
192        else if (pVbi_Fld->ulErrInfo & BVBI_LINE_ERROR_TELETEXT_NOENCODE)
193                eErr = (BVBI_ERR_FIELD_BADDATA);
194
195    /* Pull out the mask of valid lines */
196        pTTData = BVBI_P_LCOP_GET_isr (pVbi_Fld, TTDataO);
197        lineMask = pTTData->lineMask;
198        lineMask <<= (pTTData->firstLine);
199
200#ifdef BVBI_P_TTE_WA15
201        /* Abort if user's array is too small */
202        if (pTTData->firstLine >= nLines)
203        {
204                BDBG_ERR(("User array too small\n"));
205                return BERR_TRACE(BERR_INVALID_PARAMETER);
206        }
207
208        /* Loop over initial unused lines */
209        for (iLine = 0 ; iLine < pTTData->firstLine ; ++iLine)
210        {
211                ttLines->ucFramingCode = BVBI_TT_INVALID_FRAMING_CODE;
212                ++ttLines;
213        }
214#endif
215
216        /* Loop over teletext data lines in the field handle */
217        pData = pTTData->pucData + 4;
218        for (iLine = 0 ; iLine < pTTData->ucLines ; ++iLine)
219        {
220                /* If data line is valid */
221                if ((lineMask >> iLine) & 0x1)
222                {
223                        /* Abort if user's array is too small */
224#ifdef BVBI_P_TTE_WA15
225                        if (pTTData->firstLine + iLine >= nLines)
226#else
227                        if (iLine >= nLines)
228#endif
229                        {
230                                BDBG_ERR(("User array too small\n"));
231                                return BERR_TRACE(BERR_INVALID_PARAMETER);
232                        }
233
234                        ttLines->ucFramingCode = *pData++;
235                        for (iChar = 0 ; iChar < pTTData->ucLineSize - 1 ; ++iChar)
236                        {
237                                ttLines->aucData[iChar] = *pData++;
238                        }
239                        for ( ; iChar < BVBI_TT_MAX_LINESIZE ; ++iChar)
240                        {
241                                ttLines->aucData[iChar] = 0x0;
242                        }
243                }
244                else /* data line is invalid */
245                {
246#ifdef BVBI_P_TTE_WA15
247                        /* Info for user */
248                        if ( pTTData->firstLine + iLine < nLines)
249                        ttLines->ucFramingCode = BVBI_TT_INVALID_FRAMING_CODE;
250
251                        /* Skip over wasted space */
252                        pData += pTTData->ucLineSize;
253#else
254                        ttLines->ucFramingCode = BVBI_TT_INVALID_FRAMING_CODE;
255#endif
256                }
257
258                /* Next element of user's array */
259                ++ttLines;
260        }
261       
262        /* Indicate the rest of the lines in the user's data array is empty */
263#ifdef BVBI_P_TTE_WA15
264        for ( ; pTTData->firstLine + iLine < nLines ; ++iLine)
265#else
266        for ( ; iLine < nLines ; ++iLine)
267#endif
268        {
269                ttLines->ucFramingCode = BVBI_TT_INVALID_FRAMING_CODE;
270                ++ttLines;
271        }
272       
273        BDBG_LEAVE(BVBI_Field_GetTTData_isr);
274        return eErr;
275}
276
277
278/***************************************************************************
279 *
280 */
281BERR_Code BVBI_Field_SetTTData_isr ( 
282        BVBI_Field_Handle fieldHandle,
283        BFMT_VideoFmt    eVideoFormat,
284        int                    nLines,
285        BVBI_TT_Line *        ttLines
286)
287{
288        uint32_t lineMask;
289        uint8_t *pData;
290        uint8_t  lineWidth;
291        int      iLine;
292        int      iChar;
293        BVBI_P_Field_Handle* pVbi_Fld;
294        BVBI_P_TTData* pTTData;
295        uint16_t bytes_used;
296#ifdef BVBI_P_TTXADR_WAROUND
297        bool firstLine = true;
298#endif
299
300        BDBG_ENTER(BVBI_Field_SetTTData_isr);
301
302        /* check parameters */
303        BVBI_P_GET_FIELD_CONTEXT(fieldHandle, pVbi_Fld);
304        if((!pVbi_Fld) || (!ttLines))
305        {
306                BDBG_ERR(("Invalid parameter\n"));
307                return BERR_TRACE(BERR_INVALID_PARAMETER);
308        }
309
310        switch (eVideoFormat)
311        {
312        case BFMT_VideoFmt_eNTSC:
313        case BFMT_VideoFmt_eNTSC_J:
314                lineWidth = 34;
315                break;
316    case BFMT_VideoFmt_ePAL_B:
317    case BFMT_VideoFmt_ePAL_B1:
318    case BFMT_VideoFmt_ePAL_D:
319    case BFMT_VideoFmt_ePAL_D1:
320    case BFMT_VideoFmt_ePAL_G:
321    case BFMT_VideoFmt_ePAL_H:
322    case BFMT_VideoFmt_ePAL_K:
323    case BFMT_VideoFmt_ePAL_I:
324    case BFMT_VideoFmt_ePAL_M:
325    case BFMT_VideoFmt_ePAL_N:
326    case BFMT_VideoFmt_ePAL_NC:
327    case BFMT_VideoFmt_eSECAM_L:
328    case BFMT_VideoFmt_eSECAM_B:
329    case BFMT_VideoFmt_eSECAM_G:
330    case BFMT_VideoFmt_eSECAM_D:
331    case BFMT_VideoFmt_eSECAM_K:
332    case BFMT_VideoFmt_eSECAM_H:
333                lineWidth = 43;
334                break;
335        default:
336                BDBG_LEAVE(BVBI_Field_SetTTData_isr);
337                return BERR_TRACE (BERR_INVALID_PARAMETER);
338                break;
339        }
340
341        /* Mark TT data in field handle "invalid" until it is complete */
342        pVbi_Fld->ulWhichPresent &= ~BVBI_P_SELECT_TT;
343
344        /* Initialize line mask to "empty" */
345        lineMask = 0x0;
346
347        /* Initialize pointer into field handle data */
348        BVBI_P_LCOP_WRITE_isr (
349                pVbi_Fld, TTDataO, &pVbi_Fld->pVbi->ttFreelist, clink);
350        pTTData = BVBI_P_LCOP_GET_isr (pVbi_Fld, TTDataO);
351        pData = pTTData->pucData + 4;
352
353        /* Check that the field handle is big enough to start. 
354           More checking will follow */
355        bytes_used = 4;
356        if (pTTData->ucDataSize < bytes_used)
357        {
358                BDBG_ERR(("Field handle cannot accomodate teletext data\n"));
359                return BERR_TRACE(BVBI_ERR_FLDH_CONFLICT);
360        }
361
362        /* Loop over lines of user's TT data */
363        pTTData->firstLine = 0xFF;
364        for (iLine = 0 ; iLine < nLines ; ++iLine)
365        {
366                /* If there is data on this line in user space */
367                if (ttLines->ucFramingCode != BVBI_TT_INVALID_FRAMING_CODE)
368                {
369                        /* Verify that there is enough room in field handle */
370                        bytes_used += lineWidth;
371#ifdef BVBI_P_TTXADR_WAROUND
372                        if (firstLine)
373                        {
374                                ++bytes_used;
375                        }
376#endif
377                        if (bytes_used > pTTData->ucDataSize)
378                        {
379                                BDBG_ERR(("Field handle cannot accomodate teletext data\n"));
380                                return BERR_TRACE(BVBI_ERR_FLDH_CONFLICT);
381                        }
382
383                        if (pTTData->firstLine == 0xFF)
384                                pTTData->firstLine = iLine;
385
386                        /* Copy one line of data */
387                        *pData++ = ttLines->ucFramingCode;
388#ifdef BVBI_P_TTXADR_WAROUND
389                        if (firstLine)
390                        {
391                                /* Write framing code again! */
392                                *pData++ = ttLines->ucFramingCode;
393                                firstLine = false;
394                        }
395#endif
396                        for (iChar = 0 ; iChar < lineWidth - 1 ; ++iChar)
397                        {
398                                *pData++ = ttLines->aucData[iChar];
399                        }
400
401                        /* Update line mask */
402                        lineMask |= (0x1 << iLine);
403
404                        /* Update line count in private data */
405                        pTTData->ucLines = (uint8_t)(iLine + 1);
406                }
407#ifdef BVBI_P_TTE_WA15
408                else /* No data on this line in user space */
409                {
410                        /* Create wasted space in the field handle! */
411                        if (pTTData->firstLine != 0xFF)
412                        {
413                                bytes_used += lineWidth;
414                                pData += lineWidth;
415                        }
416
417                } /* If there is data on this line in user space */
418#endif
419
420                /* Go to next line of user's data */
421                ++ttLines;
422        }
423
424        /* Write the line mask and line width to the start of the data */
425        if (pTTData->firstLine == 0xFF)
426#ifdef BVBI_P_TTE_WA15
427                pTTData->firstLine = 0;
428#else
429                lineMask = 0x0;
430#endif
431        else
432                lineMask = lineMask >> pTTData->firstLine;
433        pTTData->lineMask = lineMask;
434        *(uint32_t*)(pTTData->pucData) = 0xFFFFFFFF;
435        pTTData->ucLineSize = lineWidth;
436
437        /* Indicate valid data is present */
438        pVbi_Fld->ulWhichPresent |= BVBI_P_SELECT_TT;
439
440        BDBG_LEAVE(BVBI_Field_SetTTData_isr);
441        return BERR_SUCCESS;
442}
443
444
445/***************************************************************************
446* Implementation of supporting teletext functions that are not in API
447***************************************************************************/
448
449
450BERR_Code BVBI_P_TT_Init( BVBI_P_Handle *pVbi )
451{
452#if (BVBI_P_NUM_TTE == 0) && (BVBI_P_NUM_TTE_656 == 0) /** { **/
453        BSTD_UNUSED (pVbi);
454#else /** } { **/
455        uint8_t hwIndex;
456#if (BVBI_P_NUM_VDEC >= 1)
457        uint32_t ulCoreOffset;
458#endif
459
460        BDBG_ENTER(BVBI_P_TT_Init);
461
462        /* Initialize TT decoder */
463#if (BVBI_P_NUM_VDEC >= 1)
464        ulCoreOffset = 0x0;
465        BVBI_P_TT_Dec_Init (pVbi->hReg, ulCoreOffset);
466#endif
467#if (BVBI_P_NUM_VDEC >= 2)
468        ulCoreOffset = BCHP_TTD_1_reset - BCHP_TTD_0_reset;
469        BVBI_P_TT_Dec_Init (pVbi->hReg, ulCoreOffset);
470#endif
471
472        /* Initialize TT encoders */
473#if (BVBI_P_NUM_TTE > 0)
474        for (hwIndex = 0 ; hwIndex < BVBI_P_NUM_TTE ; ++hwIndex)
475                BVBI_P_TT_Enc_Init (pVbi->hReg, false, hwIndex);
476#endif
477#if (BVBI_P_NUM_TTE_656 > 0)
478        for (hwIndex = 0 ; hwIndex < BVBI_P_NUM_TTE_656 ; ++hwIndex)
479                BVBI_P_TT_Enc_Init (pVbi->hReg, true, hwIndex);
480#endif
481
482        BDBG_LEAVE(BVBI_P_TT_Init);
483#endif /** } **/
484        return BERR_SUCCESS;
485}
486
487
488uint32_t BVBI_P_TT_Size_Storage(uint32_t ulMaxLines, uint32_t ulMaxLineSize)
489/*
490        Sizes teletext data "slab."  Includes space for framing code.  Does not
491        include space for alignment.
492*/
493{
494        return 4  +  ulMaxLines * ulMaxLineSize;
495}
496
497/***************************************************************************
498 *
499 */
500BERR_Code BVBI_P_TTData_Alloc (
501        BMEM_Handle hMem, uint8_t ucMaxLines, uint8_t ucLineSize, 
502        BVBI_P_TTData* pTTData)
503{
504        /* Sanity check */
505        if (!hMem || !pTTData)
506        {
507                return BERR_TRACE(BERR_INVALID_PARAMETER);
508        }
509
510        /* Deallocate data if necessary */
511        if (pTTData->pucData != 0)
512        {
513                BMEM_Free (hMem, pTTData->pucData);
514                pTTData->ucDataSize =   0;
515                pTTData->ucLines    =   0;
516                pTTData->ucLineSize =   0;
517                pTTData->pucData    = 0x0;
518        }
519
520        /* If user wants to hold any teletext data */
521        if (ucMaxLines != 0)
522        {
523                uint32_t dataSize = BVBI_P_TT_Size_Storage (ucMaxLines, ucLineSize);
524#ifdef BVBI_P_TTXADR_WAROUND
525                ++dataSize;
526#endif
527                pTTData->pucData = 
528                        (uint8_t*)(BMEM_AllocAligned (
529                                hMem,
530                                dataSize,
531                                8,
532                                0));
533                if (!pTTData->pucData)
534                {
535                        return BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
536                }
537               
538                /* Zero out the line mask */
539                *(uint32_t*)(pTTData->pucData) = 0x0;
540
541                /* Complete the self-description of the teletext data */
542                pTTData->ucDataSize =   dataSize;
543                pTTData->ucLines    =          0;
544                pTTData->ucLineSize =          0;
545
546                /* Debug code */
547                /*
548                {
549                uint8_t* start = pTTData->pucData;
550                uint8_t* end = start + dataSize;
551                while (start < end)
552                {
553                        *(uint32_t*)start = 0xDEADBEEF;
554                        start += sizeof(uint32_t);
555                }
556                }
557                */
558        }
559
560        return BERR_SUCCESS;
561}
562
563/***************************************************************************
564* Static (private) functions
565***************************************************************************/
566
567
568/* End of file */
Note: See TracBrowser for help on using the repository browser.