diff --git a/src/httpserver/http_tcp_server.c b/src/httpserver/http_tcp_server.c index 7ad9579d3..fe7663ce6 100644 --- a/src/httpserver/http_tcp_server.c +++ b/src/httpserver/http_tcp_server.c @@ -72,6 +72,7 @@ static void tcp_client_thread(beken_thread_arg_t arg) //char reply[8192]; //my_fd = fd; + rtos_delay_milliseconds(20); reply = (char*)os_malloc(replyBufferSize); buf = (char*)os_malloc(INCOMING_BUFFER_SIZE); @@ -112,7 +113,7 @@ static void tcp_client_thread(beken_thread_arg_t arg) send(fd, reply, lenret, 0); } - rtos_delay_milliseconds(10); + //rtos_delay_milliseconds(10); exit: if (err != kNoErr) @@ -177,6 +178,12 @@ static void tcp_server_thread(beken_thread_arg_t arg) // right now, I am getting OS_ThreadCreate everytime on XR809 platform tcp_client_thread((beken_thread_arg_t)client_fd); #else + // delay each accept by 20ms + // this allows previous to finish if + // in a loop of sends from the browser, e.g. OTA + // and we MUST get some IDLE thread time, else + // thread resources are not deleted. + rtos_delay_milliseconds(20); // Create separate thread for client if (kNoErr != #if PLATFORM_XR809 diff --git a/src/ota/ota.c b/src/ota/ota.c index 757ef25ab..1be7a7103 100644 --- a/src/ota/ota.c +++ b/src/ota/ota.c @@ -60,9 +60,14 @@ void close_ota(){ } void add_otadata(unsigned char *data, int len){ + if (!sector) return; //addLogAdv(LOG_INFO, LOG_FEATURE_OTA,"OTA DataRxed start: %02.2x %02.2x len %d\r\n", data[0], data[1], len); while (len){ + // force it to sleep... we MUST have some idle task processing + // else task memory doesn't get freed + rtos_delay_milliseconds(40); + if (sectorlen < SECTOR_SIZE){ int lenstore = SECTOR_SIZE - sectorlen; if (lenstore > len) lenstore = len; diff --git a/src/user_main.c b/src/user_main.c index c0aa24984..8e1fb27ae 100644 --- a/src/user_main.c +++ b/src/user_main.c @@ -58,6 +58,8 @@ static int g_timeSinceLastPingReply = 0; // was it ran? static int g_bPingWatchDogStarted = 0; +uint32_t idleCount = 0; + #define LOG_FEATURE LOG_FEATURE_MAIN @@ -264,8 +266,8 @@ void Main_OnEverySecond() //int mqtt_max, mqtt_cur, mqtt_mem; //MQTT_GetStats(&mqtt_cur, &mqtt_max, &mqtt_mem); //ADDLOGF_INFO("mqtt req %i/%i, free mem %i\n", mqtt_cur,mqtt_max,mqtt_mem); - ADDLOGF_INFO("%sTime %i, free %d, MQTT %i(%i), bWifi %i, secondsWithNoPing %i, socks %i/%i\n", - safe, g_secondsElapsed, xPortGetFreeHeapSize(),bMQTTconnected, MQTT_GetConnectEvents(), + ADDLOGF_INFO("%sTime %i, idle %i, free %d, MQTT %i(%i), bWifi %i, secondsWithNoPing %i, socks %i/%i\n", + safe, g_secondsElapsed, idleCount, xPortGetFreeHeapSize(),bMQTTconnected, MQTT_GetConnectEvents(), g_bHasWiFiConnected, g_timeSinceLastPingReply, LWIP_GetActiveSockets(), LWIP_GetMaxSockets()); } @@ -375,6 +377,9 @@ void Main_OnEverySecond() } } + // force it to sleep... we MUST have some idle task processing + // else task memory doesn't get freed + rtos_delay_milliseconds(1); } @@ -404,12 +409,23 @@ int Main_GetLastRebootBootFailures() #define RESTARTS_REQUIRED_FOR_SAFE_MODE 4 + +// called from idle thread each loop. +// - just so we know it is running. +void isidle(){ + idleCount++; +} + void Main_Init() { const char *wifi_ssid, *wifi_pass; // read or initialise the boot count flash area HAL_FlashVars_IncreaseBootCount(); + + #ifdef PLATFORM_BEKEN + bg_register_irda_check_func(isidle); + #endif g_bootFailures = HAL_FlashVars_GetBootFailures(); if (g_bootFailures > RESTARTS_REQUIRED_FOR_SAFE_MODE)