//-----------------------------------------------------------------------------
///
/// \brief  calculate timer values
///
///         e.g. get prescaler and period for a given frequencie.
///
/// \date   20121117
/// \author Maximilian Seesslen <development@seesslen.net>
///
//-----------------------------------------------------------------------------


//---Includes------------------------------------------------------------------


//---Own------------------------------

#include <biwak/timer.hpp>      // frequency_t
#include <HALWrapper/stm32_hal.h>    // HAL_RCC_GetSysClockFreq()


//---Implementation------------------------------------------------------------


int timerClockFrequency()
{
   return(HAL_RCC_GetSysClockFreq() );
}

/*
void _calculateValuesByFrequency(frequency_t frequency, unsigned int* pPrescaler, unsigned int* pPeriod)
{
   *pPrescaler=( timerClockFrequency() / frequency / 65536 ) + 1;
   *pPeriod=( timerClockFrequency() / frequency / *pPrescaler );
   return;
};
*/

frequency_t _calculateFrequencyByValues(int prescaler, int period)
{
   return(
      (frequency_t)timerClockFrequency() / (prescaler * period) );
}


//---fin-----------------------------------------------------------------------
