From 1910386729c58621a1e9fa85793b596659ba00b9 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 16 Jan 2017 16:37:53 +0100 Subject: [PATCH 1/5] Added support for Telnet commands to generate BREAK BREAK could be generated through Telnet command syntax (see RFC2217) by offering "Set BREAK state ON", "Set BREAK state OFF" and "Request BREAK state". --- serial/serbridge.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/serial/serbridge.c b/serial/serbridge.c index d233375..ee5ea37 100644 --- a/serial/serbridge.c +++ b/serial/serbridge.c @@ -44,6 +44,9 @@ serbridgeConnData connData[MAX_CONN]; #define SetDataSize 2 // Set data size #define SetParity 3 // Set parity #define SetControl 5 // Set control lines +#define BRK_REQ 4 // request current BREAK state +#define BRK_ON 5 // set BREAK (TX-line to LOW) +#define BRK_OFF 6 // reset BREAK #define DTR_ON 8 // used here to reset microcontroller #define DTR_OFF 9 #define RTS_ON 11 // used here to signal ISP (in-system-programming) to uC @@ -156,6 +159,28 @@ telnetUnwrap(serbridgeConnData *conn, uint8_t *inBuf, int len) } if (in_mcu_flashing > 0) in_mcu_flashing--; break; + case BRK_REQ: + char respBuf[7] = { IAC, SB, ComPortOpt, SetControl, GPIO_INPUT_GET(1), IAC, SE }; + espbuffsend(conn, respBuf, 7); +#ifdef SERBR_DBG + os_printf("Telnet: BREAK state requested: state = %d)\n", GPIO_INPUT_GET(1)); +#endif + break; + case BRK_ON: + while (((READ_PERI_REG(UART_STATUS(UART0))>>UART_TXFIFO_CNT_S)&UART_TXFIFO_CNT)>0); // wait until TX-FIFO of UART0 is empty + PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_GPIO1); // set TX pint to IO + GPIO_OUTPUT_SET(1, 0); +#ifdef SERBR_DBG + os_printf("Telnet: BREAK ON: set TX to LOW\n"); +#endif + break; + case BRK_OFF: + GPIO_OUTPUT_SET(1, 1); + PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD); +#ifdef SERBR_DBG + os_printf("Telnet: BREAK OFF: set TX to HIGH\n"); +#endif + break; } state = TN_end; break; From 3ef8dd6820d96ca277d23720ea9adf762db8007d Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 17 Jan 2017 12:20:45 +0100 Subject: [PATCH 2/5] do not wait for TX-FIFO Waiting for the FIFO to flush may cause watchdog resets. Now, just ensure thats FIFO is empty bevore raising BREAK. Also only handle BRK_OFF if BRK_ON was issued before. --- serial/serbridge.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/serial/serbridge.c b/serial/serbridge.c index ee5ea37..365e5ba 100644 --- a/serial/serbridge.c +++ b/serial/serbridge.c @@ -57,6 +57,7 @@ enum { TN_normal, TN_iac, TN_will, TN_start, TN_end, TN_comPort, TN_setControl, TN_setDataSize, TN_setParity }; static char tn_baudCnt; static uint32_t tn_baud; // shared across all sockets, thus possible race condition +static uint8_t tn_break = 0; // 0=BREAK-OFF, 1=BREAK-ON // process a buffer-full on a telnet connection static void ICACHE_FLASH_ATTR @@ -159,28 +160,33 @@ telnetUnwrap(serbridgeConnData *conn, uint8_t *inBuf, int len) } if (in_mcu_flashing > 0) in_mcu_flashing--; break; - case BRK_REQ: - char respBuf[7] = { IAC, SB, ComPortOpt, SetControl, GPIO_INPUT_GET(1), IAC, SE }; + case BRK_REQ: + char respBuf[7] = { IAC, SB, ComPortOpt, SetControl, tn_break, IAC, SE }; espbuffsend(conn, respBuf, 7); #ifdef SERBR_DBG - os_printf("Telnet: BREAK state requested: state = %d)\n", GPIO_INPUT_GET(1)); + os_printf("Telnet: BREAK state requested: state = %d)\n", tn_break); #endif break; - case BRK_ON: - while (((READ_PERI_REG(UART_STATUS(UART0))>>UART_TXFIFO_CNT_S)&UART_TXFIFO_CNT)>0); // wait until TX-FIFO of UART0 is empty - PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_GPIO1); // set TX pint to IO - GPIO_OUTPUT_SET(1, 0); + case BRK_ON: + if (((READ_PERI_REG(UART_STATUS(UART0))>>UART_TXFIFO_CNT_S)&UART_TXFIFO_CNT) == 0) { // TX-FIFO of UART0 must be empty + PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_GPIO1); + GPIO_OUTPUT_SET(1, 0); + tn_break = 1; #ifdef SERBR_DBG - os_printf("Telnet: BREAK ON: set TX to LOW\n"); + os_printf("Telnet: BREAK ON: set TX to LOW\n"); #endif - break; - case BRK_OFF: - GPIO_OUTPUT_SET(1, 1); - PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD); + } + break; + case BRK_OFF: + if (tn_break == 1) { + GPIO_OUTPUT_SET(1, 1); + PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD); + tn_break = 0; #ifdef SERBR_DBG - os_printf("Telnet: BREAK OFF: set TX to HIGH\n"); + os_printf("Telnet: BREAK OFF: set TX to HIGH\n"); #endif - break; + } + break; } state = TN_end; break; From 0ce029b16a4c8e0ecf164d1d9a49431037975523 Mon Sep 17 00:00:00 2001 From: igittigitt Date: Tue, 17 Jan 2017 04:41:58 -0800 Subject: [PATCH 3/5] Local changes and compiler warning --- serial/serbridge.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/serial/serbridge.c b/serial/serbridge.c index 365e5ba..5ce6ae0 100644 --- a/serial/serbridge.c +++ b/serial/serbridge.c @@ -160,13 +160,13 @@ telnetUnwrap(serbridgeConnData *conn, uint8_t *inBuf, int len) } if (in_mcu_flashing > 0) in_mcu_flashing--; break; - case BRK_REQ: + case BRK_REQ: { char respBuf[7] = { IAC, SB, ComPortOpt, SetControl, tn_break, IAC, SE }; espbuffsend(conn, respBuf, 7); #ifdef SERBR_DBG os_printf("Telnet: BREAK state requested: state = %d)\n", tn_break); #endif - break; + break; } case BRK_ON: if (((READ_PERI_REG(UART_STATUS(UART0))>>UART_TXFIFO_CNT_S)&UART_TXFIFO_CNT) == 0) { // TX-FIFO of UART0 must be empty PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_GPIO1); From 11d8364164a7cb708209dffce0fa84099bca2977 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 17 Jan 2017 13:40:42 +0100 Subject: [PATCH 4/5] Added PURGE_DATA --- serial/serbridge.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/serial/serbridge.c b/serial/serbridge.c index 5ce6ae0..3c36112 100644 --- a/serial/serbridge.c +++ b/serial/serbridge.c @@ -44,6 +44,8 @@ serbridgeConnData connData[MAX_CONN]; #define SetDataSize 2 // Set data size #define SetParity 3 // Set parity #define SetControl 5 // Set control lines +#define PurgeData 12 // Flush FIFO buffer(s) +#define PURGE_TX 2 #define BRK_REQ 4 // request current BREAK state #define BRK_ON 5 // set BREAK (TX-line to LOW) #define BRK_OFF 6 // reset BREAK @@ -54,7 +56,7 @@ serbridgeConnData connData[MAX_CONN]; // telnet state machine states enum { TN_normal, TN_iac, TN_will, TN_start, TN_end, TN_comPort, TN_setControl, TN_setBaud, - TN_setDataSize, TN_setParity }; + TN_setDataSize, TN_setParity, TN_purgeData }; static char tn_baudCnt; static uint32_t tn_baud; // shared across all sockets, thus possible race condition static uint8_t tn_break = 0; // 0=BREAK-OFF, 1=BREAK-ON @@ -114,9 +116,18 @@ telnetUnwrap(serbridgeConnData *conn, uint8_t *inBuf, int len) case SetDataSize: state = TN_setDataSize; break; case SetParity: state = TN_setParity; break; case SetBaud: state = TN_setBaud; tn_baudCnt = 0; tn_baud = 0; break; + case PrugeData: state = TN_purgeData; break; default: state = TN_end; break; } break; + case TN_purgeData: // purge FIFO-buffers + switch (c) { + case PURGE_TX: + // TODO: flush TX buffer + break; + } + state = TN_end; + break; case TN_setControl: // switch control line and delay a tad switch (c) { case DTR_ON: From 4bb78e3ec2a5cddd75141bd9a66050d6fcc627a3 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 23 Jan 2017 16:52:44 +0100 Subject: [PATCH 5/5] Typo error in "PurgeData" constant --- serial/serbridge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serial/serbridge.c b/serial/serbridge.c index 3c36112..29c03b2 100644 --- a/serial/serbridge.c +++ b/serial/serbridge.c @@ -116,7 +116,7 @@ telnetUnwrap(serbridgeConnData *conn, uint8_t *inBuf, int len) case SetDataSize: state = TN_setDataSize; break; case SetParity: state = TN_setParity; break; case SetBaud: state = TN_setBaud; tn_baudCnt = 0; tn_baud = 0; break; - case PrugeData: state = TN_purgeData; break; + case PurgeData: state = TN_purgeData; break; default: state = TN_end; break; } break;