/*
 * @file hv_pm51_driver_Timer.h
 * @brief Header file of internal and external timer driver.
 *
 * @verbatim
 * ==============================================================================
 *                        ##### How to use #####
 * ==============================================================================
 * (+) Use ()
 *
 * @endverbatim
 * @author HiView SoC Software Team
 * @version 1.0.0
 * @date 2023-03-01
 */

#ifndef __HV_PM51_DRIVER_TIMER_H__
#define __HV_PM51_DRIVER_TIMER_H__

#include "hv_pm51_Base.h"
#include "hv_pm51_Setting.h"
#include "hv_pm51_driver_Interrupt.h"

typedef enum _TimerEn
{
    INNERTIMER0 = 0,                /* conter = 26.6M clk */
    INNERTIMER1,                    /* conter = 26.6M clk */
    INNERTIMER2,                    /* no use */
    EXTIMER0,                       /* default divider setting, conter+1 = 10us */
    EXTIMER1,                       /* default divider setting, conter+1 = 1ms */
    TIMERNUM
}TimerEn;

typedef enum _TimerMode
{
    E_TIMER_MODE_NULL,
    E_13BIT,
    E_16BIT,
    E_AUTOLOAD,
    E_DIVISION
}TimerMode;

/**
 * @brief This function init all timer, after this function all timer disabled
 * @return None. 
*/
void Hv_PM51_Timer_Init(TimerEn enTimerSel, TimerMode enMode);

/**
 * @brief This function set a timer for an interval, timer interrupt signal will auto clear by hardware
 * @param [in] enTimerSel        Timer index want to set
 * @param [in] enInterval        Timer interval in ticks
 * @return HV_TRUE: successfully  HV_FALSE:  failed. 
*/
iBOOL Hv_PM51_Timer_Set(TimerEn enTimerSel, USHORT16 usInterval);

/**
 * @brief This function set a timer for an interval in milliseconds, timer interrupt signal will auto clear by hardware
 * @param [in] enTimerSel         Timer index want to set
 * @param [in] enInterval        Timer interval in ms(except external timer1 in usInterval*100 ms)
 * @return HV_TRUE: successfully  HV_FALSE:  failed. 
*/
iBOOL Hv_PM51_Timer_SetMs(TimerEn enTimerSel, USHORT16 usInterval);
    
/**
 * @brief This function clear specified timer, after this function, the timer will never be trigged
 * @param [in] enTimerSel         Timer index want to clear
 * @return None. 
*/
void Hv_PM51_Timer_Clear(TimerEn enTimerSel);

/**
 * @brief This function clear specified timer, after this function, the timer will never be trigged
 * @param [in] enTimerSel         Timer index want to get
 * @param [out] pulInterval       return the interval of timer
 * @return HV_TRUE: successfully  HV_FALSE:  failed.
*/
iBOOL Hv_PM51_Timer_Get(TimerEn enTimerSel, ULONG32 *pulInterval);

#endif
