Exemplo n.º 1
0
static u32 timer_set_clock( unsigned id, u32 clock )
{
  TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
  TIM_TypeDef *ptimer = timer[ id ];
  u16 pre = ( TIM_GET_BASE_CLK( id ) / clock ) - 1;
  
  TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
  TIM_TimeBaseStructure.TIM_Prescaler = pre;
  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0x0000;
  TIM_TimeBaseInit( timer[ id ], &TIM_TimeBaseStructure );
  TIM_Cmd( ptimer, ENABLE );
  
  return TIM_GET_BASE_CLK( id ) / ( pre + 1 );
}
Exemplo n.º 2
0
static u32 platform_timer_set_clock( unsigned id, u32 clock )
{
  TIM_TimeBaseInitTypeDef timer_base_struct;
  TIM_TypeDef *ptimer = (TIM_TypeDef*)timer[ id ];
  u32 pre = ( TIM_GET_BASE_CLK( id ) / clock ) - 1;

  if( pre > 65535 ) // Limit prescaler to 16-bits
    pre = 65535;

  timer_base_struct.TIM_Period = 0xFFFF;
  timer_base_struct.TIM_Prescaler = ( u16 )pre;
  timer_base_struct.TIM_ClockDivision = TIM_CKD_DIV1;
  timer_base_struct.TIM_CounterMode = TIM_CounterMode_Up;
  timer_base_struct.TIM_RepetitionCounter = 0x0000;
  TIM_TimeBaseInit( (TIM_TypeDef*)timer[ id ], &timer_base_struct );
  TIM_Cmd( ptimer, ENABLE );

  return  platform_timer_get_clock( id );
}
Exemplo n.º 3
0
static u32 timer_get_clock( unsigned id )
{
  TIM_TypeDef* ptimer = timer[ id ];

  return TIM_GET_BASE_CLK( id ) / ( TIM_GetPrescaler( ptimer ) + 1 );
}