Merge pull request #12871 from benpicco/lpc2387_rtc_cleanup

cpu/lpc2387: rtc: remove use of localtime()
This commit is contained in:
benpicco 2020-02-10 23:36:14 +01:00 committed by GitHub
commit eede974fa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 17 deletions

View File

@ -88,7 +88,7 @@ static inline void _init_data(void)
#ifdef CPU_HAS_BACKUP_RAM #ifdef CPU_HAS_BACKUP_RAM
/* only initialize battery backup on cold boot */ /* only initialize battery backup on cold boot */
if (cpu_woke_from_backup()) { if (cpu_backup_ram_is_initialized()) {
return; return;
} }

View File

@ -139,12 +139,19 @@ void cpu_init(void)
/* RSIR will only have POR bit set even when waking up from Deep Power Down /* RSIR will only have POR bit set even when waking up from Deep Power Down
* Use signature in battery RAM to discriminate between Deep Power Down and POR * Use signature in battery RAM to discriminate between Deep Power Down and POR
*/ */
bool cpu_woke_from_backup(void) bool cpu_backup_ram_is_initialized(void)
{ {
static char signature[] __attribute__((section(".backup.data"))) = { static char signature[] __attribute__((section(".backup.data"))) = {
'R', 'I', 'O', 'T' 'R', 'I', 'O', 'T'
}; };
/* Only in case when a reset occurs and the POR = 0, the BODR bit
* indicates if the V_DD (3V3) voltage was below 2.6 V or not.
*/
if ((RSIR & (RSIR_BODR | RSIR_POR)) == (RSIR_BODR | RSIR_POR)) {
RSIR |= RSIR_BODR;
}
/* external reset */ /* external reset */
if (RSIR & RSIR_EXTR) { if (RSIR & RSIR_EXTR) {
return false; return false;
@ -166,6 +173,11 @@ bool cpu_woke_from_backup(void)
return false; return false;
} }
/* When we wake from Deep Sleep only POR is set, just like in the real
* POR case. Clear the bit to create a new, distinct state.
*/
RSIR |= RSIR_POR;
return true; return true;
} }

View File

@ -60,7 +60,14 @@ static inline void cpu_print_last_instruction(void)
/** /**
* @brief Returns true if the CPU woke from Deep Sleep * @brief Returns true if the CPU woke from Deep Sleep
*/ */
bool cpu_woke_from_backup(void); static inline bool cpu_woke_from_backup(void) {
return RSIR == 0;
}
/**
* @brief Returns true if the backup RAM has been initialized
*/
bool cpu_backup_ram_is_initialized(void);
/** /**
* @brief The CPU has RAM that is retained in the deepest sleep mode. * @brief The CPU has RAM that is retained in the deepest sleep mode.

View File

@ -40,9 +40,6 @@ static rtc_alarm_cb_t _cb;
/* Argument to alarm callback */ /* Argument to alarm callback */
static void *_cb_arg; static void *_cb_arg;
/* internal function to set time based on time_t */
static void _rtc_set(time_t time);
void RTC_IRQHandler(void) __attribute__((interrupt("IRQ"))); void RTC_IRQHandler(void) __attribute__((interrupt("IRQ")));
void rtc_init(void) void rtc_init(void)
@ -56,10 +53,12 @@ void rtc_init(void)
RTC_CCR = CCR_CLKSRC; /* Clock from external 32 kHz Osc. */ RTC_CCR = CCR_CLKSRC; /* Clock from external 32 kHz Osc. */
/* initialize clock with valid unix compatible values /* Initialize clock to a a sane and predictable default
* If RTC_YEAR contains an value larger unix time_t we must reset. */ * after cold boot or external reset.
if (RTC_YEAR > 2037) { */
_rtc_set(0); if ((RSIR == RSIR_POR) || (RSIR == (RSIR_POR | RSIR_EXTR))) {
struct tm localt = { .tm_year = 70 };
rtc_set_time(&localt);
} }
rtc_poweron(); rtc_poweron();
@ -201,10 +200,3 @@ void RTC_IRQHandler(void)
VICVectAddr = 0; /* Acknowledge Interrupt */ VICVectAddr = 0; /* Acknowledge Interrupt */
} }
static void _rtc_set(time_t time)
{
struct tm *localt;
localt = localtime(&time); /* convert seconds to broken-down time */
rtc_set_time(localt);
}