/****************************************************************************** * (c)2008-2009 Broadcom Corporation * * This program is the proprietary software of Broadcom Corporation and/or its licensors, * and may only be used, duplicated, modified or distributed pursuant to the terms and * conditions of a separate, written license agreement executed between you and Broadcom * (an "Authorized License"). Except as set forth in an Authorized License, Broadcom grants * no license (express or implied), right to use, or waiver of any kind with respect to the * Software, and Broadcom expressly reserves all rights in and to the Software and all * intellectual property rights therein. IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU * HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY * NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE. * * Except as expressly set forth in the Authorized License, * * 1. This program, including its structure, sequence and organization, constitutes the valuable trade * secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof, * and to use this information only in connection with your use of Broadcom integrated circuit products. * * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" * AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO * THE SOFTWARE. BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, * LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION * OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF * USE OR PERFORMANCE OF THE SOFTWARE. * * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS * LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR * EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR * USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF * THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT * ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF * ANY LIMITED REMEDY. * * $brcm_Workfile: $ * $brcm_Revision: $ * $brcm_Date: $ * * Module Description: * * Utility to handle the frontend configuration and tuning. * * Revision History: * * Created: 09/28/2009 by Jeff Fisher * * $brcm_Log: $ * * *****************************************************************************/ #include "bapp_tune.h" #include "bapp.h" #include "nexus_frontend.h" #include "nexus_platform.h" #include "nexus_parser_band.h" #include "nexus_video_decoder.h" BDBG_MODULE(bapp_tune); /* Register software module with debug interface */ #define MAX_EVENT 4 enum { eFE_EVENT_NONE, eFE_EVENT_LOCK, eFE_EVENT_MAX }; struct bapp_tune { bapp_tune_event_t signal_evt; bapp_freq_table_type_t fe_type; NEXUS_FrontendHandle frontend; NEXUS_ParserBand parserBand; NEXUS_FrontendVsbSettings vsbSettings; NEXUS_FrontendQamSettings qamSettings; bapp_task_queue_t queue; bapp_task_event_t event[MAX_EVENT]; unsigned int timeout_ms; }; /* Summary: Nexus lock callback. */ static void bapp_tune_lock_callback(void *context, int param) { static NEXUS_FrontendQamStatus qamStatus; static NEXUS_FrontendVsbStatus vsbStatus; bapp_tune_t p_tune = (bapp_tune_t)context; BSTD_UNUSED(param); p_tune->signal_evt.type = eBAPP_EVENT_SIGNAL; p_tune->signal_evt.id = p_tune->fe_type; p_tune->signal_evt.ticks = bapp_util_get_ticks();; switch (p_tune->fe_type) { case eFREQ_TABLE_NORTH_AMERICA_QAM: NEXUS_Frontend_GetQamStatus(p_tune->frontend, &qamStatus); if (qamStatus.receiverLock) { bapp_task_post_event(p_tune->queue,(bapp_task_event_t)eFE_EVENT_LOCK); } break; case eFREQ_TABLE_NTIA_VSB: NEXUS_Frontend_GetVsbStatus(p_tune->frontend, &vsbStatus); if (vsbStatus.receiverLock) { bapp_task_post_event(p_tune->queue,(bapp_task_event_t)eFE_EVENT_LOCK); } break; default: break; } } /** Summary: Return a bapp_tune handle if frontend exists. NEXUS init should be called before calling this function. **/ bapp_result_t bapp_tune_open(bapp_tune_type_t fe_type, bapp_tune_t *p_app_tune, int *band) { NEXUS_PlatformConfiguration platformConfig; NEXUS_FrontendHandle frontend; NEXUS_FrontendUserParameters userParams; NEXUS_ParserBandSettings parserBandSettings; bapp_tune_t p_tune = NULL; bool found_frontend = false; int i; NEXUS_Platform_GetConfiguration(&platformConfig); BDBG_WRN(("Getting frontend capabilities...\n",__FUNCTION__)); for ( i = 0; i < NEXUS_MAX_FRONTENDS; i++ ) { NEXUS_FrontendCapabilities capabilities; frontend = platformConfig.frontend[i]; if (frontend) { NEXUS_Frontend_GetCapabilities(frontend, &capabilities); /* Does this frontend support qam? */ if ( capabilities.qam && (fe_type == eFREQ_TABLE_NORTH_AMERICA_QAM)) { BDBG_WRN(("Found QAM Annex-B Support...\n",__FUNCTION__)); found_frontend = true; break; } else if (capabilities.vsb && (fe_type == eFREQ_TABLE_NTIA_VSB)) { BDBG_WRN(("Found VSB Support...\n",__FUNCTION__)); found_frontend = true; break; } } } if (!found_frontend) return eBAPP_RESULT_FAILURE; p_tune = (bapp_tune_t)bapp_util_malloc(sizeof(struct bapp_tune)); if (!p_tune) return eBAPP_RESULT_ALLOC_FAILURE; bapp_util_memset(p_tune,0,sizeof(struct bapp_tune)); if (bapp_task_create_queue(&p_tune->queue,p_tune->event,MAX_EVENT) != eBAPP_RESULT_OK) { bapp_util_free(p_tune); return eBAPP_RESULT_ALLOC_FAILURE; } p_tune->fe_type = fe_type; p_tune->frontend = frontend; p_tune->parserBand = NEXUS_ParserBand_e0; *band = (int)(p_tune->parserBand); NEXUS_Frontend_GetUserParameters(frontend, &userParams); /* Map a parser band to the demod's input band. */ NEXUS_ParserBand_GetSettings(p_tune->parserBand, &parserBandSettings); parserBandSettings.sourceType = NEXUS_ParserBandSourceType_eInputBand; parserBandSettings.sourceTypeSettings.inputBand = userParams.param1; /* Platform initializes this to input band */ parserBandSettings.transportType = NEXUS_TransportType_eTs; parserBandSettings.maxDataRate = 42 * 1024 * 1024;/* for HD streams */ NEXUS_ParserBand_SetSettings(p_tune->parserBand, &parserBandSettings); *p_app_tune = p_tune; return eBAPP_RESULT_OK; } /** Summary: Release resources. **/ bapp_result_t bapp_tune_close(bapp_tune_t p_tune) { bapp_task_delete_queue(p_tune->queue); bapp_util_free(p_tune); return eBAPP_RESULT_OK; } /** Summary: Lock the frontend. **/ bapp_result_t bapp_tune_lock(bapp_tune_t p_tune, unsigned int freq_hz) { bapp_task_event_t event; bapp_task_reset_queue(p_tune->queue); bool locked = false; if (p_tune->fe_type == eFREQ_TABLE_NORTH_AMERICA_QAM) { NEXUS_Frontend_GetDefaultQamSettings(&p_tune->qamSettings); p_tune->qamSettings.frequency = freq_hz; p_tune->qamSettings.mode = NEXUS_FrontendQamMode_eAuto_64_256; p_tune->qamSettings.annex = NEXUS_FrontendQamAnnex_eB; p_tune->qamSettings.lockCallback.callback = bapp_tune_lock_callback; p_tune->qamSettings.lockCallback.context = p_tune; if (NEXUS_Frontend_TuneQam(p_tune->frontend, &p_tune->qamSettings) == BERR_SUCCESS) { locked = true; } } else { NEXUS_Frontend_GetDefaultVsbSettings(&p_tune->vsbSettings); p_tune->vsbSettings.frequency = freq_hz; p_tune->vsbSettings.mode = NEXUS_FrontendVsbMode_e8; p_tune->vsbSettings.lockCallback.callback = bapp_tune_lock_callback; p_tune->vsbSettings.lockCallback.context = p_tune; NEXUS_Frontend_TuneVsb(p_tune->frontend, &p_tune->vsbSettings); } #if 0 event = bapp_task_pend_event(p_tune->queue,p_tune->timeout_ms); if (eFE_EVENT_LOCK != (int)event) { return eBAPP_RESULT_TIMEOUT; } #else if (!locked) { return eBAPP_RESULT_TIMEOUT; } #endif return eBAPP_RESULT_OK; } /** Summary: Unlock the frontend. **/ bapp_result_t bapp_tune_unlock(bapp_tune_t p_tune) { NEXUS_Frontend_Untune(p_tune->frontend); return eBAPP_RESULT_OK; } /* Summary: Send frontend status event to the application. */ void bapp_tune_send_status(bapp_tune_t p_tune) { static NEXUS_FrontendQamStatus qamStatus; static NEXUS_FrontendVsbStatus vsbStatus; p_tune->signal_evt.type = eBAPP_EVENT_SIGNAL; p_tune->signal_evt.id = p_tune->fe_type; p_tune->signal_evt.ticks = bapp_util_get_ticks();; switch (p_tune->fe_type) { case eFREQ_TABLE_NORTH_AMERICA_QAM: NEXUS_Frontend_GetQamStatus(p_tune->frontend, &qamStatus); p_tune->signal_evt.lock = qamStatus.receiverLock; p_tune->signal_evt.SNR = qamStatus.snrEstimate; p_tune->signal_evt.power = qamStatus.dsChannelPower; p_tune->signal_evt.mode = qamStatus.settings.mode; p_tune->signal_evt.freq_hz = qamStatus.settings.frequency; bapp_post_event((bapp_task_event_t)&p_tune->signal_evt); break; case eFREQ_TABLE_NTIA_VSB: NEXUS_Frontend_GetVsbStatus(p_tune->frontend, &vsbStatus); p_tune->signal_evt.lock = vsbStatus.receiverLock; p_tune->signal_evt.SNR = vsbStatus.snrEstimate; p_tune->signal_evt.mode = vsbStatus.settings.mode; p_tune->signal_evt.freq_hz = vsbStatus.settings.frequency; bapp_post_event((bapp_task_event_t)&p_tune->signal_evt); break; default: break; } }