You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/09/27 19:18:03 UTC

[1/6] incubator-mynewt-core git commit: Console history - WIP

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 263d87624 -> 8897a2f1a


Console history - WIP


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/a731e4ed
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/a731e4ed
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/a731e4ed

Branch: refs/heads/develop
Commit: a731e4edbaa938253cabf9e400ab33c6f92e9bdd
Parents: 263d876
Author: Fabio Utzig <ut...@utzig.org>
Authored: Sun Aug 28 18:39:58 2016 -0300
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Sep 27 09:11:16 2016 -0700

----------------------------------------------------------------------
 libs/console/full/src/cons_tty.c | 162 +++++++++++++++++++++++++++++-----
 1 file changed, 142 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a731e4ed/libs/console/full/src/cons_tty.c
----------------------------------------------------------------------
diff --git a/libs/console/full/src/cons_tty.c b/libs/console/full/src/cons_tty.c
index 2b5ea97..b98928b 100644
--- a/libs/console/full/src/cons_tty.c
+++ b/libs/console/full/src/cons_tty.c
@@ -31,19 +31,21 @@
 /** Indicates whether the previous line of output was completed. */
 int console_is_midline;
 
-#define CONSOLE_TX_BUF_SZ	32	/* IO buffering, must be power of 2 */
-#define CONSOLE_RX_BUF_SZ	128
-#define CONSOLE_RX_CHUNK	16
+#define CONSOLE_TX_BUF_SZ       32      /* IO buffering, must be power of 2 */
+#define CONSOLE_RX_BUF_SZ       128
 
-#define CONSOLE_DEL		0x7f	/* del character */
-#define CONSOLE_ESC		0x1b	/* esc character */
-#define CONSOLE_LEFT		'D'     /* esc-[-D emitted when moving left */
-#define CONSOLE_UP		'A'     /* esc-[-A moving up */
-#define CONSOLE_RIGHT		'C'     /* esc-[-C moving right */
-#define CONSOLE_DOWN		'B'     /* esc-[-B moving down */
+#define CONSOLE_HIST_SZ         32
 
-#define CONSOLE_HEAD_INC(cr)	(((cr)->cr_head + 1) & ((cr)->cr_size - 1))
-#define CONSOLE_TAIL_INC(cr)	(((cr)->cr_tail + 1) & ((cr)->cr_size - 1))
+
+#define CONSOLE_DEL             0x7f    /* del character */
+#define CONSOLE_ESC             0x1b    /* esc character */
+#define CONSOLE_LEFT            'D'     /* esc-[-D emitted when moving left */
+#define CONSOLE_UP              'A'     /* esc-[-A moving up */
+#define CONSOLE_RIGHT           'C'     /* esc-[-C moving right */
+#define CONSOLE_DOWN            'B'     /* esc-[-B moving down */
+
+#define CONSOLE_HEAD_INC(cr)    (((cr)->cr_head + 1) & ((cr)->cr_size - 1))
+#define CONSOLE_TAIL_INC(cr)    (((cr)->cr_tail + 1) & ((cr)->cr_size - 1))
 
 typedef void (*console_write_char)(char);
 void console_print_prompt(void);
@@ -62,12 +64,19 @@ struct console_tty {
     uint8_t ct_tx_buf[CONSOLE_TX_BUF_SZ]; /* must be after console_ring */
     struct console_ring ct_rx;
     uint8_t ct_rx_buf[CONSOLE_RX_BUF_SZ]; /* must be after console_ring */
-    console_rx_cb ct_rx_cb;	/* callback that input is ready */
+    console_rx_cb ct_rx_cb; /* callback that input is ready */
     console_write_char ct_write_char;
     uint8_t ct_echo_off:1;
     uint8_t ct_esc_seq:2;
 } console_tty;
 
+struct console_hist {
+    uint8_t ch_head;
+    uint8_t ch_tail;
+    uint8_t ch_curr;
+    uint8_t ch_buf[CONSOLE_HIST_SZ][CONSOLE_RX_BUF_SZ];
+} console_hist;
+
 static void
 console_add_char(struct console_ring *cr, char ch)
 {
@@ -89,6 +98,7 @@ static int
 console_pull_char_head(struct console_ring *cr)
 {
     if (cr->cr_head != cr->cr_tail) {
+        // TODO: CONSOLE_HEAD_DEC
         cr->cr_head = (cr->cr_head - 1) & (cr->cr_size - 1);
         return 0;
     } else {
@@ -107,9 +117,9 @@ console_queue_char(char ch)
         /* TX needs to drain */
         uart_start_tx(ct->ct_dev);
         OS_EXIT_CRITICAL(sr);
-	if (os_started()) {
+    if (os_started()) {
             os_time_delay(1);
-	}
+    }
         OS_ENTER_CRITICAL(sr);
     }
     console_add_char(&ct->ct_tx, ch);
@@ -117,6 +127,93 @@ console_queue_char(char ch)
 }
 
 static void
+console_hist_init(void)
+{
+    struct console_hist *ch = &console_hist;
+
+    ch->ch_head = 0;
+    ch->ch_tail = 0;
+    ch->ch_curr = 0;
+}
+
+static void
+console_hist_add(struct console_ring *rx)
+{
+    struct console_hist *ch = &console_hist;
+    uint8_t *str = ch->ch_buf[ch->ch_head];
+    uint8_t tail;
+
+    /* TODO: don't add empty lines? */
+    tail = rx->cr_tail;
+    while (tail != rx->cr_head) {
+        *str = rx->cr_buf[tail];
+        if (*str == '\n') {
+            *str = '\0';
+            break;
+        }
+        str++;
+        tail = (tail + 1) % CONSOLE_RX_BUF_SZ;
+    }
+
+    ch->ch_head = (ch->ch_head + 1) % CONSOLE_HIST_SZ;
+    ch->ch_curr = ch->ch_head;
+
+    /* buffer full, start overwriting old history */
+    if (ch->ch_head == ch->ch_tail) {
+        ch->ch_tail = (ch->ch_tail + 1) % CONSOLE_HIST_SZ;
+    }
+}
+
+static int
+console_hist_prev(struct console_ring *rx, uint8_t *tx_buf)
+{
+    struct console_hist *ch = &console_hist;
+    uint8_t *str = NULL;
+    int space = 0;
+
+    /* no more history to return */
+    if (ch->ch_curr == ch->ch_tail) {
+        return 0;
+    }
+
+    ch->ch_curr = (ch->ch_curr - 1) % CONSOLE_HIST_SZ;
+    str = ch->ch_buf[ch->ch_curr];
+
+    /* consume all chars */
+    while (console_pull_char_head(rx) == 0) {
+        /* do nothing */
+    }
+
+    for (int i = 0; i < CONSOLE_RX_BUF_SZ; ++i) {
+        if (str[i] == '\0') {
+            break;
+        }
+        tx_buf[i] = str[i];
+        console_add_char(rx, str[i]);
+        space++;
+    }
+
+    return space;
+}
+
+static int
+console_hist_next(struct console_ring *rx, uint8_t *tx_buf)
+{
+    struct console_hist *ch = &console_hist;
+    //uint8_t *str = ch->ch_buf[ch->ch_curr];
+    //int space = 0;
+
+    /* no more history to return */
+    if (ch->ch_curr == ch->ch_head) {
+        return 0;
+    }
+
+    ch->ch_curr = (ch->ch_curr + 1) % CONSOLE_HIST_SZ;
+
+    return 0;
+}
+
+static void
 console_blocking_tx(char ch)
 {
     struct console_tty *ct = &console_tty;
@@ -270,7 +367,7 @@ console_rx_char(void *arg, uint8_t data)
     struct console_ring *rx = &ct->ct_rx;
     int tx_space = 0;
     int i;
-    int tx_buf[3];
+    uint8_t tx_buf[CONSOLE_RX_BUF_SZ];
 
     if (CONSOLE_HEAD_INC(&ct->ct_rx) == ct->ct_rx.cr_tail) {
         /*
@@ -294,6 +391,7 @@ console_rx_char(void *arg, uint8_t data)
         tx_buf[1] = '\r';
         tx_space = 2;
         console_add_char(rx, '\n');
+        console_hist_add(rx);
         if (ct->ct_rx_cb) {
             ct->ct_rx_cb();
         }
@@ -319,13 +417,36 @@ console_rx_char(void *arg, uint8_t data)
     case CONSOLE_UP:
     case CONSOLE_DOWN:
         if (ct->ct_esc_seq == 2) {
-            /*
-             * Do nothing.
-             */
+            if (data == CONSOLE_UP) {
+                tx_space = console_hist_prev(rx, tx_buf);
+            } else {
+                tx_space = console_hist_next(rx, tx_buf);
+            }
+            tx_buf[tx_space] = 0;
             ct->ct_esc_seq = 0;
-            goto out;
+            if (tx_space == 0) {
+                goto out;
+            }
+            if (!ct->ct_echo_off) {
+                i = 0;
+                while (console_pull_char_head(tx) == 0) {
+                    i++;
+                }
+                //FIXME: pulling doesnt get real count of chars...
+#if 1
+                while (i) {
+                    console_add_char(tx, '\b');
+                    console_add_char(tx, ' ');
+                    console_add_char(tx, '\b');
+                    hal_uart_start_tx(CONSOLE_UART);
+                    i--;
+                }
+#endif
+            }
+        } else {
+            goto queue_char;
         }
-        goto queue_char;
+        break;
     case CONSOLE_RIGHT:
         if (ct->ct_esc_seq == 2) {
             data = ' '; /* add space */
@@ -411,6 +532,7 @@ console_init(console_rx_cb rx_cb)
     }
 
     console_print_prompt();
+    console_hist_init();
 
     return 0;
 }


[4/6] incubator-mynewt-core git commit: Add conditional inclusion of console history

Posted by ma...@apache.org.
Add conditional inclusion of console history


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/437b5fc7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/437b5fc7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/437b5fc7

Branch: refs/heads/develop
Commit: 437b5fc78bc0c86efe7c76b3e5474475d3857632
Parents: 37c0cb4
Author: Fabio Utzig <ut...@utzig.org>
Authored: Sun Sep 4 18:21:03 2016 -0300
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Sep 27 09:30:40 2016 -0700

----------------------------------------------------------------------
 libs/console/full/src/cons_tty.c | 68 +++++++++++++++++++++--------------
 1 file changed, 41 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/437b5fc7/libs/console/full/src/cons_tty.c
----------------------------------------------------------------------
diff --git a/libs/console/full/src/cons_tty.c b/libs/console/full/src/cons_tty.c
index 1a54c88..95a5ecb 100644
--- a/libs/console/full/src/cons_tty.c
+++ b/libs/console/full/src/cons_tty.c
@@ -34,8 +34,9 @@ int console_is_midline;
 #define CONSOLE_TX_BUF_SZ       32      /* IO buffering, must be power of 2 */
 #define CONSOLE_RX_BUF_SZ       128
 
+#ifdef CONSOLE_HIST_ENABLE
 #define CONSOLE_HIST_SZ         32
-
+#endif
 
 #define CONSOLE_DEL             0x7f    /* del character */
 #define CONSOLE_ESC             0x1b    /* esc character */
@@ -70,6 +71,7 @@ struct console_tty {
     uint8_t ct_esc_seq:2;
 } console_tty;
 
+#ifdef CONSOLE_HIST_ENABLE
 struct console_hist {
     uint8_t ch_head;
     uint8_t ch_tail;
@@ -77,6 +79,7 @@ struct console_hist {
     uint8_t ch_curr;
     uint8_t ch_buf[CONSOLE_HIST_SZ][CONSOLE_RX_BUF_SZ];
 } console_hist;
+#endif
 
 static void
 console_add_char(struct console_ring *cr, char ch)
@@ -99,7 +102,6 @@ static int
 console_pull_char_head(struct console_ring *cr)
 {
     if (cr->cr_head != cr->cr_tail) {
-        // TODO: CONSOLE_HEAD_DEC
         cr->cr_head = (cr->cr_head - 1) & (cr->cr_size - 1);
         return 0;
     } else {
@@ -127,6 +129,7 @@ console_queue_char(char ch)
     OS_EXIT_CRITICAL(sr);
 }
 
+#ifdef CONSOLE_HIST_ENABLE
 static void
 console_hist_init(void)
 {
@@ -209,6 +212,7 @@ console_hist_move(struct console_ring *rx, uint8_t *tx_buf, uint8_t direction)
 
     return space;
 }
+#endif
 
 static void
 console_blocking_tx(char ch)
@@ -388,7 +392,9 @@ console_rx_char(void *arg, uint8_t data)
         tx_buf[1] = '\r';
         tx_space = 2;
         console_add_char(rx, '\n');
+#ifdef CONSOLE_HIST_ENABLE
         console_hist_add(rx);
+#endif
         if (ct->ct_rx_cb) {
             ct->ct_rx_cb();
         }
@@ -413,33 +419,40 @@ console_rx_char(void *arg, uint8_t data)
         break;
     case CONSOLE_UP:
     case CONSOLE_DOWN:
-        if (ct->ct_esc_seq == 2) {
-            tx_space = console_hist_move(rx, tx_buf, data);
-            tx_buf[tx_space] = 0;
-            ct->ct_esc_seq = 0;
-            /*
-             * when moving up, stop on oldest history entry
-             * when moving down, let it delete input before leaving...
-             */
-            if (data == CONSOLE_UP && tx_space == 0) {
-                goto out;
-            }
-            if (!ct->ct_echo_off) {
-                /* HACK: clean line by backspacing up to maximum possible space */
-                for (i = 0; i < CONSOLE_TX_BUF_SZ; i++) {
-                    if (console_buf_space(tx) < 3) {
-                        console_tx_flush(ct, 3);
-                    }
-                    console_add_char(tx, '\b');
-                    console_add_char(tx, ' ');
-                    console_add_char(tx, '\b');
-                    hal_uart_start_tx(CONSOLE_UART);
+        if (ct->ct_esc_seq != 2) {
+            goto queue_char;
+        }
+#ifdef CONSOLE_HIST_ENABLE
+        tx_space = console_hist_move(rx, tx_buf, data);
+        tx_buf[tx_space] = 0;
+        ct->ct_esc_seq = 0;
+        /*
+         * when moving up, stop on oldest history entry
+         * when moving down, let it delete input before leaving...
+         */
+        if (data == CONSOLE_UP && tx_space == 0) {
+            goto out;
+        }
+        if (!ct->ct_echo_off) {
+            /* HACK: clean line by backspacing up to maximum possible space */
+            for (i = 0; i < CONSOLE_TX_BUF_SZ; i++) {
+                if (console_buf_space(tx) < 3) {
+                    console_tx_flush(ct, 3);
                 }
+                console_add_char(tx, '\b');
+                console_add_char(tx, ' ');
+                console_add_char(tx, '\b');
+                hal_uart_start_tx(CONSOLE_UART);
             }
-            if (tx_space == 0) {
-                goto out;
-            }
+        }
+        if (tx_space == 0) {
+            goto out;
+        }
         break;
+#else
+        ct->ct_esc_seq = 0;
+        goto out;
+#endif
     case CONSOLE_RIGHT:
         if (ct->ct_esc_seq == 2) {
             data = ' '; /* add space */
@@ -524,8 +537,9 @@ console_init(console_rx_cb rx_cb)
         ct->ct_echo_off = ! MYNEWT_VAL(CONSOLE_ECHO);
     }
 
-    console_print_prompt();
+#ifdef CONSOLE_HIST_ENABLE
     console_hist_init();
+#endif
 
     return 0;
 }


[2/6] incubator-mynewt-core git commit: Fix identation

Posted by ma...@apache.org.
Fix identation


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/711b31dd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/711b31dd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/711b31dd

Branch: refs/heads/develop
Commit: 711b31dd3eee0da8952a44a929304d7791af2c35
Parents: a731e4e
Author: Fabio Utzig <ut...@utzig.org>
Authored: Sun Aug 28 19:23:32 2016 -0300
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Sep 27 09:11:54 2016 -0700

----------------------------------------------------------------------
 libs/console/full/src/cons_tty.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/711b31dd/libs/console/full/src/cons_tty.c
----------------------------------------------------------------------
diff --git a/libs/console/full/src/cons_tty.c b/libs/console/full/src/cons_tty.c
index b98928b..b26604a 100644
--- a/libs/console/full/src/cons_tty.c
+++ b/libs/console/full/src/cons_tty.c
@@ -117,9 +117,9 @@ console_queue_char(char ch)
         /* TX needs to drain */
         uart_start_tx(ct->ct_dev);
         OS_EXIT_CRITICAL(sr);
-    if (os_started()) {
+        if (os_started()) {
             os_time_delay(1);
-    }
+        }
         OS_ENTER_CRITICAL(sr);
     }
     console_add_char(&ct->ct_tx, ch);


[3/6] incubator-mynewt-core git commit: Fix deleting old chars and movement in both history directions

Posted by ma...@apache.org.
Fix deleting old chars and movement in both history directions


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/37c0cb4e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/37c0cb4e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/37c0cb4e

Branch: refs/heads/develop
Commit: 37c0cb4e8c47d75bacea31eda54a09c50fce1060
Parents: 711b31d
Author: Fabio Utzig <ut...@utzig.org>
Authored: Mon Aug 29 23:52:16 2016 -0300
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Sep 27 09:12:23 2016 -0700

----------------------------------------------------------------------
 libs/console/full/src/cons_tty.c | 79 ++++++++++++++++-------------------
 1 file changed, 36 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37c0cb4e/libs/console/full/src/cons_tty.c
----------------------------------------------------------------------
diff --git a/libs/console/full/src/cons_tty.c b/libs/console/full/src/cons_tty.c
index b26604a..1a54c88 100644
--- a/libs/console/full/src/cons_tty.c
+++ b/libs/console/full/src/cons_tty.c
@@ -73,6 +73,7 @@ struct console_tty {
 struct console_hist {
     uint8_t ch_head;
     uint8_t ch_tail;
+    uint8_t ch_size;
     uint8_t ch_curr;
     uint8_t ch_buf[CONSOLE_HIST_SZ][CONSOLE_RX_BUF_SZ];
 } console_hist;
@@ -134,6 +135,7 @@ console_hist_init(void)
     ch->ch_head = 0;
     ch->ch_tail = 0;
     ch->ch_curr = 0;
+    ch->ch_size = CONSOLE_HIST_SZ;
 }
 
 static void
@@ -142,48 +144,60 @@ console_hist_add(struct console_ring *rx)
     struct console_hist *ch = &console_hist;
     uint8_t *str = ch->ch_buf[ch->ch_head];
     uint8_t tail;
+    uint8_t empty = 1;
 
-    /* TODO: don't add empty lines? */
     tail = rx->cr_tail;
     while (tail != rx->cr_head) {
         *str = rx->cr_buf[tail];
+        if (*str != ' ' && *str != '\t' && *str != '\n') {
+            empty = 0;
+        }
         if (*str == '\n') {
             *str = '\0';
+            /* don't save empty history */
+            if (empty) {
+                return;
+            }
             break;
         }
         str++;
         tail = (tail + 1) % CONSOLE_RX_BUF_SZ;
     }
 
-    ch->ch_head = (ch->ch_head + 1) % CONSOLE_HIST_SZ;
+    ch->ch_head = (ch->ch_head + 1) & (ch->ch_size - 1);
     ch->ch_curr = ch->ch_head;
 
     /* buffer full, start overwriting old history */
     if (ch->ch_head == ch->ch_tail) {
-        ch->ch_tail = (ch->ch_tail + 1) % CONSOLE_HIST_SZ;
+        ch->ch_tail = (ch->ch_tail + 1) & (ch->ch_size - 1);
     }
 }
 
 static int
-console_hist_prev(struct console_ring *rx, uint8_t *tx_buf)
+console_hist_move(struct console_ring *rx, uint8_t *tx_buf, uint8_t direction)
 {
     struct console_hist *ch = &console_hist;
     uint8_t *str = NULL;
     int space = 0;
+    uint8_t limit = direction == CONSOLE_UP ? ch->ch_tail : ch->ch_head;
 
-    /* no more history to return */
-    if (ch->ch_curr == ch->ch_tail) {
+    /* no more history to return in this direction */
+    if (ch->ch_curr == limit) {
         return 0;
     }
 
-    ch->ch_curr = (ch->ch_curr - 1) % CONSOLE_HIST_SZ;
-    str = ch->ch_buf[ch->ch_curr];
+    if (direction == CONSOLE_UP) {
+        ch->ch_curr = (ch->ch_curr - 1) & (ch->ch_size - 1);
+    } else {
+        ch->ch_curr = (ch->ch_curr + 1) & (ch->ch_size - 1);
+    }
 
     /* consume all chars */
     while (console_pull_char_head(rx) == 0) {
         /* do nothing */
     }
 
+    str = ch->ch_buf[ch->ch_curr];
     for (int i = 0; i < CONSOLE_RX_BUF_SZ; ++i) {
         if (str[i] == '\0') {
             break;
@@ -196,23 +210,6 @@ console_hist_prev(struct console_ring *rx, uint8_t *tx_buf)
     return space;
 }
 
-static int
-console_hist_next(struct console_ring *rx, uint8_t *tx_buf)
-{
-    struct console_hist *ch = &console_hist;
-    //uint8_t *str = ch->ch_buf[ch->ch_curr];
-    //int space = 0;
-
-    /* no more history to return */
-    if (ch->ch_curr == ch->ch_head) {
-        return 0;
-    }
-
-    ch->ch_curr = (ch->ch_curr + 1) % CONSOLE_HIST_SZ;
-
-    return 0;
-}
-
 static void
 console_blocking_tx(char ch)
 {
@@ -417,35 +414,31 @@ console_rx_char(void *arg, uint8_t data)
     case CONSOLE_UP:
     case CONSOLE_DOWN:
         if (ct->ct_esc_seq == 2) {
-            if (data == CONSOLE_UP) {
-                tx_space = console_hist_prev(rx, tx_buf);
-            } else {
-                tx_space = console_hist_next(rx, tx_buf);
-            }
+            tx_space = console_hist_move(rx, tx_buf, data);
             tx_buf[tx_space] = 0;
             ct->ct_esc_seq = 0;
-            if (tx_space == 0) {
+            /*
+             * when moving up, stop on oldest history entry
+             * when moving down, let it delete input before leaving...
+             */
+            if (data == CONSOLE_UP && tx_space == 0) {
                 goto out;
             }
             if (!ct->ct_echo_off) {
-                i = 0;
-                while (console_pull_char_head(tx) == 0) {
-                    i++;
-                }
-                //FIXME: pulling doesnt get real count of chars...
-#if 1
-                while (i) {
+                /* HACK: clean line by backspacing up to maximum possible space */
+                for (i = 0; i < CONSOLE_TX_BUF_SZ; i++) {
+                    if (console_buf_space(tx) < 3) {
+                        console_tx_flush(ct, 3);
+                    }
                     console_add_char(tx, '\b');
                     console_add_char(tx, ' ');
                     console_add_char(tx, '\b');
                     hal_uart_start_tx(CONSOLE_UART);
-                    i--;
                 }
-#endif
             }
-        } else {
-            goto queue_char;
-        }
+            if (tx_space == 0) {
+                goto out;
+            }
         break;
     case CONSOLE_RIGHT:
         if (ct->ct_esc_seq == 2) {


[5/6] incubator-mynewt-core git commit: This closes #100.

Posted by ma...@apache.org.
This closes #100.

Use less memory when console history is disabled


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/1c362560
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/1c362560
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/1c362560

Branch: refs/heads/develop
Commit: 1c362560d1b9267a97747261b871ce80aa05ea1d
Parents: 437b5fc
Author: Fabio Utzig <ut...@utzig.org>
Authored: Sun Sep 4 18:26:44 2016 -0300
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Sep 27 12:13:54 2016 -0700

----------------------------------------------------------------------
 libs/console/full/src/cons_tty.c | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1c362560/libs/console/full/src/cons_tty.c
----------------------------------------------------------------------
diff --git a/libs/console/full/src/cons_tty.c b/libs/console/full/src/cons_tty.c
index 95a5ecb..b14fd07 100644
--- a/libs/console/full/src/cons_tty.c
+++ b/libs/console/full/src/cons_tty.c
@@ -368,7 +368,11 @@ console_rx_char(void *arg, uint8_t data)
     struct console_ring *rx = &ct->ct_rx;
     int tx_space = 0;
     int i;
+#ifdef CONSOLE_HIST_ENABLE
     uint8_t tx_buf[CONSOLE_RX_BUF_SZ];
+#else
+    uint8_t tx_buf[3];
+#endif
 
     if (CONSOLE_HEAD_INC(&ct->ct_rx) == ct->ct_rx.cr_tail) {
         /*


[6/6] incubator-mynewt-core git commit: console; make console history configurable with syscfg.

Posted by ma...@apache.org.
console; make console history configurable with syscfg.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/8897a2f1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/8897a2f1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/8897a2f1

Branch: refs/heads/develop
Commit: 8897a2f1a64486ca5a3656cd9796b685a1b68683
Parents: 1c36256
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Sep 27 12:17:32 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Sep 27 12:17:32 2016 -0700

----------------------------------------------------------------------
 libs/console/full/pkg.yml        |  5 ++++-
 libs/console/full/src/cons_tty.c | 27 ++++++++++++++-------------
 2 files changed, 18 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8897a2f1/libs/console/full/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/console/full/pkg.yml b/libs/console/full/pkg.yml
index f7b895f..80242ca 100644
--- a/libs/console/full/pkg.yml
+++ b/libs/console/full/pkg.yml
@@ -38,4 +38,7 @@ pkg.syscfg_defs:
         value: '0'
     CONSOLE_ECHO:
         description: 'Default console echo '
-        value: '0'
\ No newline at end of file
+        value: '1'
+    CONSOLE_HIST_ENABLE:
+        description: 'Console history '
+        value: 1

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8897a2f1/libs/console/full/src/cons_tty.c
----------------------------------------------------------------------
diff --git a/libs/console/full/src/cons_tty.c b/libs/console/full/src/cons_tty.c
index b14fd07..f9690d3 100644
--- a/libs/console/full/src/cons_tty.c
+++ b/libs/console/full/src/cons_tty.c
@@ -33,8 +33,9 @@ int console_is_midline;
 
 #define CONSOLE_TX_BUF_SZ       32      /* IO buffering, must be power of 2 */
 #define CONSOLE_RX_BUF_SZ       128
+#define CONSOLE_RX_CHUNK        16
 
-#ifdef CONSOLE_HIST_ENABLE
+#if MYNEWT_VAL(CONSOLE_HIST_ENABLE)
 #define CONSOLE_HIST_SZ         32
 #endif
 
@@ -71,7 +72,7 @@ struct console_tty {
     uint8_t ct_esc_seq:2;
 } console_tty;
 
-#ifdef CONSOLE_HIST_ENABLE
+#if MYNEWT_VAL(CONSOLE_HIST_ENABLE)
 struct console_hist {
     uint8_t ch_head;
     uint8_t ch_tail;
@@ -129,7 +130,7 @@ console_queue_char(char ch)
     OS_EXIT_CRITICAL(sr);
 }
 
-#ifdef CONSOLE_HIST_ENABLE
+#if MYNEWT_VAL(CONSOLE_HIST_ENABLE)
 static void
 console_hist_init(void)
 {
@@ -368,7 +369,7 @@ console_rx_char(void *arg, uint8_t data)
     struct console_ring *rx = &ct->ct_rx;
     int tx_space = 0;
     int i;
-#ifdef CONSOLE_HIST_ENABLE
+#if MYNEWT_VAL(CONSOLE_HIST_ENABLE)
     uint8_t tx_buf[CONSOLE_RX_BUF_SZ];
 #else
     uint8_t tx_buf[3];
@@ -387,8 +388,6 @@ console_rx_char(void *arg, uint8_t data)
     /* echo */
     switch (data) {
     case '\r':
-        break;
-    case '\n':
         /*
          * linefeed
          */
@@ -396,7 +395,7 @@ console_rx_char(void *arg, uint8_t data)
         tx_buf[1] = '\r';
         tx_space = 2;
         console_add_char(rx, '\n');
-#ifdef CONSOLE_HIST_ENABLE
+#if MYNEWT_VAL(CONSOLE_HIST_ENABLE)
         console_hist_add(rx);
 #endif
         if (ct->ct_rx_cb) {
@@ -426,7 +425,7 @@ console_rx_char(void *arg, uint8_t data)
         if (ct->ct_esc_seq != 2) {
             goto queue_char;
         }
-#ifdef CONSOLE_HIST_ENABLE
+#if MYNEWT_VAL(CONSOLE_HIST_ENABLE)
         tx_space = console_hist_move(rx, tx_buf, data);
         tx_buf[tx_space] = 0;
         ct->ct_esc_seq = 0;
@@ -446,11 +445,13 @@ console_rx_char(void *arg, uint8_t data)
                 console_add_char(tx, '\b');
                 console_add_char(tx, ' ');
                 console_add_char(tx, '\b');
-                hal_uart_start_tx(CONSOLE_UART);
+                uart_start_tx(ct->ct_dev);
             }
-        }
-        if (tx_space == 0) {
-            goto out;
+            if (tx_space == 0) {
+                goto out;
+            }
+        } else {
+            goto queue_char;
         }
         break;
 #else
@@ -541,7 +542,7 @@ console_init(console_rx_cb rx_cb)
         ct->ct_echo_off = ! MYNEWT_VAL(CONSOLE_ECHO);
     }
 
-#ifdef CONSOLE_HIST_ENABLE
+#if MYNEWT_VAL(CONSOLE_HIST_ENABLE)
     console_hist_init();
 #endif