/*************************************************************************** * Copyright (c) 2012, Broadcom Corporation * All Rights Reserved * Confidential Property of Broadcom Corporation * * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. * * $brcm_Workfile: $ * $brcm_Revision: $ * $brcm_Date: $ * * Module Description: tuner test module * * Revision History: * * $brcm_Log: $ * * ***************************************************************************/ #include "bstd.h" #include "bkni.h" #include "bdbg.h" #include "serial.h" #include "input_parser.h" #include "bcrc32.h" #include "bsettop.h" #include "bsettop_tuner.h" #include "bsettop_smessage.h" BDBG_MODULE(test_tuner); #define MAX_MSG_BUFFERS 0x400 #define MSG_BUFFER_SIZE 0x1000 unsigned char filter_msg_buffer[MSG_BUFFER_SIZE]; void *filter_msg_callback(void *context, size_t data_size) { uint8_t *msg; uint32_t crc, i; msg = (uint8_t*)filter_msg_buffer; /* check syntax indicator to see if we need to do crc */ if(0 == (msg[1] & 0x80)){ crc = bcrc32(msg, data_size); if(0 != crc){ BDBG_ERR(("crc error detected")); } } BDBG_ERR(("msg %hx size %u", msg[0], data_size)); //#define DUMP_MSG #ifdef DUMP_MSG for (i = 0; i < 16; i++) { BKNI_Printf("[%3d]=0x%02x\n", i, msg[i]); } #endif return msg; } static btuner_t tuner = NULL; static btuner_params tuner_params; static smessage_stream_t filter_msg = NULL; static unsigned int freq_khz = 549000; /* 549 MHz */ bool qam_tuner_init(void) { if (tuner) return true; tuner = btuner_open(0); if (NULL == tuner) { BKNI_Printf("btuner_open failed"); return false; } return true; } bool qam_tune(unsigned int freq) { if (NULL == tuner) { BKNI_Printf("tuner is not initialized"); return false; } btuner_params_init(&tuner_params, tuner); tuner_params.wait_for_lock = false; tuner_params.fecMode = eFEC_ANNEX_B; tuner_params.qamMode = eQAM_Scan; freq_khz = freq / 1000; if (btuner_tune(tuner, freq_khz * 1000, &tuner_params) < 0) { BKNI_Printf("btuner_tune failed\n"); return false; } return true; } bool qam_get_status(void) { btuner_status status; if (NULL == tuner) { BKNI_Printf("tuner is not initialized"); return false; } btuner_get_status(tuner, &status); BKNI_Printf("tuner is %s on frequency %d KHz\n", status.lock ? "locked" : "not locked", freq_khz); return true; } bool qam_start_message(unsigned short pid) { bresult bres; smessage_stream_params_t params; /* if started already */ if (filter_msg) return true; filter_msg = smessage_open(smessage_format_psi); if (NULL == filter_msg) { BKNI_Printf("smessage_open failed"); return false; } smessage_stream_params_init(¶ms, NULL); params.band = TUNER_BAND; params.pid = pid; params.buffer = filter_msg_buffer; params.buffer_size = MSG_BUFFER_SIZE; params.crc_disabled = true; params.data_ready_callback = filter_msg_callback; params.overflow = NULL; //params.priv = (void *)4; bres = smessage_start(¶ms, filter_msg); if (b_ok != bres) { BDBG_ERR(("%s:%d",__FILE__, __LINE__)); smessage_close(filter_msg); filter_msg = NULL; return false; } return true; } bool qam_stop_message(void) { if (!filter_msg) { BKNI_Printf("message filtering is not started yet"); return false; } smessage_stop(filter_msg); smessage_close(filter_msg); filter_msg = NULL; return true; }