/*********************************************************************************************************//**
* @file ht32f5xxxx_tm.c
* @version $Rev:: 4431 $
* @date $Date:: 2019-12-19 #$
* @brief This file provides all the TM firmware functions.
*************************************************************************************************************
* @attention
*
* Firmware Disclaimer Information
*
* 1. The customer hereby acknowledges and agrees that the program technical documentation, including the
* code, which is supplied by Holtek Semiconductor Inc., (hereinafter referred to as "HOLTEK") is the
* proprietary and confidential intellectual property of HOLTEK, and is protected by copyright law and
* other intellectual property laws.
*
* 2. The customer hereby acknowledges and agrees that the program technical documentation, including the
* code, is confidential information belonging to HOLTEK, and must not be disclosed to any third parties
* other than HOLTEK and the customer.
*
* 3. The program technical documentation, including the code, is provided "as is" and for customer reference
* only. After delivery by HOLTEK, the customer shall use the program technical documentation, including
* the code, at their own risk. HOLTEK disclaims any expressed, implied or statutory warranties, including
* the warranties of merchantability, satisfactory quality and fitness for a particular purpose.
*
* <h2><center>Copyright (C) Holtek Semiconductor Inc. All rights reserved</center></h2>
************************************************************************************************************/
/* Includes ------------------------------------------------------------------------------------------------*/
#include "ht32f5xxxx_tm.h"
/** @addtogroup HT32F5xxxx_Peripheral_Driver HT32F5xxxx Peripheral Driver
* @{
*/
/** @defgroup TM TM
* @brief TM driver modules
* @{
*/
/* Private constants ---------------------------------------------------------------------------------------*/
/** @defgroup TM_Private_Define TM private definitions
* @{
*/
#define CNTCFR_UEVDIS 0x00000001ul
#define CNTCFR_UGDIS 0x00000002ul
#define CNTCFR_DIR 0x01000000ul
#define CNTCFR_CMSEL_MASK ~0x00030000ul
#define CNTCFR_CKDIV_MASK ~0x00000300ul
#define MDCFR_SPMSET 0x01000000ul
#define MDCFR_TSE 0x00000001ul
#define MDCFR_SMSEL_MASK ~0x00000700ul
#define MDCFR_MMSEL_MASK ~0x00070000ul
#define TRCFR_ECME 0x01000000ul
#define TRCFR_ETI_POL 0x00010000ul
#define TRCFR_ETI_PSC_MASK ~0x00003000ul
#define TRCFR_ETIF_MASK ~0x00000F00ul
#define TRCFR_TRSEL_MASK ~0x0000000Ful
#define TRCFR_ETI_CONF_MASK ~0x00013F00ul
#define CTR_TME 0x00000001ul
#define CTR_CRBE 0x00000002ul
#define CTR_CHCCDS 0x00010000ul
#define CH0ICFR_CH0SRC 0x80000000ul
#define CHICFR_CHF_MASK ~0x0000000Ful
#define CHICFR_CHCCS_MASK ~0x00030000ul
#define CHICFR_CHPSC_MASK ~0x000C0000ul
#define CHOCFR_REFCE 0x00000008ul
#define CHOCFR_CHPRE 0x00000010ul
#define CHOCFR_IMAE 0x00000020ul
#define CHOCFR_CHOM_MASK ~0x00000107ul
#define CHPOLR_CH0P 0x00000001ul
#define CHPOLR_CH1P 0x00000004ul
/**
* @}
*/
/* Private function prototypes -----------------------------------------------------------------------------*/
static void _TM_CHx_Config(HT_TM_TypeDef* TMx, TM_CH_Enum Ch, TM_CHP_Enum Pol, TM_CHCCS_Enum Sel, u8 Filter);
/* Global functions ----------------------------------------------------------------------------------------*/
/** @defgroup TM_Exported_Functions TM exported functions
* @{
*/
/*********************************************************************************************************//**
* @brief Deinitialize the TMx peripheral registers to their default reset values.
* @param TMx: where TMx is the selected TM from the TM peripheral.
* @retval None
************************************************************************************************************/
void TM_DeInit(HT_TM_TypeDef* TMx)
{
RSTCU_PeripReset_TypeDef RSTCUReset = {{0}};
/* Check the parameters */
Assert_Param(IS_TM(TMx));
if (TMx == HT_GPTM0)
{
RSTCUReset.Bit.GPTM0 = 1;
}
#if (LIBCFG_GPTM1)
else if (TMx == HT_GPTM1)
{
RSTCUReset.Bit.GPTM1 = 1;
}
#endif
#if (LIBCFG_MCTM0)
else if (TMx == HT_MCTM0)
{
RSTCUReset.Bit.MCTM0 = 1;
}
#endif
#if (LIBCFG_NO_SCTM)
#else
else if (TMx == HT_SCTM0)
{
RSTCUReset.Bit.SCTM0 = 1;
}
else if (TMx == HT_SCTM1)
{
RSTCUReset.Bit.SCTM1 = 1;
}
#if (LIBCFG_SCTM2)
else if (TMx == HT_SCTM2)
{
RSTCUReset.Bit.SCTM2 = 1;
}
#endif
#if (LIBCFG_SCTM3)
else if (TMx == HT_SCTM3)
{
RSTCUReset.Bit.SCTM3 = 1;
}
#endif
#endif
#if (LIBCFG_PWM0)
else if (TMx == HT_PWM0)
{
RSTCUReset.Bit.PWM0 = 1;
}
#endif
#if (LIBCFG_PWM1)
else if (TMx == HT_PWM1)
{
RSTCUReset.Bit.PWM1 = 1;
}
#endif
RSTCU_PeripReset(RSTCUReset, ENABLE);
}
/*********************************************************************************************************//**
* @brief Initialize the TMx counter to reload, prescaler, counter mode and repetition counter.
* @param TMx: where TMx is the selected TM from the TM peripheral.
* @param TimeBaseInit: Point to a \ref TM_TimeBaseInitTypeDef that contains the configuration information.
* @retval None
************************************************************************************************************/
void TM_TimeBaseInit(HT_TM_TypeDef* TMx, TM_TimeBaseInitTypeDef* TimeBaseInit)
{
/* Check the parameters */
Assert_Param(IS_TM(TMx));
Assert_Param(IS_TM_CNT_MODE(TimeBaseInit->CounterMode));
Assert_Param(IS_TM_PSC_RLD(TimeBaseInit->PSCReloadTime));
/* Set the counter reload value */
TMx->CRR = TimeBaseInit->CounterReload;
/* Set the Prescaler value */
TMx->PSCR = TimeBaseInit->Prescaler;
/* Select the Counter Mode */
TMx->CNTCFR &= CNTCFR_CMSEL_MASK; /* CNTCFR_DIR is read only when the timer configured as */
TMx->CNTCFR &= ~(u32)CNTCFR_DIR; /* Center-aligned mode. Reset mode first and then reset the */
/* CNTCFR_DIR bit (separate as two steps). */
TMx->CNTCFR |= TimeBaseInit->CounterMode;
#if (LIBCFG_MCTM0)
if (TMx == HT_MCTM0)
{
/* Set the Repetition value */
TMx->REPR = TimeBaseInit->RepetitionCounter;
}
#endif
/* To reload the Prescaler value immediatly or next update event */
TMx->EVGR = TimeBaseInit->PSCReloadTime;
}
/*********************************************************************************************************//**
* @brief Initialize the TMx channel N output.
* @param TMx: where TMx is the selected TM from the TM peripheral.
* @param OutInit: Point to a \ref TM_OutputInitTypeDef structure that contains
the configuration information.
* @retval None
************************************************************************************************************/
void TM_OutputInit(HT_TM_TypeDef* TMx, TM_OutputInitTypeDef* OutInit)
{
vu32 *pOcfr = (vu32*)&TMx->CH0OCFR + OutInit->Channel;
vu32 *pCcr = (vu32*)&TMx->CH0CCR + OutInit->Channel;
vu32 *pAcr = (vu32*)&TMx->CH0ACR + OutInit->Channel;
u8 bChPos = OutInit->Channel << 1;
u32 wTmpMask;
u
MarcoPage
- 粉丝: 4419
- 资源: 8836
最新资源
- 大学生智能消费记账系统的设计与实现-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.rar
- 个人博客系统的设计与实现-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.rar
- 洞见研报ZDEER左点(全场景科技医疗及健康生活解决方案服务商,左点健康产业(深圳)有限公司)创投信息
- javaweb的新能源充电系统pf-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- 基于Java的大学生考勤系统的设计与实现--论文pf-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- 基于Java Web的考编论坛网站的设计与实现pf-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- +vue校园求职招聘系统设计和实现pf-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- 地理信息系统考研复习笔记,助力上岸
- 洞见研报和府捞面(面食餐饮品牌,江苏和府餐饮管理有限公司)创投信息
- 基于html5+css3的在线英语阅读分级平台--论文pf-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- 交流互动系统(1)-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- 教师人事档案管理系统-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- 基于javaweb的宠物猫认养系统pf-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- 酒店管理系统-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- 基于javaweb的城乡居民基本医疗信息管理系统pf-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- arm64架构下gmssl工具
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈