close Warning: Can't use blame annotator:
No changeset 2 in the repository

source: svn/newcon3bcm2_21bu/nexus/app/bapp_tune.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: 9.4 KB
RevLine 
1/******************************************************************************
2 *    (c)2008-2009 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:  $
39 * $brcm_Revision:  $
40 * $brcm_Date:  $
41 *
42 * Module Description:
43 *
44 * Utility to handle the frontend configuration and tuning.
45 *
46 * Revision History:
47 *
48 * Created: 09/28/2009 by Jeff Fisher
49 *
50 * $brcm_Log:  $
51 *
52 *
53 *****************************************************************************/
54#include "bapp_tune.h"
55#include "bapp.h"
56#include "nexus_frontend.h"
57#include "nexus_platform.h"
58#include "nexus_parser_band.h"
59#include "nexus_video_decoder.h"
60BDBG_MODULE(bapp_tune);         /* Register software module with debug interface */
61
62#define MAX_EVENT 4
63
64enum
65{
66        eFE_EVENT_NONE,
67        eFE_EVENT_LOCK,
68        eFE_EVENT_MAX
69};
70
71struct bapp_tune
72{
73        bapp_tune_event_t signal_evt;
74        bapp_freq_table_type_t  fe_type;
75        NEXUS_FrontendHandle frontend;
76        NEXUS_ParserBand parserBand;
77    NEXUS_FrontendVsbSettings vsbSettings;
78    NEXUS_FrontendQamSettings qamSettings;
79        bapp_task_queue_t   queue;
80        bapp_task_event_t   event[MAX_EVENT];   
81        unsigned int timeout_ms;
82};
83
84
85/*
86Summary:
87        Nexus lock callback.
88*/
89
90static void bapp_tune_lock_callback(void *context, int param)
91{
92        static NEXUS_FrontendQamStatus qamStatus;
93        static NEXUS_FrontendVsbStatus vsbStatus;
94        bapp_tune_t p_tune = (bapp_tune_t)context;
95
96        BSTD_UNUSED(param);
97        p_tune->signal_evt.type = eBAPP_EVENT_SIGNAL;
98        p_tune->signal_evt.id = p_tune->fe_type;
99        p_tune->signal_evt.ticks = bapp_util_get_ticks();;
100
101        switch (p_tune->fe_type)
102        {
103        case eFREQ_TABLE_NORTH_AMERICA_QAM:
104                NEXUS_Frontend_GetQamStatus(p_tune->frontend, &qamStatus);
105                if (qamStatus.receiverLock)
106                {
107                        bapp_task_post_event(p_tune->queue,(bapp_task_event_t)eFE_EVENT_LOCK);
108                }
109                break;
110
111        case eFREQ_TABLE_NTIA_VSB:
112                NEXUS_Frontend_GetVsbStatus(p_tune->frontend, &vsbStatus);
113                if (vsbStatus.receiverLock)
114                {
115                        bapp_task_post_event(p_tune->queue,(bapp_task_event_t)eFE_EVENT_LOCK);
116                }
117                break;
118        default:
119                break;
120        }
121}
122
123/**
124Summary:
125        Return a bapp_tune handle if frontend exists.  NEXUS init should be called before calling this function.
126**/
127bapp_result_t bapp_tune_open(bapp_tune_type_t fe_type, bapp_tune_t *p_app_tune, int *band)
128{
129    NEXUS_PlatformConfiguration platformConfig;
130        NEXUS_FrontendHandle frontend;
131    NEXUS_FrontendUserParameters userParams;
132    NEXUS_ParserBandSettings parserBandSettings;
133        bapp_tune_t p_tune = NULL;
134        bool found_frontend = false;
135        int i;
136
137        NEXUS_Platform_GetConfiguration(&platformConfig);
138        BDBG_WRN(("Getting frontend capabilities...\n",__FUNCTION__));
139       
140    for ( i = 0; i < NEXUS_MAX_FRONTENDS; i++ )
141    {
142        NEXUS_FrontendCapabilities capabilities;
143        frontend = platformConfig.frontend[i];
144        if (frontend) 
145                {
146            NEXUS_Frontend_GetCapabilities(frontend, &capabilities);
147            /* Does this frontend support qam? */
148            if ( capabilities.qam && (fe_type == eFREQ_TABLE_NORTH_AMERICA_QAM))
149            {
150                                BDBG_WRN(("Found QAM Annex-B Support...\n",__FUNCTION__));
151                                found_frontend = true;
152                break;
153            }
154                        else if (capabilities.vsb && (fe_type == eFREQ_TABLE_NTIA_VSB))
155                        {
156                                BDBG_WRN(("Found VSB Support...\n",__FUNCTION__));
157                                found_frontend = true;
158                break;
159                        }
160        }
161    }
162       
163        if (!found_frontend)
164                return eBAPP_RESULT_FAILURE;
165   
166        p_tune = (bapp_tune_t)bapp_util_malloc(sizeof(struct bapp_tune));
167
168        if (!p_tune)
169                return eBAPP_RESULT_ALLOC_FAILURE;
170       
171        bapp_util_memset(p_tune,0,sizeof(struct bapp_tune));
172       
173        if (bapp_task_create_queue(&p_tune->queue,p_tune->event,MAX_EVENT) != eBAPP_RESULT_OK)
174        {
175                bapp_util_free(p_tune);
176                return eBAPP_RESULT_ALLOC_FAILURE;
177        }
178
179        p_tune->fe_type = fe_type;
180        p_tune->frontend = frontend;
181        p_tune->parserBand = NEXUS_ParserBand_e0;
182        *band = (int)(p_tune->parserBand);
183       
184        NEXUS_Frontend_GetUserParameters(frontend, &userParams);
185
186        /* Map a parser band to the demod's input band. */
187        NEXUS_ParserBand_GetSettings(p_tune->parserBand, &parserBandSettings);
188        parserBandSettings.sourceType = NEXUS_ParserBandSourceType_eInputBand;
189        parserBandSettings.sourceTypeSettings.inputBand = userParams.param1;  /* Platform initializes this to input band */
190        parserBandSettings.transportType = NEXUS_TransportType_eTs;
191        parserBandSettings.maxDataRate = 42 * 1024 * 1024;/* for HD streams */
192        NEXUS_ParserBand_SetSettings(p_tune->parserBand, &parserBandSettings);
193
194        *p_app_tune = p_tune;
195        return eBAPP_RESULT_OK;
196}
197
198/**
199Summary:
200        Release resources.
201**/
202bapp_result_t bapp_tune_close(bapp_tune_t p_tune)
203{
204        bapp_task_delete_queue(p_tune->queue);
205        bapp_util_free(p_tune);
206        return eBAPP_RESULT_OK;
207}
208
209
210/**
211Summary:
212        Lock the frontend.
213**/
214bapp_result_t bapp_tune_lock(bapp_tune_t p_tune, 
215                                                         unsigned int freq_hz)
216{
217        bapp_task_event_t event;
218        bapp_task_reset_queue(p_tune->queue);
219        bool locked = false;
220        if (p_tune->fe_type == eFREQ_TABLE_NORTH_AMERICA_QAM)
221        {
222                NEXUS_Frontend_GetDefaultQamSettings(&p_tune->qamSettings);
223                p_tune->qamSettings.frequency = freq_hz;
224                p_tune->qamSettings.mode = NEXUS_FrontendQamMode_eAuto_64_256;
225                p_tune->qamSettings.annex = NEXUS_FrontendQamAnnex_eB;
226                p_tune->qamSettings.lockCallback.callback = bapp_tune_lock_callback;
227                p_tune->qamSettings.lockCallback.context = p_tune;
228                if (NEXUS_Frontend_TuneQam(p_tune->frontend, &p_tune->qamSettings) == BERR_SUCCESS)
229                {
230                        locked = true;
231                }
232
233        }
234        else
235        {
236                NEXUS_Frontend_GetDefaultVsbSettings(&p_tune->vsbSettings);
237                p_tune->vsbSettings.frequency = freq_hz;
238                p_tune->vsbSettings.mode = NEXUS_FrontendVsbMode_e8;
239                p_tune->vsbSettings.lockCallback.callback = bapp_tune_lock_callback;
240                p_tune->vsbSettings.lockCallback.context = p_tune;
241                NEXUS_Frontend_TuneVsb(p_tune->frontend, &p_tune->vsbSettings);
242        }
243
244#if 0
245        event = bapp_task_pend_event(p_tune->queue,p_tune->timeout_ms);
246
247        if (eFE_EVENT_LOCK != (int)event)
248        {
249                return eBAPP_RESULT_TIMEOUT;
250        }
251#else
252        if (!locked)
253        {
254                return eBAPP_RESULT_TIMEOUT;
255        }
256#endif
257
258        return eBAPP_RESULT_OK;
259}
260
261/**
262Summary:
263        Unlock the frontend.
264**/
265bapp_result_t bapp_tune_unlock(bapp_tune_t p_tune)
266{
267        NEXUS_Frontend_Untune(p_tune->frontend);
268        return eBAPP_RESULT_OK;
269}
270
271/*
272Summary:
273        Send frontend status event to the application.
274*/
275
276void bapp_tune_send_status(bapp_tune_t p_tune)
277{
278        static NEXUS_FrontendQamStatus qamStatus;
279        static NEXUS_FrontendVsbStatus vsbStatus;
280
281        p_tune->signal_evt.type = eBAPP_EVENT_SIGNAL;
282        p_tune->signal_evt.id = p_tune->fe_type;
283        p_tune->signal_evt.ticks = bapp_util_get_ticks();;
284
285        switch (p_tune->fe_type)
286        {
287        case eFREQ_TABLE_NORTH_AMERICA_QAM:
288                NEXUS_Frontend_GetQamStatus(p_tune->frontend, &qamStatus);
289                p_tune->signal_evt.lock = qamStatus.receiverLock;
290                p_tune->signal_evt.SNR = qamStatus.snrEstimate;
291                p_tune->signal_evt.power = qamStatus.dsChannelPower;
292                p_tune->signal_evt.mode = qamStatus.settings.mode;
293                p_tune->signal_evt.freq_hz = qamStatus.settings.frequency;
294                bapp_post_event((bapp_task_event_t)&p_tune->signal_evt);
295                break;
296
297        case eFREQ_TABLE_NTIA_VSB:
298                NEXUS_Frontend_GetVsbStatus(p_tune->frontend, &vsbStatus);
299                p_tune->signal_evt.lock = vsbStatus.receiverLock;
300                p_tune->signal_evt.SNR = vsbStatus.snrEstimate;
301                p_tune->signal_evt.mode = vsbStatus.settings.mode;
302                p_tune->signal_evt.freq_hz = vsbStatus.settings.frequency;
303                bapp_post_event((bapp_task_event_t)&p_tune->signal_evt);
304                break;
305        default:
306                break;
307        }
308}
309
Note: See TracBrowser for help on using the repository browser.