This is an automated email from the ASF dual-hosted git repository. jerzy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 6ba1d07b6d67664779d870683b0a6f2cfe4a33c5 Author: Jerzy Kasenberg <[email protected]> AuthorDate: Tue Oct 15 10:47:57 2019 +0200 sys/console: console nlip state optimized nlip_state was treated in the code as bit field that could suggest that few independent bits can be set at given time. In reality values that were store in this variable were: - 0 - NLIP_PKT_START1 - NLIP_PKT_START1 | NLIP_PKT_START2 - NLIP_DATA_START1 - NLIP_DATA_START1 | NLIP_DATA_START2 5 different states only. Other combination of 4 bits were not permitted by code. Setting bits instead of state values could lead to wrong conclusion. Now nlip_tate is not treated as bit field that will make it more clear and reduce code size by tiny bit. --- sys/console/full/src/console.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/sys/console/full/src/console.c b/sys/console/full/src/console.c index 4d3e550..fec003c 100644 --- a/sys/console/full/src/console.c +++ b/sys/console/full/src/console.c @@ -56,10 +56,10 @@ #define CONSOLE_NLIP_DATA_START1 (4) #define CONSOLE_NLIP_DATA_START2 (20) -#define NLIP_PKT_START1 (1 << 0) -#define NLIP_PKT_START2 (1 << 1) -#define NLIP_DATA_START1 (1 << 2) -#define NLIP_DATA_START2 (1 << 3) +#define NLIP_PKT_START1 (CONSOLE_NLIP_PKT_START1) +#define NLIP_PKT_START2 (CONSOLE_NLIP_PKT_START2) +#define NLIP_DATA_START1 (CONSOLE_NLIP_DATA_START1) +#define NLIP_DATA_START2 (CONSOLE_NLIP_DATA_START2) /* Indicates whether the previous line of output was completed. */ int console_is_midline; @@ -663,21 +663,19 @@ ansi_cmd: static int handle_nlip(uint8_t byte) { - if (((nlip_state & NLIP_PKT_START1) && - (nlip_state & NLIP_PKT_START2)) || - ((nlip_state & NLIP_DATA_START1) && - (nlip_state & NLIP_DATA_START2))) + if ((nlip_state == NLIP_PKT_START2) || + (nlip_state == NLIP_DATA_START2)) { return 1; } - if ((nlip_state & NLIP_PKT_START1) && + if ((nlip_state == NLIP_PKT_START1) && (byte == CONSOLE_NLIP_PKT_START2)) { - nlip_state |= NLIP_PKT_START2; + nlip_state == NLIP_PKT_START2; return 1; - } else if ((nlip_state & NLIP_DATA_START1) && + } else if ((nlip_state == NLIP_DATA_START1) && (byte == CONSOLE_NLIP_DATA_START2)) { - nlip_state |= NLIP_DATA_START2; + nlip_state == NLIP_DATA_START2; return 1; } else { nlip_state = 0; @@ -798,10 +796,10 @@ console_handle_char(uint8_t byte) handle_ansi(byte, input->line); switch (byte) { case CONSOLE_NLIP_PKT_START1: - nlip_state |= NLIP_PKT_START1; + nlip_state == NLIP_PKT_START1; break; case CONSOLE_NLIP_DATA_START1: - nlip_state |= NLIP_DATA_START1; + nlip_state == NLIP_DATA_START1; break; case DEL: case BS:
