vscode_embedded/vscode_stm32f1_test/hal/STM32F10x_StdPeriph_Driver/src/stm32f10x_tim.c
/**
  * @brief  Initializes the TIMx Time Base Unit peripheral according to 
  *         the specified parameters in the TIM_TimeBaseInitStruct.
  * @param  TIMx: where x can be 1 to 17 to select the TIM peripheral.
  * @param  TIM_TimeBaseInitStruct: pointer to a TIM_TimeBaseInitTypeDef
  *         structure that contains the configuration information for the 
  *         specified TIM peripheral.
  * @retval None
  */
@brief  Initializes the TIMx Time Base Unit peripheral according to
the specified parameters in the TIM_TimeBaseInitStruct.
@param  TIMx: where x can be 1 to 17 to select the TIM peripheral.
@param  TIM_TimeBaseInitStruct: pointer to a TIM_TimeBaseInitTypeDef
structure that contains the configuration information for the
specified TIM peripheral.
@retval None
@brief Initializes the TIMx Time Base Unit peripheral according to the specified parameters in the TIM_TimeBaseInitStruct . @param TIMx : where x can be 1 to 17 to select the TIM peripheral . @param TIM_TimeBaseInitStruct : pointer to a TIM_TimeBaseInitTypeDef structure that contains the configuration information for the specified TIM peripheral . @retval None
void TIM_TimeBaseInit(TIM_TypeDef* TIMx, TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct)
{
  uint16_t tmpcr1 = 0;
  assert_param(IS_TIM_ALL_PERIPH(TIMx)); 
  assert_param(IS_TIM_COUNTER_MODE(TIM_TimeBaseInitStruct->TIM_CounterMode));
  assert_param(IS_TIM_CKD_DIV(TIM_TimeBaseInitStruct->TIM_ClockDivision));
  tmpcr1 = TIMx->CR1;  
  if((TIMx == TIM1) || (TIMx == TIM8)|| (TIMx == TIM2) || (TIMx == TIM3)||
     (TIMx == TIM4) || (TIMx == TIM5)) 
  {
    tmpcr1 &= (uint16_t)(~((uint16_t)(TIM_CR1_DIR | TIM_CR1_CMS)));
    tmpcr1 |= (uint32_t)TIM_TimeBaseInitStruct->TIM_CounterMode;
  }
  if((TIMx != TIM6) && (TIMx != TIM7))
  {
    tmpcr1 &= (uint16_t)(~((uint16_t)TIM_CR1_CKD));
    tmpcr1 |= (uint32_t)TIM_TimeBaseInitStruct->TIM_ClockDivision;
  }
  TIMx->CR1 = tmpcr1;
  TIMx->ARR = TIM_TimeBaseInitStruct->TIM_Period ;
  TIMx->PSC = TIM_TimeBaseInitStruct->TIM_Prescaler;
  if ((TIMx == TIM1) || (TIMx == TIM8)|| (TIMx == TIM15)|| (TIMx == TIM16) || (TIMx == TIM17))  
  {
    TIMx->RCR = TIM_TimeBaseInitStruct->TIM_RepetitionCounter;
  }
  TIMx->EGR = TIM_PSCReloadMode_Immediate;           
}
void TIM_TimeBaseInit ( TIM_TypeDef * TIMx , TIM_TimeBaseInitTypeDef * TIM_TimeBaseInitStruct ) { uint16_t tmpcr1 = 0 ; assert_param ( IS_TIM_ALL_PERIPH ( TIMx ) ) ; assert_param ( IS_TIM_COUNTER_MODE ( TIM_TimeBaseInitStruct -> TIM_CounterMode ) ) ; assert_param ( IS_TIM_CKD_DIV ( TIM_TimeBaseInitStruct -> TIM_ClockDivision ) ) ; tmpcr1 = TIMx -> CR1 ; if ( ( TIMx == TIM1 ) || ( TIMx == TIM8 ) || ( TIMx == TIM2 ) || ( TIMx == TIM3 ) || ( TIMx == TIM4 ) || ( TIMx == TIM5 ) ) { tmpcr1 &= ( uint16_t ) ( ~ ( ( uint16_t ) ( TIM_CR1_DIR | TIM_CR1_CMS ) ) ) ; tmpcr1 |= ( uint32_t ) TIM_TimeBaseInitStruct -> TIM_CounterMode ; } if ( ( TIMx != TIM6 ) && ( TIMx != TIM7 ) ) { tmpcr1 &= ( uint16_t ) ( ~ ( ( uint16_t ) TIM_CR1_CKD ) ) ; tmpcr1 |= ( uint32_t ) TIM_TimeBaseInitStruct -> TIM_ClockDivision ; } TIMx -> CR1 = tmpcr1 ; TIMx -> ARR = TIM_TimeBaseInitStruct -> TIM_Period ; TIMx -> PSC = TIM_TimeBaseInitStruct -> TIM_Prescaler ; if ( ( TIMx == TIM1 ) || ( TIMx == TIM8 ) || ( TIMx == TIM15 ) || ( TIMx == TIM16 ) || ( TIMx == TIM17 ) ) { TIMx -> RCR = TIM_TimeBaseInitStruct -> TIM_RepetitionCounter ; } TIMx -> EGR = TIM_PSCReloadMode_Immediate ; }
@brief  Initializes the TIMx Time Base Unit peripheral according to
         the specified parameters in the TIM_TimeBaseInitStruct.
@brief Initializes the TIMx Time Base Unit peripheral according to the specified parameters in the TIM_TimeBaseInitStruct .
/* Check the parameters */ /* Select the Counter Mode */ /* Set the clock division */ /* Set the Autoreload value */ /* Set the Prescaler value */ /* Set the Repetition Counter value */ /* Generate an update event to reload the Prescaler and the Repetition counter
     values immediately */