summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoritz Fischer <moritz.fischer@ettus.com>2019-01-02 16:26:12 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-01-09 06:26:08 -0800
commitc78bd78daca4d6a3f5befbfe9475eaf306e5238e (patch)
treeac2c91fead6e4ea02b484c2759785ab7ae9ba6db
parent7ced9b2e02cdb49b78384ecb93978c1bab5cd015 (diff)
downloadchrome-ec-stabilize-11554.B.tar.gz
chip: stm32: clock-stm32f4: Implement rtc_set() for RTCstabilize-11554.B
Implement rtc_set() function for STM32F4 chip variant BUG=none BRANCH=none TEST=Using eval-board, use rtc set 0, observe increments Change-Id: I63abe0c388b7a0ba9ed881b393ffdbcc69e6d75a Signed-off-by: Moritz Fischer <moritz.fischer@ettus.com> Reviewed-on: https://chromium-review.googlesource.com/1401017 Reviewed-by: Philip Chen <philipchen@chromium.org>
-rw-r--r--chip/stm32/clock-stm32f4.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/chip/stm32/clock-stm32f4.c b/chip/stm32/clock-stm32f4.c
index 5ece4fde27..8dbfd2fcca 100644
--- a/chip/stm32/clock-stm32f4.c
+++ b/chip/stm32/clock-stm32f4.c
@@ -34,12 +34,12 @@
#define RTC_PREDIV_S (RTC_FREQ - 1)
#define US_PER_RTC_TICK (1000000 / RTC_FREQ)
-int32_t rtc_ssr_to_us(uint32_t rtcss)
+int32_t rtcss_to_us(uint32_t rtcss)
{
return ((RTC_PREDIV_S - rtcss) * US_PER_RTC_TICK);
}
-uint32_t us_to_rtc_ssr(int32_t us)
+uint32_t us_to_rtcss(int32_t us)
{
return (RTC_PREDIV_S - (us / US_PER_RTC_TICK));
}
@@ -267,3 +267,31 @@ void rtc_init(void)
rtc_lock_regs();
}
+
+#if defined(CONFIG_CMD_RTC) || defined(CONFIG_HOSTCMD_RTC)
+void rtc_set(uint32_t sec)
+{
+ struct rtc_time_reg rtc;
+
+ sec_to_rtc(sec, &rtc);
+ rtc_unlock_regs();
+
+ /* Disable alarm */
+ STM32_RTC_CR &= ~STM32_RTC_CR_ALRAE;
+
+ /* Enter RTC initialize mode */
+ STM32_RTC_ISR |= STM32_RTC_ISR_INIT;
+ while (!(STM32_RTC_ISR & STM32_RTC_ISR_INITF))
+ ;
+
+ /* Set clock prescalars */
+ STM32_RTC_PRER = (RTC_PREDIV_A << 16) | RTC_PREDIV_S;
+
+ STM32_RTC_TR = rtc.rtc_tr;
+ STM32_RTC_DR = rtc.rtc_dr;
+ /* Start RTC timer */
+ STM32_RTC_ISR &= ~STM32_RTC_ISR_INIT;
+
+ rtc_lock_regs();
+}
+#endif