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/06/29 13:06:40 UTC

[GitHub] andrzej-kaczmarek closed pull request #1221: RTT updates

andrzej-kaczmarek closed pull request #1221: RTT updates
URL: https://github.com/apache/mynewt-core/pull/1221
 
 
   

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/hw/drivers/rtt/include/rtt/SEGGER_RTT.h b/hw/drivers/rtt/include/rtt/SEGGER_RTT.h
index b4417a0f75..4c3ff7ac01 100644
--- a/hw/drivers/rtt/include/rtt/SEGGER_RTT.h
+++ b/hw/drivers/rtt/include/rtt/SEGGER_RTT.h
@@ -1,9 +1,9 @@
 /*********************************************************************
-*               SEGGER MICROCONTROLLER GmbH & Co. KG                 *
+*                    SEGGER Microcontroller GmbH                     *
 *       Solutions for real time microcontroller applications         *
 **********************************************************************
 *                                                                    *
-*       (c) 2014 - 2016  SEGGER Microcontroller GmbH & Co. KG        *
+*            (c) 1995 - 2018 SEGGER Microcontroller GmbH             *
 *                                                                    *
 *       www.segger.com     Support: support@segger.com               *
 *                                                                    *
@@ -31,7 +31,7 @@
 *   disclaimer in the documentation and/or other materials provided  *
 *   with the distribution.                                           *
 *                                                                    *
-* o Neither the name of SEGGER Microcontroller GmbH & Co. KG         *
+* o Neither the name of SEGGER Microcontroller GmbH         *
 *   nor the names of its contributors may be used to endorse or      *
 *   promote products derived from this software without specific     *
 *   prior written permission.                                        *
@@ -56,14 +56,14 @@ File    : SEGGER_RTT.h
 Purpose : Implementation of SEGGER real-time transfer which allows
           real-time communication on targets which support debugger 
           memory accesses while the CPU is running.
-Revision: $Rev: 4351 $
+Revision: $Rev: 11303 $
 ----------------------------------------------------------------------
 */
 
 #ifndef SEGGER_RTT_H
 #define SEGGER_RTT_H
 
-#include "rtt/SEGGER_RTT_Conf.h"
+#include "SEGGER_RTT_Conf.h"
 
 /*********************************************************************
 *
@@ -142,6 +142,7 @@ int          SEGGER_RTT_ConfigDownBuffer        (unsigned BufferIndex, const cha
 int          SEGGER_RTT_GetKey                  (void);
 unsigned     SEGGER_RTT_HasData                 (unsigned BufferIndex);
 int          SEGGER_RTT_HasKey                  (void);
+unsigned     SEGGER_RTT_HasDataUp               (unsigned BufferIndex);
 void         SEGGER_RTT_Init                    (void);
 unsigned     SEGGER_RTT_Read                    (unsigned BufferIndex,       void* pBuffer, unsigned BufferSize);
 unsigned     SEGGER_RTT_ReadNoLock              (unsigned BufferIndex,       void* pData,   unsigned BufferSize);
@@ -155,6 +156,9 @@ unsigned     SEGGER_RTT_WriteNoLock             (unsigned BufferIndex, const voi
 unsigned     SEGGER_RTT_WriteSkipNoLock         (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
 unsigned     SEGGER_RTT_WriteString             (unsigned BufferIndex, const char* s);
 void         SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
+unsigned     SEGGER_RTT_PutChar                 (unsigned BufferIndex, char c);
+unsigned     SEGGER_RTT_PutCharSkip             (unsigned BufferIndex, char c);
+unsigned     SEGGER_RTT_PutCharSkipNoLock       (unsigned BufferIndex, char c);
 //
 // Function macro for performance optimization
 //
@@ -199,44 +203,44 @@ int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...);
 // Control sequences, based on ANSI.
 // Can be used to control color, and clear the screen
 //
-#define RTT_CTRL_RESET                ""         // Reset to default colors
-#define RTT_CTRL_CLEAR                ""         // Clear screen, reposition cursor to top left
-
-#define RTT_CTRL_TEXT_BLACK           ""
-#define RTT_CTRL_TEXT_RED             ""
-#define RTT_CTRL_TEXT_GREEN           ""
-#define RTT_CTRL_TEXT_YELLOW          ""
-#define RTT_CTRL_TEXT_BLUE            ""
-#define RTT_CTRL_TEXT_MAGENTA         ""
-#define RTT_CTRL_TEXT_CYAN            ""
-#define RTT_CTRL_TEXT_WHITE           ""
-
-#define RTT_CTRL_TEXT_BRIGHT_BLACK    ""
-#define RTT_CTRL_TEXT_BRIGHT_RED      ""
-#define RTT_CTRL_TEXT_BRIGHT_GREEN    ""
-#define RTT_CTRL_TEXT_BRIGHT_YELLOW   ""
-#define RTT_CTRL_TEXT_BRIGHT_BLUE     ""
-#define RTT_CTRL_TEXT_BRIGHT_MAGENTA  ""
-#define RTT_CTRL_TEXT_BRIGHT_CYAN     ""
-#define RTT_CTRL_TEXT_BRIGHT_WHITE    ""
-
-#define RTT_CTRL_BG_BLACK             ""
-#define RTT_CTRL_BG_RED               ""
-#define RTT_CTRL_BG_GREEN             ""
-#define RTT_CTRL_BG_YELLOW            ""
-#define RTT_CTRL_BG_BLUE              ""
-#define RTT_CTRL_BG_MAGENTA           ""
-#define RTT_CTRL_BG_CYAN              ""
-#define RTT_CTRL_BG_WHITE             ""
-
-#define RTT_CTRL_BG_BRIGHT_BLACK      ""
-#define RTT_CTRL_BG_BRIGHT_RED        ""
-#define RTT_CTRL_BG_BRIGHT_GREEN      ""
-#define RTT_CTRL_BG_BRIGHT_YELLOW     ""
-#define RTT_CTRL_BG_BRIGHT_BLUE       ""
-#define RTT_CTRL_BG_BRIGHT_MAGENTA    ""
-#define RTT_CTRL_BG_BRIGHT_CYAN       ""
-#define RTT_CTRL_BG_BRIGHT_WHITE      ""
+#define RTT_CTRL_RESET                "\x1B[0m"         // Reset to default colors
+#define RTT_CTRL_CLEAR                "\x1B[2J"         // Clear screen, reposition cursor to top left
+
+#define RTT_CTRL_TEXT_BLACK           "\x1B[2;30m"
+#define RTT_CTRL_TEXT_RED             "\x1B[2;31m"
+#define RTT_CTRL_TEXT_GREEN           "\x1B[2;32m"
+#define RTT_CTRL_TEXT_YELLOW          "\x1B[2;33m"
+#define RTT_CTRL_TEXT_BLUE            "\x1B[2;34m"
+#define RTT_CTRL_TEXT_MAGENTA         "\x1B[2;35m"
+#define RTT_CTRL_TEXT_CYAN            "\x1B[2;36m"
+#define RTT_CTRL_TEXT_WHITE           "\x1B[2;37m"
+
+#define RTT_CTRL_TEXT_BRIGHT_BLACK    "\x1B[1;30m"
+#define RTT_CTRL_TEXT_BRIGHT_RED      "\x1B[1;31m"
+#define RTT_CTRL_TEXT_BRIGHT_GREEN    "\x1B[1;32m"
+#define RTT_CTRL_TEXT_BRIGHT_YELLOW   "\x1B[1;33m"
+#define RTT_CTRL_TEXT_BRIGHT_BLUE     "\x1B[1;34m"
+#define RTT_CTRL_TEXT_BRIGHT_MAGENTA  "\x1B[1;35m"
+#define RTT_CTRL_TEXT_BRIGHT_CYAN     "\x1B[1;36m"
+#define RTT_CTRL_TEXT_BRIGHT_WHITE    "\x1B[1;37m"
+
+#define RTT_CTRL_BG_BLACK             "\x1B[24;40m"
+#define RTT_CTRL_BG_RED               "\x1B[24;41m"
+#define RTT_CTRL_BG_GREEN             "\x1B[24;42m"
+#define RTT_CTRL_BG_YELLOW            "\x1B[24;43m"
+#define RTT_CTRL_BG_BLUE              "\x1B[24;44m"
+#define RTT_CTRL_BG_MAGENTA           "\x1B[24;45m"
+#define RTT_CTRL_BG_CYAN              "\x1B[24;46m"
+#define RTT_CTRL_BG_WHITE             "\x1B[24;47m"
+
+#define RTT_CTRL_BG_BRIGHT_BLACK      "\x1B[4;40m"
+#define RTT_CTRL_BG_BRIGHT_RED        "\x1B[4;41m"
+#define RTT_CTRL_BG_BRIGHT_GREEN      "\x1B[4;42m"
+#define RTT_CTRL_BG_BRIGHT_YELLOW     "\x1B[4;43m"
+#define RTT_CTRL_BG_BRIGHT_BLUE       "\x1B[4;44m"
+#define RTT_CTRL_BG_BRIGHT_MAGENTA    "\x1B[4;45m"
+#define RTT_CTRL_BG_BRIGHT_CYAN       "\x1B[4;46m"
+#define RTT_CTRL_BG_BRIGHT_WHITE      "\x1B[4;47m"
 
 
 #endif
diff --git a/hw/drivers/rtt/include/rtt/SEGGER_RTT_Conf.h b/hw/drivers/rtt/include/rtt/SEGGER_RTT_Conf.h
index b9d287a901..a7b084c91d 100644
--- a/hw/drivers/rtt/include/rtt/SEGGER_RTT_Conf.h
+++ b/hw/drivers/rtt/include/rtt/SEGGER_RTT_Conf.h
@@ -1,274 +1,63 @@
-/*********************************************************************
-*               SEGGER MICROCONTROLLER GmbH & Co. KG                 *
-*       Solutions for real time microcontroller applications         *
-**********************************************************************
-*                                                                    *
-*       (c) 2014 - 2016  SEGGER Microcontroller GmbH & Co. KG        *
-*                                                                    *
-*       www.segger.com     Support: support@segger.com               *
-*                                                                    *
-**********************************************************************
-*                                                                    *
-*       SEGGER RTT * Real Time Transfer for embedded targets         *
-*                                                                    *
-**********************************************************************
-*                                                                    *
-* All rights reserved.                                               *
-*                                                                    *
-* SEGGER strongly recommends to not make any changes                 *
-* to or modify the source code of this software in order to stay     *
-* compatible with the RTT protocol and J-Link.                       *
-*                                                                    *
-* Redistribution and use in source and binary forms, with or         *
-* without modification, are permitted provided that the following    *
-* conditions are met:                                                *
-*                                                                    *
-* o Redistributions of source code must retain the above copyright   *
-*   notice, this list of conditions and the following disclaimer.    *
-*                                                                    *
-* o Redistributions in binary form must reproduce the above          *
-*   copyright notice, this list of conditions and the following      *
-*   disclaimer in the documentation and/or other materials provided  *
-*   with the distribution.                                           *
-*                                                                    *
-* o Neither the name of SEGGER Microcontroller GmbH & Co. KG         *
-*   nor the names of its contributors may be used to endorse or      *
-*   promote products derived from this software without specific     *
-*   prior written permission.                                        *
-*                                                                    *
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
-* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
-* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
-* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
-* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
-* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
-* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
-* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
-* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
-* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
-* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
-* DAMAGE.                                                            *
-*                                                                    *
-**********************************************************************
----------------------------END-OF-HEADER------------------------------
-File    : SEGGER_RTT_Conf.h
-Purpose : Implementation of SEGGER real-time transfer (RTT) which 
-          allows real-time communication on targets which support 
-          debugger memory accesses while the CPU is running.
-Revision: $Rev: 4351 $
-----------------------------------------------------------------------
-*/
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 
 #ifndef SEGGER_RTT_CONF_H
 #define SEGGER_RTT_CONF_H
 
-#include "os/mynewt.h"
+#include "syscfg/syscfg.h"
+#include "os/os.h"
 
-#ifdef __IAR_SYSTEMS_ICC__
-  #include <intrinsics.h>
-#endif
-
-#include "rtt/SEGGER_RTT_Conf_Mynewt.h"
-
-/*********************************************************************
-*
-*       Defines, configurable
-*
-**********************************************************************
-*/
-
-#define SEGGER_RTT_MAX_NUM_UP_BUFFERS             (3)     // Max. number of up-buffers (T->H) available on this target    (Default: 3)
-#define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS           (3)     // Max. number of down-buffers (H->T) available on this target  (Default: 3)
-
-#define BUFFER_SIZE_UP                            (MYNEWT_VAL(RTT_BUFFER_SIZE_UP))  // Size of the buffer for terminal output of target, up to host (Default: 1k)
-#define BUFFER_SIZE_DOWN                          (MYNEWT_VAL(RTT_BUFFER_SIZE_DOWN))    // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16)
-
-#define SEGGER_RTT_PRINTF_BUFFER_SIZE             (64u)    // Size of buffer for RTT printf to bulk-send chars via RTT     (Default: 64)
-
-#define SEGGER_RTT_MODE_DEFAULT                   SEGGER_RTT_MODE_NO_BLOCK_SKIP // Mode for pre-initialized terminal channel (buffer 0)
-
-//
-// Target is not allowed to perform other RTT operations while string still has not been stored completely.
-// Otherwise we would probably end up with a mixed string in the buffer.
-// If using  RTT from within interrupts, multiple tasks or multi processors, define the SEGGER_RTT_LOCK() and SEGGER_RTT_UNLOCK() function here.
-// 
-// SEGGER_RTT_MAX_INTERRUPT_PRIORITY can be used in the sample lock routines on Cortex-M3/4.
-// Make sure to mask all interrupts which can send RTT data, i.e. generate SystemView events, or cause task switches.
-// When high-priority interrupts must not be masked while sending RTT data, SEGGER_RTT_MAX_INTERRUPT_PRIORITY needs to be adjusted accordingly.
-// (Higher priority = lower priority number)
-// Default value for embOS: 128u
-// Default configuration in FreeRTOS: configMAX_SYSCALL_INTERRUPT_PRIORITY: ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
-// In case of doubt mask all interrupts: 1 << (8 - BASEPRI_PRIO_BITS) i.e. 1 << 5 when 3 bits are implemented in NVIC
-// or define SEGGER_RTT_LOCK() to completely disable interrupts.
-// 
-
-#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY         (0x20)   // Interrupt priority to lock on SEGGER_RTT_LOCK on Cortex-M3/4 (Default: 0x20)
-
-/*********************************************************************
-*
-*       RTT lock configuration for SEGGER Embedded Studio, 
-*       Rowley CrossStudio and GCC
-*/
-#if (defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__)
-  #ifdef __ARM_ARCH_6M__
-    #define SEGGER_RTT_LOCK()   {                                                                   \
-                                    unsigned int LockState;                                         \
-                                  __asm volatile ("mrs   %0, primask  \n\t"                         \
-                                                  "mov   r1, $1     \n\t"                           \
-                                                  "msr   primask, r1  \n\t"                         \
-                                                  : "=r" (LockState)                                \
-                                                  :                                                 \
-                                                  : "r1"                                            \
-                                                  );                            
-    
-    #define SEGGER_RTT_UNLOCK()   __asm volatile ("msr   primask, %0  \n\t"                         \
-                                                  :                                                 \
-                                                  : "r" (LockState)                                 \
-                                                  :                                                 \
-                                                  );                                                \
-                                }                                             
-                                  
-  #elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__))
-    #ifndef   SEGGER_RTT_MAX_INTERRUPT_PRIORITY
-      #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY   (0x20)
-    #endif
-    #define SEGGER_RTT_LOCK()   {                                                                   \
-                                    unsigned int LockState;                                         \
-                                  __asm volatile ("mrs   %0, basepri  \n\t"                         \
-                                                  "mov   r1, %1       \n\t"                         \
-                                                  "msr   basepri, r1  \n\t"                         \
-                                                  : "=r" (LockState)                                \
-                                                  : "i"(SEGGER_RTT_MAX_INTERRUPT_PRIORITY)          \
-                                                  : "r1"                                            \
-                                                  );                            
-    
-    #define SEGGER_RTT_UNLOCK()   __asm volatile ("msr   basepri, %0  \n\t"                         \
-                                                  :                                                 \
-                                                  : "r" (LockState)                                 \
-                                                  :                                                 \
-                                                  );                                                \
-                                }
-  
-  #elif defined(__ARM_ARCH_7A__)
-    #define SEGGER_RTT_LOCK() {                                                \
-                                 unsigned int LockState;                       \
-                                 __asm volatile ("mrs r1, CPSR \n\t"           \
-                                                 "mov %0, r1 \n\t"             \
-                                                 "orr r1, r1, #0xC0 \n\t"      \
-                                                 "msr CPSR_c, r1 \n\t"         \
-                                                 : "=r" (LockState)            \
-                                                 :                             \
-                                                 : "r1"                        \
-                                                 );
-
-    #define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t"              \
-                                                "mrs r1, CPSR \n\t"            \
-                                                "bic r1, r1, #0xC0 \n\t"       \
-                                                "and r0, r0, #0xC0 \n\t"       \
-                                                "orr r1, r1, r0 \n\t"          \
-                                                "msr CPSR_c, r1 \n\t"          \
-                                                :                              \
-                                                : "r" (LockState)              \
-                                                : "r0", "r1"                   \
-                                                );                             \
-                            }
+#if MYNEWT_VAL(OS_SYSVIEW)
+#define NUM_BUFFERS_OS_SYSVIEW          1
 #else
-    #ifndef   SEGGER_RTT_LOCK
-      #define SEGGER_RTT_LOCK()                // Lock RTT (nestable)   (i.e. disable interrupts)
-    #endif
-
-    #ifndef   SEGGER_RTT_UNLOCK
-      #define SEGGER_RTT_UNLOCK()              // Unlock RTT (nestable) (i.e. enable previous interrupt lock state)
-    #endif
-  #endif
+#define NUM_BUFFERS_OS_SYSVIEW          0
 #endif
 
-/*********************************************************************
-*
-*       RTT lock configuration for IAR EWARM
-*/
-#ifdef __ICCARM__
-  #if (defined (__ARM6M__) && (__CORE__ == __ARM6M__))
-    #define SEGGER_RTT_LOCK()   {                                                                   \
-                                  unsigned int LockState;                                           \
-                                  LockState = __get_PRIMASK();                                      \
-                                  __set_PRIMASK(1);                           
-                                    
-    #define SEGGER_RTT_UNLOCK()   __set_PRIMASK(LockState);                                         \
-                                }
-  #elif ((defined (__ARM7EM__) && (__CORE__ == __ARM7EM__)) || (defined (__ARM7M__) && (__CORE__ == __ARM7M__)))
-    #ifndef   SEGGER_RTT_MAX_INTERRUPT_PRIORITY
-      #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY   (0x20)
-    #endif
-    #define SEGGER_RTT_LOCK()   {                                                                   \
-                                  unsigned int LockState;                                           \
-                                  LockState = __get_BASEPRI();                                      \
-                                  __set_BASEPRI(SEGGER_RTT_MAX_INTERRUPT_PRIORITY);                           
-                                    
-    #define SEGGER_RTT_UNLOCK()   __set_BASEPRI(LockState);                                         \
-                                }  
-  #endif
+#if MYNEWT_VAL(BLE_MONITOR_RTT)
+#define NUM_BUFFERS_BLE_MONITOR         1
+#else
+#define NUM_BUFFERS_BLE_MONITOR         0
 #endif
 
-/*********************************************************************
-*
-*       RTT lock configuration for IAR RX
-*/
-#ifdef __ICCRX__
-  #define SEGGER_RTT_LOCK()   {                                                                     \
-                                unsigned long LockState;                                            \
-                                LockState = __get_interrupt_state();                                \
-                                __disable_interrupt();                           
-                                  
-  #define SEGGER_RTT_UNLOCK()   __set_interrupt_state(LockState);                                   \
-                              }
-#endif
+/* Maximum number of up-buffers (target -> host) available */
+#define SEGGER_RTT_MAX_NUM_UP_BUFFERS   \
+    (1 + (NUM_BUFFERS_OS_SYSVIEW) + (NUM_BUFFERS_BLE_MONITOR) + \
+     (MYNEWT_VAL(RTT_NUM_BUFFERS_UP)))
+/* Maximum number of down-buffers (host -> target) available */
+#define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS \
+    (1 + (NUM_BUFFERS_OS_SYSVIEW) + (MYNEWT_VAL(RTT_NUM_BUFFERS_DOWN)))
 
-/*********************************************************************
-*
-*       RTT lock configuration for KEIL ARM
-*/
-#ifdef __CC_ARM
-  #if (defined __TARGET_ARCH_6S_M)
-    #define SEGGER_RTT_LOCK()   {                                                                   \
-                                  unsigned int LockState;                                           \
-                                  register unsigned char PRIMASK __asm( "primask");                 \
-                                  LockState = PRIMASK;                                              \
-                                  PRIMASK = 1u;                                                     \
-                                  __schedule_barrier();
+/* Size of up-buffer for Terminal (console output) */
+#define BUFFER_SIZE_UP                  (MYNEWT_VAL(RTT_TERMINAL_BUFFER_SIZE_UP))
+/* Size of down-buffer for Terminal (console input) */
+#define BUFFER_SIZE_DOWN                (MYNEWT_VAL(RTT_TERMINAL_BUFFER_SIZE_DOWN))
 
-    #define SEGGER_RTT_UNLOCK()   PRIMASK = LockState;                                              \
-                                  __schedule_barrier();                                             \
-                                }
-  #elif (defined(__TARGET_ARCH_7_M) || defined(__TARGET_ARCH_7E_M))
-    #ifndef   SEGGER_RTT_MAX_INTERRUPT_PRIORITY
-      #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY   (0x20)
-    #endif
-    #define SEGGER_RTT_LOCK()   {                                                                   \
-                                  unsigned int LockState;                                           \
-                                  register unsigned char BASEPRI __asm( "basepri");                 \
-                                  LockState = BASEPRI;                                              \
-                                  BASEPRI = SEGGER_RTT_MAX_INTERRUPT_PRIORITY;                      \
-                                  __schedule_barrier();
+/* Mode for default channel (Terminal) */
+#define SEGGER_RTT_MODE_DEFAULT         SEGGER_RTT_MODE_NO_BLOCK_SKIP
 
-    #define SEGGER_RTT_UNLOCK()   BASEPRI = LockState;                                              \
-                                  __schedule_barrier();                                             \
-                                }
-  #endif
-#endif
-
-/*********************************************************************
-*
-*       RTT lock configuration fallback
-*/
-#ifndef   SEGGER_RTT_LOCK
-  #define SEGGER_RTT_LOCK()                // Lock RTT (nestable)   (i.e. disable interrupts)
-#endif
-
-#ifndef   SEGGER_RTT_UNLOCK
-  #define SEGGER_RTT_UNLOCK()              // Unlock RTT (nestable) (i.e. enable previous interrupt lock state)
-#endif
+/* RTT locking functions */
+#define SEGGER_RTT_LOCK()               \
+        {                               \
+            os_sr_t sr;                 \
+            OS_ENTER_CRITICAL(sr);
+#define SEGGER_RTT_UNLOCK()             \
+            OS_EXIT_CRITICAL(sr);       \
+        }
 
 #endif
-/*************************** End of file ****************************/
diff --git a/hw/drivers/rtt/include/rtt/SEGGER_RTT_Conf_Mynewt.h b/hw/drivers/rtt/include/rtt/SEGGER_RTT_Conf_Mynewt.h
deleted file mode 100644
index b6aaee1882..0000000000
--- a/hw/drivers/rtt/include/rtt/SEGGER_RTT_Conf_Mynewt.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef SEGGER_RTT_CONF_H
-#define SEGGER_RTT_CONF_H
-
-#include "os/mynewt.h"
-
-#define SEGGER_RTT_LOCK()   {                       \
-                            int sr;                 \
-                            OS_ENTER_CRITICAL(sr);
-#define SEGGER_RTT_UNLOCK() OS_EXIT_CRITICAL(sr)    \
-                            }
-
-#endif
diff --git a/hw/drivers/rtt/pkg.yml b/hw/drivers/rtt/pkg.yml
index 962547ae07..47608f8fad 100644
--- a/hw/drivers/rtt/pkg.yml
+++ b/hw/drivers/rtt/pkg.yml
@@ -18,11 +18,12 @@
 #
 
 pkg.name: hw/drivers/rtt
-pkg.description: Segger RTT driver
+pkg.description: SEGGER RTT target implementation
 pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
 pkg.homepage: "http://mynewt.apache.org/"
 pkg.keywords:
 pkg.deps:
 pkg.req_apis: 
-pkg.init:
-    rtt_pkg_init: 19
\ No newline at end of file
+
+pkg.cflags:
+    - -DSEGGER_RTT_SECTION=".rtt"
diff --git a/hw/drivers/rtt/src/SEGGER_RTT.c b/hw/drivers/rtt/src/SEGGER_RTT.c
index 465fe7e531..f8d80e293d 100644
--- a/hw/drivers/rtt/src/SEGGER_RTT.c
+++ b/hw/drivers/rtt/src/SEGGER_RTT.c
@@ -1,9 +1,9 @@
 /*********************************************************************
-*               SEGGER MICROCONTROLLER GmbH & Co. KG                 *
+*                    SEGGER Microcontroller GmbH                     *
 *       Solutions for real time microcontroller applications         *
 **********************************************************************
 *                                                                    *
-*       (c) 2014 - 2016  SEGGER Microcontroller GmbH & Co. KG        *
+*            (c) 1995 - 2018 SEGGER Microcontroller GmbH             *
 *                                                                    *
 *       www.segger.com     Support: support@segger.com               *
 *                                                                    *
@@ -31,7 +31,7 @@
 *   disclaimer in the documentation and/or other materials provided  *
 *   with the distribution.                                           *
 *                                                                    *
-* o Neither the name of SEGGER Microcontroller GmbH & Co. KG         *
+* o Neither the name of SEGGER Microcontroller GmbH                  *
 *   nor the names of its contributors may be used to endorse or      *
 *   promote products derived from this software without specific     *
 *   prior written permission.                                        *
@@ -56,7 +56,7 @@ File    : SEGGER_RTT.c
 Purpose : Implementation of SEGGER real-time transfer (RTT) which
           allows real-time communication on targets which support
           debugger memory accesses while the CPU is running.
-Revision: $Rev: 4351 $
+Revision: $Rev: 10904 $
 
 Additional information:
           Type "int" is assumed to be 32-bits in size
@@ -79,10 +79,10 @@ Additional information:
 ----------------------------------------------------------------------
 */
 
-#include <string.h>                 // for memcpy
-#include "os/mynewt.h"
 #include "rtt/SEGGER_RTT.h"
 
+#include <string.h>                 // for memcpy
+
 /*********************************************************************
 *
 *       Configuration, default values
@@ -136,8 +136,16 @@ Additional information:
   #define STRLEN(a)                                       strlen((a))
 #endif
 
-#ifndef   MEMCPY
-  #define MEMCPY(pDest, pSrc, NumBytes)                   memcpy((pDest), (pSrc), (NumBytes))
+#ifndef   SEGGER_RTT_MEMCPY_USE_BYTELOOP
+  #define SEGGER_RTT_MEMCPY_USE_BYTELOOP                  0
+#endif
+
+#ifndef   SEGGER_RTT_MEMCPY
+  #ifdef  MEMCPY
+    #define SEGGER_RTT_MEMCPY(pDest, pSrc, NumBytes)      MEMCPY((pDest), (pSrc), (NumBytes))
+  #else
+    #define SEGGER_RTT_MEMCPY(pDest, pSrc, NumBytes)      memcpy((pDest), (pSrc), (NumBytes))
+  #endif
 #endif
 
 #ifndef   MIN
@@ -171,7 +179,7 @@ Additional information:
     #define PRAGMA(A) _Pragma(#A)
 #define SEGGER_RTT_ALIGN(Var, Alignment) RTT_PRAGMA(data_alignment=Alignment) \
                                   Var
-  #elif (defined __CC_ARM__)
+  #elif (defined __CC_ARM)
     #define SEGGER_RTT_ALIGN(Var, Alignment) Var __attribute__ ((aligned (Alignment)))
   #else
     #error "Alignment not supported for this compiler."
@@ -186,7 +194,7 @@ Additional information:
   #elif (defined __ICCARM__) || (defined __ICCRX__)
 #define SEGGER_RTT_PUT_SECTION(Var, Section) RTT_PRAGMA(location=Section) \
                                         Var
-  #elif (defined __CC_ARM__)
+  #elif (defined __CC_ARM)
     #define SEGGER_RTT_PUT_SECTION(Var, Section) __attribute__ ((section (Section), zero_init))  Var
   #else
     #error "Section placement not supported for this compiler."
@@ -325,6 +333,9 @@ static unsigned _WriteBlocking(SEGGER_RTT_BUFFER_UP* pRing, const char* pBuffer,
   unsigned NumBytesWritten;
   unsigned RdOff;
   unsigned WrOff;
+#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
+  char*    pDst;
+#endif
   //
   // Write data to buffer and handle wrap-around if necessary
   //
@@ -339,11 +350,21 @@ static unsigned _WriteBlocking(SEGGER_RTT_BUFFER_UP* pRing, const char* pBuffer,
     }
     NumBytesToWrite = MIN(NumBytesToWrite, (pRing->SizeOfBuffer - WrOff));      // Number of bytes that can be written until buffer wrap-around
     NumBytesToWrite = MIN(NumBytesToWrite, NumBytes);
-    memcpy(pRing->pBuffer + WrOff, pBuffer, NumBytesToWrite);
+#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
+    pDst = pRing->pBuffer + WrOff;
+    NumBytesWritten += NumBytesToWrite;
+    NumBytes        -= NumBytesToWrite;
+    WrOff           += NumBytesToWrite;
+    while (NumBytesToWrite--) {
+      *pDst++ = *pBuffer++;
+    };
+#else
+    SEGGER_RTT_MEMCPY(pRing->pBuffer + WrOff, pBuffer, NumBytesToWrite);
     NumBytesWritten += NumBytesToWrite;
     pBuffer         += NumBytesToWrite;
     NumBytes        -= NumBytesToWrite;
     WrOff           += NumBytesToWrite;
+#endif
     if (WrOff == pRing->SizeOfBuffer) {
       WrOff = 0u;
     }
@@ -375,6 +396,9 @@ static void _WriteNoCheck(SEGGER_RTT_BUFFER_UP* pRing, const char* pData, unsign
   unsigned NumBytesAtOnce;
   unsigned WrOff;
   unsigned Rem;
+#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
+  char*    pDst;
+#endif
 
   WrOff = pRing->WrOff;
   Rem = pRing->SizeOfBuffer - WrOff;
@@ -382,17 +406,40 @@ static void _WriteNoCheck(SEGGER_RTT_BUFFER_UP* pRing, const char* pData, unsign
     //
     // All data fits before wrap around
     //
-    memcpy(pRing->pBuffer + WrOff, pData, NumBytes);
+#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
+    pDst = pRing->pBuffer + WrOff;
+    WrOff += NumBytes;
+    while (NumBytes--) {
+      *pDst++ = *pData++;
+    };
+    pRing->WrOff = WrOff;
+#else
+    SEGGER_RTT_MEMCPY(pRing->pBuffer + WrOff, pData, NumBytes);
     pRing->WrOff = WrOff + NumBytes;
+#endif
   } else {
     //
     // We reach the end of the buffer, so need to wrap around
     //
+#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
+    pDst = pRing->pBuffer + WrOff;
+    NumBytesAtOnce = Rem;
+    while (NumBytesAtOnce--) {
+      *pDst++ = *pData++;
+    };
+    pDst = pRing->pBuffer;
+    NumBytesAtOnce = NumBytes - Rem;
+    while (NumBytesAtOnce--) {
+      *pDst++ = *pData++;
+    };
+    pRing->WrOff = NumBytes - Rem;
+#else
     NumBytesAtOnce = Rem;
-    memcpy(pRing->pBuffer + WrOff, pData, NumBytesAtOnce);
+    SEGGER_RTT_MEMCPY(pRing->pBuffer + WrOff, pData, NumBytesAtOnce);
     NumBytesAtOnce = NumBytes - Rem;
-    memcpy(pRing->pBuffer, pData + Rem, NumBytesAtOnce);
+    SEGGER_RTT_MEMCPY(pRing->pBuffer, pData + Rem, NumBytesAtOnce);
     pRing->WrOff = NumBytesAtOnce;
+#endif
   }
 }
 
@@ -410,11 +457,11 @@ static void _WriteNoCheck(SEGGER_RTT_BUFFER_UP* pRing, const char* pData, unsign
 *    TerminalId   Terminal ID to switch to.
 */
 static void _PostTerminalSwitch(SEGGER_RTT_BUFFER_UP* pRing, unsigned char TerminalId) {
-  char ac[2];
+  unsigned char ac[2];
 
   ac[0] = 0xFFu;
   ac[1] = _aTerminalId[TerminalId];  // Caller made already sure that TerminalId does not exceed our terminal limit
-  _WriteBlocking(pRing, ac, 2u);
+  _WriteBlocking(pRing, (const char*)ac, 2u);
 }
 
 /*********************************************************************
@@ -479,6 +526,9 @@ unsigned SEGGER_RTT_ReadNoLock(unsigned BufferIndex, void* pData, unsigned Buffe
   unsigned                WrOff;
   unsigned char*          pBuffer;
   SEGGER_RTT_BUFFER_DOWN* pRing;
+#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
+  const char*             pSrc;
+#endif
   //
   INIT();
   pRing = &_SEGGER_RTT.aDown[BufferIndex];
@@ -492,11 +542,21 @@ unsigned SEGGER_RTT_ReadNoLock(unsigned BufferIndex, void* pData, unsigned Buffe
   if (RdOff > WrOff) {
     NumBytesRem = pRing->SizeOfBuffer - RdOff;
     NumBytesRem = MIN(NumBytesRem, BufferSize);
-    memcpy(pBuffer, pRing->pBuffer + RdOff, NumBytesRem);
+#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
+    pSrc = pRing->pBuffer + RdOff;
+    NumBytesRead += NumBytesRem;
+    BufferSize   -= NumBytesRem;
+    RdOff        += NumBytesRem;
+    while (NumBytesRem--) {
+      *pBuffer++ = *pSrc++;
+    };
+#else
+    SEGGER_RTT_MEMCPY(pBuffer, pRing->pBuffer + RdOff, NumBytesRem);
     NumBytesRead += NumBytesRem;
     pBuffer      += NumBytesRem;
     BufferSize   -= NumBytesRem;
     RdOff        += NumBytesRem;
+#endif
     //
     // Handle wrap-around of buffer
     //
@@ -510,11 +570,21 @@ unsigned SEGGER_RTT_ReadNoLock(unsigned BufferIndex, void* pData, unsigned Buffe
   NumBytesRem = WrOff - RdOff;
   NumBytesRem = MIN(NumBytesRem, BufferSize);
   if (NumBytesRem > 0u) {
-    memcpy(pBuffer, pRing->pBuffer + RdOff, NumBytesRem);
+#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
+    pSrc = pRing->pBuffer + RdOff;
+    NumBytesRead += NumBytesRem;
+    BufferSize   -= NumBytesRem;
+    RdOff        += NumBytesRem;
+    while (NumBytesRem--) {
+      *pBuffer++ = *pSrc++;
+    };
+#else
+    SEGGER_RTT_MEMCPY(pBuffer, pRing->pBuffer + RdOff, NumBytesRem);
     NumBytesRead += NumBytesRem;
     pBuffer      += NumBytesRem;
     BufferSize   -= NumBytesRem;
     RdOff        += NumBytesRem;
+#endif
   }
   if (NumBytesRead) {
     pRing->RdOff = RdOff;
@@ -582,6 +652,9 @@ void SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuff
   const char*           pData;
   SEGGER_RTT_BUFFER_UP* pRing;
   unsigned              Avail;
+#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
+  char*                 pDst;
+#endif
 
   pData = (const char *)pBuffer;
   //
@@ -613,26 +686,35 @@ void SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuff
       //
       // Last round
       //
-#if 1 // memcpy() is good for large amounts of data, but the overhead is too big for small amounts. Use a simple byte loop instead.
-      char* pDst;
+#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
       pDst = pRing->pBuffer + pRing->WrOff;
-      pRing->WrOff += NumBytes;
-      do {
+      Avail = NumBytes;
+      while (NumBytes--) {
         *pDst++ = *pData++;
-      } while (--NumBytes);
+      };
+      pRing->WrOff += Avail;
 #else
-      memcpy(pRing->pBuffer + WrOff, pData, NumBytes);
+      SEGGER_RTT_MEMCPY(pRing->pBuffer + pRing->WrOff, pData, NumBytes);
       pRing->WrOff += NumBytes;
 #endif
-      break;  //Alternatively: NumBytes = 0;
+      break;
     } else {
       //
       //  Wrap-around necessary, write until wrap-around and reset WrOff
       //
-      memcpy(pRing->pBuffer + pRing->WrOff, pData, Avail);
+#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
+      pDst = pRing->pBuffer + pRing->WrOff;
+      NumBytes -= Avail;
+      while (Avail--) {
+        *pDst++ = *pData++;
+      };
+      pRing->WrOff = 0;
+#else
+      SEGGER_RTT_MEMCPY(pRing->pBuffer + pRing->WrOff, pData, Avail);
       pData += Avail;
       pRing->WrOff = 0;
       NumBytes -= Avail;
+#endif
       Avail = (pRing->SizeOfBuffer - 1);
     }
   } while (NumBytes);
@@ -669,6 +751,9 @@ unsigned SEGGER_RTT_WriteSkipNoLock(unsigned BufferIndex, const void* pBuffer, u
   unsigned              RdOff;
   unsigned              WrOff;
   unsigned              Rem;
+#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
+  char*                 pDst;
+#endif
 
   pData = (const char *)pBuffer;
   //
@@ -696,16 +781,15 @@ unsigned SEGGER_RTT_WriteSkipNoLock(unsigned BufferIndex, const void* pBuffer, u
     //
     Avail = pRing->SizeOfBuffer - 1u - WrOff ;
     if (Avail >= NumBytes) {
-#if 1 // memcpy() is good for large amounts of data, but the overhead is too big for small amounts. Use a simple byte loop instead.
-      char* pDst;
+#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
       pDst = pRing->pBuffer + WrOff;
       WrOff += NumBytes;
-      do {
+      while (NumBytes--) {
         *pDst++ = *pData++;
-      } while (--NumBytes);
-      pRing->WrOff = WrOff + NumBytes;
+      };
+      pRing->WrOff = WrOff;
 #else
-      memcpy(pRing->pBuffer + WrOff, pData, NumBytes);
+      SEGGER_RTT_MEMCPY(pRing->pBuffer + WrOff, pData, NumBytes);
       pRing->WrOff = WrOff + NumBytes;
 #endif
       return 1;
@@ -723,23 +807,55 @@ unsigned SEGGER_RTT_WriteSkipNoLock(unsigned BufferIndex, const void* pBuffer, u
       //
       Rem = pRing->SizeOfBuffer - WrOff;      // Space until end of buffer
       if (Rem > NumBytes) {
-        memcpy(pRing->pBuffer + WrOff, pData, NumBytes);
+#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
+        pDst = pRing->pBuffer + WrOff;
+        WrOff += NumBytes;
+        while (NumBytes--) {
+          *pDst++ = *pData++;
+        };
+        pRing->WrOff = WrOff;
+#else
+        SEGGER_RTT_MEMCPY(pRing->pBuffer + WrOff, pData, NumBytes);
         pRing->WrOff = WrOff + NumBytes;
+#endif
       } else {
         //
         // We reach the end of the buffer, so need to wrap around
         //
-        memcpy(pRing->pBuffer + WrOff, pData, Rem);
-        memcpy(pRing->pBuffer, pData + Rem, NumBytes - Rem);
+#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
+        pDst = pRing->pBuffer + WrOff;
+        NumBytes -= Rem;
+        WrOff = NumBytes;
+        do {
+          *pDst++ = *pData++;
+        } while (--Rem);
+        pDst = pRing->pBuffer;
+        while (NumBytes--) {
+          *pDst++ = *pData++;
+        };
+        pRing->WrOff = WrOff;
+#else
+        SEGGER_RTT_MEMCPY(pRing->pBuffer + WrOff, pData, Rem);
+        SEGGER_RTT_MEMCPY(pRing->pBuffer, pData + Rem, NumBytes - Rem);
         pRing->WrOff = NumBytes - Rem;
+#endif
       }
       return 1;
     }
   } else {
     Avail = RdOff - WrOff - 1u;
     if (Avail >= NumBytes) {
-      memcpy(pRing->pBuffer + WrOff, pData, NumBytes);
+#if SEGGER_RTT_MEMCPY_USE_BYTELOOP
+      pDst = pRing->pBuffer + WrOff;
+      WrOff += NumBytes;
+      while (NumBytes--) {
+        *pDst++ = *pData++;
+      };
+      pRing->WrOff = WrOff;
+#else
+      SEGGER_RTT_MEMCPY(pRing->pBuffer + WrOff, pData, NumBytes);
       pRing->WrOff = WrOff + NumBytes;
+#endif
       return 1;
     }
   }
@@ -767,7 +883,7 @@ unsigned SEGGER_RTT_WriteSkipNoLock(unsigned BufferIndex, const void* pBuffer, u
 *    Number of bytes which have been stored in the "Up"-buffer.
 *
 *  Notes
-*    (1) If there is not enough space in the "Up"-buffer, remaining characters of pBuffer are dropped.
+*    (1) Data is stored according to buffer flags.
 *    (2) For performance reasons this function does not call Init()
 *        and may only be called after RTT has been initialized.
 *        Either by calling SEGGER_RTT_Init() or calling another RTT API function first.
@@ -841,7 +957,7 @@ unsigned SEGGER_RTT_WriteNoLock(unsigned BufferIndex, const void* pBuffer, unsig
 *    Number of bytes which have been stored in the "Up"-buffer.
 *
 *  Notes
-*    (1) If there is not enough space in the "Up"-buffer, remaining characters of pBuffer are dropped.
+*    (1) Data is stored according to buffer flags.
 */
 unsigned SEGGER_RTT_Write(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes) {
   unsigned Status;
@@ -876,8 +992,7 @@ unsigned SEGGER_RTT_Write(unsigned BufferIndex, const void* pBuffer, unsigned Nu
 *    Number of bytes which have been stored in the "Up"-buffer.
 *
 *  Notes
-*    (1) If there is not enough space in the "Up"-buffer, depending on configuration,
-*        remaining characters may be dropped or RTT module waits until there is more space in the buffer.
+*    (1) Data is stored according to buffer flags.
 *    (2) String passed to this function has to be \0 terminated
 *    (3) \0 termination character is *not* stored in RTT buffer
 */
@@ -888,6 +1003,178 @@ unsigned SEGGER_RTT_WriteString(unsigned BufferIndex, const char* s) {
   return SEGGER_RTT_Write(BufferIndex, s, Len);
 }
 
+/*********************************************************************
+*
+*       SEGGER_RTT_PutCharSkipNoLock
+*
+*  Function description
+*    Stores a single character/byte in SEGGER RTT buffer.
+*    SEGGER_RTT_PutCharSkipNoLock does not lock the application and
+*    skips the byte, if it does not fit into the buffer.
+*
+*  Parameters
+*    BufferIndex  Index of "Up"-buffer to be used (e.g. 0 for "Terminal").
+*    c            Byte to be stored.
+*
+*  Return value
+*    Number of bytes which have been stored in the "Up"-buffer.
+*
+*  Notes
+*    (1) If there is not enough space in the "Up"-buffer, the character is dropped.
+*    (2) For performance reasons this function does not call Init()
+*        and may only be called after RTT has been initialized.
+*        Either by calling SEGGER_RTT_Init() or calling another RTT API function first.
+*/
+
+unsigned SEGGER_RTT_PutCharSkipNoLock(unsigned BufferIndex, char c) {
+  SEGGER_RTT_BUFFER_UP* pRing;
+  unsigned              WrOff;
+  unsigned              Status;
+  //
+  // Get "to-host" ring buffer.
+  //
+  pRing = &_SEGGER_RTT.aUp[BufferIndex];
+  //
+  // Get write position and handle wrap-around if necessary
+  //
+  WrOff = pRing->WrOff + 1;
+  if (WrOff == pRing->SizeOfBuffer) {
+    WrOff = 0;
+  }
+  //
+  // Output byte if free space is available
+  //
+  if (WrOff != pRing->RdOff) {
+    pRing->pBuffer[pRing->WrOff] = c;
+    pRing->WrOff = WrOff;
+    Status = 1;
+  } else {
+    Status = 0;
+  }
+  //
+  return Status;
+}
+
+/*********************************************************************
+*
+*       SEGGER_RTT_PutCharSkip
+*
+*  Function description
+*    Stores a single character/byte in SEGGER RTT buffer.
+*
+*  Parameters
+*    BufferIndex  Index of "Up"-buffer to be used (e.g. 0 for "Terminal").
+*    c            Byte to be stored.
+*
+*  Return value
+*    Number of bytes which have been stored in the "Up"-buffer.
+*
+*  Notes
+*    (1) If there is not enough space in the "Up"-buffer, the character is dropped.
+*/
+
+unsigned SEGGER_RTT_PutCharSkip(unsigned BufferIndex, char c) {
+  SEGGER_RTT_BUFFER_UP* pRing;
+  unsigned              WrOff;
+  unsigned              Status;
+  //
+  // Prepare
+  //
+  INIT();
+  SEGGER_RTT_LOCK();
+  //
+  // Get "to-host" ring buffer.
+  //
+  pRing = &_SEGGER_RTT.aUp[BufferIndex];
+  //
+  // Get write position and handle wrap-around if necessary
+  //
+  WrOff = pRing->WrOff + 1;
+  if (WrOff == pRing->SizeOfBuffer) {
+    WrOff = 0;
+  }
+  //
+  // Output byte if free space is available
+  //
+  if (WrOff != pRing->RdOff) {
+    pRing->pBuffer[pRing->WrOff] = c;
+    pRing->WrOff = WrOff;
+    Status = 1;
+  } else {
+    Status = 0;
+  }
+  //
+  // Finish up.
+  //
+  SEGGER_RTT_UNLOCK();
+  //
+  return Status;
+}
+
+ /*********************************************************************
+*
+*       SEGGER_RTT_PutChar
+*
+*  Function description
+*    Stores a single character/byte in SEGGER RTT buffer.
+*
+*  Parameters
+*    BufferIndex  Index of "Up"-buffer to be used (e.g. 0 for "Terminal").
+*    c            Byte to be stored.
+*
+*  Return value
+*    Number of bytes which have been stored in the "Up"-buffer.
+*
+*  Notes
+*    (1) Data is stored according to buffer flags.
+*/
+
+unsigned SEGGER_RTT_PutChar(unsigned BufferIndex, char c) {
+  SEGGER_RTT_BUFFER_UP* pRing;
+  unsigned              WrOff;
+  unsigned              Status;
+  //
+  // Prepare
+  //
+  INIT();
+  SEGGER_RTT_LOCK();
+  //
+  // Get "to-host" ring buffer.
+  //
+  pRing = &_SEGGER_RTT.aUp[BufferIndex];
+  //
+  // Get write position and handle wrap-around if necessary
+  //
+  WrOff = pRing->WrOff + 1;
+  if (WrOff == pRing->SizeOfBuffer) {
+    WrOff = 0;
+  }
+  //
+  // Wait for free space if mode is set to blocking
+  //
+  if (pRing->Flags == SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL) {
+    while (WrOff == pRing->RdOff) {
+      ;
+    }
+  }
+  //
+  // Output byte if free space is available
+  //
+  if (WrOff != pRing->RdOff) {
+    pRing->pBuffer[pRing->WrOff] = c;
+    pRing->WrOff = WrOff;
+    Status = 1;
+  } else {
+    Status = 0;
+  }
+  //
+  // Finish up.
+  //
+  SEGGER_RTT_UNLOCK();
+  //
+  return Status;
+}
+
 /*********************************************************************
 *
 *       SEGGER_RTT_GetKey
@@ -989,6 +1276,27 @@ unsigned SEGGER_RTT_HasData(unsigned BufferIndex) {
   return v - pRing->RdOff;
 }
 
+/*********************************************************************
+*
+*       SEGGER_RTT_HasDataUp
+*
+*  Function description
+*    Check if there is data remaining to be sent in the given buffer.
+*
+*  Return value:
+*  ==0:  No data
+*  !=0:  Data in buffer
+*
+*/
+unsigned SEGGER_RTT_HasDataUp(unsigned BufferIndex) {
+  SEGGER_RTT_BUFFER_UP* pRing;
+  unsigned                v;
+
+  pRing = &_SEGGER_RTT.aUp[BufferIndex];
+  v = pRing->RdOff;
+  return pRing->WrOff - v;
+}
+
 /*********************************************************************
 *
 *       SEGGER_RTT_AllocDownBuffer
@@ -1325,7 +1633,7 @@ void SEGGER_RTT_Init (void) {
 *     < 0  Error (e.g. if RTT is configured for non-blocking mode and there was no space in the buffer to set the new terminal Id)
 */
 int SEGGER_RTT_SetTerminal (char TerminalId) {
-  char                  ac[2];
+  unsigned char         ac[2];
   SEGGER_RTT_BUFFER_UP* pRing;
   unsigned Avail;
   int r;
@@ -1333,19 +1641,19 @@ int SEGGER_RTT_SetTerminal (char TerminalId) {
   INIT();
   //
   r = 0;
-  ac[0] = 0xFFU;
+  ac[0] = 0xFFu;
   if ((unsigned char)TerminalId < (unsigned char)sizeof(_aTerminalId)) { // We only support a certain number of channels
     ac[1] = _aTerminalId[(unsigned char)TerminalId];
     pRing = &_SEGGER_RTT.aUp[0];    // Buffer 0 is always reserved for terminal I/O, so we can use index 0 here, fixed
     SEGGER_RTT_LOCK();    // Lock to make sure that no other task is writing into buffer, while we are and number of free bytes in buffer does not change downwards after checking and before writing
     if ((pRing->Flags & SEGGER_RTT_MODE_MASK) == SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL) {
       _ActiveTerminal = TerminalId;
-      _WriteBlocking(pRing, ac, 2u);
+      _WriteBlocking(pRing, (const char*)ac, 2u);
     } else {                                                                            // Skipping mode or trim mode? => We cannot trim this command so handling is the same for both modes
       Avail = _GetAvailWriteSpace(pRing);
       if (Avail >= 2) {
         _ActiveTerminal = TerminalId;    // Only change active terminal in case of success
-        _WriteNoCheck(pRing, ac, 2u);
+        _WriteNoCheck(pRing, (const char*)ac, 2u);
       } else {
         r = -1;
       }
@@ -1393,7 +1701,7 @@ int SEGGER_RTT_TerminalOut (char TerminalId, const char* s) {
     // Need to be able to change terminal, write data, change back.
     // Compute the fixed and variable sizes.
     //
-    FragLen = strlen(s);
+    FragLen = STRLEN(s);
     //
     // How we output depends upon the mode...
     //
@@ -1450,12 +1758,4 @@ int SEGGER_RTT_TerminalOut (char TerminalId, const char* s) {
 }
 
 
-void
-rtt_pkg_init(void)
-{
-    /* Ensure this function only gets called by sysinit. */
-    SYSINIT_ASSERT_ACTIVE();
-    SEGGER_RTT_Init();
-}
-
 /*************************** End of file ****************************/
diff --git a/hw/drivers/rtt/src/SEGGER_RTT_printf.c b/hw/drivers/rtt/src/SEGGER_RTT_printf.c
index 995a88398e..861600c54d 100644
--- a/hw/drivers/rtt/src/SEGGER_RTT_printf.c
+++ b/hw/drivers/rtt/src/SEGGER_RTT_printf.c
@@ -1,9 +1,9 @@
 /*********************************************************************
-*               SEGGER MICROCONTROLLER GmbH & Co. KG                 *
+*                    SEGGER Microcontroller GmbH                     *
 *       Solutions for real time microcontroller applications         *
 **********************************************************************
 *                                                                    *
-*       (c) 2014 - 2016  SEGGER Microcontroller GmbH & Co. KG        *
+*            (c) 1995 - 2018 SEGGER Microcontroller GmbH             *
 *                                                                    *
 *       www.segger.com     Support: support@segger.com               *
 *                                                                    *
@@ -31,7 +31,7 @@
 *   disclaimer in the documentation and/or other materials provided  *
 *   with the distribution.                                           *
 *                                                                    *
-* o Neither the name of SEGGER Microcontroller GmbH & Co. KG         *
+* o Neither the name of SEGGER Microcontroller GmbH         *
 *   nor the names of its contributors may be used to endorse or      *
 *   promote products derived from this software without specific     *
 *   prior written permission.                                        *
@@ -54,7 +54,7 @@
 ---------------------------END-OF-HEADER------------------------------
 File    : SEGGER_RTT_printf.c
 Purpose : Replacement for printf to write formatted data via RTT
-Revision: $Rev: 4351 $
+Revision: $Rev: 9599 $
 ----------------------------------------------------------------------
 */
 #include "rtt/SEGGER_RTT.h"
diff --git a/hw/drivers/rtt/syscfg.yml b/hw/drivers/rtt/syscfg.yml
index 155c700748..08f410a9cb 100644
--- a/hw/drivers/rtt/syscfg.yml
+++ b/hw/drivers/rtt/syscfg.yml
@@ -19,6 +19,38 @@
 # Package: hw/drivers/rtt
 
 syscfg.defs:
+    RTT:
+        description: >
+            Static value indicating that RTT is present in the system.
+            Do not override this value.
+        value: 1
+
+    RTT_NUM_BUFFERS_UP:
+        description: >
+            Number of RTT up-buffers (target -> host) available.
+            Note that buffers required by features included in
+            Mynewt (RTT Console, BLE Monitor and SystemView) are
+            reserved automatically.
+        value: 0
+    RTT_NUM_BUFFERS_DOWN:
+        description: >
+            Number of RTT down-buffers (host -> target) available.
+            Note that buffers required by features included in
+            Mynewt (RTT Console, BLE Monitor and SystemView) are
+            reserved automatically.
+        value: 0
+
+    RTT_TERMINAL_BUFFER_SIZE_UP:
+        description: >
+            Size of terminal output buffer (up-buffer).
+        value: 'MYNEWT_VAL_RTT_BUFFER_SIZE_UP'
+    RTT_TERMINAL_BUFFER_SIZE_DOWN:
+        description: >
+            Size of terminal input buffer (down-buffer).
+        value: 'MYNEWT_VAL_RTT_BUFFER_SIZE_DOWN'
+
+# Values below are deprecated and only used for backwards compatibility.
+# Please use new values instead.
     RTT_BUFFER_SIZE_UP:
         description: 'Size of the output buffer'
         value: 1024
diff --git a/hw/mcu/nordic/nrf51xxx/nrf51.ld b/hw/mcu/nordic/nrf51xxx/nrf51.ld
index 354c193521..19ecfe5f46 100644
--- a/hw/mcu/nordic/nrf51xxx/nrf51.ld
+++ b/hw/mcu/nordic/nrf51xxx/nrf51.ld
@@ -109,6 +109,14 @@ SECTIONS
         . = ALIGN(4);
     } > RAM
 
+    /* This section will be zeroed by RTT package init */
+    .rtt (NOLOAD):
+    {
+        . = ALIGN(4);
+        *(.rtt)
+        . = ALIGN(4);
+    } > RAM
+
     .data :
     {
         __data_start__ = .;
diff --git a/hw/mcu/nordic/nrf52xxx/nrf52.ld b/hw/mcu/nordic/nrf52xxx/nrf52.ld
index 447b5582b7..b9a1ecb538 100644
--- a/hw/mcu/nordic/nrf52xxx/nrf52.ld
+++ b/hw/mcu/nordic/nrf52xxx/nrf52.ld
@@ -108,6 +108,14 @@ SECTIONS
         . = ALIGN(4);
     } > RAM
 
+    /* This section will be zeroed by RTT package init */
+    .rtt (NOLOAD):
+    {
+        . = ALIGN(4);
+        *(.rtt)
+        . = ALIGN(4);
+    } > RAM
+
     .data :
     {
         __data_start__ = .;
diff --git a/kernel/os/src/os.c b/kernel/os/src/os.c
index 423d5ad675..0896474f4e 100644
--- a/kernel/os/src/os.c
+++ b/kernel/os/src/os.c
@@ -26,6 +26,10 @@
 #include "hal/hal_bsp.h"
 #include "hal/hal_watchdog.h"
 
+#if MYNEWT_VAL(RTT)
+#include "rtt/SEGGER_RTT.h"
+#endif
+
 /**
  * @defgroup OSKernel Operating System Kernel
  * @brief This section contains documentation for the core operating system kernel
@@ -167,6 +171,11 @@ os_init(int (*main_fn)(int argc, char **arg))
 {
     os_error_t err;
 
+#if MYNEWT_VAL(RTT)
+    memset(&_SEGGER_RTT, 0, sizeof(_SEGGER_RTT));
+    SEGGER_RTT_Init();
+#endif
+
     TAILQ_INIT(&g_callout_list);
     STAILQ_INIT(&g_os_task_list);
     os_eventq_init(os_eventq_dflt_get());
diff --git a/sys/console/full/src/rtt_console.c b/sys/console/full/src/rtt_console.c
index 9b8a9e89a5..0ff1739fe6 100644
--- a/sys/console/full/src/rtt_console.c
+++ b/sys/console/full/src/rtt_console.c
@@ -55,8 +55,8 @@ console_out(int character)
 #define RTT_INPUT_POLL_INTERVAL_STEP    10 /* ms */
 #define RTT_INPUT_POLL_INTERVAL_MAX     MYNEWT_VAL(CONSOLE_RTT_INPUT_POLL_INTERVAL_MAX)
 
-void
-rtt(void *arg)
+static void
+rtt_console_poll_func(void *arg)
 {
     static uint32_t itvl_ms = RTT_INPUT_POLL_INTERVAL_MIN;
     int key;
@@ -87,7 +87,7 @@ int
 rtt_console_init(void)
 {
 #if MYNEWT_VAL(CONSOLE_INPUT)
-    os_cputime_timer_init(&rtt_timer, rtt, NULL);
+    os_cputime_timer_init(&rtt_timer, rtt_console_poll_func, NULL);
     /* start after a second */
     os_cputime_timer_relative(&rtt_timer, 1000000);
 #endif


 

----------------------------------------------------------------
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