/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/

/*----------------------------------------------------------------------------*/
/*! @file u_sb_ntsc_eng.h 
 *  $RCSfile: $
 *  $Revision: #1 $
 *  $Date: 2015/11/10 $
 *  $Author: dtvbm11 $
 *  
 *  @par Description:
 *         This header file contains exported definitions and delcarations of
 *         SVL Builder NTSC engine.
 */
/*----------------------------------------------------------------------------*/ 
 
#ifndef _U_SB_NTSC_ENG_H_
#define _U_SB_NTSC_ENG_H_
/*----------------------------------------------------------------------------*/
/*! @defgroup groupMW_SB_NTSC_ENG NTSC Engine
 *
 *  @ingroup groupMW_SVL_BLDR
 *  @brief The ntsc engine module is the module of terrestrial/cable svl builder engine
 *  %MW Application API would be used by Application, lot of these APIs would
 *   be wrapped from Exported API. Using these APIs, application could create scan engine
 *   or start scan from the exported API of svl builder.
 *   
 *  @see groupMW_SVL_BLDR
 *  @{ 
 */
/*----------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------
                    include files
 ----------------------------------------------------------------------------*/
#include "u_common.h"
#include "u_handle.h"


/*-----------------------------------------------------------------------------
                    macros, defines, typedefs, enums
 ----------------------------------------------------------------------------*/

#define SB_NTSC_TER_ENG_NAME            "sb_ntsc_ter"  /**<  Define the NTSC terrestrial build engine name */
#define SB_NTSC_CAB_ENG_NAME            "sb_ntsc_cab"  /**<  Define the NTSCC cable build engine name */
                                    
#define SB_NTSC_FAKE_TSL_REC            ((UINT8) 1)

#define SB_NTSC_TER_SCAN_FIRST_CHANNEL  ((UINT16)  2)  /**<  MACRO to define the first channe no of air*/
#define SB_NTSC_TER_SCAN_LAST_CHANNEL   ((UINT16) 69)  /**<  MACRO to define the last channe no of air*/ 

#ifndef MW_SB_CABLE_LAST_CHANNEL
#define MW_SB_CABLE_LAST_CHANNEL             135   /**<  MACRO to define the last channe no of cable*/
#endif

#ifndef MW_SB_CABLE_FIRST_CHANNEL
#define MW_SB_CABLE_FIRST_CHANNEL             1    /**<  MACRO to define the first channe no of cable*/
#endif

#define SB_NTSC_CAB_SCAN_FIRST_CHANNEL  ((UINT16)   MW_SB_CABLE_FIRST_CHANNEL) /**<  MACRO to define the first channe no of cable*/
#define SB_NTSC_CAB_SCAN_LAST_CHANNEL   ((UINT16) MW_SB_CABLE_LAST_CHANNEL)  /**<  MACRO to define the last channe no of cable*/

/* This data type contains different configuration flags for the 
   scan process. */
typedef UINT32      SB_NTSC_CONFIG_T;    /**< Define the different configuration flags for the NTSC scan process*/

/** <  To support customer tuner LNA, when set this mask, means AP LNA cfg ON. else, OFF */
#define SB_NTSC_CONFIG_TUNER_LNA						(MAKE_BIT_MASK_32(0))


/*
 *  The structure SB_NTSC_OPEN_DATA_T is used as the argument
 *  pv_open_data of the API c_sb_open_builder()/x_sb_open_builder()
 *  when opening an SVL Builder with NTSC engine.
 *
 *  ui4_svl_id          The id of SVL to be loaded.
 *  ps_svl_name         The name of SVL to be loaded.
 *  ps_file_name        The file name from which the SVL/TSL
 *                      will be loaded.
 *  b_use_orig          A flag. When set to true, use the existed SVL,
 *                      instead of reloading it.  When set to false,
 *                      overwrite the SVL (if exists) by reloading.
 */
 /*------------------------------------------------------------------*/
/*! @struct SB_NTSC_OPEN_DATA_T
 *  @brief It is used as the argument pv_open_data of the API c_sb_open_builder()/x_sb_open_builder() when opening an SVL Builder with ATSC engine.
 *  @code
 *  typedef struct _SB_ATSC_OPEN_DATA_T
 *  {
 *      UINT16                          ui2_svl_id;
 *      CHAR*                           ps_svl_name;
 *      CHAR*                           ps_file_name;
 *      CHAR*                           ps_tuner_name;    
 *      BOOL                            b_use_orig;
 *  }   SB_NTSC_OPEN_DATA_T;
 *  @endcode
 *  @li@c  ui2_svl_id                                        - The id of SVL to be loaded.
 *  @li@c  ps_svl_name                                       - The name of SVL to be loaded.
 *  @li@c  ps_file_name                                      - The file name from which the SVL/TSL will be loaded.
 *  @li@c  ps_tuner_name                                     - The name of tuner to be connectted.
 *  @li@c  b_use_orig                                        - A flag. When set to true, use the existed SVL, instead of reloading it
 */
/*------------------------------------------------------------------*/
typedef struct _SB_NTSC_OPEN_DATA_T
{
    UINT16      ui2_svl_id;
    CHAR*       ps_svl_name;
    CHAR*       ps_file_name;
    CHAR*       ps_tuner_name;    
    BOOL        b_use_orig;
} SB_NTSC_OPEN_DATA_T;


/* NTSC scan type */
/*------------------------------------------------------------------*/
/*! @enum SB_NTSC_SCAN_TYPE_T
 *  @brief It contains different scan types that are used to initialize scan parameters.
 *  @code
 *  typedef enum
 *  {
 *     SB_NTSC_SCAN_TYPE_UNKNOWN = 0,
 *     SB_NTSC_SCAN_TYPE_FULL_MODE,
 *     SB_NTSC_SCAN_TYPE_QUICK_MODE,
 *     SB_NTSC_SCAN_TYPE_ADD_ON_MODE,
 *     SB_NTSC_SCAN_TYPE_SINGLE_RF_CHANNEL,
 *     SB_NTSC_SCAN_TYPE_RANGE_RF_CHANNEL,    
 *     SB_NTSC_SCAN_TYPE_NUM 
 *  } SB_NTSC_SCAN_TYPE_T;
 *  @endcode
 *  @li@c  SB_NTSC_SCAN_TYPE_UNKNOWN                         - Unknown.
 *  @li@c  SB_NTSC_SCAN_TYPE_FULL_MODE                       - Scan all frequency of all bands. It means from first scan index to last.
 *  @li@c  SB_NTSC_SCAN_TYPE_QUICK_MODE                      - Scan all frequency with skip the frequency that already scanned
 *  @li@c  SB_NTSC_SCAN_TYPE_ADD_ON_MODE                     - Add digital channels
 *  @li@c  SB_NTSC_SCAN_TYPE_SINGLE_RF_CHANNEL               - Single Rf scan
 *  @li@c  SB_NTSC_SCAN_TYPE_RANGE_RF_CHANNEL                - Range scan
 *  @li@c  SB_NTSC_SCAN_TYPE_NUM                             - The number of scan type.
 */
/*------------------------------------------------------------------*/
typedef enum
{
    SB_NTSC_SCAN_TYPE_UNKNOWN = 0,
    SB_NTSC_SCAN_TYPE_FULL_MODE,
    SB_NTSC_SCAN_TYPE_QUICK_MODE,
    SB_NTSC_SCAN_TYPE_ADD_ON_MODE,
    SB_NTSC_SCAN_TYPE_SINGLE_RF_CHANNEL,
    SB_NTSC_SCAN_TYPE_RANGE_RF_CHANNEL,    
    SB_NTSC_SCAN_TYPE_NUM /* number of scan types */
} SB_NTSC_SCAN_TYPE_T;

/* frequency plan */
#define SB_NTSC_TER_FREQ_PLAN       ((UINT8) 0x0)  /**<  MACRO to define the frequency plan of air program*/

#define SB_NTSC_CAB_FREQ_PLAN_STD   ((UINT8) 0x1)  /**<  MACRO to define the frequency plan of cable*/
#define SB_NTSC_CAB_FREQ_PLAN_IRC   ((UINT8) 0x2)  /**<  MACRO to define the frequency plan of cable*/
#define SB_NTSC_CAB_FREQ_PLAN_HRC   ((UINT8) 0x4)  /**<  MACRO to define the frequency plan of cable*/
#define SB_NTSC_CAB_FREQ_PLAN_AUTO  ((UINT8) 0x7)  /**<  MACRO to define the frequency plan of cable*/

/*
    callback to calculate the steps of frequency offset
*/

typedef INT16 (*x_sb_ntsc_calc_freq_offset_fct) (
      UINT32            ui4_freq,
      UINT32            ui4_central_freq);

/*
 *  The structure SB_NTSC_SCAN_DATA_T is used as the argument 
 *  pv_scan_data of the API x_sb_start_scan() when scaning 
 *  a media.
 *
 *  e_scan_type     Specifies the way to scan.
 *
 *  ui4_scan_info   Contains the required scan information. 
 * 
 *                  The most significant two bytes indicate the index where
 *                  an engine should start scan while the least significant
 *                  two bytes indicate the index where an engine should 
 *                  stop scan.
 *
 *                  For SB_NTSC_SCAN_TYPE_FULL_MODE, SB_NTSC_SCAN_TYPE_QUICK_MODE,
 *                  SB_NTSC_SCAN_TYPE_ADD_ON_MODE, and 
 *                  SB_NTSC_SCAN_TYPE_SINGLE_RF_CHANNEL and
 *                  SB_NTSC_SCAN_TYPE_RANGE_RF_CHANNELmodes, only the most 
 *                  significant two bytes are taken.       
 *
 *  ps_tuner_name   An optional parameter.  If not NULL, it will be
 *                  used to perform the connection routines. 
 */
 
 /*------------------------------------------------------------------*/
/*! @struct SB_NTSC_SCAN_DATA_T
 *  @brief The sub information for the range of scan index in NTSC scan process.
 *  @code
 *  typedef struct _SB_NTSC_SCAN_DATA_T
 * {
 *   SB_NTSC_SCAN_TYPE_T     e_scan_type;
 *   UINT16                  ui2_start_idx;
 *   UINT16                  ui2_end_idx;
 *   UINT8                   ui1_freq_plan;
 *  } SB_NTSC_SCAN_DATA_T;
 *  @endcode
 *  @li@c  e_scan_type                                      -Specifies the way to scan.
 *  @li@c  ui2_start_scan_idx                               -The start index in this scan process.
 *  @li@c  ui2_end_scan_idx                                 -The end index in this scan process.
 *  @li@c  ui1_freq_plan                                    -The frequency plan for NTSC standard, IRC, HRC
 */
/*------------------------------------------------------------------*/
typedef struct _SB_NTSC_SCAN_DATA_T
{
    HANDLE_T                h_svctx;   
    HANDLE_T                h_svctx_tv_scart_bypass;
    HANDLE_T                h_svctx_monitor_scart_bypass;
    SB_NTSC_SCAN_TYPE_T     e_scan_type;
    UINT16                  ui2_start_idx;
    UINT16                  ui2_end_idx;
    UINT8                   ui1_freq_plan;
	SB_NTSC_CONFIG_T        t_eng_cfg_flag;                  
} SB_NTSC_SCAN_DATA_T;

/*----------------------------------------------------------------------------*/
/*! @} */                                        /* end of groupMW_SB_NTSC_ENG*/
/*----------------------------------------------------------------------------*/

#endif /* _U_SB_NTSCs_ENG_H_ */
