/**
  ******************************************************************************
  * @file    pit32_drv.h
  * @author  Product application department
  * @version V1.0
  * @date    2020.02.25
  * @brief   Header file of PIT32 HAL module.
  * 
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __PIT32_DRV_H
#define __PIT32_DRV_H

#ifdef __cplusplus
extern "C"
{
#endif

/* Includes ------------------------------------------------------------------*/
#include "drv_reg.h"

#ifdef FILE_OUT
/**@defgroup DRV 3 HAL driver
  *
  *@{
  */

/** @defgroup DRV_PIT32 PIT32
  *
  *@{
  */
#endif
/*** 宏定义 *******************************************************************/
#ifdef FILE_OUT
/** @defgroup DRV_PIT32_Exported_Macros Exported Macros
  *
  * @{
  */
#endif

//PCSR
#define _pit32_start(pit)                 _bit_set(pit->PCSR, PIT_PCSR_EN)          /*!< PIT功能启动*/
#define _pit32_stop(pit)                  _bit_clr(pit->PCSR, PIT_PCSR_EN)          /*!< PIT功能停止*/
#define _pit32_en_reload(pit)             _bit_set(pit->PCSR, PIT_PCSR_RLD)         /*!< 当PIT计数器为0时,重载PMR值到PIT计数器 */
#define _pit32_dis_reload(pit)            _bit_clr(pit->PCSR, PIT_PCSR_RLD)         /*!< 当PIT计数器为0时,重载0xFFFF到PIT计数器 */
#define _pit32_get_int_flag(pit)          _reg_chk(pit->PCSR, PIT_PCSR_PIF)         /*!< 检测PIT中断标志位 */
#define _pit32_clr_int_flag(pit)          _bit_set(pit->PCSR, PIT_PCSR_PIF)         /*!< 清除PIT中断标志位 */
#define _pit32_en_interrupt(pit)          _bit_set(pit->PCSR, PIT_PCSR_PIE)         /*!< PIT中断请求开启 */
#define _pit32_dis_interrupt(pit)         _bit_clr(pit->PCSR, PIT_PCSR_PIE)         /*!< PIT中断请求关闭 */
#define _pit32_relaod_mode_immediat(pit)  _bit_set(pit->PCSR, PIT_PCSR_OVW)         /*!< 写PMR寄存器,则立即更新PIT计数器 */
#define _pit32_relaod_mode_cntzero(pit)   _bit_clr(pit->PCSR, PIT_PCSR_OVW)         /*!< 写PMR寄存器,不立即更新PIT计数器,直到PIT计数为0 */
#define _pit32_set_debug_stop(pit)        _bit_set(pit->PCSR, PIT_PCSR_PDBG)        /*!< 在调试模式下，PIT功能停止 */
#define _pit32_set_debug_run(pit)         _bit_clr(pit->PCSR, PIT_PCSR_PDBG)        /*!< 在调试模式下，PIT功能不受影响 */
#define _pit32_set_doze_stop(pit)         _bit_set(pit->PCSR, PIT_PCSR_PDOZE)       /*!< 在瞌睡模式下，PIT功能停止 */
#define _pit32_set_doze_run(pit)          _bit_clr(pit->PCSR, PIT_PCSR_PDOZE)       /*!< 在瞌睡模式下，PIT功能不受影响 */
#define _pit32_set_prescaler(pit,value)   _reg_modify(pit->PCSR,0xF0FF,value);
#define _pit32_clr_pcsr_all(pit)          _reg_clear(pit->PCSR)
#define _pit32_get_pcsr_all(pit)          _reg_read(pit->PCSR)
#define _pit32_set_pcsr_all(pit,value)    _reg_write(pit->PCSR)

//PMR
#define _pit32_clr_pmr_all(pit)          _reg_clear(pit->PMR)
#define _pit32_get_pmr_all(pit)          _reg_read(pit->PMR)
#define _pit32_set_pmr_all(pit,value)    _reg_write(pit->PMR,value)

//PCNTR
#define _pit32_get_pcntr_all(pit)       _reg_read(pit->PCNTR)

/**
  * @}
  */

/*** 结构体、枚举变量定义 *****************************************************/
#ifdef FILE_OUT
/** @defgroup DRV_PIT32_Exported_Types Exported Types
  *
  * @{
  */
#endif

/**
  * @brief PIT32分频定义
  */
typedef enum _PIT32_CLKDIV_
 {
     PIT32_CLK_DIV_1 = PIT_PCSR_PRESCALER_1,   /*!< 1分频 */
     PIT32_CLK_DIV_2 = PIT_PCSR_PRESCALER_2,   /*!< 2分频 */
     PIT32_CLK_DIV_4 = PIT_PCSR_PRESCALER_4,   /*!< 4分频 */
     PIT32_CLK_DIV_8 = PIT_PCSR_PRESCALER_8,   /*!< 8分频 */
     PIT32_CLK_DIV_16 = PIT_PCSR_PRESCALER_16, /*!< 16分频 */
     PIT32_CLK_DIV_32 = PIT_PCSR_PRESCALER_32,
     PIT32_CLK_DIV_64 = PIT_PCSR_PRESCALER_64,
     PIT32_CLK_DIV_128 = PIT_PCSR_PRESCALER_128,
     PIT32_CLK_DIV_256 = PIT_PCSR_PRESCALER_256,
     PIT32_CLK_DIV_512 = PIT_PCSR_PRESCALER_512,
     PIT32_CLK_DIV_1024 = PIT_PCSR_PRESCALER_1024,
     PIT32_CLK_DIV_2048 = PIT_PCSR_PRESCALER_2048,
     PIT32_CLK_DIV_4096 = PIT_PCSR_PRESCALER_4096,
     PIT32_CLK_DIV_8192 = PIT_PCSR_PRESCALER_8192,
     PIT32_CLK_DIV_16384 = PIT_PCSR_PRESCALER_16384,
     PIT32_CLK_DIV_32768 = PIT_PCSR_PRESCALER_32968 /*!< 32768分频 */
 } PIT32_CLKDIV;

/**
  * @}
  */

/*** 全局变量声明 **************************************************************/
#ifdef FILE_OUT
 /** @defgroup DRV_PIT32_Exported_Variables Exported Variables
  *
  * @{
  */
#endif


/**
  * @}
  */

/*** 函数声明 ******************************************************************/
#ifdef FILE_OUT
 /** @defgroup DRV_PIT32_Exported_Functions Exported Functions
  * @{
  */
#endif
 extern void DRV_PIT32_Cmd(PIT32_TypeDef *ppit,FunctionalStateTypeDef status);

 extern void DRV_PIT32_InterruptCmd(PIT32_TypeDef *ppit,FunctionalStateTypeDef status);

 extern void DRV_PIT32_ReloadCmd(PIT32_TypeDef *ppit,FunctionalStateTypeDef status);

 extern void DRV_PIT32_ImmediatelyUpdateCNTCmd(PIT32_TypeDef *ppit,FunctionalStateTypeDef status);

 extern void DRV_PIT32_DebugCmd(PIT32_TypeDef *ppit,FunctionalStateTypeDef status);

 extern void DRV_PIT32_DozeCmd(PIT32_TypeDef *ppit,FunctionalStateTypeDef status);

 extern void DRV_PIT32_SetPrescaler(PIT32_TypeDef *ppit,PIT32_CLKDIV prescaler);

 extern void DRV_PIT32_SetCounter(PIT32_TypeDef *ppit,uint32_t cnt);

 extern uint32_t DRV_PIT32_GetCounter(PIT32_TypeDef *ppit);

/**
  * @}
  */

/**
  *@}
  */

/**
  *@}
  */

#ifdef __cplusplus
}
#endif

#endif /* __PIT32_DRV_H */

