| 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_ttd.c $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/3 $ |
|---|
| 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_ttd.c $ |
|---|
| 19 | * |
|---|
| 20 | * Hydra_Software_Devel/3 12/21/09 7:06p darnstein |
|---|
| 21 | * SW7550-120: Add support for SECAM variants. |
|---|
| 22 | * |
|---|
| 23 | * Hydra_Software_Devel/2 12/3/08 7:57p darnstein |
|---|
| 24 | * PR45819: New, more modular form of most BVBI source files. |
|---|
| 25 | * |
|---|
| 26 | * Hydra_Software_Devel/43 7/30/08 8:40p darnstein |
|---|
| 27 | * PR43926,PR43413: Workaround for TTD addressing error in hardware. |
|---|
| 28 | * Decodes at most one line of teletext per video field. Will not |
|---|
| 29 | * corrrupt memory if input signal actually contains more teletext. |
|---|
| 30 | * |
|---|
| 31 | * Hydra_Software_Devel/42 7/30/08 5:41p darnstein |
|---|
| 32 | * PR43926: A basic solution to the memory addressing problem is in place. |
|---|
| 33 | * It can decode one line of teletext. If more teletext is present, then |
|---|
| 34 | * memory corruption will occur. This danger will be eliminated next. |
|---|
| 35 | * |
|---|
| 36 | * Hydra_Software_Devel/41 5/12/08 2:56p darnstein |
|---|
| 37 | * PR42416: Implement Grossman's work-around for the conflict between VDEC |
|---|
| 38 | * frame comb filter and teletext decoder (TTD). |
|---|
| 39 | * |
|---|
| 40 | * Hydra_Software_Devel/40 4/2/08 1:34p darnstein |
|---|
| 41 | * PR38531,PR40702: |
|---|
| 42 | * 1. Use magic line mask setting discovered by Brad Delanghe. |
|---|
| 43 | * 2. Change line numbering. |
|---|
| 44 | * |
|---|
| 45 | * Hydra_Software_Devel/39 3/11/08 6:52p darnstein |
|---|
| 46 | * PR23201: Change start_delay of teletext decoder core to 0, in the case |
|---|
| 47 | * of PAL video input. Per Brad Grossman. |
|---|
| 48 | * |
|---|
| 49 | * Hydra_Software_Devel/38 1/18/08 1:09p darnstein |
|---|
| 50 | * PR32758,PR38531: Fix bug in programming decoder black level register. |
|---|
| 51 | * Thank you Ming Dei. |
|---|
| 52 | * |
|---|
| 53 | * Hydra_Software_Devel/37 1/11/08 4:37p darnstein |
|---|
| 54 | * PR32758,PR38531: Corrected black_level setting (thank you hardware |
|---|
| 55 | * architect). |
|---|
| 56 | * |
|---|
| 57 | * Hydra_Software_Devel/36 1/2/08 2:27p darnstein |
|---|
| 58 | * PR32758: use PAL decoder settings from Brad Grossman. |
|---|
| 59 | * |
|---|
| 60 | * Hydra_Software_Devel/35 1/17/07 5:32p darnstein |
|---|
| 61 | * PR26464: correctly handle teletext output to multiple VECs |
|---|
| 62 | * |
|---|
| 63 | * Hydra_Software_Devel/34 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/33 8/31/06 2:09p darnstein |
|---|
| 68 | * PR23869: clean up the handling of multiple VECs and VDECs. |
|---|
| 69 | * |
|---|
| 70 | * Hydra_Software_Devel/32 8/18/06 6:51p darnstein |
|---|
| 71 | * PR23178: basic compile on 93563 is possible. |
|---|
| 72 | * |
|---|
| 73 | * Hydra_Software_Devel/31 2/21/06 6:20p darnstein |
|---|
| 74 | * PR18343: Move top line for teletext output up raster by 1 (numerically |
|---|
| 75 | * smaller by 1), but ONLY for PAL. |
|---|
| 76 | * |
|---|
| 77 | * Hydra_Software_Devel/30 1/16/06 12:40p darnstein |
|---|
| 78 | * PR18903: Use BSTD_UNUSED macro to suppress compiler warnings in |
|---|
| 79 | * VxWorks. |
|---|
| 80 | * |
|---|
| 81 | * Hydra_Software_Devel/29 12/22/05 5:53p darnstein |
|---|
| 82 | * PR18234: use some filter_phase_adjustment settings provided by Brad |
|---|
| 83 | * Grossman. |
|---|
| 84 | * |
|---|
| 85 | * Hydra_Software_Devel/28 9/23/05 2:47p darnstein |
|---|
| 86 | * PR13750: Proper use of BERR_TRACE and BERR_CODEs. |
|---|
| 87 | * |
|---|
| 88 | * Hydra_Software_Devel/27 9/19/05 2:57p darnstein |
|---|
| 89 | * PR17151: Check for chip name where needed. Also, convert to new scheme |
|---|
| 90 | * for testing chip revisions (BCHP_VER). |
|---|
| 91 | * |
|---|
| 92 | * Hydra_Software_Devel/26 6/15/05 12:03p darnstein |
|---|
| 93 | * PR 14487: bring up VBI decoding on 97038-C1. |
|---|
| 94 | * |
|---|
| 95 | * Hydra_Software_Devel/25 4/14/05 12:01p darnstein |
|---|
| 96 | * PR 14720: For each reference to BCHP_REV_B[01], add a BCHP_REV_B2. |
|---|
| 97 | * Still untested. |
|---|
| 98 | * |
|---|
| 99 | * Hydra_Software_Devel/24 4/4/05 11:53a darnstein |
|---|
| 100 | * PR 13952: BCM97038-C0 bringup. |
|---|
| 101 | * |
|---|
| 102 | * Hydra_Software_Devel/23 3/11/05 3:49p darnstein |
|---|
| 103 | * PR 14426: use new _0 names for VDEC cores. |
|---|
| 104 | * |
|---|
| 105 | * Hydra_Software_Devel/22 1/5/05 4:27p jasonh |
|---|
| 106 | * PR 13700: Fixed VBI compile issues for 7038 C0. |
|---|
| 107 | * |
|---|
| 108 | * Hydra_Software_Devel/21 9/21/04 2:02p darnstein |
|---|
| 109 | * PR 12728: Replace a line of code that was too long for some compilers |
|---|
| 110 | * to handle. |
|---|
| 111 | * |
|---|
| 112 | * Hydra_Software_Devel/20 7/16/04 7:07p darnstein |
|---|
| 113 | * PR 9080: merge in 656 input and output work. Some testing and debugging |
|---|
| 114 | * remains to be done. |
|---|
| 115 | * |
|---|
| 116 | * Hydra_Software_Devel/I656/1 7/8/04 7:45p darnstein |
|---|
| 117 | * ITU-R 656 decoding of VBI seems to be ready for bring up. Expect bugs. |
|---|
| 118 | * |
|---|
| 119 | * Hydra_Software_Devel/19 6/17/04 5:57p darnstein |
|---|
| 120 | * PR 9080: get decoding working for 7038-B0 hardware. |
|---|
| 121 | * |
|---|
| 122 | * Hydra_Software_Devel/18 5/24/04 5:08p jasonh |
|---|
| 123 | * PR 11189: Merge down from B0 to main-line |
|---|
| 124 | * |
|---|
| 125 | * Hydra_Software_Devel/Refsw_Devel_7038_B0/1 4/19/04 2:45p darnstein |
|---|
| 126 | * PR 9080: Compilation is possible with 7038 B0. Correct execution is not |
|---|
| 127 | * likely. |
|---|
| 128 | * |
|---|
| 129 | * Hydra_Software_Devel/17 4/2/04 6:42p darnstein |
|---|
| 130 | * PR 9080: Allow NTSC-J video format. |
|---|
| 131 | * |
|---|
| 132 | * Hydra_Software_Devel/16 3/26/04 1:47p darnstein |
|---|
| 133 | * PR 9080: remove some kludgey code regarding choice of top or bottom |
|---|
| 134 | * field. |
|---|
| 135 | * |
|---|
| 136 | * Hydra_Software_Devel/15 3/18/04 11:15a darnstein |
|---|
| 137 | * PR 9080: commented out some debugging code. |
|---|
| 138 | * |
|---|
| 139 | * Hydra_Software_Devel/14 3/12/04 5:52p darnstein |
|---|
| 140 | * PR 9080: Teletext for NTSC is working, with a kludge for an A0 hardware |
|---|
| 141 | * flaw. There is a lot of debug code that will be removed later. |
|---|
| 142 | * |
|---|
| 143 | * Hydra_Software_Devel/13 3/4/04 4:28p darnstein |
|---|
| 144 | * PR 9080: improve allocation of teletext private data. |
|---|
| 145 | * |
|---|
| 146 | * Hydra_Software_Devel/12 3/2/04 4:41p darnstein |
|---|
| 147 | * PR 9080: many fixes and additions discovered during bring-up. |
|---|
| 148 | * |
|---|
| 149 | * Hydra_Software_Devel/11 2/27/04 6:10p darnstein |
|---|
| 150 | * PR 9080: handle all of the PAL formats. Fix misuse of BDBG_ASSERT |
|---|
| 151 | * macro. |
|---|
| 152 | * |
|---|
| 153 | * Hydra_Software_Devel/10 2/19/04 2:51p darnstein |
|---|
| 154 | * PR 9493: Use new PAL format enums. |
|---|
| 155 | * |
|---|
| 156 | * Hydra_Software_Devel/9 2/6/04 11:50a darnstein |
|---|
| 157 | * PR 9080: better handle VBI decoding errors. |
|---|
| 158 | * |
|---|
| 159 | * Hydra_Software_Devel/8 2/3/04 4:43p darnstein |
|---|
| 160 | * PR 9080: fix logic errors in handling decoding errors. A few other |
|---|
| 161 | * minor fixes. |
|---|
| 162 | * |
|---|
| 163 | * Hydra_Software_Devel/7 1/23/04 4:08p darnstein |
|---|
| 164 | * PR 9080: Routines used in (pseudo) ISRs have no critical sections. |
|---|
| 165 | * |
|---|
| 166 | * Hydra_Software_Devel/6 12/19/03 5:07p darnstein |
|---|
| 167 | * PR 9080: adapt to changed BAVC enum for field polarity. |
|---|
| 168 | * |
|---|
| 169 | * Hydra_Software_Devel/5 10/16/03 4:26p darnstein |
|---|
| 170 | * Use revised #define BAVC_SourceId_Vdec0. |
|---|
| 171 | * |
|---|
| 172 | * Hydra_Software_Devel/4 10/16/03 1:21p darnstein |
|---|
| 173 | * Fix usage of BDBG_ENTER(), BDBG_LEAVE(). |
|---|
| 174 | * |
|---|
| 175 | * Hydra_Software_Devel/3 9/29/03 5:00p darnstein |
|---|
| 176 | * Put in critical sections. |
|---|
| 177 | * |
|---|
| 178 | * Hydra_Software_Devel/2 9/25/03 4:48p darnstein |
|---|
| 179 | * BVBI module is mostly complete. The only things that I know are missing |
|---|
| 180 | * are the critical sections, 656 support, macrovision support, and LOTS |
|---|
| 181 | * OF TESTING. |
|---|
| 182 | * |
|---|
| 183 | * Hydra_Software_Devel/1 9/22/03 5:43p darnstein |
|---|
| 184 | * Teletext specific code to support VBI decoding. |
|---|
| 185 | * |
|---|
| 186 | ***************************************************************************/ |
|---|
| 187 | |
|---|
| 188 | #include "bstd.h" /* standard types */ |
|---|
| 189 | #include "bdbg.h" /* Dbglib */ |
|---|
| 190 | #include "bkni.h" /* For critical sections */ |
|---|
| 191 | #include "bvbi.h" /* VBI processing, this module. */ |
|---|
| 192 | #include "bvbi_priv.h" /* VBI internal data structures */ |
|---|
| 193 | |
|---|
| 194 | #if (BVBI_P_NUM_VDEC >= 1) /** { **/ |
|---|
| 195 | |
|---|
| 196 | #include "bchp_ttd_0.h" /* RDB info for TTD core */ |
|---|
| 197 | |
|---|
| 198 | #define TTD_0_ACKNOWLEDGE_READ 1 |
|---|
| 199 | |
|---|
| 200 | BDBG_MODULE(BVBI); |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | /*************************************************************************** |
|---|
| 204 | * Forward declarations of static (private) functions |
|---|
| 205 | ***************************************************************************/ |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | /*************************************************************************** |
|---|
| 209 | * Implementation of "BVBI_" API functions |
|---|
| 210 | ***************************************************************************/ |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | /*************************************************************************** |
|---|
| 214 | * |
|---|
| 215 | */ |
|---|
| 216 | void BVBI_P_TT_Dec_Init (BREG_Handle hReg, uint32_t ulCoreOffset) |
|---|
| 217 | { |
|---|
| 218 | uint32_t ulReg = 0x0; |
|---|
| 219 | |
|---|
| 220 | BDBG_ENTER(BVBI_P_TT_Dec_Init); |
|---|
| 221 | |
|---|
| 222 | BKNI_EnterCriticalSection(); |
|---|
| 223 | |
|---|
| 224 | BREG_Write32 (hReg, BCHP_TTD_0_reset + ulCoreOffset, ulReg); |
|---|
| 225 | |
|---|
| 226 | BKNI_LeaveCriticalSection(); |
|---|
| 227 | |
|---|
| 228 | BDBG_LEAVE(BVBI_P_TT_Dec_Init); |
|---|
| 229 | } |
|---|
| 230 | |
|---|
| 231 | |
|---|
| 232 | /*************************************************************************** |
|---|
| 233 | * |
|---|
| 234 | */ |
|---|
| 235 | BERR_Code BVBI_P_TT_Dec_Program ( |
|---|
| 236 | BREG_Handle hReg, |
|---|
| 237 | BMEM_Handle hMem, |
|---|
| 238 | BAVC_SourceId eSource, |
|---|
| 239 | bool bActive, |
|---|
| 240 | BFMT_VideoFmt eVideoFormat, |
|---|
| 241 | #ifdef BVBI_P_TTD_SCB2_ERROR |
|---|
| 242 | uint8_t* topTTscratch, |
|---|
| 243 | uint8_t* botTTscratch, |
|---|
| 244 | #endif |
|---|
| 245 | BVBI_P_TTData* topData, |
|---|
| 246 | BVBI_P_TTData* botData) |
|---|
| 247 | { |
|---|
| 248 | uint32_t H_TopMask; |
|---|
| 249 | uint32_t H_BotMask; |
|---|
| 250 | uint32_t H_TopInsert; |
|---|
| 251 | uint32_t H_BotInsert; |
|---|
| 252 | uint32_t H_AddrTop; |
|---|
| 253 | uint32_t H_AddrBot; |
|---|
| 254 | uint32_t H_Control; |
|---|
| 255 | uint32_t H_Lock; |
|---|
| 256 | uint32_t H_Shift; |
|---|
| 257 | uint32_t H_Filter; |
|---|
| 258 | uint32_t H_TeletextFreq; |
|---|
| 259 | uint32_t H_Window; |
|---|
| 260 | uint32_t H_FramCod; |
|---|
| 261 | uint32_t H_TfFcSel; |
|---|
| 262 | uint32_t H_BfFcSel; |
|---|
| 263 | uint32_t H_BlkLev; |
|---|
| 264 | |
|---|
| 265 | uint32_t ulTopMaskReg; |
|---|
| 266 | uint32_t ulBotMaskReg; |
|---|
| 267 | uint32_t ulTopInsertReg; |
|---|
| 268 | uint32_t ulBotInsertReg; |
|---|
| 269 | /* uint32_t ulAddrTopReg; */ |
|---|
| 270 | /* uint32_t ulAddrBotReg; */ |
|---|
| 271 | uint32_t ulControlReg; |
|---|
| 272 | uint32_t ulLockReg; |
|---|
| 273 | uint32_t ulShiftReg; |
|---|
| 274 | uint32_t ulFilterReg; |
|---|
| 275 | uint32_t ulTeletextFreqReg; |
|---|
| 276 | uint32_t ulWindowReg; |
|---|
| 277 | uint32_t ulFramCodReg; |
|---|
| 278 | uint32_t ulTfFcSelReg; |
|---|
| 279 | uint32_t ulBfFcSelReg; |
|---|
| 280 | uint32_t ulCoreOffset; |
|---|
| 281 | uint32_t ulBlkLevReg; |
|---|
| 282 | |
|---|
| 283 | uint8_t ucNumLinesTF; |
|---|
| 284 | uint8_t ucNumLinesBF; |
|---|
| 285 | uint8_t ucBytesPerLine; |
|---|
| 286 | uint16_t usStartLineTF; |
|---|
| 287 | uint16_t usStartLineBF; |
|---|
| 288 | |
|---|
| 289 | int index; |
|---|
| 290 | uint32_t offset; |
|---|
| 291 | BERR_Code eErr; |
|---|
| 292 | |
|---|
| 293 | BDBG_ENTER(BVBI_P_TT_Dec_Program); |
|---|
| 294 | |
|---|
| 295 | /* Figure out which decoder core to use */ |
|---|
| 296 | switch (eSource) |
|---|
| 297 | { |
|---|
| 298 | case BAVC_SourceId_eVdec0: |
|---|
| 299 | H_TopMask = BCHP_TTD_0_tf_mask; |
|---|
| 300 | H_BotMask = BCHP_TTD_0_bf_mask; |
|---|
| 301 | H_TopInsert = BCHP_TTD_0_tf_insert; |
|---|
| 302 | H_BotInsert = BCHP_TTD_0_bf_insert; |
|---|
| 303 | H_AddrTop = BCHP_TTD_0_write_address_top; |
|---|
| 304 | H_AddrBot = BCHP_TTD_0_write_address_bottom; |
|---|
| 305 | H_Control = BCHP_TTD_0_control; |
|---|
| 306 | H_Lock = BCHP_TTD_0_lock_control; |
|---|
| 307 | H_Shift = BCHP_TTD_0_shift_control; |
|---|
| 308 | H_Filter = BCHP_TTD_0_filter_control; |
|---|
| 309 | H_TeletextFreq = BCHP_TTD_0_teletext_freq; |
|---|
| 310 | H_Window = BCHP_TTD_0_window_control; |
|---|
| 311 | H_FramCod = BCHP_TTD_0_framing_code; |
|---|
| 312 | H_TfFcSel = BCHP_TTD_0_tf_fc_select; |
|---|
| 313 | H_BfFcSel = BCHP_TTD_0_bf_fc_select; |
|---|
| 314 | ulCoreOffset = 0x0; |
|---|
| 315 | H_BlkLev = BCHP_TTD_0_black_level; |
|---|
| 316 | index = 0; |
|---|
| 317 | break; |
|---|
| 318 | #if (BVBI_P_NUM_VDEC > 1) |
|---|
| 319 | case BAVC_SourceId_eVdec1: |
|---|
| 320 | H_TopMask = BCHP_TTD_1_tf_mask; |
|---|
| 321 | H_BotMask = BCHP_TTD_1_bf_mask; |
|---|
| 322 | H_TopInsert = BCHP_TTD_1_tf_insert; |
|---|
| 323 | H_BotInsert = BCHP_TTD_1_bf_insert; |
|---|
| 324 | H_AddrTop = BCHP_TTD_1_write_address_top; |
|---|
| 325 | H_AddrBot = BCHP_TTD_1_write_address_bottom; |
|---|
| 326 | H_Control = BCHP_TTD_1_control; |
|---|
| 327 | H_Lock = BCHP_TTD_1_lock_control; |
|---|
| 328 | H_Shift = BCHP_TTD_1_shift_control; |
|---|
| 329 | H_Filter = BCHP_TTD_1_filter_control; |
|---|
| 330 | H_TeletextFreq = BCHP_TTD_1_teletext_freq; |
|---|
| 331 | H_Window = BCHP_TTD_1_window_control; |
|---|
| 332 | H_FramCod = BCHP_TTD_1_framing_code; |
|---|
| 333 | H_TfFcSel = BCHP_TTD_1_tf_fc_select; |
|---|
| 334 | H_BfFcSel = BCHP_TTD_1_bf_fc_select; |
|---|
| 335 | ulCoreOffset = BCHP_TTD_1_reset - BCHP_TTD_0_reset; |
|---|
| 336 | break; |
|---|
| 337 | #endif |
|---|
| 338 | default: |
|---|
| 339 | /* This should never happen! This parameter was checked by |
|---|
| 340 | BVBI_Decode_Create() */ |
|---|
| 341 | BDBG_LEAVE(BVBI_P_TT_Dec_Program); |
|---|
| 342 | return BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 343 | break; |
|---|
| 344 | } |
|---|
| 345 | |
|---|
| 346 | /* TODO: handle little endian vs. big endian */ |
|---|
| 347 | |
|---|
| 348 | /* If user wants to turn off teletext processing, just reset the |
|---|
| 349 | entire core. */ |
|---|
| 350 | if (!bActive) |
|---|
| 351 | { |
|---|
| 352 | BVBI_P_TT_Dec_Init (hReg, ulCoreOffset); |
|---|
| 353 | BDBG_LEAVE(BVBI_P_TT_Dec_Program); |
|---|
| 354 | return BERR_SUCCESS; |
|---|
| 355 | } |
|---|
| 356 | |
|---|
| 357 | BKNI_EnterCriticalSection(); |
|---|
| 358 | |
|---|
| 359 | /* Start programming the TTD control register */ |
|---|
| 360 | ulControlReg = BREG_Read32 (hReg, H_Control); |
|---|
| 361 | ulControlReg &= ~( |
|---|
| 362 | BCHP_MASK (TTD_0_control, enable_tf ) | |
|---|
| 363 | BCHP_MASK (TTD_0_control, enable_bf ) ); |
|---|
| 364 | ulControlReg |= ( |
|---|
| 365 | BCHP_FIELD_DATA (TTD_0_control, enable_tf, 1) | |
|---|
| 366 | BCHP_FIELD_DATA (TTD_0_control, enable_bf, 1) ); |
|---|
| 367 | |
|---|
| 368 | /* Read the lock control register */ |
|---|
| 369 | ulLockReg = BREG_Read32 (hReg, H_Lock); |
|---|
| 370 | |
|---|
| 371 | /* Program the top insert register */ |
|---|
| 372 | ulTopInsertReg = BREG_Read32 (hReg, H_TopInsert); |
|---|
| 373 | ulTopInsertReg &= ~( |
|---|
| 374 | BCHP_MASK (TTD_0_tf_insert, Insert ) ); |
|---|
| 375 | ulTopInsertReg |= ( |
|---|
| 376 | BCHP_FIELD_DATA (TTD_0_tf_insert, Insert, 0) ); |
|---|
| 377 | BREG_Write32 (hReg, H_TopInsert, ulTopInsertReg); |
|---|
| 378 | |
|---|
| 379 | /* Program the bottom insert register */ |
|---|
| 380 | ulBotInsertReg = BREG_Read32 (hReg, H_BotInsert); |
|---|
| 381 | ulBotInsertReg &= ~( |
|---|
| 382 | BCHP_MASK (TTD_0_bf_insert, Insert ) ); |
|---|
| 383 | ulBotInsertReg |= ( |
|---|
| 384 | BCHP_FIELD_DATA (TTD_0_bf_insert, Insert, 0) ); |
|---|
| 385 | BREG_Write32 (hReg, H_BotInsert, ulBotInsertReg); |
|---|
| 386 | |
|---|
| 387 | /* Start programming the shift control register */ |
|---|
| 388 | ulShiftReg = BREG_Read32 (hReg, H_Shift); |
|---|
| 389 | ulShiftReg &= ~( |
|---|
| 390 | BCHP_MASK (TTD_0_shift_control, shift_direction ) | |
|---|
| 391 | BCHP_MASK (TTD_0_shift_control, signal_threshold ) ); |
|---|
| 392 | ulShiftReg |= ( |
|---|
| 393 | #if (BSTD_CPU_ENDIAN == BSTD_ENDIAN_LITTLE) |
|---|
| 394 | BCHP_FIELD_ENUM (TTD_0_shift_control, shift_direction, MSBToLSB) | |
|---|
| 395 | #else |
|---|
| 396 | BCHP_FIELD_ENUM (TTD_0_shift_control, shift_direction, LSBToMSB) | |
|---|
| 397 | #endif |
|---|
| 398 | BCHP_FIELD_DATA (TTD_0_shift_control, signal_threshold, 0x07) ); |
|---|
| 399 | |
|---|
| 400 | /* Read the filter control register */ |
|---|
| 401 | ulFilterReg = BREG_Read32 (hReg, H_Filter); |
|---|
| 402 | |
|---|
| 403 | /* Read the frequency register */ |
|---|
| 404 | ulTeletextFreqReg = BREG_Read32 (hReg, H_TeletextFreq); |
|---|
| 405 | |
|---|
| 406 | /* Read the window control register */ |
|---|
| 407 | ulWindowReg = BREG_Read32 (hReg, H_Window); |
|---|
| 408 | |
|---|
| 409 | /* Start programming the framing code register */ |
|---|
| 410 | ulFramCodReg = BREG_Read32 (hReg, H_FramCod); |
|---|
| 411 | |
|---|
| 412 | /* Start programming the top field framing code selection register */ |
|---|
| 413 | ulTfFcSelReg = BREG_Read32 (hReg, H_TfFcSel); |
|---|
| 414 | ulTfFcSelReg &= ~BCHP_MASK (TTD_0_tf_fc_select, select ); |
|---|
| 415 | ulTfFcSelReg |= BCHP_FIELD_DATA (TTD_0_tf_fc_select, select, 0x0); |
|---|
| 416 | |
|---|
| 417 | /* Start programming the bottom field framing code selection register */ |
|---|
| 418 | ulBfFcSelReg = BREG_Read32 (hReg, H_BfFcSel); |
|---|
| 419 | ulBfFcSelReg &= ~BCHP_MASK (TTD_0_bf_fc_select, select ); |
|---|
| 420 | ulBfFcSelReg |= BCHP_FIELD_DATA (TTD_0_bf_fc_select, select, 0x0); |
|---|
| 421 | |
|---|
| 422 | /* Select video format */ |
|---|
| 423 | switch (eVideoFormat) |
|---|
| 424 | { |
|---|
| 425 | case BFMT_VideoFmt_eNTSC: |
|---|
| 426 | case BFMT_VideoFmt_eNTSC_J: |
|---|
| 427 | /* NTSC specific settings */ |
|---|
| 428 | |
|---|
| 429 | ucNumLinesTF = 11; |
|---|
| 430 | ucNumLinesBF = 11; |
|---|
| 431 | usStartLineTF = 11; |
|---|
| 432 | usStartLineBF = 273; |
|---|
| 433 | ucBytesPerLine = 34; |
|---|
| 434 | |
|---|
| 435 | ulControlReg &= ~( |
|---|
| 436 | BCHP_MASK (TTD_0_control, startline_tf ) | |
|---|
| 437 | BCHP_MASK (TTD_0_control, startline_bf ) | |
|---|
| 438 | BCHP_MASK (TTD_0_control, start_delay ) | |
|---|
| 439 | BCHP_MASK (TTD_0_control, teletext_mode ) ); |
|---|
| 440 | ulControlReg |= ( |
|---|
| 441 | BCHP_FIELD_DATA (TTD_0_control, startline_tf, usStartLineTF - 2) | |
|---|
| 442 | BCHP_FIELD_DATA (TTD_0_control, startline_bf, usStartLineBF - 264) | |
|---|
| 443 | BCHP_FIELD_DATA (TTD_0_control, start_delay, 0x01) | |
|---|
| 444 | BCHP_FIELD_ENUM (TTD_0_control, teletext_mode, NABTS) ); |
|---|
| 445 | |
|---|
| 446 | /* Program the TTD lock register */ |
|---|
| 447 | ulLockReg &= ~( |
|---|
| 448 | BCHP_MASK (TTD_0_lock_control, frame_code_lines ) | |
|---|
| 449 | BCHP_MASK (TTD_0_lock_control, write_inhibit ) ); |
|---|
| 450 | ulLockReg |= ( |
|---|
| 451 | BCHP_FIELD_DATA (TTD_0_lock_control, frame_code_lines, 0x10) | |
|---|
| 452 | BCHP_FIELD_DATA (TTD_0_lock_control, write_inhibit, 0) ); |
|---|
| 453 | |
|---|
| 454 | ulShiftReg &= |
|---|
| 455 | ~BCHP_MASK (TTD_0_shift_control, shift_direction ); |
|---|
| 456 | ulShiftReg |= |
|---|
| 457 | #if (BSTD_CPU_ENDIAN == BSTD_ENDIAN_LITTLE) |
|---|
| 458 | BCHP_FIELD_ENUM (TTD_0_shift_control, shift_direction, MSBToLSB); |
|---|
| 459 | #else |
|---|
| 460 | BCHP_FIELD_ENUM (TTD_0_shift_control, shift_direction, LSBToMSB); |
|---|
| 461 | #endif |
|---|
| 462 | |
|---|
| 463 | /* Program the filter control register */ |
|---|
| 464 | ulFilterReg &= ~( |
|---|
| 465 | BCHP_MASK (TTD_0_filter_control, filter_phase_adjustment ) | |
|---|
| 466 | BCHP_MASK (TTD_0_filter_control, min_signal_mean ) | |
|---|
| 467 | BCHP_MASK (TTD_0_filter_control, avg_threshold ) | |
|---|
| 468 | BCHP_MASK (TTD_0_filter_control, last_position ) | |
|---|
| 469 | BCHP_MASK (TTD_0_filter_control, fc_one_bit_off ) ); |
|---|
| 470 | ulFilterReg |= ( |
|---|
| 471 | BCHP_FIELD_DATA (TTD_0_filter_control, filter_phase_adjustment, 0x6b) | |
|---|
| 472 | BCHP_FIELD_DATA (TTD_0_filter_control, min_signal_mean, 0x4) | |
|---|
| 473 | BCHP_FIELD_DATA (TTD_0_filter_control, avg_threshold, 0x2) | |
|---|
| 474 | BCHP_FIELD_DATA (TTD_0_filter_control, last_position, 0x0) | |
|---|
| 475 | BCHP_FIELD_DATA (TTD_0_filter_control, fc_one_bit_off, 0x0) ); |
|---|
| 476 | |
|---|
| 477 | ulTeletextFreqReg &= |
|---|
| 478 | ~BCHP_MASK (TTD_0_teletext_freq, Frequency ); |
|---|
| 479 | ulTeletextFreqReg |= |
|---|
| 480 | BCHP_FIELD_DATA (TTD_0_teletext_freq, Frequency, 0x1b26c978); |
|---|
| 481 | |
|---|
| 482 | ulWindowReg &= ~( |
|---|
| 483 | BCHP_MASK (TTD_0_window_control, enable ) | |
|---|
| 484 | BCHP_MASK (TTD_0_window_control, window_lock_lines ) | |
|---|
| 485 | BCHP_MASK (TTD_0_window_control, window_length ) ); |
|---|
| 486 | ulWindowReg |= ( |
|---|
| 487 | BCHP_FIELD_ENUM (TTD_0_window_control, enable, ENABLED ) | |
|---|
| 488 | BCHP_FIELD_DATA (TTD_0_window_control, window_lock_lines, 1) | |
|---|
| 489 | BCHP_FIELD_DATA (TTD_0_window_control, window_length, 0x74) ); |
|---|
| 490 | |
|---|
| 491 | ulFramCodReg &= ~( |
|---|
| 492 | BCHP_MASK (TTD_0_framing_code, framing_code_1 ) | |
|---|
| 493 | BCHP_MASK (TTD_0_framing_code, framing_code_0 ) ); |
|---|
| 494 | ulFramCodReg |= ( |
|---|
| 495 | BCHP_FIELD_DATA ( |
|---|
| 496 | TTD_0_framing_code, framing_code_1, BVBI_TT_NABTS_FRAMING_CODE) | |
|---|
| 497 | BCHP_FIELD_DATA ( |
|---|
| 498 | TTD_0_framing_code, framing_code_0, BVBI_TT_NABTS_FRAMING_CODE) ); |
|---|
| 499 | |
|---|
| 500 | /* Continue programming the black level register */ |
|---|
| 501 | ulBlkLevReg = BREG_Read32 (hReg, H_BlkLev); |
|---|
| 502 | ulBlkLevReg &= ~BCHP_MASK (TTD_0_black_level, black_level ); |
|---|
| 503 | ulBlkLevReg |= BCHP_FIELD_DATA (TTD_0_black_level, black_level, 0x49); |
|---|
| 504 | |
|---|
| 505 | break; |
|---|
| 506 | |
|---|
| 507 | case BFMT_VideoFmt_ePAL_B: |
|---|
| 508 | case BFMT_VideoFmt_ePAL_B1: |
|---|
| 509 | case BFMT_VideoFmt_ePAL_D: |
|---|
| 510 | case BFMT_VideoFmt_ePAL_D1: |
|---|
| 511 | case BFMT_VideoFmt_ePAL_G: |
|---|
| 512 | case BFMT_VideoFmt_ePAL_H: |
|---|
| 513 | case BFMT_VideoFmt_ePAL_K: |
|---|
| 514 | case BFMT_VideoFmt_ePAL_I: |
|---|
| 515 | case BFMT_VideoFmt_ePAL_M: |
|---|
| 516 | case BFMT_VideoFmt_ePAL_N: |
|---|
| 517 | case BFMT_VideoFmt_ePAL_NC: |
|---|
| 518 | case BFMT_VideoFmt_eSECAM_L: |
|---|
| 519 | case BFMT_VideoFmt_eSECAM_B: |
|---|
| 520 | case BFMT_VideoFmt_eSECAM_G: |
|---|
| 521 | case BFMT_VideoFmt_eSECAM_D: |
|---|
| 522 | case BFMT_VideoFmt_eSECAM_K: |
|---|
| 523 | case BFMT_VideoFmt_eSECAM_H: |
|---|
| 524 | /* 576I settings */ |
|---|
| 525 | |
|---|
| 526 | ucNumLinesTF = 17; |
|---|
| 527 | ucNumLinesBF = 18; |
|---|
| 528 | usStartLineTF = 7; |
|---|
| 529 | usStartLineBF = 319; |
|---|
| 530 | /* PR18343 */ |
|---|
| 531 | usStartLineTF -= 1; |
|---|
| 532 | |
|---|
| 533 | /* Working with 93563-C0 */ |
|---|
| 534 | usStartLineBF -= 1; |
|---|
| 535 | |
|---|
| 536 | #if (BVDC_P_3DCOMB_TTD_CONFLICT) |
|---|
| 537 | usStartLineTF -= 1; |
|---|
| 538 | usStartLineBF -= 1; |
|---|
| 539 | #endif |
|---|
| 540 | |
|---|
| 541 | ucBytesPerLine = 43; |
|---|
| 542 | |
|---|
| 543 | ulControlReg &= ~( |
|---|
| 544 | BCHP_MASK (TTD_0_control, startline_tf ) | |
|---|
| 545 | BCHP_MASK (TTD_0_control, startline_bf ) | |
|---|
| 546 | BCHP_MASK (TTD_0_control, start_delay ) | |
|---|
| 547 | BCHP_MASK (TTD_0_control, teletext_mode ) ); |
|---|
| 548 | ulControlReg |= ( |
|---|
| 549 | BCHP_FIELD_DATA (TTD_0_control, startline_tf, usStartLineTF - 2) | |
|---|
| 550 | BCHP_FIELD_DATA (TTD_0_control, startline_bf, usStartLineBF - 314) | |
|---|
| 551 | BCHP_FIELD_DATA (TTD_0_control, start_delay, 0) | |
|---|
| 552 | BCHP_FIELD_ENUM (TTD_0_control, teletext_mode, ETSTeletext) ); |
|---|
| 553 | |
|---|
| 554 | /* Program the TTD lock register */ |
|---|
| 555 | ulLockReg &= ~( |
|---|
| 556 | BCHP_MASK (TTD_0_lock_control, frame_code_lines ) | |
|---|
| 557 | BCHP_MASK (TTD_0_lock_control, write_inhibit ) ); |
|---|
| 558 | ulLockReg |= ( |
|---|
| 559 | BCHP_FIELD_DATA (TTD_0_lock_control, frame_code_lines, 0x02) | |
|---|
| 560 | BCHP_FIELD_DATA (TTD_0_lock_control, write_inhibit, 0) ); |
|---|
| 561 | |
|---|
| 562 | ulShiftReg &= |
|---|
| 563 | ~BCHP_MASK (TTD_0_shift_control, shift_direction ); |
|---|
| 564 | ulShiftReg |= |
|---|
| 565 | #if (BSTD_CPU_ENDIAN == BSTD_ENDIAN_LITTLE) |
|---|
| 566 | BCHP_FIELD_ENUM (TTD_0_shift_control, shift_direction, MSBToLSB); |
|---|
| 567 | #else |
|---|
| 568 | BCHP_FIELD_ENUM (TTD_0_shift_control, shift_direction, LSBToMSB); |
|---|
| 569 | #endif |
|---|
| 570 | |
|---|
| 571 | /* Program the filter control register */ |
|---|
| 572 | ulFilterReg &= ~( |
|---|
| 573 | BCHP_MASK (TTD_0_filter_control, filter_phase_adjustment ) | |
|---|
| 574 | BCHP_MASK (TTD_0_filter_control, min_signal_mean ) | |
|---|
| 575 | BCHP_MASK (TTD_0_filter_control, avg_threshold ) | |
|---|
| 576 | BCHP_MASK (TTD_0_filter_control, last_position ) | |
|---|
| 577 | BCHP_MASK (TTD_0_filter_control, fc_one_bit_off ) ); |
|---|
| 578 | ulFilterReg |= ( |
|---|
| 579 | BCHP_FIELD_DATA (TTD_0_filter_control, filter_phase_adjustment, 0x23) | |
|---|
| 580 | BCHP_FIELD_DATA (TTD_0_filter_control, min_signal_mean, 0x4) | |
|---|
| 581 | BCHP_FIELD_DATA (TTD_0_filter_control, avg_threshold, 0x1) | |
|---|
| 582 | BCHP_FIELD_DATA (TTD_0_filter_control, last_position, 0x0) | |
|---|
| 583 | BCHP_FIELD_DATA (TTD_0_filter_control, fc_one_bit_off, 0x0) ); |
|---|
| 584 | |
|---|
| 585 | ulTeletextFreqReg &= |
|---|
| 586 | ~BCHP_MASK (TTD_0_teletext_freq, Frequency ); |
|---|
| 587 | ulTeletextFreqReg |= |
|---|
| 588 | BCHP_FIELD_DATA (TTD_0_teletext_freq, Frequency, 0x20e38e39); |
|---|
| 589 | |
|---|
| 590 | ulWindowReg &= ~( |
|---|
| 591 | BCHP_MASK (TTD_0_window_control, enable ) | |
|---|
| 592 | BCHP_MASK (TTD_0_window_control, window_lock_lines ) | |
|---|
| 593 | BCHP_MASK (TTD_0_window_control, window_length ) ); |
|---|
| 594 | ulWindowReg |= ( |
|---|
| 595 | BCHP_FIELD_ENUM (TTD_0_window_control, enable, DISABLED) | |
|---|
| 596 | BCHP_FIELD_DATA (TTD_0_window_control, window_lock_lines, 0) | |
|---|
| 597 | BCHP_FIELD_DATA (TTD_0_window_control, window_length, 0x74) ); |
|---|
| 598 | |
|---|
| 599 | ulFramCodReg &= ~( |
|---|
| 600 | BCHP_MASK (TTD_0_framing_code, framing_code_1 ) | |
|---|
| 601 | BCHP_MASK (TTD_0_framing_code, framing_code_0 ) ); |
|---|
| 602 | ulFramCodReg |= ( |
|---|
| 603 | BCHP_FIELD_DATA ( |
|---|
| 604 | TTD_0_framing_code, framing_code_1, BVBI_TT_ETS_FRAMING_CODE) | |
|---|
| 605 | BCHP_FIELD_DATA ( |
|---|
| 606 | TTD_0_framing_code, framing_code_0, BVBI_TT_ETS_FRAMING_CODE) ); |
|---|
| 607 | |
|---|
| 608 | /* Continue programming the black level register */ |
|---|
| 609 | ulBlkLevReg = BREG_Read32 (hReg, H_BlkLev); |
|---|
| 610 | ulBlkLevReg &= ~BCHP_MASK (TTD_0_black_level, black_level ); |
|---|
| 611 | ulBlkLevReg |= BCHP_FIELD_DATA (TTD_0_black_level, black_level, 240); |
|---|
| 612 | |
|---|
| 613 | break; |
|---|
| 614 | |
|---|
| 615 | default: |
|---|
| 616 | BKNI_LeaveCriticalSection(); |
|---|
| 617 | BDBG_LEAVE(BVBI_P_TT_Dec_Program); |
|---|
| 618 | return BERR_TRACE (BERR_INVALID_PARAMETER); |
|---|
| 619 | break; |
|---|
| 620 | } |
|---|
| 621 | |
|---|
| 622 | /* Program the mask registers */ |
|---|
| 623 | /* Magic number discovered by the two Brads. Works for PAL. */ |
|---|
| 624 | ulTopMaskReg = BCHP_FIELD_DATA (TTD_0_tf_mask, Mask, 0x3FFFE); |
|---|
| 625 | BREG_Write32 (hReg, H_TopMask, ulTopMaskReg); |
|---|
| 626 | ulBotMaskReg = BCHP_FIELD_DATA (TTD_0_bf_mask, Mask, 0x3FFFE); |
|---|
| 627 | BREG_Write32 (hReg, H_BotMask, ulBotMaskReg); |
|---|
| 628 | |
|---|
| 629 | /* Finish programming the black level register */ |
|---|
| 630 | BREG_Write32 (hReg, H_BlkLev, ulBlkLevReg); |
|---|
| 631 | |
|---|
| 632 | /* Prepare to collect data in the decode handle */ |
|---|
| 633 | #ifdef BVBI_P_TTD_SCB2_ERROR |
|---|
| 634 | eErr = BERR_TRACE (BMEM_ConvertAddressToOffset ( |
|---|
| 635 | hMem, topTTscratch, &offset)); |
|---|
| 636 | offset >>= 2; |
|---|
| 637 | #else |
|---|
| 638 | eErr = BERR_TRACE (BMEM_ConvertAddressToOffset ( |
|---|
| 639 | hMem, topData->pucData, &offset)); |
|---|
| 640 | #endif |
|---|
| 641 | BDBG_ASSERT (eErr == BERR_SUCCESS); |
|---|
| 642 | BREG_Write32 ( hReg, H_AddrTop, offset); |
|---|
| 643 | #ifdef BVBI_P_TTD_SCB2_ERROR |
|---|
| 644 | eErr = BERR_TRACE (BMEM_ConvertAddressToOffset ( |
|---|
| 645 | hMem, botTTscratch, &offset)); |
|---|
| 646 | offset >>= 2; |
|---|
| 647 | #else |
|---|
| 648 | eErr = BERR_TRACE (BMEM_ConvertAddressToOffset ( |
|---|
| 649 | hMem, botData->pucData, &offset)); |
|---|
| 650 | #endif |
|---|
| 651 | BDBG_ASSERT (eErr == BERR_SUCCESS); |
|---|
| 652 | BREG_Write32 ( hReg, H_AddrBot, offset); |
|---|
| 653 | |
|---|
| 654 | /* Update the field handles that receive the data */ |
|---|
| 655 | topData->ucLines = ucNumLinesTF; |
|---|
| 656 | topData->ucLineSize = ucBytesPerLine; |
|---|
| 657 | botData->ucLines = ucNumLinesBF; |
|---|
| 658 | botData->ucLineSize = ucBytesPerLine; |
|---|
| 659 | |
|---|
| 660 | /* write the ten registers with updated values */ |
|---|
| 661 | BREG_Write32 ( hReg, H_Control, ulControlReg ); |
|---|
| 662 | BREG_Write32 ( hReg, H_Lock, ulLockReg ); |
|---|
| 663 | BREG_Write32 ( hReg, H_Shift, ulShiftReg ); |
|---|
| 664 | BREG_Write32 ( hReg, H_Filter, ulFilterReg ); |
|---|
| 665 | BREG_Write32 ( hReg, H_TeletextFreq, ulTeletextFreqReg ); |
|---|
| 666 | BREG_Write32 ( hReg, H_Window, ulWindowReg ); |
|---|
| 667 | BREG_Write32 ( hReg, H_FramCod, ulFramCodReg ); |
|---|
| 668 | BREG_Write32 ( hReg, H_TfFcSel, ulTfFcSelReg ); |
|---|
| 669 | BREG_Write32 ( hReg, H_BfFcSel, ulBfFcSelReg ); |
|---|
| 670 | |
|---|
| 671 | BKNI_LeaveCriticalSection(); |
|---|
| 672 | BDBG_LEAVE(BVBI_P_TT_Dec_Program); |
|---|
| 673 | return BERR_SUCCESS; |
|---|
| 674 | } |
|---|
| 675 | |
|---|
| 676 | /* Debug code |
|---|
| 677 | volatile uint64_t passfail = 0; |
|---|
| 678 | volatile int error_index = 0; |
|---|
| 679 | volatile uint32_t error_store[64]; |
|---|
| 680 | */ |
|---|
| 681 | |
|---|
| 682 | /*************************************************************************** |
|---|
| 683 | * |
|---|
| 684 | */ |
|---|
| 685 | uint32_t BVBI_P_TT_Decode_Data_isr ( |
|---|
| 686 | BREG_Handle hReg, |
|---|
| 687 | BMEM_Handle hMem, |
|---|
| 688 | BAVC_SourceId eSource, |
|---|
| 689 | BFMT_VideoFmt eVideoFormat, |
|---|
| 690 | BAVC_Polarity polarity, |
|---|
| 691 | BVBI_P_TTData* pTTDataNext ) |
|---|
| 692 | { |
|---|
| 693 | /* |
|---|
| 694 | Programming note: the implementation here assumes that the bitfield layout |
|---|
| 695 | within registers is the same for all teletext decoder cores in the chip. |
|---|
| 696 | |
|---|
| 697 | If a chip is built that has multiple teletext decoder cores that are not |
|---|
| 698 | identical, then this routine will have to be redesigned. |
|---|
| 699 | */ |
|---|
| 700 | uint32_t ulReg; |
|---|
| 701 | uint32_t H_WrAdTop; |
|---|
| 702 | uint32_t H_WrAdBot; |
|---|
| 703 | uint32_t H_Status; |
|---|
| 704 | uint32_t ulStat; |
|---|
| 705 | uint32_t dataSize; |
|---|
| 706 | bool recognized_video_format; |
|---|
| 707 | uint32_t ulReg2 = 0x0; |
|---|
| 708 | |
|---|
| 709 | uint8_t ucMinLines = 0; |
|---|
| 710 | uint8_t ucMinLineSize = 0; |
|---|
| 711 | uint32_t ulErrInfo = 0; |
|---|
| 712 | |
|---|
| 713 | #ifndef BVBI_P_TTD_SCB2_ERROR |
|---|
| 714 | BERR_Code eErr; |
|---|
| 715 | uint32_t offset; |
|---|
| 716 | #endif |
|---|
| 717 | |
|---|
| 718 | /* Debug code |
|---|
| 719 | uint8_t* printme = 0; |
|---|
| 720 | passfail <<= 1; |
|---|
| 721 | */ |
|---|
| 722 | |
|---|
| 723 | #ifdef BVBI_P_TTD_SCB2_ERROR |
|---|
| 724 | BSTD_UNUSED (hMem); |
|---|
| 725 | #endif |
|---|
| 726 | |
|---|
| 727 | BDBG_ENTER(BVBI_P_TT_Decode_Data_isr); |
|---|
| 728 | |
|---|
| 729 | /* Figure out which decoder core to use */ |
|---|
| 730 | switch (eSource) |
|---|
| 731 | { |
|---|
| 732 | case BAVC_SourceId_eVdec0: |
|---|
| 733 | H_Status = BCHP_TTD_0_status; |
|---|
| 734 | H_WrAdTop = BCHP_TTD_0_write_address_top; |
|---|
| 735 | H_WrAdBot = BCHP_TTD_0_write_address_bottom; |
|---|
| 736 | break; |
|---|
| 737 | #if (BVBI_P_NUM_VDEC > 1) |
|---|
| 738 | case BAVC_SourceId_eVdec1: |
|---|
| 739 | H_Status = BCHP_TTD_0_status; |
|---|
| 740 | H_WrAdTop = BCHP_TTD_0_write_address_top; |
|---|
| 741 | H_WrAdBot = BCHP_TTD_0_write_address_bottom; |
|---|
| 742 | break; |
|---|
| 743 | #endif |
|---|
| 744 | default: |
|---|
| 745 | /* This should never happen! This parameter was checked by |
|---|
| 746 | BVBI_Decode_Create() */ |
|---|
| 747 | BDBG_LEAVE(BVBI_P_TT_Decode_Data_isr); |
|---|
| 748 | return (-1); |
|---|
| 749 | break; |
|---|
| 750 | } |
|---|
| 751 | |
|---|
| 752 | /* A sanity check */ |
|---|
| 753 | BDBG_ASSERT ( |
|---|
| 754 | (polarity == BAVC_Polarity_eTopField) || |
|---|
| 755 | (polarity == BAVC_Polarity_eBotField) ); |
|---|
| 756 | |
|---|
| 757 | /* Verify that field handle is big enough to hold the TT data */ |
|---|
| 758 | switch (eVideoFormat) |
|---|
| 759 | { |
|---|
| 760 | case BFMT_VideoFmt_eNTSC: |
|---|
| 761 | case BFMT_VideoFmt_eNTSC_J: |
|---|
| 762 | ucMinLines = 11; |
|---|
| 763 | ucMinLineSize = 34; |
|---|
| 764 | break; |
|---|
| 765 | case BFMT_VideoFmt_ePAL_B: |
|---|
| 766 | case BFMT_VideoFmt_ePAL_B1: |
|---|
| 767 | case BFMT_VideoFmt_ePAL_D: |
|---|
| 768 | case BFMT_VideoFmt_ePAL_D1: |
|---|
| 769 | case BFMT_VideoFmt_ePAL_G: |
|---|
| 770 | case BFMT_VideoFmt_ePAL_H: |
|---|
| 771 | case BFMT_VideoFmt_ePAL_K: |
|---|
| 772 | case BFMT_VideoFmt_ePAL_I: |
|---|
| 773 | case BFMT_VideoFmt_ePAL_M: |
|---|
| 774 | case BFMT_VideoFmt_ePAL_N: |
|---|
| 775 | case BFMT_VideoFmt_ePAL_NC: |
|---|
| 776 | case BFMT_VideoFmt_eSECAM_L: |
|---|
| 777 | case BFMT_VideoFmt_eSECAM_B: |
|---|
| 778 | case BFMT_VideoFmt_eSECAM_G: |
|---|
| 779 | case BFMT_VideoFmt_eSECAM_D: |
|---|
| 780 | case BFMT_VideoFmt_eSECAM_K: |
|---|
| 781 | case BFMT_VideoFmt_eSECAM_H: |
|---|
| 782 | ucMinLines = 18; |
|---|
| 783 | ucMinLineSize = 43; |
|---|
| 784 | break; |
|---|
| 785 | default: |
|---|
| 786 | /* This should never happen! Checked in calling routine! */ |
|---|
| 787 | recognized_video_format = false; |
|---|
| 788 | BDBG_ASSERT (recognized_video_format); |
|---|
| 789 | break; |
|---|
| 790 | } |
|---|
| 791 | dataSize = BVBI_P_TT_Size_Storage (ucMinLines, ucMinLineSize); |
|---|
| 792 | |
|---|
| 793 | if (pTTDataNext->ucDataSize < dataSize) |
|---|
| 794 | { |
|---|
| 795 | ulErrInfo |= |
|---|
| 796 | (BVBI_LINE_ERROR_FLDH_CONFLICT | BVBI_LINE_ERROR_TELETEXT_NODATA); |
|---|
| 797 | BDBG_LEAVE(BVBI_P_TT_Decode_Data_isr); |
|---|
| 798 | return ulErrInfo; |
|---|
| 799 | } |
|---|
| 800 | |
|---|
| 801 | /* Read the status register */ |
|---|
| 802 | ulReg = BREG_Read32 (hReg, H_Status); |
|---|
| 803 | |
|---|
| 804 | /* If top field */ |
|---|
| 805 | if (polarity == BAVC_Polarity_eTopField) |
|---|
| 806 | { |
|---|
| 807 | /* Verify that the hardware has finished digesting the data, if any. */ |
|---|
| 808 | ulStat = ulReg & BCHP_MASK (TTD_0_status, buffer_complete_tf); |
|---|
| 809 | if (ulStat == 0) |
|---|
| 810 | { |
|---|
| 811 | /* Inform of error */ |
|---|
| 812 | ulErrInfo |= BVBI_LINE_ERROR_TELETEXT_INCOMPLETE; |
|---|
| 813 | goto done; |
|---|
| 814 | } |
|---|
| 815 | |
|---|
| 816 | /* Will acknowledge data to hardware */ |
|---|
| 817 | ulReg2 |= ulStat; |
|---|
| 818 | |
|---|
| 819 | /* This bit should always be written? */ |
|---|
| 820 | ulStat = ulReg & BCHP_MASK (TTD_0_status, interrupt_tf); |
|---|
| 821 | if (ulStat) |
|---|
| 822 | ulReg2 |= ulStat; |
|---|
| 823 | |
|---|
| 824 | /* Debug code |
|---|
| 825 | printme = pTTDataNext->pucData; |
|---|
| 826 | */ |
|---|
| 827 | |
|---|
| 828 | /* Debug code |
|---|
| 829 | { |
|---|
| 830 | static unsigned int ticker = 0; |
|---|
| 831 | if ((++ticker % 4) == 0) |
|---|
| 832 | { |
|---|
| 833 | int index; |
|---|
| 834 | unsigned char* val = pTTDataNext->pucData + 4 + 2*43; |
|---|
| 835 | for (index = 0 ; index < 43 ; ++index) |
|---|
| 836 | *val++ = 0xab; |
|---|
| 837 | unsigned char* val = pTTDataNext->pucData + 4; |
|---|
| 838 | *val = 0xff; |
|---|
| 839 | } |
|---|
| 840 | } |
|---|
| 841 | */ |
|---|
| 842 | |
|---|
| 843 | /* Give hardware a new place to write data to */ |
|---|
| 844 | #ifndef BVBI_P_TTD_SCB2_ERROR |
|---|
| 845 | eErr = BERR_TRACE (BMEM_ConvertAddressToOffset ( |
|---|
| 846 | hMem, pTTDataNext->pucData, &offset)); |
|---|
| 847 | BDBG_ASSERT (eErr == BERR_SUCCESS); |
|---|
| 848 | BREG_Write32 (hReg, H_WrAdTop, offset); |
|---|
| 849 | #endif |
|---|
| 850 | } |
|---|
| 851 | else /* Bottom field */ |
|---|
| 852 | { |
|---|
| 853 | /* Verify that the hardware has finished digesting the data, if any. */ |
|---|
| 854 | ulStat = ulReg & BCHP_MASK (TTD_0_status, buffer_complete_bf); |
|---|
| 855 | if (ulStat == 0) |
|---|
| 856 | { |
|---|
| 857 | /* Inform of error */ |
|---|
| 858 | ulErrInfo |= BVBI_LINE_ERROR_TELETEXT_INCOMPLETE; |
|---|
| 859 | goto done; |
|---|
| 860 | } |
|---|
| 861 | |
|---|
| 862 | /* Will acknowledge data to hardware */ |
|---|
| 863 | ulReg2 |= ulStat; |
|---|
| 864 | |
|---|
| 865 | /* This bit should always be written? */ |
|---|
| 866 | ulStat = ulReg & BCHP_MASK (TTD_0_status, interrupt_bf); |
|---|
| 867 | if (ulStat) |
|---|
| 868 | ulReg2 |= ulStat; |
|---|
| 869 | |
|---|
| 870 | /* Debug code |
|---|
| 871 | printme = pTTDataNext->pucData; |
|---|
| 872 | */ |
|---|
| 873 | |
|---|
| 874 | /* Debug code |
|---|
| 875 | *(uint32_t*)(pTTDataNext->pucData)= 0x11; |
|---|
| 876 | */ |
|---|
| 877 | |
|---|
| 878 | /* Give hardware a new place to write data to */ |
|---|
| 879 | #ifndef BVBI_P_TTD_SCB2_ERROR |
|---|
| 880 | eErr = BERR_TRACE (BMEM_ConvertAddressToOffset ( |
|---|
| 881 | hMem, pTTDataNext->pucData, &offset)); |
|---|
| 882 | BDBG_ASSERT (eErr == BERR_SUCCESS); |
|---|
| 883 | BREG_Write32 (hReg, H_WrAdBot, offset); |
|---|
| 884 | #endif |
|---|
| 885 | } |
|---|
| 886 | |
|---|
| 887 | /* Success, so finish describing the captured data */ |
|---|
| 888 | pTTDataNext->ucLines = ucMinLines; |
|---|
| 889 | pTTDataNext->ucLineSize = ucMinLineSize; |
|---|
| 890 | |
|---|
| 891 | /* Debug code |
|---|
| 892 | passfail |= (uint64_t)(0x0000000000000001); |
|---|
| 893 | */ |
|---|
| 894 | |
|---|
| 895 | done: |
|---|
| 896 | |
|---|
| 897 | /* Debug code |
|---|
| 898 | ulStat = ( |
|---|
| 899 | BCHP_MASK (TTD_0_status, buffer_complete_tf) | |
|---|
| 900 | BCHP_MASK (TTD_0_status, buffer_complete_bf) ); |
|---|
| 901 | if ((ulStat & ulReg) == ulStat) |
|---|
| 902 | { |
|---|
| 903 | printf ("%c: two fields of data are waiting\n", |
|---|
| 904 | (polarity == BAVC_Polarity_eTopField) ? 'T' : 'B'); |
|---|
| 905 | } |
|---|
| 906 | if ((passfail & (uint64_t)(0x0000000000000001)) == 0) |
|---|
| 907 | { |
|---|
| 908 | error_store[error_index++] = ulReg; |
|---|
| 909 | error_index &= (sizeof(error_store)/sizeof(error_store[0]) - 1); |
|---|
| 910 | printf ("Decode error %c: %08x\n", |
|---|
| 911 | (polarity == BAVC_Polarity_eTopField) ? 'T' : 'B', |
|---|
| 912 | ulReg); |
|---|
| 913 | } |
|---|
| 914 | { |
|---|
| 915 | static uint32_t dcounter = 0; |
|---|
| 916 | ++dcounter; |
|---|
| 917 | if ((dcounter > 80) && (dcounter < 150)) |
|---|
| 918 | { |
|---|
| 919 | if (printme) |
|---|
| 920 | { |
|---|
| 921 | uint32_t mask = *(uint32_t*)printme; |
|---|
| 922 | uint8_t* p1 = printme + 4; |
|---|
| 923 | printf ("%d%c: decoded M:%08x : %02x %02x %02x %02x\n", |
|---|
| 924 | dcounter, |
|---|
| 925 | (polarity == BAVC_Polarity_eTopField) ? 'T' : 'B', |
|---|
| 926 | mask, |
|---|
| 927 | *p1, |
|---|
| 928 | *(p1 + ucMinLineSize), |
|---|
| 929 | *(p1 + 2 * ucMinLineSize), |
|---|
| 930 | *(p1 + 3 * ucMinLineSize)); |
|---|
| 931 | } |
|---|
| 932 | else |
|---|
| 933 | { |
|---|
| 934 | printf ("%d%c: did not decode anything\n", |
|---|
| 935 | dcounter, |
|---|
| 936 | (polarity == BAVC_Polarity_eTopField) ? 'T' : 'B'); |
|---|
| 937 | } |
|---|
| 938 | } |
|---|
| 939 | } |
|---|
| 940 | */ |
|---|
| 941 | |
|---|
| 942 | /* Finish acknowledging data */ |
|---|
| 943 | BREG_Write32 ( hReg, H_Status, ulReg2) ; |
|---|
| 944 | |
|---|
| 945 | BDBG_LEAVE(BVBI_P_TT_Decode_Data_isr); |
|---|
| 946 | return ulErrInfo; |
|---|
| 947 | } |
|---|
| 948 | |
|---|
| 949 | /*************************************************************************** |
|---|
| 950 | * Static (private) functions |
|---|
| 951 | ***************************************************************************/ |
|---|
| 952 | |
|---|
| 953 | #endif /** } (BVBI_P_NUM_VDEC >= 1) **/ |
|---|
| 954 | |
|---|
| 955 | /* End of file */ |
|---|