/**
 * @file hv_comm_Timer.h
 * @brief Header file of mute module.
 *
 * @verbatim
 * ==============================================================================
 *                        ##### How to use #####
 * ==============================================================================
 *
 * @endverbatim
 *
 * @author HiView SoC Software Team
 * @version 1.0.0
 * @date 2022-08-22
 */

#ifndef _HV_COMMON_TIMER_H
#define _HV_COMMON_TIMER_H

#include "hv_vos_Comm.h"
#include "hv_comm_DataType.h"
#include "hv_comm_Event.h"
#ifdef __cplusplus
extern "C" {
#endif

typedef enum
{
    SYS_EVENT_TIMER_START                 = 0x4000, /*Defined the timer event start from 0x4000*/
    /* Here add the system event timer enum */
    SYS_EVENT_TIMER_POWR_BEGIN            = SYS_EVENT_TIMER_START,
    SYS_EVENT_TIMER_TYPEC_PARSE_TIME_OUT  = 0x4001,
    SYS_EVENT_TIMER_POWER_SIGNAL_CHECK    = 0x4002,
    SYS_EVENT_TIMER_POWR_END              = 0x4003,
    
    /*SystemTask Inputport module timer begin*/
    SYS_EVENT_TIMER_IP_BEGIN              = 0x4004,
    SYS_EVENT_TIMER_DP0_BEGIN             = SYS_EVENT_TIMER_IP_BEGIN,
    SYS_EVENT_TIMER_DP0_HPD_TIMEOUT       = 0x4005,
    SYS_EVENT_TIMER_DP0_TIMING_CHECK      = 0x4006,
    SYS_EVENT_TIMER_DP0_TRAINING_NG       = 0x4007,
    SYS_EVENT_TIMER_DP0_AUDIO_CHECK       = 0x4008,
    SYS_EVENT_TIMER_DP0_END               = 0x4009,

    SYS_EVENT_TIMER_DP1_BEGIN             = 0x400A,
    SYS_EVENT_TIMER_DP1_HPD_TIMEOUT       = SYS_EVENT_TIMER_DP1_BEGIN,
    SYS_EVENT_TIMER_DP1_TIMING_CHECK      = 0x400B,
    SYS_EVENT_TIMER_DP1_TRAINING_NG       = 0x400C,
    SYS_EVENT_TIMER_DP1_AUDIO_CHECK       = 0x400D,
    SYS_EVENT_TIMER_DP1_END               = 0x400E,
    
    SYS_EVENT_TIMER_HDMI0_BEGIN           = 0x400F,
    SYS_EVENT_TIMER_HDMI0_WAITSYNC        = SYS_EVENT_TIMER_HDMI0_BEGIN,
    SYS_EVENT_TIMER_HDMI0_SYNCOK          = 0x4010,
    SYS_EVENT_TIMER_HDMI0_HPD_SET_HIGH    = 0x4011,
    SYS_EVENT_TIMER_HDMI0_WAIT_EQ_DONE    = 0x4012,
    SYS_EVENT_TIMER_HDMI0_FASTLCK         = 0x4013,
    SYS_EVENT_TIMER_HDMI0_HDCPSYNC        = 0x4014,
    SYS_EVENT_TIMER_HDMI0_END             = 0x4015,
    SYS_EVENT_TIMER_HDMI0_RATIO           = SYS_EVENT_TIMER_HDMI0_END,

    SYS_EVENT_TIMER_HDMI1_BEGIN           = 0x4016,
    SYS_EVENT_TIMER_HDMI1_WAITSYNC        = SYS_EVENT_TIMER_HDMI1_BEGIN,
    SYS_EVENT_TIMER_HDMI1_SYNCOK          = 0x4017,
    SYS_EVENT_TIMER_HDMI1_HPD_SET_HIGH    = 0x4018,
    SYS_EVENT_TIMER_HDMI1_WAIT_EQ_DONE    = 0x4019,
    SYS_EVENT_TIMER_HDMI1_FASTLCK         = 0x401A,
    SYS_EVENT_TIMER_HDMI1_HDCPSYNC        = 0x401B,
    SYS_EVENT_TIMER_HDMI1_END             = 0x401C,
    SYS_EVENT_TIMER_HDMI1_RATIO           = SYS_EVENT_TIMER_HDMI1_END,

    SYS_EVENT_TIMER_IP_END                = 0x401D,
    /*SystemTask Inputport module timer end*/
    SYS_EVENT_TIMER_HDCP0                 = 0x401E,
    SYS_EVENT_TIMER_HDCP1                 = 0x401F,

    /*SystemTask Channel module timer begin*/
    SYS_EVENT_TIMER_CHANNEL_BEGIN         = 0x4020,
    SYS_EVENT_TIMER_CH_MAIN_SERACH_OUT    = SYS_EVENT_TIMER_CHANNEL_BEGIN,
    SYS_EVENT_TIMER_CH_SUB_SERACH_OUT     = 0x4021,
    SYS_EVENT_TIMER_CH_MAIN_PERIOD_SERACH = 0x4022,
    SYS_EVENT_TIMER_CH_SUB_PERIOD_SERACH  = 0x4023,
    SYS_EVENT_TIMER_CH_MAIN_AV_STABLE     = 0x4024,
    SYS_EVENT_TIMER_CH_SUB_AV_STABLE      = 0x4025,
    SYS_EVENT_TIMER_MAIN_NO_SIGNAL_TIMER  = 0x4026,
    SYS_EVENT_TIMER_SUB_NO_SIGNAL_TIMER   = 0x4027,
    SYS_EVENT_TIMER_MAIN_MUTE_TIMER       = 0x4028,
    SYS_EVENT_TIMER_SUB_MUTE_TIMER        = 0x4029,
    SYS_EVENT_TIMER_MAIN_AUDIO_MUTE_TIMER = 0x402A,
    SYS_EVENT_TIMER_SUB_AUDIO_MUTE_TIMER  = 0x402B,
    SYS_EVENT_TIMER_BURN_IN_PERIOD_CHECK_TIMER = 0x402C,
    SYS_EVENT_TIMER_AUDIO_DELAY           = 0x402D,
    SYS_EVENT_TIMER_DATABASE_SYNC_TIMER   = 0x402E,    /*周期性判断*/
    SYS_EVENT_TIMER_AV_WATCHDOG_TIMER     = 0x402F,
    SYS_EVENT_TIMER_MAIN_AUDIO_FS_CHECK_TIMER  = 0x4030,
    SYS_EVENT_TIMER_SUB_AUDIO_FS_CHECK_TIMER  = 0x4031,
    SYS_EVENT_TIMER_CHANNEL_TIMER_END     = 0x4032,
    /*SystemTask Channel module timer end*/

    /*SystemTask Pannel module timer begin*/
    SYS_EVENT_TIMER_PANEL_BEGIN           = 0x4033,
    SYS_EVENT_TIMER_PANEL_POWER_ON        = SYS_EVENT_TIMER_PANEL_BEGIN,  /* Panel开始上电 */
    SYS_EVENT_TIMER_PANEL_DATA_ON         = 0x4034,                       /* Panel上电完成，开始传输数据 */
    SYS_EVENT_TIMER_PANEL_BLK_ON          = 0x4035,                       /* 开始传输有效数据，背光上电 */
    SYS_EVENT_TIMER_PANEL_BLK_OFF         = 0x4036,                       /* 关闭背光*/
    SYS_EVENT_TIMER_PANEL_DATA_OFF        = 0x4037,                       /* 关闭数据*/
    SYS_EVENT_TIMER_PANEL_POWER_OFF       = 0x4038,                       /* Panel断电*/
    SYS_EVENT_TIMER_CHECK_TRAINING_STATUS = 0x4039,                       /* 等待KTX PLL 锁定*/
    SYS_EVENT_TIMER_PANEL_IDLE_PATT       = 0x403A,                       /* 发送idle pattern*/
    SYS_EVENT_TIMER_SPI_BACK_LIGHT        = 0x403B,                       /* SPI_BACK_LIGHT*/
    SYS_EVENT_TIMER_PANEL_END             = 0x403C,                       /*SystemTask Pannel module timer end*/
    SYS_EVENT_TIMER_END                   = 0x403D,
    /*发送到SystemTask end*/

    /*发送到OsdTask begin*/
    OSD_EVENT_TIMER_START                 = 0x403E,
    OSD_EVENT_TIMER_KEY_REPEAT            = OSD_EVENT_TIMER_START,
    OSD_EVENT_TIMER_KEY_HOLD              = 0x403F,
    OSD_EVENT_TIMER_AUTO_CLOSE            = 0x4040,
    OSD_EVENT_TIMER_AUTO_REFRESH          = 0x4041,
    OSD_EVENT_TIMER_LOGO_HIDE             = 0x4042,
    OSD_EVENT_TIMER_REMIND                = 0x4043,
    OSD_EVENT_TIMER_AUTO_TEST             = 0x4044,
    OSD_EVENT_TIMER_END                   = 0x4045,
    /*发送到OsdTask end*/

    /*发送到EventHubTask begin*/
    EVENT_HUB_TIMER_START                 = 0x4046,
    EVENT_HUB_TIMER_END                   = 0x4047,
    /*发送到EventHubTask End*/

    /*周期检测SDR或者ucBrightness*/
    EVENT_POWER_LOAD_CHECK_TIMER        = 0x4048,    /*周期性判断*/

    /*在timer任务中 回调不会 将timeout消息发送给任务!!!*/
    EVENT_TIMER_MAX = 0x4049, //0x4049 - 0x4000 = 72个在裸机下TIMER_NUM对应

 
}TIMER_EVENT_E;

typedef struct _HwTimerParams HvCommonHwTimer;
typedef void (*HV_HW_TMR_CALLBACK)(HvCommonHwTimer* pstTimer);

typedef struct _HwTimerParams{
    const CHAR8 * name;                  /* Hardware timer name for debug */
    UINT64 periodMs;                /* Hardware timer period */
    HV_HW_TMR_CALLBACK callbackFn;  /* Hardware timer callback function */
    TIMER_EVENT_E timerEvent;       /* Hardware timer eventID that send to conrresponding task */
    HvCommonHwTimer* next;            /* Hardware timer next pointer */
    UINT32 param;                   /* Hardware timer param */
} HwTimerParams;


void Hv_Common_Timer_DispatchEvent(VOID* pvArgument, USHORT16 usTimerId);
/**
 * @brief Create Hardware timer instance.
 * @param[in] timer init struct parm.
 * @return malloc timer instance.
 */
HvCommonHwTimer* Hv_Common_HwTimer_Create(HvCommonHwTimer* pstTimer);

/**
 * @brief Delete Hardware timer instance.
 * @param[in] timer instance brefore creating.
 * @return None.
 */
void Hv_Common_HwTimer_Delete(HvCommonHwTimer* pstTimer);

/**
 * @brief Start Hardware timer instance.
 * @param[in] timer instance brefore creating.
 * @return None.
 */
void Hv_Common_HwTimer_Start(HvCommonHwTimer* pstTimer);

/**
 * @brief Stop Hardware timer instance.
 * @param[in] timer instance brefore creating.
 * @return None.
 */
void Hv_Common_HwTimer_Stop(HvCommonHwTimer* pstTimer);

/**
 * @brief Test function for Demo.
 * @param[in] None.
 * @return None.
 */
void Hv_Test_Timer_Event();

#ifdef HV_SCALER_DEBUG_VERSION
CHAR8* TimerEventIDConvert(TIMER_EVENT_E enEventType);
#endif

#ifdef __cplusplus
}
#endif
#endif /* _HV_COMMON_TIMER_H */
