Code:
typedef struct {
uint32 magic ;
uint32 rst_count;
uint64 Reserved;
}RTC_RST_STRUCT;
bool ICACHE_FLASH_ATTR StoreRSTCount(uint32 Count)
{
os_printf("[%s][%s][%d] - creating with: %u\r\n", __FILE__ ,__func__, __LINE__, Count);
//system_rtc_mem_write(68, &Count, sizeof(Count));
RTC_RST_STRUCT rtc_rst;
rtc_rst.magic = 0xDEADBEEF;
rtc_rst.rst_count = Count;
system_rtc_mem_write(72, &rtc_rst, sizeof(rtc_rst));
}
uint32_t ICACHE_FLASH_ATTR GetRSTCount(void)
{
os_printf("[%s][%s][%d]\r\n", __FILE__ ,__func__, __LINE__);
uint32 count;
//system_rtc_mem_read(68, &count, sizeof(count));
RTC_RST_STRUCT rtc_rst;
system_rtc_mem_read(72, &rtc_rst, sizeof(rtc_rst));
if(rtc_rst.magic==0xDEADBEEF)
{
os_printf("[%s][%s][%d] - GET GetRSTCount %u\r\n", __FILE__ ,__func__, __LINE__, rtc_rst.rst_count);
return rtc_rst.rst_count;
}
else
{
return NULL;
}
}
Code:
struct rst_info *rtc_info = system_get_rst_info();
os_printf("reset reason: %x\n", rtc_info->reason);
switch (rtc_info->reason)
{
case REASON_DEFAULT_RST:
os_printf("REASON_DEFAULT_RST\r\n");
break;
case REASON_WDT_RST:
os_printf("REASON_WDT_RST\r\n");
break;
case REASON_SOFT_WDT_RST:
os_printf("REASON_SOFT_WDT_RST\r\n");
break;
case REASON_SOFT_RESTART:
os_printf("REASON_SOFT_RESTART\r\n");
break;
case REASON_EXCEPTION_RST:
os_printf("REASON_EXCEPTION_RST (%d)\r\n", rtc_info->exccause); //Add recovery code logic here
uint32_t EXC = GetEXCCount();
if (EXC == NULL)
{
StoreEXCCount(1);
}
else
{
EXC++;
StoreEXCCount(EXC);
}
//Add some Call back register here! =)
break;
case REASON_DEEP_SLEEP_AWAKE:
os_printf("REASON_DEEP_SLEEP_AWAKE\r\n");
break;
case REASON_EXT_SYS_RST:
os_printf("REASON_EXT_SYS_RST - Button Press\r\n"); //When freshly Flashed we get this or a Hard button Reset
common_RSTCount = GetRSTCount();
if (common_RSTCount == NULL)
{
os_printf("common_RSTCount == NULL / ZERO\r\n");
StoreRSTCount(1);
}
else if(common_RSTCount == 9)
{
os_printf("common_RSTCount == %u, setting up WiFi\r\n", common_RSTCount);
}
else
{
os_printf("common_RSTCount == %u\r\n", common_RSTCount);
common_RSTCount++;
StoreRSTCount(common_RSTCount);
}
delay_5seconds(); //Give the user five seconds to reset once more to higher the count!
//Add some Call back register here! =)
if(common_RSTCount >= 3 || false) //true for debugging code
{
os_printf("Entering Debug Mode");
FlickerLED(2, 30);
FlickerLED(2, 60);
FlickerLED(2, 30);
FlickerLED(2, 60);
//Add some debug code here
spi_flash_read(WifiMemorySpace,(uint32 *)&GlobalFlashConfig,sizeof(GlobalFlashConfig));
uart_init(BIT_RATE_115200, BIT_RATE_115200, &UartReceive); //This only seems to be kicked off via the COM-USB onboard, Not the TX/RX port
InDebugMode = true;
}
StoreRSTCount(0); //Reset value to zero
break;
default:
os_printf("Some other REASON?!\r\n");
break;
}
if (rtc_info->reason == REASON_WDT_RST || rtc_info->reason == REASON_EXCEPTION_RST || rtc_info->reason == REASON_SOFT_WDT_RST)
{
os_printf("epc1=0x%08x, epc2=0x%08x, epc3=0x%08x, excvaddr=0x%08x, depc=0x%08x\n", rtc_info->epc1, rtc_info->epc2, rtc_info->epc3, rtc_info->excvaddr, rtc_info->depc);//debug garbled output.
halt();
}
Statistics: Posted by AgentSmithers — Thu Dec 09, 2021 4:42 pm
Statistics: Posted by Her Mary — Wed Dec 01, 2021 11:12 am
Statistics: Posted by 315002181huang — Fri Nov 26, 2021 7:10 pm