/* 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.
 *
 *****************************************************************************/

/*-----------------------------------------------------------------------------
 *
 * $Author: danning.wang $
 * $Date: 2016/01/26 $
 * $RCSfile: dmx_emu_if.h,v $
 * $Revision: #2 $
 *
 *---------------------------------------------------------------------------*/

/** @file dmx_emu_if.h
 *  Interface of demux emulation driver
 */


#ifndef TLV_EMU_IF_H
#define TLV_EMU_IF_H

//-----------------------------------------------------------------------------
// Include files
//-----------------------------------------------------------------------------

#include "x_lint.h"

LINT_EXT_HEADER_BEGIN

#include "tlv_if.h"
#include "tlv_mm.h"
LINT_EXT_HEADER_END


//-----------------------------------------------------------------------------
// Configurations
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Constant definitions
//-----------------------------------------------------------------------------
typedef enum
{
    FULL_PUSH_MODE = 0,
    HALF_PULL_PUSH_MODE = 1,
    FULL_PULL_MODE = 3
} PUL_MODE_T;

typedef enum
{
    PACKET_TLV_SI = 0,
    TLV_IPv6,
    TLV_COMPRESSED_IPv6,
    TLV_TYPE_NTP,
    TLV_ALL,
} TLV_PACKET_TYPE_T;

typedef enum
{
    TLV_TEST_RECEIVER = 0,                              //
    TLV_TEST_SI,                                        //TLV SI TEST
    TLV_TEST_NTP,                                           //TLV NTP TEST  
    TLV_TEST_IPUDP_FILTER,                              //TLV IP FIlter TEST
    TLV_TEST_CID_FILTER,                                    //TLV CID FItler TEST
    TLV_TEST_MMTP_PID,                                  //PID Filter
    TLV_TEST_INTEGRATE_TEST,                                //TLV Framer Integrate TEST
    TLV_TEST_FE,
    TLV_TEST_PVR,
} TLV_TEST_TYPE_T;


typedef enum
{
    TLV_TEST_CAPTURE_ALL = 0,
    TLV_TEST_CAPTURE_VIDEO_ES,
    TLV_TEST_CAPTURE_AUDIO_ES,
    TLV_TEST_CAPTURE_CAPTION_ES,
    TLV_TEST_CAPTURE_TLV_SI,
    TLV_TEST_CAPTURE_MMT_SI,
    TLV_TEST_CAPTURE_APPLICATION,
} TLV_CAPTURE_TYPE_T;

typedef enum
{
    DATA_SRC_DEMOD = 0,
    DATA_SRC_DDI,   
} TLV_DATA_SRC_T;


typedef enum
{
    TLV_UCODE_TEST_TLV_SI = 0,
    TLV_UCODE_TEST_MMT_SI,
    TLV_UCODE_TEST_VIDEO_ES,
    TLV_UCODE_TEST_AUDIO_ES,
    TLV_UCODE_TEST_CAP,
    TLV_UCODE_TEST_APP,
    TLV_UCODE_TEST_PVR,
}TLV_EMU_UCODE_TEST_TYPE_T;

//-----------------------------------------------------------------------------
// Macro definitions
//-----------------------------------------------------------------------------
#define FPGA
//-----------------------------------------------------------------------------
// Prototype  of inter-file functions
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Prototype  of public functions
//-----------------------------------------------------------------------------

//---------------------------------------------------------------------
/// Emulation
//---------------------------------------------------------------------

#ifdef FPGA
extern UINT32 UDVT_IF_OpenFile(const char *filename,const char *mode);
extern UINT32 UDVT_IF_ReadFile(void *ptr,UINT32 size,UINT32 count,UINT32 stream);
extern UINT32 UDVT_IF_WriteFile(void *ptr,UINT32 size,UINT32 count,UINT32 stream);
extern UINT32 UDVT_IF_GetFileLength(UINT32 stream);
extern UINT32 UDVT_IF_CloseFile(UINT32 stream);
extern UINT32 UDVT_IF_SeekFile(UINT32 stream,INT32 offset,UINT32 origin);

extern UINT32 DMX_UDVT_IF_OpenFile(const char *filename,const char *mode);
extern UINT32 DMX_UDVT_IF_ReadFile(void *ptr,UINT32 size,UINT32 count,UINT32 stream);
extern UINT32 DMX_UDVT_IF_WriteFile(void *ptr,UINT32 size,UINT32 count,UINT32 stream);
extern UINT32 DMX_UDVT_IF_GetFileLength(UINT32 stream);
extern UINT32 DMX_UDVT_IF_CloseFile(UINT32 stream);
extern UINT32 DMX_UDVT_IF_SeekFile(UINT32 stream,INT32 offset,UINT32 origin);
#else
extern struct file * DMX_UDVT_IF_OpenFile(const char *filename,const char *mode);
extern UINT32 DMX_UDVT_IF_ReadFile(void *ptr,UINT32 size,UINT32 count, struct file *filep);
extern UINT32 DMX_UDVT_IF_WriteFile(void *ptr,UINT32 size,UINT32 count,struct file *filep);
extern UINT32 DMX_UDVT_IF_GetFileLength(struct file *filep);
extern UINT32 DMX_UDVT_IF_CloseFile(struct file *filep);
extern UINT32 DMX_UDVT_IF_SeekFile(struct file *filep,INT32 offset,UINT32 origin);

#endif

EXTERN BOOL TLV_EMU_TEST_SET_ES_PID(UINT8 u1TsIdx, UINT8 u1IpIdx, UINT16 u2VidPid, UINT16 u2AudPid, UINT16 u2CapPid);
EXTERN BOOL TLV_EMU_TEST_SET_TLV_SI(UINT8 u1TsIdx, UINT8 u1TableId, UINT8 u1Version);
EXTERN BOOL TLV_EMU_TEST_SET_MMTP_SI(UINT8 u1TsIdx, UINT8 u1IpIdx, UINT16 u2Pid, UINT8 u1TableId, UINT8 u1Version);
EXTERN BOOL TLV_EMU_TEST_SET_TLV_NTP(UINT8 u1TsIdx);

EXTERN BOOL TLV_EMU_TEST_Integrate(UINT8 u1SrcType, UINT8 u1TsIdx, UINT32 u4Offset);
EXTERN BOOL TLV_EMU_TEST_DEMOD(UINT8 u1TsIdx, TLV_CAPTURE_TYPE_T eType, UINT32 u2Pid);

EXTERN BOOL TLV_EMU_TEST_PVR(UINT8 u1TsIdx, UINT32 u4Offset);
EXTERN BOOL TLV_EMU_TEST_SET_PVR_PID(UINT8 u1TsIdx, UINT8 u1IpIdx, UINT16 u2Pid0, UINT16 u2Pid1, UINT16 u2Pid2, UINT16 u2Pid3);


EXTERN BOOL TLV_EMU_FE_TEST(UINT8 u1TsIdx, BOOL fgBypassMixSync, BOOL fgBypassIpFilter, BOOL fgBypassPidFilter);

EXTERN BOOL TLV_EMU_DDI_Framer_FUNCTION_TEST(TLV_TEST_TYPE_T eType, UINT8 u1TsIdx, BOOL fgBypassMixSync, BOOL fgBypassIpFilter, BOOL fgBypassPidFilter);
EXTERN BOOL TLV_EMU_NTP_LeapSecond_TEST(UINT8 u1Type, UINT8 u1TsIdx, UINT8 u1StcId, TLV_NTP_MODE_T eNtpMode);
EXTERN BOOL TLV_EMU_SMART_PCR_TEST(UINT8 u1TsIdx, BOOL fgEnable, BOOL fgStepZero, BOOL fg16MCLK);
EXTERN BOOL TLV_EMU_Descramble_TEST(UINT8 u1TsIdx);

EXTERN BOOL TLV_EMU_DDI_Framer_TEST(TLV_PACKET_TYPE_T eTlvType, UINT8 u1TsIdx, BOOL fgBypassMixSync, BOOL fgBypassIpFilter, BOOL fgBypassPidFilter);

EXTERN BOOL TLV_Construct_GoldenPattern(TLV_TEST_TYPE_T eType, UPTR *pu4TlvGoldenSreamAddr, UINT32 *pu4TlvGoldenSize,
                                                        UINT32 *pu4SizeArray, UINT32 *pu4PacketCount);

EXTERN BOOL TLV_Construct_TestStream(TLV_TEST_TYPE_T eType, UPTR *pu4TlvSreamAddr, UINT32 *pu4TlvStreamSize);

EXTERN BOOL TLV_Ucode_Construct_TestStream(TLV_EMU_UCODE_TEST_TYPE_T eTestType, UPTR *pu4TlvStreamAddr, UINT32 *pu4TlvStreamSize);
EXTERN BOOL TLV_EMU_UCODE_TLV_SI_TEST(UINT8 u1TsIdx, UINT8 u1TableId, BOOL fgToCaOut);
EXTERN BOOL TLV_Ucode_Test_SI_Golden(UINT8 u1TableId, UPTR *pu4TlvGoldenData, UINT32 *pu4TlvGoldenSize);

EXTERN BOOL TLV_EMU_UCODE_MMT_SI_TEST(UINT8 u1TsIdx, UINT8 u1TableId, UINT8 u1Version, BOOL fgToCaOut);
EXTERN BOOL TLV_Ucode_Test_MMT_SI_Golden(UINT8 u1TableId, UINT8 u1Version, UPTR *pu4TlvGoldenData, UINT32 *pu4TlvGoldenSize);

EXTERN BOOL TLV_EMU_UCODE_VIDEO_ES_TEST(UINT8 u1TsIdx, BOOL fgToCaOut);
EXTERN BOOL TLV_EMU_UCODE_AUDIO_ES_TEST(UINT8 u1TsIdx, BOOL fgToCaOut);
EXTERN BOOL TLV_EMU_UCODE_CAPTION_TEST(UINT8 u1TsIdx, BOOL fgToCaOut);

EXTERN BOOL TLV_EMU_PVR_TEST(UINT8 u1TsIdx, BOOL fgToCaOut, BOOL fgBypassIpFilter, BOOL fgBypassPidFIlter);

EXTERN BOOL TLV_EMU_PVR_Encrypt_TEST(UINT8 u1TsIdx);
EXTERN BOOL TLV_EMU_PVR_Descramble_ENCRYPT_TEST(UINT8 u1TsIdx);

EXTERN BOOL TLV_DMX_EMU_PSI_Test(UINT8 u1TsIdx);

#endif  // DMX_EMU_IF_H

