From 6674a9d941bf9933ed31a85bf479c9a986c1b358 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Thu, 15 Sep 2016 22:02:00 -0400 Subject: [PATCH] auto-sync --- .../chibios/os/hal/platforms/STM32/RTCv2/rtc_lld.c | 13 ++++++++++--- firmware/chibios/os/hal/src/rtc.c | 4 ++++ firmware/hw_layer/hardware.cpp | 6 ++++-- firmware/hw_layer/rtc_helper.cpp | 6 ++---- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/firmware/chibios/os/hal/platforms/STM32/RTCv2/rtc_lld.c b/firmware/chibios/os/hal/platforms/STM32/RTCv2/rtc_lld.c index d556398fa3..48dee3a058 100644 --- a/firmware/chibios/os/hal/platforms/STM32/RTCv2/rtc_lld.c +++ b/firmware/chibios/os/hal/platforms/STM32/RTCv2/rtc_lld.c @@ -52,7 +52,7 @@ RTCDriver RTCD1; /* Driver local functions. */ /*===========================================================================*/ -extern int lseTimeout; +extern bool rtcWorks; /** * @brief Wait for synchronization of RTC registers with APB1 bus. @@ -62,7 +62,9 @@ extern int lseTimeout; */ #define rtc_lld_apb1_sync() { \ int counter = 0; \ - while ((RTCD1.id_rtc->ISR & RTC_ISR_RSF) == 0 && ++counter ISR & RTC_ISR_RSF) == 0 && ++counter ISR & RTC_ISR_INITF) == 0 && ++counter h12) RTCD1.id_rtc->CR |= RTC_CR_FMT; @@ -305,7 +311,8 @@ uint32_t rtc_lld_get_time_fat(RTCDriver *rtcp) { uint32_t v; chSysLock(); - rtcGetTimeI(rtcp, ×pec); + if (rtcWorks) + rtcGetTimeI(rtcp, ×pec); chSysUnlock(); tv_time = timespec.tv_time; diff --git a/firmware/chibios/os/hal/src/rtc.c b/firmware/chibios/os/hal/src/rtc.c index 25ae0e6796..35bccbe306 100644 --- a/firmware/chibios/os/hal/src/rtc.c +++ b/firmware/chibios/os/hal/src/rtc.c @@ -91,6 +91,8 @@ void rtcSetTime(RTCDriver *rtcp, const RTCTime *timespec) { chSysUnlock(); } +extern bool rtcWorks; + /** * @brief Get current time. * @@ -103,6 +105,8 @@ void rtcGetTime(RTCDriver *rtcp, RTCTime *timespec) { chDbgCheck((rtcp != NULL) && (timespec != NULL), "rtcGetTime"); + if (!rtcWorks) + return; chSysLock(); rtcGetTimeI(rtcp, timespec); chSysUnlock(); diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index 30dae6c75b..5b58c0c32d 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -61,8 +61,10 @@ int maxNesting = 0; #if HAL_USE_SPI || defined(__DOXYGEN__) extern bool isSpiInitialized[5]; -// todo: use larger value if LSE is available, make this a boardConfiguration option -int lseTimeout = 0; +/** + * #311 we want to test RTC before engine start so that we do not test it while engine is running + */ +bool rtcWorks = true; /** * Only one consumer can use SPI bus at a given time diff --git a/firmware/hw_layer/rtc_helper.cpp b/firmware/hw_layer/rtc_helper.cpp index 72dee4b5e4..09e4d2f5ee 100644 --- a/firmware/hw_layer/rtc_helper.cpp +++ b/firmware/hw_layer/rtc_helper.cpp @@ -125,9 +125,7 @@ void setDateTime(const char *strDate) { void initRtc(void) { #if EFI_RTC || defined(__DOXYGEN__) + rtcGetTimeUnixSec(&RTCD1); // this would test RTC, see 'rtcWorks' variable, see #311 printMsg(&logger, "initRtc()"); - - // yes, it's my begin time and we always start from this one 1391894433 - 2014-02-08 21:20:03 -// rtcSetTimeUnixSec(&RTCD1, 1391894433); -#endif +#endif /* EFI_RTC */ }