From 60f47ba8bcd1096335361cd0dff0458dc9ee7382 Mon Sep 17 00:00:00 2001 From: cskarai Date: Tue, 20 Sep 2016 20:00:53 +0200 Subject: [PATCH] Refactored MCU flashing protection --- serial/serbridge.c | 14 +++++++------- serial/serbridge.h | 2 +- serial/slip.c | 2 -- web-server/web-server.c | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/serial/serbridge.c b/serial/serbridge.c index e1f3fdc..9f782bb 100644 --- a/serial/serbridge.c +++ b/serial/serbridge.c @@ -23,7 +23,7 @@ static struct espconn serbridgeConn2; // programming port static esp_tcp serbridgeTcp1, serbridgeTcp2; static int8_t mcu_reset_pin, mcu_isp_pin; -extern uint8_t slip_disabled; // disable slip to allow flashing of attached MCU +uint8_t in_mcu_flashing; // for disabling slip during MCU flashing void (*programmingCB)(char *buffer, short length) = NULL; @@ -124,14 +124,14 @@ telnetUnwrap(uint8_t *inBuf, int len, uint8_t state) #ifdef SERBR_DBG else { os_printf("MCU isp: no pin\n"); } #endif - slip_disabled++; + in_mcu_flashing++; break; case RTS_OFF: if (mcu_isp_pin >= 0) { GPIO_OUTPUT_SET(mcu_isp_pin, 1); os_delay_us(100L); } - if (slip_disabled > 0) slip_disabled--; + if (in_mcu_flashing > 0) in_mcu_flashing--; break; } state = TN_end; @@ -222,7 +222,7 @@ serbridgeRecvCb(void *arg, char *data, unsigned short len) //if (mcu_isp_pin >= 0) GPIO_OUTPUT_SET(mcu_isp_pin, 1); os_delay_us(1000L); // wait a millisecond before writing to the UART below conn->conn_mode = cmPGM; - slip_disabled++; // disable SLIP so it doesn't interfere with flashing + in_mcu_flashing++; // disable SLIP so it doesn't interfere with flashing #ifdef SKIP_AT_RESET serledFlash(50); // short blink on serial LED return; @@ -355,7 +355,7 @@ serbridgeUartCb(char *buf, short length) { if (programmingCB) { programmingCB(buf, length); - } else if (!flashConfig.slip_enable || slip_disabled > 0) { + } else if (!flashConfig.slip_enable || in_mcu_flashing > 0) { //os_printf("SLIP: disabled got %d\n", length); console_process(buf, length); } else { @@ -505,7 +505,7 @@ serbridgeInit(int port1, int port2) espconn_regist_time(&serbridgeConn2, SER_BRIDGE_TIMEOUT, 0); } -int ICACHE_FLASH_ATTR serbridgeInProgramming() +int ICACHE_FLASH_ATTR serbridgeInMCUFlashing() { - return slip_disabled; + return in_mcu_flashing; } diff --git a/serial/serbridge.h b/serial/serbridge.h index c24953c..ed661e1 100644 --- a/serial/serbridge.h +++ b/serial/serbridge.h @@ -36,7 +36,7 @@ void ICACHE_FLASH_ATTR serbridgeInitPins(void); void ICACHE_FLASH_ATTR serbridgeUartCb(char *buf, short len); void ICACHE_FLASH_ATTR serbridgeReset(); -int ICACHE_FLASH_ATTR serbridgeInProgramming(); +int ICACHE_FLASH_ATTR serbridgeInMCUFlashing(); // callback when receiving UART chars when in programming mode extern void (*programmingCB)(char *buffer, short length); diff --git a/serial/slip.c b/serial/slip.c index 76d8f97..2f15186 100644 --- a/serial/slip.c +++ b/serial/slip.c @@ -13,8 +13,6 @@ #define DBG(format, ...) do { } while(0) #endif -uint8_t slip_disabled; // temporarily disable slip to allow flashing of attached MCU - extern void ICACHE_FLASH_ATTR console_process(char *buf, short len); // This SLIP parser tries to conform to RFC 1055 https://tools.ietf.org/html/rfc1055. diff --git a/web-server/web-server.c b/web-server/web-server.c index 4689014..0d323a2 100644 --- a/web-server/web-server.c +++ b/web-server/web-server.c @@ -167,7 +167,7 @@ static int ICACHE_FLASH_ATTR WEB_handleJSONRequest(HttpdConnData *connData) errorResponse(connData, 500, "No MCU callback is registered!"); return HTTPD_CGI_DONE; } - if( serbridgeInProgramming() ) + if( serbridgeInMCUFlashing() ) { errorResponse(connData, 500, "Slip disabled at uploading program onto the MCU!"); return HTTPD_CGI_DONE;