From a82e14961cf6fec12060044ef3d55aefc9f3aeaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Tue, 5 Sep 2017 01:48:37 +0200 Subject: [PATCH] RAM tuning --- CMakeLists.txt | 1 + esphttpdconfig.mk | 5 ++++- html_orig/build_html.php | 4 +++- user/cgi_sockets.c | 11 ++++++++--- user/routes.c | 4 ++-- user/screen.c | 2 ++ user/screen.h | 2 +- user/serial.c | 2 +- user/uart_buffer.c | 22 +++++++++++----------- 9 files changed, 33 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cd28108..5bebbdb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -163,6 +163,7 @@ add_definitions( -DADMIN_PASSWORD="asdf" -DGIT_HASH="blabla" -DDEBUG_HEAP=1 + -DDEBUG_MALLOC=1 -DESPFS_HEATSHRINK) add_executable(ESPTerm ${SOURCE_FILES}) diff --git a/esphttpdconfig.mk b/esphttpdconfig.mk index dd465f6..dc03845 100644 --- a/esphttpdconfig.mk +++ b/esphttpdconfig.mk @@ -50,5 +50,8 @@ GLOBAL_CFLAGS = \ -DDEBUG_ANSI=1 \ -DDEBUG_ANSI_NOIMPL=1 \ -DHTTPD_MAX_BACKLOG_SIZE=8192 \ + -DHTTPD_MAX_HEAD_LEN=512 \ + -DHTTPD_MAX_POST_LEN=512 \ -DDEBUG_INPUT=0 \ - -DDEBUG_HEAP=1 + -DDEBUG_HEAP=1 \ + -DDEBUG_MALLOC=0 diff --git a/html_orig/build_html.php b/html_orig/build_html.php index d123e1e..4d1269f 100755 --- a/html_orig/build_html.php +++ b/html_orig/build_html.php @@ -14,6 +14,8 @@ function process_html($s) { return $s; } +$no_tpl_files = ['help', 'cfg_wifi_conn']; + ob_start(); foreach($_pages as $_k => $p) { if ($p->bodyclass == 'api') continue; @@ -30,7 +32,7 @@ foreach($_pages as $_k => $p) { // $s = process_html($s); ob_clean(); // clean up - $of = __DIR__ . '/../html/' . $_k . '.tpl'; + $of = __DIR__ . '/../html/' . $_k . (in_array($_k, $no_tpl_files) ? '.html' : '.tpl'); file_put_contents($of, $s); // write to a file } diff --git a/user/cgi_sockets.c b/user/cgi_sockets.c index f65bb6e..23b65d7 100644 --- a/user/cgi_sockets.c +++ b/user/cgi_sockets.c @@ -11,8 +11,9 @@ #define LOOPBACK 0 -#define SOCK_BUF_LEN 1024 -static char sock_buff[SOCK_BUF_LEN]; +#define HB_TIME 1500 + +#define SOCK_BUF_LEN 2000 volatile bool notify_available = true; volatile bool notify_cooldown = false; @@ -41,6 +42,8 @@ notifyContentTimCb(void *arg) { void *data = NULL; int max_bl, total_bl; + char sock_buff[SOCK_BUF_LEN]; + cgiWebsockMeasureBacklog(URL_WS_UPDATE, &max_bl, &total_bl); if (!notify_available || notify_cooldown || (max_bl > 2048)) { // do not send if we have anything significant backlogged @@ -71,6 +74,8 @@ notifyContentTimCb(void *arg) static void ICACHE_FLASH_ATTR notifyLabelsTimCb(void *arg) { + char sock_buff[SOCK_BUF_LEN]; + if (!notify_available || notify_cooldown) { // postpone a little TIMER_START(¬ifyLabelsTim, notifyLabelsTimCb, 1, 0); @@ -250,5 +255,5 @@ void ICACHE_FLASH_ATTR updateSockConnect(Websock *ws) ws_info("Socket connected to "URL_WS_UPDATE); ws->recvCb = updateSockRx; - TIMER_START(&heartbeatTim, heartbeatTimCb, 1000, 1); + TIMER_START(&heartbeatTim, heartbeatTimCb, HB_TIME, 1); } diff --git a/user/routes.c b/user/routes.c index de199ff..9a5845e 100644 --- a/user/routes.c +++ b/user/routes.c @@ -29,7 +29,7 @@ HttpdBuiltInUrl routes[] = { // --- Web pages --- ROUTE_TPL_FILE("/", tplScreen, "/term.tpl"), ROUTE_TPL_FILE("/about/?", tplAbout, "/about.tpl"), - ROUTE_FILE("/help/?", "/help.tpl"), + ROUTE_FILE("/help/?", "/help.html"), // --- Sockets --- ROUTE_CGI("/term/init", cgiTermInitialImage), @@ -46,7 +46,7 @@ HttpdBuiltInUrl routes[] = { ROUTE_REDIRECT("/cfg/?", "/cfg/wifi"), ROUTE_TPL_FILE("/cfg/wifi/?", tplWlan, "/cfg_wifi.tpl"), - ROUTE_FILE("/cfg/wifi/connecting/?", "/cfg_wifi_conn.tpl"), + ROUTE_FILE("/cfg/wifi/connecting/?", "/cfg_wifi_conn.html"), ROUTE_CGI("/cfg/wifi/scan", cgiWiFiScan), ROUTE_CGI("/cfg/wifi/connstatus", cgiWiFiConnStatus), ROUTE_CGI("/cfg/wifi/set", cgiWiFiSetParams), diff --git a/user/screen.c b/user/screen.c index 7ea042f..9c774e1 100644 --- a/user/screen.c +++ b/user/screen.c @@ -201,6 +201,8 @@ terminal_apply_settings_noclear(void) void ICACHE_FLASH_ATTR screen_init(void) { + dbg("Screen buffer size = %d bytes", sizeof(screen)); + NOTIFY_LOCK(); screen_reset(); NOTIFY_DONE(); diff --git a/user/screen.h b/user/screen.h index 3c1ea3b..ae461cf 100644 --- a/user/screen.h +++ b/user/screen.h @@ -50,7 +50,7 @@ #define SCR_DEF_TITLE "ESPTerm" /** Maximum screen size (determines size of the static data array) */ -#define MAX_SCREEN_SIZE (80*26) +#define MAX_SCREEN_SIZE (80*25) #define TERMCONF_VERSION 1 diff --git a/user/serial.c b/user/serial.c index 67e7ba3..dce1f85 100644 --- a/user/serial.c +++ b/user/serial.c @@ -4,7 +4,7 @@ #include "ansi_parser.h" #include "syscfg.h" -#define LOGBUF_SIZE 1500 +#define LOGBUF_SIZE 2048 static char logbuf[LOGBUF_SIZE]; static u32 lb_nw = 1; static u32 lb_ls = 0; diff --git a/user/uart_buffer.c b/user/uart_buffer.c index 952fde1..6a26d11 100644 --- a/user/uart_buffer.c +++ b/user/uart_buffer.c @@ -45,9 +45,9 @@ UART_AsyncBufferInit(uint32 buf_size) return NULL; } else { - struct UartBuffer *pBuff = (struct UartBuffer *) os_malloc(sizeof(struct UartBuffer)); + struct UartBuffer *pBuff = (struct UartBuffer *) malloc(sizeof(struct UartBuffer)); pBuff->UartBuffSize = buf_size; - pBuff->pUartBuff = (uint8 *) os_malloc(pBuff->UartBuffSize); + pBuff->pUartBuff = (uint8 *) malloc(pBuff->UartBuffSize); pBuff->pInPos = pBuff->pUartBuff; pBuff->pOutPos = pBuff->pUartBuff; pBuff->Space = (uint16) pBuff->UartBuffSize; @@ -68,17 +68,17 @@ static void UART_WriteToAsyncBuffer(struct UartBuffer *pCur, const char *pdata, uint16 tail_len = (uint16) (pCur->pUartBuff + pCur->UartBuffSize - pCur->pInPos); if (tail_len >= data_len) { //do not need to loop back the queue - os_memcpy(pCur->pInPos, pdata, data_len); + memcpy(pCur->pInPos, pdata, data_len); pCur->pInPos += (data_len); pCur->pInPos = (pCur->pUartBuff + (pCur->pInPos - pCur->pUartBuff) % pCur->UartBuffSize); pCur->Space -= data_len; } else { - os_memcpy(pCur->pInPos, pdata, tail_len); + memcpy(pCur->pInPos, pdata, tail_len); pCur->pInPos += (tail_len); pCur->pInPos = (pCur->pUartBuff + (pCur->pInPos - pCur->pUartBuff) % pCur->UartBuffSize); pCur->Space -= tail_len; - os_memcpy(pCur->pInPos, pdata + tail_len, data_len - tail_len); + memcpy(pCur->pInPos, pdata + tail_len, data_len - tail_len); pCur->pInPos += (data_len - tail_len); pCur->pInPos = (pCur->pUartBuff + (pCur->pInPos - pCur->pUartBuff) % pCur->UartBuffSize); pCur->Space -= (data_len - tail_len); @@ -93,8 +93,8 @@ static void UART_WriteToAsyncBuffer(struct UartBuffer *pCur, const char *pdata, *******************************************************************************/ void ICACHE_FLASH_ATTR UART_FreeAsyncBuffer(struct UartBuffer *pBuff) { - os_free(pBuff->pUartBuff); - os_free(pBuff); + free(pBuff->pUartBuff); + free(pBuff); } u16 ICACHE_FLASH_ATTR UART_AsyncRxCount(void) @@ -116,19 +116,19 @@ UART_ReadAsync(char *pdata, uint16 data_len) uint16 len_tmp = 0; len_tmp = ((data_len > buf_len) ? buf_len : data_len); if (pRxBuffer->pOutPos <= pRxBuffer->pInPos) { - os_memcpy(pdata, pRxBuffer->pOutPos, len_tmp); + memcpy(pdata, pRxBuffer->pOutPos, len_tmp); pRxBuffer->pOutPos += len_tmp; pRxBuffer->Space += len_tmp; } else { if (len_tmp > tail_len) { - os_memcpy(pdata, pRxBuffer->pOutPos, tail_len); + memcpy(pdata, pRxBuffer->pOutPos, tail_len); pRxBuffer->pOutPos += tail_len; pRxBuffer->pOutPos = (pRxBuffer->pUartBuff + (pRxBuffer->pOutPos - pRxBuffer->pUartBuff) % pRxBuffer->UartBuffSize); pRxBuffer->Space += tail_len; - os_memcpy(pdata + tail_len, pRxBuffer->pOutPos, len_tmp - tail_len); + memcpy(pdata + tail_len, pRxBuffer->pOutPos, len_tmp - tail_len); pRxBuffer->pOutPos += (len_tmp - tail_len); pRxBuffer->pOutPos = (pRxBuffer->pUartBuff + (pRxBuffer->pOutPos - pRxBuffer->pUartBuff) % pRxBuffer->UartBuffSize); @@ -136,7 +136,7 @@ UART_ReadAsync(char *pdata, uint16 data_len) } else { //os_printf("case 3 in rx deq\n\r"); - os_memcpy(pdata, pRxBuffer->pOutPos, len_tmp); + memcpy(pdata, pRxBuffer->pOutPos, len_tmp); pRxBuffer->pOutPos += len_tmp; pRxBuffer->pOutPos = (pRxBuffer->pUartBuff + (pRxBuffer->pOutPos - pRxBuffer->pUartBuff) % pRxBuffer->UartBuffSize);