You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2019/11/08 15:21:08 UTC

[mynewt-core] branch master updated: sys/console: Allow history to be preserved during reset

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


The following commit(s) were added to refs/heads/master by this push:
     new 5001bc2  sys/console: Allow history to be preserved during reset
5001bc2 is described below

commit 5001bc223dd055143a0ae162bbe5a31ea6aecebb
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Wed Nov 6 13:08:56 2019 +0100

    sys/console: Allow history to be preserved during reset
    
    It cab be useful to preserver console history in RAM when
    code is begin debugged and application is intentionally
    rebooted i.e. mon reset.
    History memory is put in bssnz section and magic value is
    stored to detect RAM preservation.
    
    History will be preserved on some platforms where during
    reboot history data is not overwritten by bootloader data.
    Tested to work on hifive1 board with custom reset handler,
    and dialog da14699 board.
---
 sys/console/full/src/console.c | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/sys/console/full/src/console.c b/sys/console/full/src/console.c
index e259a5a..2ae1be9 100644
--- a/sys/console/full/src/console.c
+++ b/sys/console/full/src/console.c
@@ -23,6 +23,7 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <string.h>
+#include <bsp/bsp.h>
 
 #include "os/mynewt.h"
 #include "os/os_task.h"
@@ -689,9 +690,18 @@ console_clear_line(void)
 }
 
 #if MYNEWT_VAL(CONSOLE_HISTORY_SIZE) > 0
-static char console_hist_lines[ MYNEWT_VAL(CONSOLE_HISTORY_SIZE) ][ MYNEWT_VAL(CONSOLE_MAX_INPUT_LEN) ];
 
-static struct console_hist {
+#ifndef bssnz_t
+/* Just in case bsp.h does not define it, in this case console history will
+ * not be preserved across software resets
+ */
+#define bssnz_t
+#endif
+
+bssnz_t static char console_hist_lines[ MYNEWT_VAL(CONSOLE_HISTORY_SIZE) ][ MYNEWT_VAL(CONSOLE_MAX_INPUT_LEN) ];
+
+bssnz_t static struct console_hist {
+    uint32_t magic;
     uint8_t head;
     uint8_t tail;
     uint8_t size;
@@ -705,13 +715,16 @@ console_hist_init(void)
     struct console_hist *sh = &console_hist;
     int i;
 
-    memset(console_hist_lines, 0, sizeof(console_hist_lines));
-    memset(&console_hist, 0, sizeof(console_hist));
+    if (sh->magic != 0xBABEFACE) {
+        memset(console_hist_lines, 0, sizeof(console_hist_lines));
+        memset(&console_hist, 0, sizeof(console_hist));
 
-    sh->size = MYNEWT_VAL(CONSOLE_HISTORY_SIZE) + 1;
+        sh->size = MYNEWT_VAL(CONSOLE_HISTORY_SIZE) + 1;
 
-    for (i = 0; i < sh->size - 1; i++) {
-        sh->lines[i] = console_hist_lines[i];
+        for (i = 0; i < sh->size - 1; i++) {
+            sh->lines[i] = console_hist_lines[i];
+        }
+        sh->magic = 0xBABEFACE;
     }
 }