soc/rtc: round APB clock frequency to nearest MHz

This commit is contained in:
Ivan Grokhotkov 2017-08-21 22:33:52 +08:00
parent d24e0dcc2c
commit c743bdac88

View file

@ -500,7 +500,11 @@ void rtc_clk_apb_freq_update(uint32_t apb_freq)
uint32_t rtc_clk_apb_freq_get()
{
return reg_val_to_clk_val(READ_PERI_REG(RTC_APB_FREQ_REG)) << 12;
uint32_t freq_hz = reg_val_to_clk_val(READ_PERI_REG(RTC_APB_FREQ_REG)) << 12;
// round to the nearest MHz
freq_hz += MHZ / 2;
uint32_t remainder = freq_hz % MHZ;
return freq_hz - remainder;
}