/**
  ******************************************************************************
  * @file    pit32_hal.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_HAL_H
#define __PIT32_HAL_H

#ifdef __cplusplus
extern "C"
{
#endif

/* Includes ------------------------------------------------------------------*/
#include "pit32_drv.h"
#include "hal_def.h"

  /**@defgroup HAL HAL driver
  *
  *@{
  */

  /** @defgroup HAL_PIT32 PIT32
  *
  *@{
  */

  /*** 宏定义 *******************************************************************/
  /** @defgroup PIT32_Exported_Macros Exported Macros
  *
  * @{
  */

#define HAL_PIT32_CALC_COUNTER(clk,div,time)	  (uint32_t)(clk / (1 << (div>>8)) / time)

  /**
  * @}
  */

  /*** 结构体、枚举变量定义 *****************************************************/
  /** @defgroup PIT32_Exported_Types Exported Types
  *
  * @{
  */

  typedef void (*pit32_callback_t)(void *);

  /**
* @brief PIT32 初始化结构体定义
*
*/
  typedef struct
  {
    FunctionalStateTypeDef reLoad;     /**< reload使能  */
    FunctionalStateTypeDef enableIE;   /**< 中断使能  */
    FunctionalStateTypeDef updateCNT;  /**< 写入PMR寄存器的值后立即更新计数器  */
    FunctionalStateTypeDef runatDoze;  /**< 在doze模式下是否正常运行  */
    FunctionalStateTypeDef runatDebug; /**< 在debug模式下是否正常运行  */

    PIT32_CLKDIV prescaler; /**< 分频系数  */
    uint32_t counter;       /**< 计数器     cnt = (Fsys/(prescaler *second))/ */
  } PIT32_InitTypeDef;

  /**
* @brief PIT32  句柄结构体定义
*
*/
  typedef struct
  {
    PIT32_TypeDef *instance; /**< PIT32实例寄存器 */
    PIT32_InitTypeDef init;  /**< PIT32初始化结构体 */

    pit32_callback_t callback; /**< 回调函数*/
  } PIT32_HandleTypeDef;

  /**
  * @}
  */

  /*** 全局变量声明 **************************************************************/
  /** @defgroup PIT32_Exported_Variables Exported Variables
  *
  * @{
  */

  /**
  * @}
  */

  /*** 函数声明 ******************************************************************/
  /** @defgroup PIT32_Exported_Functions Exported Functions
  * @{
  */	
  extern void HAL_PIT32_Start(PIT32_HandleTypeDef *hpit32);

  extern void HAL_PIT32_Stop(PIT32_HandleTypeDef *hpit32);

  extern void HAL_PIT32_Callback(void *hpit32);

  extern HAL_StatusTypeDef HAL_PIT32_Init(PIT32_HandleTypeDef *hpit32);

  extern void HAL_PIT32_CMD(PIT32_HandleTypeDef *hpit32, FunctionalState NewState);

  extern void HAL_PIT32_ITConfig(PIT32_HandleTypeDef *hpit32, FunctionalState NewState);

  extern void HAL_PIT32_SetCounter(PIT32_HandleTypeDef *hpit32, uint16_t cnt);

  extern uint16_t HAL_PIT32_GetCounter(PIT32_HandleTypeDef *hpit32);

  extern void HAL_PIT32_SetPrescaler(PIT32_HandleTypeDef *hpit32, PIT32_CLKDIV prescaler);

  extern uint8_t HAL_PIT32_GetPrescaler(PIT32_HandleTypeDef *hpit32);

  extern uint8_t HAL_PIT32_GetITStatus(PIT32_HandleTypeDef *hpit32);

  extern void HAL_PIT32_CleanITStatus(PIT32_HandleTypeDef *hpit32);

  /**
  * @}
  */

  /**
  *@}
  */

  /**
  *@}
  */

#ifdef __cplusplus
}
#endif

#endif /* __PIT32_HAL_H */

