/* Initializes the tim Time Base Unit peripheral according to the specified parameters in the init_struct.  */
void TIM_TimeBaseInit(TIM_TypeDef *tim, TIM_TimeBaseInitTypeDef *init_struct)
/* Initializes the tim Time Base Unit peripheral according to the specified parameters in the init_struct.  */
void TIM_TimeBaseInit(TIM_TypeDef *tim, TIM_TimeBaseInitTypeDef *init_struct)
{
    MODIFY_REG(tim->CR1, TIM_CR1_CKD, init_struct->TIM_ClockDivision);
    if ((tim == TIM1) || (tim == TIM2) || (tim == TIM3) || (tim == TIM4) || (tim == TIM5) || (tim == TIM8))
        MODIFY_REG(tim->CR1, TIM_CR1_CMS | TIM_CR1_DIR, init_struct->TIM_CounterMode);
    if ((tim == TIM1) || (tim == TIM8) )
        MODIFY_REG(tim->RCR, TIM_RCR_REP, init_struct->TIM_RepetitionCounter);
    WRITE_REG(tim->ARR, init_struct->TIM_Period);
    WRITE_REG(tim->PSC, init_struct->TIM_Prescaler);
    WRITE_REG(tim->EGR, TIM_PSCReloadMode_Immediate);
}