/*!
* @file apm32f4xx_tmr.c
*
* @brief This file provides all the TMR firmware functions.
*
* @version V1.0.2
*
* @date 2022-06-23
*
* @attention
*
* Copyright (C) 2021-2022 Geehy Semiconductor
*
* You may not use this file except in compliance with the
* GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
*
* The program is only for reference, which is distributed in the hope
* that it will be usefull and instructional for customers to develop
* their software. Unless required by applicable law or agreed to in
* writing, the program is distributed on an "AS IS" BASIS, WITHOUT
* ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
* See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
* and limitations under the License.
*/
#include "apm32f4xx_tmr.h"
#include "apm32f4xx_rcm.h"
/** @addtogroup APM32F4xx_StdPeriphDriver
@{
*/
/** @defgroup TMR_Driver
* @brief TMR driver modules
@{
*/
/** @defgroup TMR_Functions
@{
*/
static void TI1Config(TMR_T* tmr, uint16_t ICpolarity, uint16_t ICselection, uint16_t ICfilter);
static void TI2Config(TMR_T* tmr, uint16_t ICpolarity, uint16_t ICselection, uint16_t ICfilter);
static void TI3Config(TMR_T* tmr, uint16_t ICpolarity, uint16_t ICselection, uint16_t ICfilter);
static void TI4Config(TMR_T* tmr, uint16_t ICpolarity, uint16_t ICselection, uint16_t ICfilter);
/*!
* @brief Deinitializes the TMRx peripheral registers to their default reset values.
*
* @param tmr: Select TMRx peripheral, The x can be from 1 to 14.
*
* @retval None
*
* @note
*/
void TMR_Reset(TMR_T* tmr)
{
if (tmr == TMR1)
{
RCM_EnableAPB2PeriphReset(RCM_APB2_PERIPH_TMR1);
RCM_DisableAPB2PeriphReset(RCM_APB2_PERIPH_TMR1);
}
else if (tmr == TMR2)
{
RCM_EnableAPB1PeriphReset(RCM_APB1_PERIPH_TMR2);
RCM_DisableAPB1PeriphReset(RCM_APB1_PERIPH_TMR2);
}
else if (tmr == TMR3)
{
RCM_EnableAPB1PeriphReset(RCM_APB1_PERIPH_TMR3);
RCM_DisableAPB1PeriphReset(RCM_APB1_PERIPH_TMR3);
}
else if (tmr == TMR4)
{
RCM_EnableAPB1PeriphReset(RCM_APB1_PERIPH_TMR4);
RCM_DisableAPB1PeriphReset(RCM_APB1_PERIPH_TMR4);
}
else if (tmr == TMR5)
{
RCM_EnableAPB1PeriphReset(RCM_APB1_PERIPH_TMR5);
RCM_DisableAPB1PeriphReset(RCM_APB1_PERIPH_TMR5);
}
else if (tmr == TMR6)
{
RCM_EnableAPB1PeriphReset(RCM_APB1_PERIPH_TMR6);
RCM_DisableAPB1PeriphReset(RCM_APB1_PERIPH_TMR6);
}
else if (tmr == TMR7)
{
RCM_EnableAPB1PeriphReset(RCM_APB1_PERIPH_TMR7);
RCM_DisableAPB1PeriphReset(RCM_APB1_PERIPH_TMR7);
}
else if (tmr == TMR8)
{
RCM_EnableAPB2PeriphReset(RCM_APB2_PERIPH_TMR8);
RCM_DisableAPB2PeriphReset(RCM_APB2_PERIPH_TMR8);
}
else if (tmr == TMR9)
{
RCM_EnableAPB2PeriphReset(RCM_APB2_PERIPH_TMR9);
RCM_DisableAPB2PeriphReset(RCM_APB2_PERIPH_TMR9);
}
else if (tmr == TMR10)
{
RCM_EnableAPB2PeriphReset(RCM_APB2_PERIPH_TMR10);
RCM_DisableAPB2PeriphReset(RCM_APB2_PERIPH_TMR10);
}
else if (tmr == TMR11)
{
RCM_EnableAPB2PeriphReset(RCM_APB2_PERIPH_TMR11);
RCM_DisableAPB2PeriphReset(RCM_APB2_PERIPH_TMR11);
}
else if (tmr == TMR12)
{
RCM_EnableAPB1PeriphReset(RCM_APB1_PERIPH_TMR12);
RCM_DisableAPB1PeriphReset(RCM_APB1_PERIPH_TMR12);
}
else if (tmr == TMR13)
{
RCM_EnableAPB1PeriphReset(RCM_APB1_PERIPH_TMR13);
RCM_DisableAPB1PeriphReset(RCM_APB1_PERIPH_TMR13);
}
else if (tmr == TMR14)
{
RCM_EnableAPB1PeriphReset(RCM_APB1_PERIPH_TMR14);
RCM_DisableAPB1PeriphReset(RCM_APB1_PERIPH_TMR14);
}
}
/*!
* @brief Config the base timer through the structure
*
* @param tmr: Select TMRx peripheral, The x can be 1 to 14
*
* @param baseConfig: Pointer to a TMR_BaseConfig_T structure
*
* @retval None
*/
void TMR_ConfigTimeBase(TMR_T* tmr, TMR_BaseConfig_T* baseConfig)
{
if ((tmr == TMR1) || (tmr == TMR2) || \
(tmr == TMR3) || (tmr == TMR4) || \
(tmr == TMR5) || (tmr == TMR8))
{
/** Count Direction */
tmr->CTRL1_B.CNTDIR = baseConfig->countMode & 0x01;
/** Aligned mode */
tmr->CTRL1_B.CAMSEL = baseConfig->countMode >> 4;
}
if ((tmr != TMR6) && (tmr != TMR7))
{
tmr->CTRL1_B.CLKDIV = baseConfig->clockDivision;
}
tmr->AUTORLD = baseConfig->period ;
tmr->PSC = baseConfig->division;
if ((tmr == TMR1) || (tmr == TMR8))
{
tmr->REPCNT = baseConfig->repetitionCounter;
}
tmr->CEG_B.UEG = TMR_PSC_RELOAD_IMMEDIATE;
}
/*!
* @brief Config the Base timer with its default value.
*
* @param baseConfig: pointer to a TMR_BaseConfig_T
*
* @retval None
*/
void TMR_ConfigTimeBaseStructInit(TMR_BaseConfig_T* baseConfig)
{
baseConfig->countMode = TMR_COUNTER_MODE_UP;
baseConfig->clockDivision = TMR_CLOCK_DIV_1;
baseConfig->period = 0xFFFF;
baseConfig->division = 0x0000;
baseConfig->repetitionCounter = 0x0000;
}
/*!
* @brief Configures the TMRx Prescaler.
*
* @param tmr: Select TMRx peripheral, The x can be 1 to 14
*
* @param psc: specifies the Prescaler Register value
*
* @param reload: specifies the TMR Prescaler Reload mode
* The parameter can be one of following values:
* @arg TMR_PSC_RELOAD_UPDATE: The Prescaler reload at the update event
* @arg TMR_PSC_RELOAD_IMMEDIATE: The Prescaler reload immediately
*
* @retval None
*/
void TMR_ConfigPrescaler(TMR_T* tmr, uint16_t psc, TMR_PSC_RELOAD_T reload)
{
tmr->PSC_B.PSC = psc;
tmr->CEG_B.UEG = reload;
}
/*!
* @brief Config counter mode.
*
* @param tmr: The TMRx can be 1 to 8 except 6 and 7
*
* @param countMode: specifies the Counter Mode to be used
* The parameter can be one of following values:
* @arg TMR_COUNTER_MODE_UP: Timer Up Counting Mode
* @arg TMR_COUNTER_MODE_DOWN: Timer Down Counting Mode
* @arg TMR_COUNTER_MODE_CENTER_ALIGNED1: Timer Center Aligned Mode1
* @arg TMR_COUNTER_MODE_CENTER_ALIGNED2: Timer Center Aligned Mode2
* @arg TMR_COUNTER_MODE_CENTER_ALIGNED3: Timer Center Aligned Mode3
*
* @retval None
*/
void TMR_ConfigCounterMode(TMR_T* tmr, TMR_COUNTER_MODE_T countMode)
{
tmr->CTRL1_B.CNTDIR = countMode & 0x01;
tmr->CTRL1_B.CAMSEL = countMode >> 4;
}
/*!
* @brief Configs the Counter Register value
*
* @param tmr: The TMRx can be 1 to 14
*
* @param counter: Counter register new value
*
* @retval None
*/
void TMR_ConfigCounter(TMR_T* tmr, uint16_t counter)
{
tmr->CNT = counter;
}
/*!
* @brief Configs the value of AutoReload Register.
*
* @param tmr: The TMRx can be 1 to 14
*
* @param autoReload: autoReload register new value
*
* @retval None
*/
void TMR_ConfigAutoreload(TMR_T* tmr, uint16_t autoReload)
{
tmr->AUTORLD_B.AUTORLD = autoReload;
}
/*!
* @brief Read the TMRx Counter value.
*
* @param tmr: The TMRx can be 1 to 14
*
* @retval Counter Register value.
*/
uint16_t TMR_ReadCounter(TMR_T* tmr)
{
return tmr->CNT;
}
/*!
* @brief Read the TMRx Prescaler value.
*
* @param tmr: The TMRx can be 1 to 14
*
* @retval Prescaler Register value.
*/
uint16_t TMR_ReadPrescaler(TMR_T* tmr)
{
return tmr->PSC;
}
/*!
* @brief Enable the TMRx update event
*
* @param t
没有合适的资源?快使用搜索试试~ 我知道了~
APM32F407实现通用定时器中断【支持APM32F4系列单片机】.zip
共86个文件
h:41个
c:40个
s:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 41 浏览量
2023-04-17
15:46:25
上传
评论
收藏 310KB ZIP 举报
温馨提示
APM32F407驱动程序,支持APM32F4系列单片机。 项目代码可顺利编译和运行~
资源推荐
资源详情
资源评论
收起资源包目录
APM32F407实现通用定时器中断【支持APM32F4系列单片机】.zip (86个子文件)
APM32F407实现通用定时器中断【支持APM32F4系列单片机】
Drivers
BSP
LED
led.h 2KB
led.c 2KB
TMR
gtmr.c 2KB
gtmr.h 1KB
APM32F4xx_StdPeriphDriver
inc
apm32f4xx_dma.h 16KB
apm32f4xx_smc.h 12KB
apm32f4xx_sdio.h 14KB
apm32f4xx_dmc.h 13KB
apm32f4xx_rng.h 2KB
apm32f4xx_tmr.h 27KB
apm32f4xx_misc.h 3KB
apm32f4xx_dci.h 8KB
apm32f4xx_cryp.h 8KB
apm32f4xx_usart.h 10KB
apm32f4xx_rtc.h 20KB
apm32f4xx_fmc.h 14KB
apm32f4xx_crc.h 2KB
apm32f4xx_i2c.h 13KB
apm32f4xx_rcm.h 18KB
apm32f4xx_spi.h 10KB
apm32f4xx_gpio.h 11KB
apm32f4xx_can.h 13KB
apm32f4xx_syscfg.h 4KB
apm32f4xx_pmu.h 4KB
apm32f4xx_adc.h 18KB
apm32f4xx_wwdt.h 2KB
apm32f4xx_dbgmcu.h 5KB
apm32f4xx_hash.h 6KB
apm32f4xx_dac.h 8KB
apm32f4xx_iwdt.h 3KB
apm32f4xx_eint.h 5KB
src
apm32f4xx_dac.c 15KB
apm32f4xx_smc.c 35KB
apm32f4xx_crc.c 3KB
apm32f4xx_rng.c 4KB
apm32f4xx_hash_sha1.c 7KB
apm32f4xx_cryp.c 12KB
apm32f4xx_hash_md5.c 7KB
apm32f4xx_fmc.c 22KB
apm32f4xx_iwdt.c 3KB
apm32f4xx_dbgmcu.c 8KB
apm32f4xx_tmr.c 72KB
apm32f4xx_i2c.c 28KB
apm32f4xx_syscfg.c 6KB
apm32f4xx_dmc.c 11KB
apm32f4xx_dma.c 19KB
apm32f4xx_hash.c 10KB
apm32f4xx_wwdt.c 4KB
apm32f4xx_pmu.c 8KB
apm32f4xx_cryp_tdes.c 7KB
apm32f4xx_adc.c 33KB
apm32f4xx_gpio.c 15KB
apm32f4xx_usart.c 25KB
apm32f4xx_cryp_aes.c 17KB
apm32f4xx_dci.c 10KB
apm32f4xx_eint.c 12KB
apm32f4xx_misc.c 7KB
apm32f4xx_rcm.c 63KB
apm32f4xx_cryp_des.c 7KB
apm32f4xx_sdio.c 23KB
apm32f4xx_can.c 32KB
apm32f4xx_spi.c 20KB
apm32f4xx_rtc.c 54KB
CMSIS
Include
core_cmFunc.h 18KB
cmsis_armcc.h 28KB
core_cm4.h 112KB
core_cmInstr.h 27KB
core_cmSimd.h 22KB
cmsis_compiler.h 10KB
Device
Geehy
APM32F4xx
Source
system_apm32f4xx.c 9KB
arm
startup_apm32f41x.s 19KB
startup_apm32f40x.s 19KB
Include
system_apm32f4xx.h 2KB
apm32f4xx.h 242KB
SYSTEM
delay
delay.h 1KB
delay.c 9KB
usart
usart.h 2KB
usart.c 6KB
sys
sys.h 2KB
sys.c 5KB
User
apm32f4xx_int.h 2KB
apm32f4xx_int.c 3KB
main.c 1KB
Output
atk_f407.hex 11KB
Projects
MDK-ARM
atk_f407.uvoptx 25KB
atk_f407.uvprojx 24KB
Middlewares
共 86 条
- 1
资源评论
不脱发的程序猿
- 粉丝: 24w+
- 资源: 5773
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- QuestionTwo.java
- QuestionOne.java
- OA办公自动化管理系统(Struts1.2+Hibernate3.0+Spring2+DWR).rar
- 简历-求职简历-word-文件-简历模版免费分享-应届生-高颜值简历模版-个人简历模版-简约大气-大学生在校生-求职-实习
- 南京邮电大学数学实验:熟练掌握 Matlab 软件的基本命令和操作
- 简历-求职简历-word-文件-简历模版免费分享-应届生-高颜值简历模版-个人简历模版-简约大气-大学生在校生-求职-实习
- 2017校招真题校园招聘真题算法题(37道)Python源码.zip
- 基于单片机protues仿真的多功能自动饮水机系统设计(仿真图、源代码、演示视频)
- 论文《一种修复流程挖掘事件日志中缺失活动标签的深度学习方法》翻译
- 智慧电厂相关资料发电控制的方式
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功