mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #12871 from benpicco/lpc2387_rtc_cleanup
cpu/lpc2387: rtc: remove use of localtime()
This commit is contained in:
commit
eede974fa0
@ -88,7 +88,7 @@ static inline void _init_data(void)
|
||||
|
||||
#ifdef CPU_HAS_BACKUP_RAM
|
||||
/* only initialize battery backup on cold boot */
|
||||
if (cpu_woke_from_backup()) {
|
||||
if (cpu_backup_ram_is_initialized()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -139,12 +139,19 @@ void cpu_init(void)
|
||||
/* 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
|
||||
*/
|
||||
bool cpu_woke_from_backup(void)
|
||||
bool cpu_backup_ram_is_initialized(void)
|
||||
{
|
||||
static char signature[] __attribute__((section(".backup.data"))) = {
|
||||
'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 */
|
||||
if (RSIR & RSIR_EXTR) {
|
||||
return false;
|
||||
@ -166,6 +173,11 @@ bool cpu_woke_from_backup(void)
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,14 @@ static inline void cpu_print_last_instruction(void)
|
||||
/**
|
||||
* @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.
|
||||
|
@ -40,9 +40,6 @@ static rtc_alarm_cb_t _cb;
|
||||
/* Argument to alarm callback */
|
||||
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_init(void)
|
||||
@ -56,10 +53,12 @@ void rtc_init(void)
|
||||
|
||||
RTC_CCR = CCR_CLKSRC; /* Clock from external 32 kHz Osc. */
|
||||
|
||||
/* initialize clock with valid unix compatible values
|
||||
* If RTC_YEAR contains an value larger unix time_t we must reset. */
|
||||
if (RTC_YEAR > 2037) {
|
||||
_rtc_set(0);
|
||||
/* Initialize clock to a a sane and predictable default
|
||||
* after cold boot or external reset.
|
||||
*/
|
||||
if ((RSIR == RSIR_POR) || (RSIR == (RSIR_POR | RSIR_EXTR))) {
|
||||
struct tm localt = { .tm_year = 70 };
|
||||
rtc_set_time(&localt);
|
||||
}
|
||||
|
||||
rtc_poweron();
|
||||
@ -201,10 +200,3 @@ void RTC_IRQHandler(void)
|
||||
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user