rtctime.dsleep() current draw improvements (#1659)

* Switch off interrupts before rtctime dsleep.

* Deal with the fact that MCU keeps running after being told to enter deep sleep
(It can keep running for quite a few instructions at times (and none at
all at others), and it appears that trying to cache additional code from
SPI flash while trying to go to sleep fails miserably at both....)

* Ensure flash is not active when going into deep sleep.
This commit is contained in:
Johny Mattsson 2016-12-14 22:39:31 +11:00 committed by Marcel Stör
parent 1b8e9a33e5
commit c5c0143b2f
3 changed files with 27 additions and 4 deletions

View File

@ -54,4 +54,17 @@ static inline uint32_t rtc_reg_read(uint32_t addr)
rtc_memw();
return *((volatile uint32_t*)addr);
}
static inline void rtc_reg_write_and_loop(uint32_t addr, uint32_t val)
{
addr+=RTC_MMIO_BASE;
rtc_memw();
asm("j 1f\n"
".align 32\n"
"1:\n"
"s32i.n %1,%0,0\n"
"2:\n"
"j 2b\n"::"r"(addr),"r"(val):);
}
#endif

View File

@ -396,6 +396,8 @@ static inline void rtc_time_add_sleep_tracking(uint32_t us, uint32_t cycles)
}
}
extern void rtc_time_enter_deep_sleep_final(void);
static void rtc_time_enter_deep_sleep_us(uint32_t us)
{
if (rtc_time_check_wake_magic())
@ -430,14 +432,14 @@ static void rtc_time_enter_deep_sleep_us(uint32_t us)
rtc_reg_write(0x9c,17);
rtc_reg_write(0xa0,3);
// Clear bit 0 of DPORT 0x04. Doesn't seem to be necessary
// wm(0x3fff0004,bitrm(0x3fff0004),0xfffffffe));
volatile uint32_t* dport4=(volatile uint32_t*)0x3ff00004;
*dport4&=0xfffffffe;
rtc_reg_write(0x40,-1);
rtc_reg_write(0x44,32);
rtc_reg_write(0x10,0);
rtc_reg_write(0x18,8);
rtc_reg_write(0x08,0x00100000); // go to sleep
rtc_time_enter_deep_sleep_final();
}
static inline void rtc_time_deep_sleep_us(uint32_t us)

View File

@ -35,6 +35,14 @@ static int __isleap (int year) {
}
// ******* C API functions *************
void __attribute__((noreturn)) TEXT_SECTION_ATTR rtc_time_enter_deep_sleep_final (void)
{
ets_intr_lock();
Cache_Read_Disable();
rtc_reg_write(0x18,8);
rtc_reg_write_and_loop(0x08,0x00100000); // go to sleep
__builtin_unreachable();
}
void rtctime_early_startup (void)
{