source: svn/newcon3bcm2_21bu/nexus/modules/display/7552/src/nexus_ccir656_input.c

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

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

  • Property svn:executable set to *
File size: 19.2 KB
Line 
1/***************************************************************************
2 *     (c)2007-2011 Broadcom Corporation
3 *
4 *  This program is the proprietary software of Broadcom Corporation and/or its licensors,
5 *  and may only be used, duplicated, modified or distributed pursuant to the terms and
6 *  conditions of a separate, written license agreement executed between you and Broadcom
7 *  (an "Authorized License").  Except as set forth in an Authorized License, Broadcom grants
8 *  no license (express or implied), right to use, or waiver of any kind with respect to the
9 *  Software, and Broadcom expressly reserves all rights in and to the Software and all
10 *  intellectual property rights therein.  IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU
11 *  HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY
12 *  NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE.
13 *
14 *  Except as expressly set forth in the Authorized License,
15 *
16 *  1.     This program, including its structure, sequence and organization, constitutes the valuable trade
17 *  secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof,
18 *  and to use this information only in connection with your use of Broadcom integrated circuit products.
19 *
20 *  2.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
21 *  AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR
22 *  WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
23 *  THE SOFTWARE.  BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES
24 *  OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE,
25 *  LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION
26 *  OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF
27 *  USE OR PERFORMANCE OF THE SOFTWARE.
28 *
29 *  3.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS
30 *  LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR
31 *  EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR
32 *  USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF
33 *  THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT
34 *  ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE
35 *  LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF
36 *  ANY LIMITED REMEDY.
37 *
38 * $brcm_Workfile: nexus_ccir656_input.c $
39 * $brcm_Revision: 10 $
40 * $brcm_Date: 4/20/11 6:15p $
41 *
42 * Module Description:
43 *
44 * Revision History:
45 *
46 * $brcm_Log: /nexus/modules/display/7425/src/nexus_ccir656_input.c $
47 *
48 * 10   4/20/11 6:15p jtna
49 * SW7425-365: fix build warnings for 2.6.37 kernel
50 *
51 * 9   7/1/09 5:41p katrep
52 * PR53453: compiler warning
53 *
54 * 8   6/30/09 3:22p erickson
55 * PR53453: fix DTV
56 *
57 * 7   6/30/09 8:48a erickson
58 * PR53453: request L2 interrupt from INT, then call VBI to read 656 vbi
59 *  data
60 *
61 * 6   4/9/09 9:46a erickson
62 * PR54033: turn on power for 656 shutdown
63 *
64 * 5   3/27/09 2:36p erickson
65 * PR53453: add 656 vbi support
66 *
67 * 4   3/24/09 2:34p erickson
68 * PR52818: added 656 input power management
69 *
70 * 3   11/17/08 12:28p erickson
71 * PR49203: ensure there are no unnecessary unguarded BVDC_ApplyChanges
72 *  calls in Nexus
73 *
74 * 2   6/30/08 10:02a erickson
75 * PR44326: fix warning
76 *
77 * 1   6/11/08 12:44p vsilyaev
78 * PR 43491: Added support for CCIR-656 input
79 *
80 **************************************************************************/
81#include "nexus_base.h"
82#include "nexus_display_module.h"
83#include "nexus_power_management.h"
84#include "bvbi.h"
85#if NEXUS_NUM_656_INPUTS
86#if (BCHP_CHIP == 3563) || (BCHP_CHIP == 3548) || (BCHP_CHIP == 3556)
87#include "bchp_int_id_vdec_l2.h"
88#else
89#include "bchp_int_id_bvnf_intr2_5.h"
90#endif
91#endif
92
93BDBG_MODULE(nexus_ccir656_input);
94BDBG_OBJECT_ID(NEXUS_Ccir656Input);
95#define pVideo (&g_NEXUS_DisplayModule_State)
96static unsigned NEXUS_Ccir656Input_P_FreeSpace_isr(NEXUS_Ccir656InputHandle ccir656Input);
97static void NEXUS_Ccir656Input_P_AddData_isr(NEXUS_Ccir656InputHandle ccir656Input, void *data, unsigned size);
98#if NEXUS_NUM_656_INPUTS
99static void NEXUS_Ccir656Input_P_External_isr(void* parm1, int parm2);
100#endif
101
102/*
103Define TEST_656_VBI to provide an artificial internal data feed for 656 vbi testing.
104
105#define TEST_656_VBI 1
106*/
107#if TEST_656_VBI
108static void NEXUS_Ccir656Input_P_TestVbi(void *context);
109#endif
110
111struct NEXUS_Ccir656Input {
112    BDBG_OBJECT(NEXUS_Ccir656Input)
113    unsigned index;
114    NEXUS_Ccir656InputSettings settings;
115    NEXUS_VideoInputObject input;
116    BAVC_SourceId sourceId;
117    BVBI_Decode_Handle vbiDecode;
118    uint8_t *buffer;
119    unsigned rptr, wptr;
120    unsigned lastGetBuffer;
121    NEXUS_IsrCallbackHandle dataReady;
122    BVBI_Field_Handle dummyField; /* required by VBI PI, but not used */
123    BINT_CallbackHandle tf_isr, bf_isr;
124};
125
126void
127NEXUS_Ccir656Input_GetDefaultSettings(NEXUS_Ccir656InputSettings *pSettings)
128{
129    BKNI_Memset(pSettings, 0, sizeof(*pSettings));
130    pSettings->format = NEXUS_VideoFormat_eNtsc;
131    pSettings->vbi.format = NEXUS_Ccir656VbiFormat_eSaa7113;
132    pSettings->vbi.brokenDataCount = true;
133}
134
135NEXUS_Ccir656InputHandle
136NEXUS_Ccir656Input_Open(unsigned index, const NEXUS_Ccir656InputSettings *pSettings)
137{
138#if NEXUS_NUM_656_INPUTS
139    NEXUS_Ccir656InputHandle ccir656Input;
140    NEXUS_Ccir656InputSettings settings;
141    NEXUS_Error rc;
142
143    if(index>=NEXUS_NUM_656_INPUTS) { rc = BERR_TRACE(NEXUS_NOT_SUPPORTED); goto err_config;}
144
145    if(!pSettings) {
146        NEXUS_Ccir656Input_GetDefaultSettings(&settings);
147        pSettings = &settings;
148    }
149    ccir656Input = BKNI_Malloc(sizeof(*ccir656Input));
150    if(!ccir656Input) {rc=BERR_TRACE(NEXUS_OUT_OF_SYSTEM_MEMORY);goto err_alloc;}
151
152    BKNI_Memset(ccir656Input, 0, sizeof(*ccir656Input));
153    BDBG_OBJECT_SET(ccir656Input, NEXUS_Ccir656Input);
154    NEXUS_VIDEO_INPUT_INIT(&ccir656Input->input, NEXUS_VideoInputType_eCcir656, ccir656Input);
155    ccir656Input->settings = *pSettings;
156    ccir656Input->index = index;
157    ccir656Input->sourceId = BAVC_SourceId_e656In0 + ccir656Input->index;
158
159    ccir656Input->dataReady = NEXUS_IsrCallback_Create(ccir656Input, NULL);
160    if (!ccir656Input->dataReady) {BERR_TRACE(NEXUS_UNKNOWN); goto err_callback_create;}
161
162    rc = BVBI_Decode_Create(pVideo->vbi, ccir656Input->sourceId, &ccir656Input->vbiDecode);
163    if (rc) {rc = BERR_TRACE(rc); goto err_vbi_create;}
164
165    rc = BVBI_Field_Create(&ccir656Input->dummyField, pVideo->vbi);
166    if (rc) {rc = BERR_TRACE(rc); goto err_vbi_create;}
167
168#if BCHP_CHIP == 7405
169#define BCHP_INT_ID_IN656_TopField BCHP_INT_ID_IN656_0_FILED_0_INTR
170#define BCHP_INT_ID_IN656_BotField BCHP_INT_ID_IN656_0_FILED_1_INTR
171#else
172#define BCHP_INT_ID_IN656_TopField BCHP_INT_ID_Video_Decoder_Ext_656_Field_0_INTR
173#define BCHP_INT_ID_IN656_BotField BCHP_INT_ID_Video_Decoder_Ext_656_Field_1_INTR
174#endif
175
176    rc = BINT_CreateCallback(&ccir656Input->tf_isr, g_pCoreHandles->bint, BCHP_INT_ID_IN656_TopField,
177        NEXUS_Ccir656Input_P_External_isr, ccir656Input, BAVC_Polarity_eTopField);
178    if(rc!=NEXUS_SUCCESS) { rc=BERR_TRACE(rc);goto err_settings;}
179    rc = BINT_CreateCallback(&ccir656Input->bf_isr, g_pCoreHandles->bint, BCHP_INT_ID_IN656_BotField,
180        NEXUS_Ccir656Input_P_External_isr, ccir656Input, BAVC_Polarity_eBotField);
181    if(rc!=NEXUS_SUCCESS) { rc=BERR_TRACE(rc);goto err_settings;}
182
183    rc = NEXUS_Ccir656Input_SetSettings(ccir656Input, pSettings);
184    if(rc!=NEXUS_SUCCESS) { rc=BERR_TRACE(rc);goto err_settings;}
185
186#if TEST_656_VBI
187    NEXUS_ScheduleTimer(1000, NEXUS_Ccir656Input_P_TestVbi, ccir656Input);
188#endif
189
190    return ccir656Input;
191
192err_settings:
193    if (ccir656Input->vbiDecode) {
194        BVBI_Decode_Destroy(ccir656Input->vbiDecode);
195    }
196err_vbi_create:
197    if (ccir656Input->dataReady) {
198        NEXUS_IsrCallback_Destroy(ccir656Input->dataReady);
199    }
200err_callback_create:
201    BKNI_Free(ccir656Input);
202err_alloc:
203err_config:
204    return NULL;
205#else
206    BSTD_UNUSED(index);
207    BSTD_UNUSED(pSettings);
208    return NULL;
209#endif
210}
211
212void
213NEXUS_Ccir656Input_Close(NEXUS_Ccir656InputHandle ccir656Input)
214{
215    BDBG_OBJECT_ASSERT(ccir656Input, NEXUS_Ccir656Input);
216
217    NEXUS_PowerManagement_SetCoreState(NEXUS_PowerManagementCore_eCcir656Input, true);
218    if (ccir656Input->dummyField) {
219        BVBI_Field_Destroy(ccir656Input->dummyField);
220    }
221    if (ccir656Input->vbiDecode) {
222        BVBI_Decode_Destroy(ccir656Input->vbiDecode);
223    }
224    if (ccir656Input->tf_isr) {
225        BINT_DestroyCallback(ccir656Input->tf_isr);
226    }
227    if (ccir656Input->bf_isr) {
228        BINT_DestroyCallback(ccir656Input->bf_isr);
229    }
230    NEXUS_PowerManagement_SetCoreState(NEXUS_PowerManagementCore_eCcir656Input, false);
231
232    if (ccir656Input->dataReady) {
233        NEXUS_IsrCallback_Destroy(ccir656Input->dataReady);
234    }
235    if (ccir656Input->buffer) {
236        BMEM_Free(g_pCoreHandles->heap[0], ccir656Input->buffer);
237    }
238
239    BDBG_OBJECT_DESTROY(ccir656Input, NEXUS_Ccir656Input);
240    BKNI_Free(ccir656Input);
241    return;
242}
243
244void
245NEXUS_Ccir656Input_GetSettings( NEXUS_Ccir656InputHandle ccir656Input, NEXUS_Ccir656InputSettings *pSettings)
246{
247    BDBG_OBJECT_ASSERT(ccir656Input, NEXUS_Ccir656Input);
248    BDBG_ASSERT(pSettings);
249    *pSettings = ccir656Input->settings;
250    return;
251}
252
253static NEXUS_Error
254NEXUS_VideoCcir656Input_P_ApplyVdcSettings(NEXUS_VideoInput_P_Link *link, const NEXUS_Ccir656InputSettings *pSettings)
255{
256    NEXUS_Error rc;
257    BFMT_VideoFmt formatVdc;
258
259    BDBG_ASSERT(link->sourceVdc);
260
261    rc = NEXUS_P_VideoFormat_ToMagnum(pSettings->format, &formatVdc);
262    if (rc!=NEXUS_SUCCESS) {return BERR_TRACE(rc);}
263
264    rc = BVDC_Source_SetVideoFormat(link->sourceVdc, formatVdc);
265    if (rc!=BERR_SUCCESS) {return BERR_TRACE(rc);}
266
267    /* no ApplyChanges here */
268
269    return NEXUS_SUCCESS;
270}
271
272static BERR_Code NEXUS_Ccir656Input_P_CaptureVbi_isr(void *context,
273    BFMT_VideoFmt eVideoFormat, BAVC_Polarity polarity, uint8_t data_id, uint8_t second_id,
274    uint8_t data_count, uint8_t *packet, uint8_t **vbiData, BVBI_SMPTE291M_Description *pktDesc)
275{
276    NEXUS_Ccir656InputHandle ccir656Input = context;
277    NEXUS_Ccir656InputVbiHeader vbiHeader;
278
279    BDBG_OBJECT_ASSERT(ccir656Input, NEXUS_Ccir656Input);
280
281    BSTD_UNUSED(eVideoFormat);
282
283    BDBG_MSG(("VBI: field=%d, ids=%d,%d, count=%d", polarity, data_id, second_id, data_count));
284
285    /* queue data and notify the application that data is available */
286    if (NEXUS_Ccir656Input_P_FreeSpace_isr(ccir656Input) >= sizeof(vbiHeader) + data_count) {
287        vbiHeader.topField = (polarity == BAVC_Polarity_eTopField);
288        vbiHeader.dataId = data_id;
289        vbiHeader.secondId = second_id;
290        vbiHeader.payload = data_count;
291        NEXUS_Ccir656Input_P_AddData_isr(ccir656Input, &vbiHeader, sizeof(vbiHeader));
292        NEXUS_Ccir656Input_P_AddData_isr(ccir656Input, packet, data_count);
293        NEXUS_IsrCallback_Fire_isr(ccir656Input->dataReady);
294    }
295    else {
296        BDBG_WRN(("656 ancillary data overflow. %d bytes lost.", data_count));
297    }
298
299    /* By returning a fail to the VBI PI, it will not parse the data, which is what is desired. */
300    BSTD_UNUSED(vbiData);
301    BSTD_UNUSED(pktDesc);
302    return -1;
303}
304
305NEXUS_Error
306NEXUS_Ccir656Input_SetSettings(NEXUS_Ccir656InputHandle ccir656Input, const NEXUS_Ccir656InputSettings *pSettings)
307{
308    NEXUS_Error rc;
309    NEXUS_VideoInput_P_Link *link = NEXUS_VideoInput_P_Get(&ccir656Input->input);
310
311    BDBG_OBJECT_ASSERT(ccir656Input, NEXUS_Ccir656Input);
312    BDBG_ASSERT(pSettings);
313
314    if (link) {
315        rc = NEXUS_VideoCcir656Input_P_ApplyVdcSettings(link, pSettings);
316        if (rc) return BERR_TRACE(rc);
317    }
318
319    /* apply VBI settings */
320    BDBG_CASSERT(NEXUS_Ccir656VbiFormat_eMax == (NEXUS_Ccir656VbiFormat)BVBI_656Fmt_LAST);
321    rc = BVBI_Decode_656_SetFormat(ccir656Input->vbiDecode, pSettings->vbi.format);
322    if (rc) return BERR_TRACE(rc);
323
324    rc = BVBI_Decode_656_SetSMPTE291Moptions(ccir656Input->vbiDecode, NEXUS_Ccir656Input_P_CaptureVbi_isr, ccir656Input,
325        ccir656Input->settings.vbi.longHeader,
326        ccir656Input->settings.vbi.brokenDataCount);
327    if (rc) return BERR_TRACE(rc);
328
329    rc = NEXUS_Display_P_ApplyChanges();
330    if (rc) {return BERR_TRACE(rc);}
331
332    if (pSettings->vbi.bufferSize) {
333        if (ccir656Input->buffer && pSettings->vbi.bufferSize != ccir656Input->settings.vbi.bufferSize) {
334            BMEM_Free(g_pCoreHandles->heap[0], ccir656Input->buffer);
335            ccir656Input->buffer = NULL;
336        }
337        ccir656Input->buffer = BMEM_Alloc(g_pCoreHandles->heap[0], pSettings->vbi.bufferSize);
338        if (!ccir656Input->buffer) return BERR_TRACE(NEXUS_OUT_OF_DEVICE_MEMORY);
339
340        NEXUS_Ccir656Input_Flush(ccir656Input);
341    }
342    else {
343        if (ccir656Input->buffer) {
344            BMEM_Free(g_pCoreHandles->heap[0], ccir656Input->buffer);
345            ccir656Input->buffer = NULL;
346        }
347    }
348
349    NEXUS_IsrCallback_Set(ccir656Input->dataReady, &pSettings->vbi.dataReady);
350
351    ccir656Input->settings = *pSettings;
352    return NEXUS_SUCCESS;
353}
354
355NEXUS_VideoInput
356NEXUS_Ccir656Input_GetConnector( NEXUS_Ccir656InputHandle ccir656Input)
357{
358    BDBG_OBJECT_ASSERT(ccir656Input, NEXUS_Ccir656Input);
359    return &ccir656Input->input;
360}
361
362#if NEXUS_NUM_656_INPUTS
363
364static void
365NEXUS_Ccir656Input_P_External_isr(void* parm1, int parm2)
366{
367    NEXUS_Ccir656InputHandle ccir656Input = (NEXUS_Ccir656InputHandle)parm1;
368    BAVC_Polarity field = (BAVC_Polarity)parm2;
369    BERR_Code rc;
370
371    BDBG_OBJECT_ASSERT(ccir656Input, NEXUS_Ccir656Input);
372
373    rc = BVBI_Decode_Data_isr(ccir656Input->vbiDecode, ccir656Input->dummyField, field);
374    if (rc!=BERR_SUCCESS) {
375        BDBG_ERR(("BVBI_Decode_Data_isr returned error %d", rc));
376    }
377}
378
379static NEXUS_Error
380NEXUS_VideoInput_P_ConnectCcir656Input(NEXUS_VideoInput_P_Link *link)
381{
382    NEXUS_Ccir656InputHandle ccir656Input;
383    BERR_Code rc;
384
385    BDBG_ASSERT(link->input);
386    BDBG_ASSERT(link->input->type == NEXUS_VideoInputType_eCcir656);
387    ccir656Input = link->input->source;
388    BDBG_OBJECT_ASSERT(ccir656Input, NEXUS_Ccir656Input);
389
390    NEXUS_PowerManagement_SetCoreState(NEXUS_PowerManagementCore_eCcir656Input, true);
391
392    rc = BINT_EnableCallback(ccir656Input->tf_isr);
393    if (rc) return BERR_TRACE(rc);
394    rc = BINT_EnableCallback(ccir656Input->bf_isr);
395    if (rc) return BERR_TRACE(rc);
396
397    return NEXUS_VideoCcir656Input_P_ApplyVdcSettings(link, &ccir656Input->settings);
398}
399
400static void
401NEXUS_VideoInput_P_DisconnectCcir656Input(NEXUS_VideoInput_P_Link *link)
402{
403    NEXUS_Ccir656InputHandle ccir656Input;
404
405    BDBG_ASSERT(link->input);
406    BDBG_ASSERT(link->input->type == NEXUS_VideoInputType_eCcir656);
407    ccir656Input = link->input->source;
408    BDBG_OBJECT_ASSERT(ccir656Input, NEXUS_Ccir656Input);
409
410    BINT_DisableCallback(ccir656Input->tf_isr);
411    BINT_DisableCallback(ccir656Input->bf_isr);
412
413    NEXUS_PowerManagement_SetCoreState(NEXUS_PowerManagementCore_eCcir656Input, false);
414    return;
415}
416
417NEXUS_VideoInput_P_Link *
418NEXUS_VideoInput_P_OpenCcir656(NEXUS_VideoInput input)
419{
420    NEXUS_VideoInput_P_Iface iface;
421    NEXUS_VideoInput_P_Link *link;
422    NEXUS_VideoInput_P_LinkData data;
423    NEXUS_Ccir656InputHandle ccir656Input;
424
425    BDBG_ASSERT(input->type == NEXUS_VideoInputType_eCcir656);
426    ccir656Input = input->source;
427    BDBG_OBJECT_ASSERT(ccir656Input, NEXUS_Ccir656Input);
428
429    iface.connect = NEXUS_VideoInput_P_ConnectCcir656Input;
430    iface.disconnect = NEXUS_VideoInput_P_DisconnectCcir656Input;
431    NEXUS_VideoInput_P_LinkData_Init(&data, ccir656Input->sourceId);
432    link = NEXUS_VideoInput_P_CreateLink(input, &data, &iface);
433    if(!link) {
434        return NULL;
435    }
436    return link;
437}
438
439#endif /* NEXUS_NUM_656_INPUTS */
440
441static unsigned NEXUS_Ccir656Input_P_FreeSpace_isr(NEXUS_Ccir656InputHandle ccir656Input)
442{
443    if (ccir656Input->buffer) {
444        if (ccir656Input->wptr < ccir656Input->rptr) {
445            return ccir656Input->rptr - ccir656Input->wptr - 1;
446        }
447        else {
448            return (ccir656Input->settings.vbi.bufferSize - ccir656Input->wptr) + ccir656Input->rptr - 1;
449        }
450    }
451    return 0; /* no space */
452}
453
454/* this functions assumes NEXUS_Ccir656Input_P_FreeSpace_isr was used first to qualify the addition */
455static void NEXUS_Ccir656Input_P_AddData_isr(NEXUS_Ccir656InputHandle ccir656Input, void *data, unsigned size)
456{
457    unsigned n;
458
459    if (ccir656Input->wptr < ccir656Input->rptr) {
460        n = ccir656Input->rptr - ccir656Input->wptr - 1;
461    }
462    else {
463        n = ccir656Input->settings.vbi.bufferSize - ccir656Input->wptr;
464    }
465    if (n > size) n = size;
466    BKNI_Memcpy(&ccir656Input->buffer[ccir656Input->wptr], data, n);
467    ccir656Input->wptr += n;
468    if (ccir656Input->wptr == ccir656Input->settings.vbi.bufferSize) {
469        ccir656Input->wptr = 0;
470        size -= n;
471        if (size) {
472            BKNI_Memcpy(&ccir656Input->buffer[ccir656Input->wptr], &((uint8_t*)data)[n], size);
473            ccir656Input->wptr += size;
474        }
475    }
476    BDBG_ASSERT(ccir656Input->wptr < ccir656Input->settings.vbi.bufferSize);
477}
478
479NEXUS_Error NEXUS_Ccir656Input_GetBuffer( NEXUS_Ccir656InputHandle ccir656Input, void **buffer, unsigned *size )
480{
481    BDBG_OBJECT_ASSERT(ccir656Input, NEXUS_Ccir656Input);
482
483    if (ccir656Input->buffer) {
484        BKNI_EnterCriticalSection();
485        *buffer = &ccir656Input->buffer[ccir656Input->rptr];
486        if (ccir656Input->rptr <= ccir656Input->wptr) {
487            *size = ccir656Input->wptr - ccir656Input->rptr;
488        }
489        else {
490            *size = ccir656Input->settings.vbi.bufferSize - ccir656Input->rptr;
491        }
492        BKNI_LeaveCriticalSection();
493        ccir656Input->lastGetBuffer = *size;
494        return 0;
495    }
496    else {
497        *buffer = NULL;
498        *size = 0;
499        return BERR_TRACE(NEXUS_INVALID_PARAMETER);
500    }
501}
502
503NEXUS_Error NEXUS_Ccir656Input_ReadComplete( NEXUS_Ccir656InputHandle ccir656Input, unsigned sizeConsumed )
504{
505    BDBG_OBJECT_ASSERT(ccir656Input, NEXUS_Ccir656Input);
506
507    if (sizeConsumed > ccir656Input->lastGetBuffer) {
508        return BERR_TRACE(NEXUS_INVALID_PARAMETER);
509    }
510    BKNI_EnterCriticalSection();
511    ccir656Input->rptr += sizeConsumed;
512    BDBG_ASSERT(ccir656Input->rptr <= ccir656Input->settings.vbi.bufferSize); /* if lastGetBuffer is accurate, this should be true */
513    if (ccir656Input->rptr == ccir656Input->settings.vbi.bufferSize) {
514        ccir656Input->rptr = 0;
515    }
516    BKNI_LeaveCriticalSection();
517    return 0;
518}
519
520void NEXUS_Ccir656Input_Flush( NEXUS_Ccir656InputHandle ccir656Input )
521{
522    BDBG_OBJECT_ASSERT(ccir656Input, NEXUS_Ccir656Input);
523    BKNI_EnterCriticalSection();
524    ccir656Input->wptr = ccir656Input->rptr = 0;
525    BKNI_LeaveCriticalSection();
526    ccir656Input->lastGetBuffer = 0;
527}
528
529#if TEST_656_VBI
530#include <stdlib.h>
531static void NEXUS_Ccir656Input_P_TestVbi(void *context)
532{
533    int i;
534    for (i=0;i<rand()%5;i++) {
535        unsigned char buf[100];
536        unsigned n = (rand() % 100) + 1;
537
538        /* this test code will intentionally overflow. this tests nexus ability to guarantee atomic messages */
539        BKNI_EnterCriticalSection();
540        NEXUS_Ccir656Input_P_External_isr(context, BAVC_Polarity_eTopField);
541        NEXUS_Ccir656Input_P_External_isr(context, BAVC_Polarity_eBotField);
542        NEXUS_Ccir656Input_P_CaptureVbi_isr(context, BFMT_VideoFmt_eNTSC, BAVC_Polarity_eTopField, 0, 1, n, buf, NULL, NULL);
543        BKNI_LeaveCriticalSection();
544    }
545    NEXUS_ScheduleTimer(rand()%1000, NEXUS_Ccir656Input_P_TestVbi, context);
546}
547#endif
Note: See TracBrowser for help on using the repository browser.