Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to trace where watchdog reboots on bl602 #1322

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions src/user_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,14 +480,15 @@ float g_wifi_temperature = 0;
static byte g_secondsSpentInLowMemoryWarning = 0;
void Main_OnEverySecond()
{
printf("[TRACE] Entering OnEverySecond\n");
int newMQTTState;
const char* safe;
int i;

#ifdef WINDOWS
g_bHasWiFiConnected = 1;
#endif

printf("[TRACE] Before reading temp \n");
// display temperature - thanks to giedriuslt
// only in Normal mode, and if boot is not failing
if (!bSafeMode && g_bootFailures <= 1)
Expand All @@ -501,26 +502,35 @@ void Main_OnEverySecond()
g_wifi_temperature = temperature * 0.128f;
#endif
#elif PLATFORM_BL602
get_tsen_adc(&g_wifi_temperature, 0);
//do not read temp, sometimes it's to slow and causes reboot
//get_tsen_adc(&g_wifi_temperature, 0);
#elif PLATFORM_LN882H
// this is set externally, I am just leaving comment here
#endif
}
printf("[TRACE] After reading temp\n");
// run_adc_test();
newMQTTState = MQTT_RunEverySecondUpdate();
printf("[TRACE] After MQTT_RunEverySecondUpdate\n");
if (newMQTTState != bMQTTconnected) {
bMQTTconnected = newMQTTState;
if (newMQTTState) {
printf("[TRACE] Before CMD_EVENT_MQTT_STATE 1\n");
EventHandlers_FireEvent(CMD_EVENT_MQTT_STATE, 1);
printf("[TRACE] After CMD_EVENT_MQTT_STATE 1\n");
}
else {
printf("[TRACE] Before CMD_EVENT_MQTT_STATE 0\n");
EventHandlers_FireEvent(CMD_EVENT_MQTT_STATE, 0);
printf("[TRACE] After CMD_EVENT_MQTT_STATE 0\n");
}
}
if (g_newWiFiStatus != g_prevWiFiStatus) {
g_prevWiFiStatus = g_newWiFiStatus;
// Argument type here is HALWifiStatus_t enumeration
printf("[TRACE] Before CMD_EVENT_WIFI_STATE\n");
EventHandlers_FireEvent(CMD_EVENT_WIFI_STATE, g_newWiFiStatus);
printf("[TRACE] After CMD_EVENT_WIFI_STATE\n");
}
// Update time with no MQTT
if (bMQTTconnected) {
Expand All @@ -530,15 +540,20 @@ void Main_OnEverySecond()
}
// 'i' is a new value
EventHandlers_ProcessVariableChange_Integer(CMD_EVENT_CHANGE_NOMQTTTIME, g_noMQTTTime, i);
printf("[TRACE] After CMD_EVENT_CHANGE_NOMQTTTIME\n");
// save new value
g_noMQTTTime = i;

MQTT_Dedup_Tick();
printf("[TRACE] After MQTT_Dedup_Tick\n");
LED_RunOnEverySecond();
printf("[TRACE] After LED_RunOnEverySecond\n");
#ifndef OBK_DISABLE_ALL_DRIVERS
DRV_OnEverySecond();
printf("[TRACE] After DRV_OnEverySecond\n");
#if defined(PLATFORM_BEKEN) || defined(WINDOWS) || defined(PLATFORM_BL602)
UART_RunEverySecond();
printf("[TRACE] After UART_RunEverySecond\n");
#endif
#endif

Expand All @@ -551,6 +566,7 @@ void Main_OnEverySecond()
#endif
{
CFG_Save_IfThereArePendingChanges();
printf("[TRACE] After CFG_Save_IfThereArePendingChanges\n");
}

// On Beken, do reboot if we ran into heap size problem
Expand All @@ -570,14 +586,21 @@ void Main_OnEverySecond()
const char* ip = HAL_GetMyIPString();
// this will return non-zero if there were any changes
if (strcpy_safe_checkForChanges(g_currentIPString, ip, sizeof(g_currentIPString))) {
printf("[TRACE] After strcpy_safe_checkForChanges\n");
if (MQTT_IsReady()) {
printf("[TRACE] Before MQTT_DoItemPublish\n");
MQTT_DoItemPublish(PUBLISHITEM_SELF_IP);
printf("[TRACE] After MQTT_DoItemPublish\n");
}
printf("[TRACE] Before CMD_EVENT_IPCHANGE 0\n");
EventHandlers_FireEvent(CMD_EVENT_IPCHANGE, 0);
printf("[TRACE] After CMD_EVENT_IPCHANGE 0\n");

//Invoke Hass discovery if ipaddr changed
if (CFG_HasFlag(OBK_FLAG_AUTOMAIC_HASS_DISCOVERY)) {
printf("[TRACE] Before Main_ScheduleHomeAssistantDiscovery\n");
Main_ScheduleHomeAssistantDiscovery(1);
printf("[TRACE] After Main_ScheduleHomeAssistantDiscovery\n");
}
}
}
Expand Down Expand Up @@ -614,15 +637,17 @@ void Main_OnEverySecond()
if (g_cfg.pins.roles[i] == IOR_ADC)
{
int value;
printf("[TRACE] Before HAL_ADC_Read\n");

value = HAL_ADC_Read(i);

// ADDLOGF_INFO("ADC %i=%i\r\n", i,value);
CHANNEL_Set(g_cfg.pins.channels[i], value, CHANNEL_SET_FLAG_SILENT);
printf("[TRACE] After HAL_ADC_Read\n");
}
}
}

printf("[TRACE] Before scheduled driver starts\n");
// allow for up to 4 scheduled driver starts.
for (i = 0; i < 4; i++) {
if (scheduledDelay[i] > 0) {
Expand All @@ -638,6 +663,7 @@ void Main_OnEverySecond()
}
}
}
printf("[TRACE] After scheduled driver starts\n");

g_secondsElapsed++;
if (bSafeMode) {
Expand Down Expand Up @@ -669,7 +695,9 @@ void Main_OnEverySecond()
// print network info
if (!(g_secondsElapsed % 10))
{
printf("[TRACE] Before HAL_PrintNetworkInfo\n");
HAL_PrintNetworkInfo();
printf("[TRACE] After HAL_PrintNetworkInfo\n");

}
// IR TESTING ONLY!!!!
Expand Down Expand Up @@ -753,15 +781,19 @@ void Main_OnEverySecond()
g_connectToWiFi--;
if (0 == g_connectToWiFi && g_bHasWiFiConnected == 0)
{
printf("[TRACE] Before Main_ConnectToWiFiNow\n");
Main_ConnectToWiFiNow();
printf("[TRACE] After Main_ConnectToWiFiNow\n");
}
}

// config save moved here because of stack size problems
if (g_saveCfgAfter) {
g_saveCfgAfter--;
if (!g_saveCfgAfter) {
printf("[TRACE] Before CFG_Save_IfThereArePendingChanges\n");
CFG_Save_IfThereArePendingChanges();
printf("[TRACE] After CFG_Save_IfThereArePendingChanges\n");
}
}
if (g_doUnsafeInitIn) {
Expand All @@ -779,7 +811,9 @@ void Main_OnEverySecond()
#ifndef OBK_DISABLE_ALL_DRIVERS
if (DRV_IsMeasuringPower())
{
printf("[TRACE] Before BL09XX_SaveEmeteringStatistics\n");
BL09XX_SaveEmeteringStatistics();
printf("[TRACE] After BL09XX_SaveEmeteringStatistics\n");
}
#endif
ADDLOGF_INFO("Going to call HAL_RebootModule\r\n");
Expand All @@ -794,7 +828,9 @@ void Main_OnEverySecond()
#if ENABLE_DRIVER_DHT
if (g_dhtsCount > 0) {
if (bSafeMode == 0) {
printf("[TRACE] Before DHT_OnEverySecond\n");
DHT_OnEverySecond();
printf("[TRACE] After DHT_OnEverySecond\n");
}
}
#endif
Expand All @@ -807,9 +843,11 @@ void Main_OnEverySecond()
#elif PLATFORM_LN882H
hal_wdt_cnt_restart(WDT_BASE);
#endif
printf("[TRACE] After watchdog reset\n");
// force it to sleep... we MUST have some idle task processing
// else task memory doesn't get freed
rtos_delay_milliseconds(1);
printf("[TRACE] Exiting OnEverySecond\n");

}

Expand Down
Loading