Overclock, fix buffer overflow causing total lock-up, small tweaks

removed the main make config file from VCS so it can be easier edited
added overclocking option to enable 160 MHz mode
http-comm
Ondřej Hruška 7 years ago
parent 74d52a0c61
commit 65977bfbae
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 1
      .gitignore
  2. 2
      front-end
  3. 2
      user/cgi_network.c
  4. 16
      user/cgi_system.c
  5. 9
      user/cgi_term_cfg.c
  6. 13
      user/syscfg.c
  7. 3
      user/syscfg.h
  8. 34
      user/uart_buffer.c
  9. 2
      user/uart_handler.c

1
.gitignore vendored

@ -12,6 +12,7 @@ html_compressed/
ldscript_memspecific.ld ldscript_memspecific.ld
eagle.app.sym eagle.app.sym
node_modules node_modules
esphttpdconfig.mk
# Garbage added by CLion # Garbage added by CLion
.idea/ .idea/

@ -1 +1 @@
Subproject commit c846cffedbd927433354f4fc2004154cd596916f Subproject commit f5dd70a6f32ac36f0820badc170832f27242a09d

@ -181,6 +181,8 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiNetworkSetParams(HttpdConnData *connData)
} }
} }
(void) redir_url;
if (redir_url_buf[strlen(SET_REDIR_ERR)] == 0) { if (redir_url_buf[strlen(SET_REDIR_ERR)] == 0) {
// All was OK // All was OK
cgi_info("Set network params - success, applying in 1000 ms"); cgi_info("Set network params - success, applying in 1000 ms");

@ -6,7 +6,6 @@
#include "cgi_system.h" #include "cgi_system.h"
#include "persist.h" #include "persist.h"
#include "syscfg.h" #include "syscfg.h"
#include "uart_driver.h"
#include "ansi_parser.h" #include "ansi_parser.h"
#include "cgi_logging.h" #include "cgi_logging.h"
@ -98,9 +97,7 @@ cgiSystemCfgSetParams(HttpdConnData *connData)
do { do {
if (!GET_ARG("pw")) { if (!GET_ARG("pw")) {
warn("Missing admin pw!"); break; // if no PW in GET, not trying to configure anything protected
redir_url += sprintf(redir_url, "pw,");
break;
} }
if (!streq(buff, persist.admin.pw)) { if (!streq(buff, persist.admin.pw)) {
@ -191,6 +188,14 @@ cgiSystemCfgSetParams(HttpdConnData *connData)
} }
} while (0); } while (0);
if (GET_ARG("overclock")) {
cgi_dbg("overclock = %s", buff);
int enable = atoi(buff);
if (sysconf->overclock != enable) {
sysconf->overclock = (bool)enable;
}
}
(void)redir_url; (void)redir_url;
if (redir_url_buf[strlen(SET_REDIR_ERR)] == 0) { if (redir_url_buf[strlen(SET_REDIR_ERR)] == 0) {
@ -246,6 +251,9 @@ tplSystemCfg(HttpdConnData *connData, char *token, void **arg)
else if (streq(token, "def_admin_pw")) { else if (streq(token, "def_admin_pw")) {
sprintf(buff, "%s", DEFAULT_ADMIN_PW); sprintf(buff, "%s", DEFAULT_ADMIN_PW);
} }
else if (streq(token, "overclock")) {
sprintf(buff, "%d", sysconf->overclock);
}
tplSend(connData, buff, -1); tplSend(connData, buff, -1);
return HTTPD_CGI_DONE; return HTTPD_CGI_DONE;

@ -10,6 +10,7 @@ Cgi/template routines for configuring non-wifi settings
#include "helpers.h" #include "helpers.h"
#include "cgi_logging.h" #include "cgi_logging.h"
#include "uart_driver.h" #include "uart_driver.h"
#include "serial.h"
#define SET_REDIR_SUC "/cfg/term" #define SET_REDIR_SUC "/cfg/term"
#define SET_REDIR_ERR SET_REDIR_SUC"?err=" #define SET_REDIR_ERR SET_REDIR_SUC"?err="
@ -42,6 +43,7 @@ cgiTermCfgSetParams(HttpdConnData *connData)
bool notify_screen_content = 0, notify_screen_labels = 0; bool notify_screen_content = 0, notify_screen_labels = 0;
bool shall_clear_screen = false; bool shall_clear_screen = false;
bool shall_init_uart = false;
char *redir_url = redir_url_buf; char *redir_url = redir_url_buf;
redir_url += sprintf(redir_url, SET_REDIR_ERR); redir_url += sprintf(redir_url, SET_REDIR_ERR);
@ -317,6 +319,7 @@ cgiTermCfgSetParams(HttpdConnData *connData)
baud == BIT_RATE_1843200 || baud == BIT_RATE_1843200 ||
baud == BIT_RATE_3686400) { baud == BIT_RATE_3686400) {
sysconf->uart_baudrate = (u32) baud; sysconf->uart_baudrate = (u32) baud;
shall_init_uart = true;
} else { } else {
cgi_warn("Bad baud rate %s", buff); cgi_warn("Bad baud rate %s", buff);
redir_url += sprintf(redir_url, "uart_baud,"); redir_url += sprintf(redir_url, "uart_baud,");
@ -328,6 +331,7 @@ cgiTermCfgSetParams(HttpdConnData *connData)
int parity = atoi(buff); int parity = atoi(buff);
if (parity >= 0 && parity <= 2) { if (parity >= 0 && parity <= 2) {
sysconf->uart_parity = (UartParityMode) parity; sysconf->uart_parity = (UartParityMode) parity;
shall_init_uart = true;
} else { } else {
cgi_warn("Bad parity %s", buff); cgi_warn("Bad parity %s", buff);
redir_url += sprintf(redir_url, "uart_parity,"); redir_url += sprintf(redir_url, "uart_parity,");
@ -339,6 +343,7 @@ cgiTermCfgSetParams(HttpdConnData *connData)
int stopbits = atoi(buff); int stopbits = atoi(buff);
if (stopbits >= 1 && stopbits <= 3) { if (stopbits >= 1 && stopbits <= 3) {
sysconf->uart_stopbits = (UartStopBitsNum) stopbits; sysconf->uart_stopbits = (UartStopBitsNum) stopbits;
shall_init_uart = true;
} else { } else {
cgi_warn("Bad stopbits %s", buff); cgi_warn("Bad stopbits %s", buff);
redir_url += sprintf(redir_url, "uart_stopbits,"); redir_url += sprintf(redir_url, "uart_stopbits,");
@ -359,6 +364,10 @@ cgiTermCfgSetParams(HttpdConnData *connData)
terminal_apply_settings_noclear(); terminal_apply_settings_noclear();
} }
if (shall_init_uart) {
serialInit();
}
if (notify_screen_content) { if (notify_screen_content) {
screen_notifyChange(CHANGE_CONTENT); screen_notifyChange(CHANGE_CONTENT);
} }

@ -13,10 +13,11 @@ void ICACHE_FLASH_ATTR
sysconf_apply_settings(void) sysconf_apply_settings(void)
{ {
bool changed = false; bool changed = false;
// if (sysconf->config_version < 1) { if (sysconf->config_version < 1) {
// dbg("Upgrading syscfg to v 1"); dbg("Upgrading syscfg to v 1");
// changed = true; sysconf->overclock = false;
// } changed = true;
}
sysconf->config_version = SYSCONF_VERSION; sysconf->config_version = SYSCONF_VERSION;
@ -24,7 +25,10 @@ sysconf_apply_settings(void)
persist_store(); persist_store();
} }
// uart settings live here, but the CGI handler + form has been moved to the Terminal config page
serialInit(); serialInit();
system_update_cpu_freq((uint8) (sysconf->overclock ? 160 : 80));
} }
void ICACHE_FLASH_ATTR void ICACHE_FLASH_ATTR
@ -38,4 +42,5 @@ sysconf_restore_defaults(void)
sysconf->pwlock = PWLOCK_NONE; sysconf->pwlock = PWLOCK_NONE;
strcpy(sysconf->access_pw, DEF_ACCESS_PW); strcpy(sysconf->access_pw, DEF_ACCESS_PW);
strcpy(sysconf->access_name, DEF_ACCESS_NAME); strcpy(sysconf->access_name, DEF_ACCESS_NAME);
sysconf->overclock = false;
} }

@ -10,7 +10,7 @@
// Size designed for the wifi config structure // Size designed for the wifi config structure
// Must be constant to avoid corrupting user config after upgrade // Must be constant to avoid corrupting user config after upgrade
#define SYSCONF_SIZE 300 #define SYSCONF_SIZE 300
#define SYSCONF_VERSION 0 #define SYSCONF_VERSION 1
#define DEF_ACCESS_PW "1234" #define DEF_ACCESS_PW "1234"
#define DEF_ACCESS_NAME "espterm" #define DEF_ACCESS_NAME "espterm"
@ -32,6 +32,7 @@ typedef struct {
enum pwlock pwlock : 8; // page access lock enum pwlock pwlock : 8; // page access lock
char access_pw[64]; // access password char access_pw[64]; // access password
char access_name[32]; // access name char access_name[32]; // access name
bool overclock;
} SystemConfigBundle; } SystemConfigBundle;
extern SystemConfigBundle * const sysconf; extern SystemConfigBundle * const sysconf;

@ -9,7 +9,7 @@
#include <uart_register.h> #include <uart_register.h>
#define UART_TX_BUFFER_SIZE 512 //Ring buffer length of tx buffer #define UART_TX_BUFFER_SIZE 512 //Ring buffer length of tx buffer
#define UART_RX_BUFFER_SIZE 512 //Ring buffer length of rx buffer #define UART_RX_BUFFER_SIZE 600 //Ring buffer length of rx buffer
struct UartBuffer { struct UartBuffer {
uint32 UartBuffSize; uint32 UartBuffSize;
@ -158,24 +158,34 @@ void UART_RxFifoCollect(void)
uint8 fifo_data; uint8 fifo_data;
fifo_len = (uint8) ((READ_PERI_REG(UART_STATUS(UART0)) >> UART_RXFIFO_CNT_S) & UART_RXFIFO_CNT); fifo_len = (uint8) ((READ_PERI_REG(UART_STATUS(UART0)) >> UART_RXFIFO_CNT_S) & UART_RXFIFO_CNT);
if (fifo_len >= pRxBuffer->Space) { if (fifo_len >= pRxBuffer->Space) {
UART_WriteChar(UART1, '%', 100); // try to read at least the bit we can
} fifo_len = (uint8) (pRxBuffer->Space - 1);
else { UART_WriteChar(UART1, '%', 1);
// discard contents of the FIFO - would loop forever
buf_idx = 0; buf_idx = 0;
while (buf_idx < fifo_len) { while (buf_idx < fifo_len) {
buf_idx++; buf_idx++;
fifo_data = (uint8) (READ_PERI_REG(UART_FIFO(UART0)) & 0xFF); fifo_data = (uint8) (READ_PERI_REG(UART_FIFO(UART0)) & 0xFF);
*(pRxBuffer->pInPos++) = fifo_data; (void)fifo_data; // pretend we use it
if (pRxBuffer->pInPos == (pRxBuffer->pUartBuff + pRxBuffer->UartBuffSize)) {
pRxBuffer->pInPos = pRxBuffer->pUartBuff;
}
} }
pRxBuffer->Space -= fifo_len; return;
}
if (pRxBuffer->Space >= UART_FIFO_LEN) { buf_idx = 0;
uart_rx_intr_enable(UART0); while (buf_idx < fifo_len) {
buf_idx++;
fifo_data = (uint8) (READ_PERI_REG(UART_FIFO(UART0)) & 0xFF);
*(pRxBuffer->pInPos++) = fifo_data;
if (pRxBuffer->pInPos == (pRxBuffer->pUartBuff + pRxBuffer->UartBuffSize)) {
pRxBuffer->pInPos = pRxBuffer->pUartBuff;
} }
} }
pRxBuffer->Space -= fifo_len;
//
// this is called by the processing routine, no need here
// if (pRxBuffer->Space >= UART_FIFO_LEN) {
// uart_rx_intr_enable(UART0);
// }
} }
u16 ICACHE_FLASH_ATTR UART_AsyncTxGetEmptySpace(void) u16 ICACHE_FLASH_ATTR UART_AsyncTxGetEmptySpace(void)
@ -209,7 +219,7 @@ UART_SendAsync(const char *pdata, int16_t data_len)
UART_WriteToAsyncBuffer(pTxBuffer, pdata, real_len); UART_WriteToAsyncBuffer(pTxBuffer, pdata, real_len);
} }
else { else {
UART_WriteChar(UART1, '^', 100); UART_WriteChar(UART1, '^', 1);
} }
// } // }

@ -25,7 +25,7 @@ static void uart_processTask(os_event_t *events);
// Those heavily affect the byte loss ratio // Those heavily affect the byte loss ratio
#define PROCESS_CHUNK_LEN 1 #define PROCESS_CHUNK_LEN 1
#define FIFO_FULL_THRES 4 #define FIFO_FULL_THRES 32
#define uart_recvTaskPrio 1 #define uart_recvTaskPrio 1
#define uart_recvTaskQueueLen 25 #define uart_recvTaskQueueLen 25

Loading…
Cancel
Save