📄 stm8l15x_tim4.c
字号:
/**
******************************************************************************
* @file stm8l15x_tim4.c
* @author MCD Application Team
* @version V1.5.0
* @date 13-May-2011
* @brief This file provides firmware functions to manage the following
* functionalities of the TIM4 peripheral:
* - TimeBase management
* - Interrupts, DMA and flags management
* - Clocks management
* - Synchronization management
*
* @verbatim
*
* ===================================================================
* How to use this driver
* ===================================================================
* This driver provides functions to configure and initialise the TIM4
* peripheral
* These functions are split in 4 groups:
*
* 1. TIM4 TimeBase management: this group includes all needed functions
* to configure the TIM Timebase unit:
* - Set/Get Prescaler
* - Set/Get Autoreload
* - Select the One Pulse mode
* - Update Request Configuration
* - Update Disable Configuration
* - Auto-Preload Configuration
* - Enable/Disable the counter
*
* 2. TIM4 interrupts, DMA and flags management
* - Enable/Disable interrupt sources
* - Get flags status
* - Clear flags/ Pending bits
* - Enable/Disable DMA requests
*
* 3. TIM4 clocks management: this group includes all needed functions
* to configure the clock controller unit:
* - Select internal clock
*
* 4. TIM4 synchronization management: this group includes all needed
* functions to configure the Synchronization unit:
* - Select Input Trigger
* - Select Output Trigger
* - Select Master Slave Mode
*
*
* @endverbatim
*
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm8l15x_tim4.h"
/** @addtogroup STM8L15x_StdPeriph_Driver
* @{
*/
/** @defgroup TIM4
* @brief TIM4 driver modules
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/** @defgroup TIM4_Private_Functions
* @{
*/
/** @defgroup TIM4_Group1 TimeBase management functions
* @brief TimeBase management functions
*
@verbatim
===============================================================================
TimeBase management functions
===============================================================================
===================================================================
TIM4 Driver: how to use it in Timing(Time base) Mode
===================================================================
To use the Timer in Timing(Time base) mode, the following steps are mandatory:
1. Enable TIM4 clock using CLK_PeripheralClockConfig(CLK_Peripheral_TIM4, ENABLE) function.
2. Call TIM4_TimeBaseInit() to configure the Time Base unit with the
corresponding configuration.
3. Enable global interrupts if you need to generate the update interrupt.
4. Enable the corresponding interrupt using the function TIM4_ITConfig(TIM4_IT_Update)
5. Call the TIM4_Cmd(ENABLE) function to enable the TIM4 counter.
Note1: All other functions can be used separately to modify, if needed,
a specific feature of the Timer.
@endverbatim
* @{
*/
/**
* @brief Deinitializes the TIM4 peripheral registers to their default reset values.
* @param None
* @retval None
*/
void TIM4_DeInit(void)
{
TIM4->CR1 = TIM4_CR1_RESET_VALUE;
TIM4->CR2 = TIM4_CR2_RESET_VALUE;
TIM4->SMCR = TIM4_SMCR_RESET_VALUE;
TIM4->IER = TIM4_IER_RESET_VALUE;
TIM4->CNTR = TIM4_CNTR_RESET_VALUE;
TIM4->PSCR = TIM4_PSCR_RESET_VALUE;
TIM4->ARR = TIM4_ARR_RESET_VALUE;
TIM4->SR1 = TIM4_SR1_RESET_VALUE;
}
/**
* @brief Initializes the TIM4 Time Base Unit according to the specified parameters.
* @param TIM4_Prescaler: Prescaler
* This parameter can be one of the following values:
* @arg TIM4_Prescaler_1: Time base Prescaler = 1 (No effect)
* @arg TIM4_Prescaler_2: Time base Prescaler = 2
* @arg TIM4_Prescaler_4: Time base Prescaler = 4
* @arg TIM4_Prescaler_8: Time base Prescaler = 8
* @arg TIM4_Prescaler_16: Time base Prescaler = 16
* @arg TIM4_Prescaler_32: Time base Prescaler = 32
* @arg TIM4_Prescaler_64: Time base Prescaler = 64
* @arg TIM4_Prescaler_128: Time base Prescaler = 128
* @arg TIM4_Prescaler_256: Time base Prescaler = 256
* @arg TIM4_Prescaler_512: Time base Prescaler = 512
* @arg TIM4_Prescaler_1024: Time base Prescaler = 1024
* @arg TIM4_Prescaler_2048: Time base Prescaler = 2048
* @arg TIM4_Prescaler_4096: Time base Prescaler = 4096
* @arg TIM4_Prescaler_8192: Time base Prescaler = 8192
* @arg TIM4_Prescaler_16384: Time base Prescaler = 16384
* @arg TIM4_Prescaler_32768: Time base Prescaler = 32768
* @param TIM4_Period: This parameter must be a value between 0x00 and 0xFF.
* @retval None
*/
void TIM4_TimeBaseInit(TIM4_Prescaler_TypeDef TIM4_Prescaler,
uint8_t TIM4_Period)
{
/* Check TIM4 prescaler value */
assert_param(IS_TIM4_Prescaler(TIM4_Prescaler));
/* Set the Autoreload value */
TIM4->ARR = (uint8_t)(TIM4_Period);
/* Set the Prescaler value */
TIM4->PSCR = (uint8_t)(TIM4_Prescaler);
/* Generate an update event to reload the Prescaler value immediately */
TIM4->EGR = TIM4_EventSource_Update;
}
/**
* @brief Configures the TIM4 Prescaler.
* @param Prescaler: Specifies the Prescaler Register value
* This parameter can be one of the following values:
* @arg TIM4_Prescaler_1: Time base Prescaler = 1 (No effect)
* @arg TIM4_Prescaler_2: Time base Prescaler = 2
* @arg TIM4_Prescaler_4: Time base Prescaler = 4
* @arg TIM4_Prescaler_8: Time base Prescaler = 8
* @arg TIM4_Prescaler_16: Time base Prescaler = 16
* @arg TIM4_Prescaler_32: Time base Prescaler = 32
* @arg TIM4_Prescaler_64: Time base Prescaler = 64
* @arg TIM4_Prescaler_128: Time base Prescaler = 128
* @arg TIM4_Prescaler_256: Time base Prescaler = 256
* @arg TIM4_Prescaler_512: Time base Prescaler = 512
* @arg TIM4_Prescaler_1024: Time base Prescaler = 1024
* @arg TIM4_Prescaler_2048: Time base Prescaler = 2048
* @arg TIM4_Prescaler_4096: Time base Prescaler = 4096
* @arg TIM4_Prescaler_8192: Time base Prescaler = 8192
* @arg TIM4_Prescaler_16384: Time base Prescaler = 16384
* @arg TIM4_Prescaler_32768: Time base Prescaler = 32768
* @param TIM4_PSCReloadMode: Specifies the TIM4 Prescaler Reload mode.
* This parameter can be one of the following values:
* @arg TIM4_PSCReloadMode_Update: Prescaler value is reloaded at every update
* @arg TIM4_PSCReloadMode_Immediate: Prescaler value is reloaded immediatly
* @retval None
*/
void TIM4_PrescalerConfig(TIM4_Prescaler_TypeDef Prescaler,
TIM4_PSCReloadMode_TypeDef TIM4_PSCReloadMode)
{
/* Check the parameters */
assert_param(IS_TIM4_Prescaler_RELOAD(TIM4_PSCReloadMode));
assert_param(IS_TIM4_Prescaler(Prescaler));
/* Set the Prescaler value */
TIM4->PSCR = (uint8_t) Prescaler;
/* Set or reset the UG Bit */
if (TIM4_PSCReloadMode == TIM4_PSCReloadMode_Immediate)
{
TIM4->EGR |= TIM4_EGR_UG ;
}
else
{
TIM4->EGR &= (uint8_t)(~TIM4_EGR_UG) ;
}
}
/**
* @brief Sets the TIM4 Counter Register value.
* @param Counter: Specifies the Counter register new value.
* This parameter is between 0x00 and 0xFF.
* @retval None
*/
void TIM4_SetCounter(uint8_t Counter)
{
/* Set the Counter Register value */
TIM4->CNTR = (uint8_t)(Counter);
}
/**
* @brief Sets the TIM4 Autoreload Register value.
* @param Autoreload: Specifies the Autoreload register new value.
* This parameter is between 0x00 and 0xFF.
* @retval None
*/
void TIM4_SetAutoreload(uint8_t Autoreload)
{
/* Set the Autoreload Register value */
TIM4->ARR = (uint8_t)(Autoreload);
}
/**
* @brief Gets the TIM4 Counter value.
* @param None
* @retval Counter Register value.
*/
uint8_t TIM4_GetCounter(void)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -