/**
  ******************************************************************************
  * @file    tc_drv.h
  * @author  Product application department
  * @version V1.0
  * @date    2020.03.20
  * @brief   Header file of TC DRV module.
  * 
  ******************************************************************************
  */

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

#ifdef __cplusplus
extern "C"
{
#endif

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

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

/** @defgroup DRV_TC TC
  *
  *@{
  */
#endif
  /*** 宏定义 *******************************************************************/
#ifdef FILE_OUT
/** @defgroup DRV_SPI_Exported_Macros Exported Macros
  *
  * @{
  */
#endif

#define TC_INT_NUM        0x38

#define _tc_set_debug_run(tc)                   _bit_clr(tc->CR , TC_DEBUG)
#define _tc_set_debug_stop(tc)                  _bit_set(tc->CR , TC_DEBUG)
#define _tc_set_doze_run(tc)                    _bit_clr(tc->CR , TC_DOZE)
#define _tc_set_doze_stop(tc)                   _bit_set(tc->CR , TC_DOZE)
#define _tc_set_wait_run(tc)                    _bit_clr(tc->CR , TC_WAIT)
#define _tc_set_wait_stop(tc)                   _bit_set(tc->CR , TC_WAIT)
#define _tc_set_stop_run(tc)                    _bit_clr(tc->CR , TC_STOP)
#define _tc_set_stop_stop(tc)                   _bit_set(tc->CR , TC_STOP)
#define _tc_set_reset_enable(tc)                _bit_set(tc->CR , TC_RN_MODE_MASK)
#define _tc_set_reset_disable(tc)               _bit_clr(tc->CR , TC_RN_MODE_MASK)
#define _tc_get_count(tc)                       _reg_read(tc->CNTR)
#define _tc_set_wsr(tc,value)                   _reg_write(tc->SR,value)
#define _tc_set_mr(tc,value)                 	  _reg_write(tc->MR,value) /**< 设置MR寄存器*/
#define _tc_set_prescaler(tc,value)             _reg_write(tc->CR,(tc->CR&0XFF8F)|(value<<4)) /**< 设置预分频值*/
#define _tc_enable_int(tc)                      _bit_set(tc->CR,TC_IE_MODE_MASK) /**< TC使能中断*/
#define _tc_disable_int(tc)                     _bit_clr(tc->CR,TC_IE_MODE_MASK) /**< TC禁用中断*/
#define _tc_update_wdp(tc)                      _bit_set(tc->CR,TC_CU_MODE_MASK)   /**< 立即使能设置好的分频值*/
#define _tc_clear_int_flag(tc)                  _bit_set(tc->CR,TC_IF_MODE_MASK) /**< 清除中断标志*/


 /**
  *@}
  */

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

/**
*@brief TC 预定义分频值
*
*/

typedef enum
{
    TC_WDP_2048=0x00,
    TC_WDP_1024=0x01,
    TC_WDP_512=0x02,
    TC_WDP_256=0x03,
    TC_WDP_128=0x04,
    TC_WDP_64=0x05,
    TC_WDP_32=0x06,
    TC_WDP_16=0x07
}TC_TIMER_PRESCALER;
/**
*@}
*/
/*** 全局变量声明 **************************************************************/
#ifdef FILE_OUT
/** @defgroup DRV_TC_Exported_Variables Exported Variables
  *
  * @{
  */
#endif
	extern volatile uint8_t g_tc_int_flag;

/**
  * @}
  */

/*** 函数声明 ******************************************************************/
#ifdef FILE_OUT
/** @defgroup DRV_TC_Exported_Functions Exported Functions
  * @{
  */
#endif
extern void DRV_TC_WaitCmd(TC_TypeDef *tctd,FunctionalStateTypeDef status);
extern void DRV_TC_DozeCmd(TC_TypeDef *tctd,FunctionalStateTypeDef status);
extern void DRV_TC_StopCmd(TC_TypeDef *tctd,FunctionalStateTypeDef status);
extern void DRV_TC_DebugCmd(TC_TypeDef *tctd,FunctionalStateTypeDef status);
extern void DRV_TC_ResetCmd(TC_TypeDef *tctd,FunctionalStateTypeDef status);
extern void DRV_TC_InterruptCmd(TC_TypeDef *tctd,FunctionalStateTypeDef status);

/**
* @}
*/

/**
* @}
*/

/**
* @}
*/

  #ifdef __cplusplus
  }
  #endif

  #endif /* __TC_DRV_H */

