auto-sync

This commit is contained in:
rusEfi 2016-09-15 22:02:00 -04:00
parent 22324de14c
commit 6674a9d941
4 changed files with 20 additions and 9 deletions

View File

@ -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 <lseTimeout);\
while ((RTCD1.id_rtc->ISR & RTC_ISR_RSF) == 0 && ++counter <LSE_TIMEOUT) \
; \
if (counter==LSE_TIMEOUT) {rtcWorks = false; } \
}
/**
@ -75,6 +77,7 @@ extern int lseTimeout;
int counter = 0; \
while ((RTCD1.id_rtc->ISR & RTC_ISR_INITF) == 0 && ++counter <LSE_TIMEOUT)\
; \
if (counter==LSE_TIMEOUT) {rtcWorks = false; } \
}
/**
@ -133,6 +136,9 @@ void rtc_lld_init(void){
void rtc_lld_set_time(RTCDriver *rtcp, const RTCTime *timespec) {
(void)rtcp;
if (!rtcWorks)
return;
rtc_lld_enter_init();
if (timespec->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, &timespec);
if (rtcWorks)
rtcGetTimeI(rtcp, &timespec);
chSysUnlock();
tv_time = timespec.tv_time;

View File

@ -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();

View File

@ -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

View File

@ -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 */
}