You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/10/04 09:07:02 UTC

[GitHub] andrzej-kaczmarek closed pull request #1399: RTT console fixes

andrzej-kaczmarek closed pull request #1399: RTT console fixes
URL: https://github.com/apache/mynewt-core/pull/1399
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/sys/console/full/src/rtt_console.c b/sys/console/full/src/rtt_console.c
index 0191372205..1bc9c58441 100644
--- a/sys/console/full/src/rtt_console.c
+++ b/sys/console/full/src/rtt_console.c
@@ -30,7 +30,76 @@
 static struct hal_timer rtt_timer;
 #endif
 
-static const char CR = '\r';
+#if MYNEWT_VAL(CONSOLE_RTT_RETRY_COUNT) > 0
+
+static void
+rtt_console_wait_for_retry(void)
+{
+    uint32_t ticks;
+
+    if (os_arch_in_isr()) {
+#if MYNEWT_VAL(CONSOLE_RTT_RETRY_IN_ISR)
+        os_cputime_delay_usecs(MYNEWT_VAL(CONSOLE_RTT_RETRY_DELAY_MS) * 1000);
+#endif
+    } else {
+        ticks = max(1, os_time_ms_to_ticks32(MYNEWT_VAL(CONSOLE_RTT_RETRY_DELAY_MS)));
+        os_time_delay(ticks);
+    }
+}
+
+static void
+rtt_console_write_ch(char c)
+{
+    static int rtt_console_retries_left = MYNEWT_VAL(CONSOLE_RTT_RETRY_COUNT);
+    os_sr_t sr;
+    int ret;
+
+    while (1) {
+        OS_ENTER_CRITICAL(sr);
+        ret = SEGGER_RTT_WriteNoLock(0, &c, 1);
+        OS_EXIT_CRITICAL(sr);
+
+        /*
+         * In case write failed we can wait a bit and retry to allow host pull
+         * some data from buffer. However, in case there is no host connected
+         * we should not spend time retrying over and over again so need to be
+         * smarter here:
+         * - each successful write resets retry counter to predefined value
+         * - each failed write will retry until success or retry counter drops
+         *   to zero
+         * This means that if we failed to write some character after number of
+         * retries (which means that most likely there is no host connected to
+         * read data), we stop retrying until successful write (which means that
+         * host is reading data).
+         */
+
+        if (ret) {
+            rtt_console_retries_left = MYNEWT_VAL(CONSOLE_RTT_RETRY_COUNT);
+            break;
+        }
+
+        if (!rtt_console_retries_left) {
+            break;
+        }
+
+        rtt_console_wait_for_retry();
+        rtt_console_retries_left--;
+    }
+}
+
+#else
+
+static void
+rtt_console_write_ch(char c)
+{
+    os_sr_t sr;
+
+    OS_ENTER_CRITICAL(sr);
+    SEGGER_RTT_WriteNoLock(0, &c, 1);
+    OS_EXIT_CRITICAL(sr);
+}
+
+#endif
 
 int
 console_out(int character)
@@ -42,13 +111,13 @@ console_out(int character)
     }
 
     if ('\n' == c) {
-        SEGGER_RTT_WriteWithOverwriteNoLock(0, &CR, 1);
+        rtt_console_write_ch('\r');
         console_is_midline = 0;
     } else {
         console_is_midline = 1;
     }
 
-    SEGGER_RTT_WriteWithOverwriteNoLock(0, &c, 1);
+    rtt_console_write_ch(c);
 
     return character;
 }
diff --git a/sys/console/full/syscfg.yml b/sys/console/full/syscfg.yml
index 647160e28f..92e4382a2b 100644
--- a/sys/console/full/syscfg.yml
+++ b/sys/console/full/syscfg.yml
@@ -72,6 +72,20 @@ syscfg.defs:
         description: 'Console UART device.'
         value: '"uart0"'
 
+    CONSOLE_RTT_RETRY_COUNT:
+        description: >
+            Number of retries to write data in case buffer is full. This allows
+            to wait for host to read data from buffer in case there's a lot of
+            data to write which do not fit in buffer.
+        value: 2
+    CONSOLE_RTT_RETRY_DELAY_MS:
+        description: >
+            Delay (in miliseconds) between each write retry.
+        value: 2
+    CONSOLE_RTT_RETRY_IN_ISR:
+        description: >
+            Set to non-zero to enable write retries also in ISR.
+        value: 0
     CONSOLE_RTT_INPUT_POLL_INTERVAL_MAX:
         description: >
             Maximum interval (milliseconds) to poll for RTT input.


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services