/* 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: chi.yu $
 * $Date: 2015/07/20 $
 * $RCSfile: dmx_pcr_hal.h,v $
 * $Revision: #2 $
 *
 *---------------------------------------------------------------------------*/

/** @file dmx_pcr_hal.h
 *  This header file of dmx pcr hal 
 */


#ifndef _DMX_PCR_HAL_H_
#define _DMX_PCR_HAL_H_
#include "x_typedef.h"
#include "x_debug.h"

//return value
#define STC_HAL_OK                     (0)
#define STC_HAL_FAIL                   (1)
#define STC_HAL_INV_ARG                (2)
#define STC_HAL_INTERNAL_ERR           (3)
#define STC_HAL_NOT_IMPL               (4)

#define STC_HAL_TRACE(fmt...)          LOG(11, fmt)
#define STC_MK_RET(ret)                ((__LINE__<<8)|(ret))     
#define STC_RET(ret)                   ((ret)&0x000000FF)     
#define STC_MK_REALD_DATA(tag,offset)  (((tag)<<16)|(offset))

#define STC_NULL_HANDLE                ((void *)0)
typedef VOID * STC_HANDLE_T;

typedef enum
{
    STC_HAL_ISR_CLR,
    STC_HAL_SET_STC,
    STC_HAL_ERR_CLR,
    STC_HAL_NERR_CLR,
    STC_HAL_TYPE_MAX
} STC_HAL_TYPE_T;

typedef enum
{
    STC_HAL_STATUS,
    STC_HAL_PCR_DIFF,
    STC_HAL_GET_STC,
    STC_HAL_GET_PCR,
    STC_HAL_GET_SNAP_STC,
    STC_HAL_GET_STCEXT,
    STC_HAL_GTYPE_MAX
} STC_HAL_GET_TYPE_T;

typedef enum
{
    DMX_PCR_HAL_ISTYPE_MAX
} DMX_PCR_HAL_IS_TYPE_T;

typedef struct _STC_HAL_OBJECT_T
{
    //common
    UINT8   u1Id;
    UINT8   u1Used;
    UINT8   u1Status;
    BOOL    fgDmxStc;
    BOOL    fgEnable;
    VOID*   pvHost;
   
    //function
    UINT32      (*Reset)     (struct _STC_HAL_OBJECT_T *);
    UINT32      (*Enable)    (struct _STC_HAL_OBJECT_T *);
    UINT32      (*Disable)   (struct _STC_HAL_OBJECT_T *);
    UINT32      (*Set)       (struct _STC_HAL_OBJECT_T *, STC_HAL_TYPE_T, VOID *);
    UINT32      (*Get)       (struct _STC_HAL_OBJECT_T *, STC_HAL_GET_TYPE_T, VOID *);
    UINT32      (*Is)        (struct _STC_HAL_OBJECT_T *, DMX_PCR_HAL_IS_TYPE_T, VOID *);

    UINT8 begin;
    //local 
    UCHAR ucDmxPcrId;

    UINT8 end;
}STC_HAL_OBJECT_T;

typedef struct 
{
    UINT8 u1Data;
    VOID * pvData;
} STC_OBJCfG_T;

typedef struct 
{
    UINT32 u4NoErrFst;
    UINT32 u4NoErrSnd;
} STC_HAL_STATUS_T;

typedef struct 
{
    UINT32 u4Lowbits;
    UINT32 u4Highbits;
} STC_HAL_PCR_DIFF_T;

typedef union _DMX_DELTA_UNION_T
{
    INT64 i8Delta;
    UINT32 au4Delta[2];
} DMX_DELTA_UNION_T;

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

VOID STC_HAL_Init(VOID);
STC_HANDLE_T STC_HAL_Open(VOID* pvArg);
UINT32 STC_HAL_Enable(STC_HANDLE_T hStc);
UINT32 STC_HAL_Disable(STC_HANDLE_T hStc);
UINT32 STC_HAL_Set(STC_HANDLE_T hStc, STC_HAL_TYPE_T eType, VOID *pvArg);
UINT32 STC_HAL_Get(STC_HANDLE_T hStc, STC_HAL_GET_TYPE_T eType, VOID *pvArg);
UINT32 STC_HAL_Reset(STC_HANDLE_T hStc);
STC_HAL_OBJECT_T * STC_HW_Get_Object(UINT8 u1Idx);


#endif /*_DMX_PCR_HAL_H_*/

