Seger Real time terminal, use RTT viewer to view messages through the segger debugger instead of art

Fork of SEGGER_RTT by Glimworm Beacons

Committer:
GlimwormBeacons
Date:
Sun Oct 09 09:45:11 2016 +0000
Revision:
0:a7800e894aaf
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GlimwormBeacons 0:a7800e894aaf 1 /*********************************************************************
GlimwormBeacons 0:a7800e894aaf 2 * SEGGER MICROCONTROLLER GmbH & Co. KG *
GlimwormBeacons 0:a7800e894aaf 3 * Solutions for real time microcontroller applications *
GlimwormBeacons 0:a7800e894aaf 4 **********************************************************************
GlimwormBeacons 0:a7800e894aaf 5 * *
GlimwormBeacons 0:a7800e894aaf 6 * (c) 2014 - 2016 SEGGER Microcontroller GmbH & Co. KG *
GlimwormBeacons 0:a7800e894aaf 7 * *
GlimwormBeacons 0:a7800e894aaf 8 * www.segger.com Support: support@segger.com *
GlimwormBeacons 0:a7800e894aaf 9 * *
GlimwormBeacons 0:a7800e894aaf 10 **********************************************************************
GlimwormBeacons 0:a7800e894aaf 11 * *
GlimwormBeacons 0:a7800e894aaf 12 * SEGGER RTT * Real Time Transfer for embedded targets *
GlimwormBeacons 0:a7800e894aaf 13 * *
GlimwormBeacons 0:a7800e894aaf 14 **********************************************************************
GlimwormBeacons 0:a7800e894aaf 15 * *
GlimwormBeacons 0:a7800e894aaf 16 * All rights reserved. *
GlimwormBeacons 0:a7800e894aaf 17 * *
GlimwormBeacons 0:a7800e894aaf 18 * * This software may in its unmodified form be freely redistributed *
GlimwormBeacons 0:a7800e894aaf 19 * in source form. *
GlimwormBeacons 0:a7800e894aaf 20 * * The source code may be modified, provided the source code *
GlimwormBeacons 0:a7800e894aaf 21 * retains the above copyright notice, this list of conditions and *
GlimwormBeacons 0:a7800e894aaf 22 * the following disclaimer. *
GlimwormBeacons 0:a7800e894aaf 23 * * Modified versions of this software in source or linkable form *
GlimwormBeacons 0:a7800e894aaf 24 * may not be distributed without prior consent of SEGGER. *
GlimwormBeacons 0:a7800e894aaf 25 * * This software may only be used for communication with SEGGER *
GlimwormBeacons 0:a7800e894aaf 26 * J-Link debug probes. *
GlimwormBeacons 0:a7800e894aaf 27 * *
GlimwormBeacons 0:a7800e894aaf 28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
GlimwormBeacons 0:a7800e894aaf 29 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
GlimwormBeacons 0:a7800e894aaf 30 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
GlimwormBeacons 0:a7800e894aaf 31 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
GlimwormBeacons 0:a7800e894aaf 32 * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
GlimwormBeacons 0:a7800e894aaf 33 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
GlimwormBeacons 0:a7800e894aaf 34 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
GlimwormBeacons 0:a7800e894aaf 35 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
GlimwormBeacons 0:a7800e894aaf 36 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
GlimwormBeacons 0:a7800e894aaf 37 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
GlimwormBeacons 0:a7800e894aaf 38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
GlimwormBeacons 0:a7800e894aaf 39 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
GlimwormBeacons 0:a7800e894aaf 40 * DAMAGE. *
GlimwormBeacons 0:a7800e894aaf 41 * *
GlimwormBeacons 0:a7800e894aaf 42 **********************************************************************
GlimwormBeacons 0:a7800e894aaf 43 * *
GlimwormBeacons 0:a7800e894aaf 44 * RTT version: 5.12g *
GlimwormBeacons 0:a7800e894aaf 45 * *
GlimwormBeacons 0:a7800e894aaf 46 **********************************************************************
GlimwormBeacons 0:a7800e894aaf 47 ----------------------------------------------------------------------
GlimwormBeacons 0:a7800e894aaf 48 File : SEGGER_RTT_Conf.h
GlimwormBeacons 0:a7800e894aaf 49 Purpose : Implementation of SEGGER real-time transfer (RTT) which
GlimwormBeacons 0:a7800e894aaf 50 allows real-time communication on targets which support
GlimwormBeacons 0:a7800e894aaf 51 debugger memory accesses while the CPU is running.
GlimwormBeacons 0:a7800e894aaf 52 ---------------------------END-OF-HEADER------------------------------
GlimwormBeacons 0:a7800e894aaf 53 */
GlimwormBeacons 0:a7800e894aaf 54
GlimwormBeacons 0:a7800e894aaf 55 #ifndef SEGGER_RTT_CONF_H
GlimwormBeacons 0:a7800e894aaf 56 #define SEGGER_RTT_CONF_H
GlimwormBeacons 0:a7800e894aaf 57
GlimwormBeacons 0:a7800e894aaf 58 #ifdef __ICCARM__
GlimwormBeacons 0:a7800e894aaf 59 #include <intrinsics.h>
GlimwormBeacons 0:a7800e894aaf 60 #endif
GlimwormBeacons 0:a7800e894aaf 61
GlimwormBeacons 0:a7800e894aaf 62 /*********************************************************************
GlimwormBeacons 0:a7800e894aaf 63 *
GlimwormBeacons 0:a7800e894aaf 64 * Defines, configurable
GlimwormBeacons 0:a7800e894aaf 65 *
GlimwormBeacons 0:a7800e894aaf 66 **********************************************************************
GlimwormBeacons 0:a7800e894aaf 67 */
GlimwormBeacons 0:a7800e894aaf 68
GlimwormBeacons 0:a7800e894aaf 69 #define SEGGER_RTT_MAX_NUM_UP_BUFFERS (2) // Max. number of up-buffers (T->H) available on this target (Default: 2)
GlimwormBeacons 0:a7800e894aaf 70 #define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (2) // Max. number of down-buffers (H->T) available on this target (Default: 2)
GlimwormBeacons 0:a7800e894aaf 71
GlimwormBeacons 0:a7800e894aaf 72 #define BUFFER_SIZE_UP (1024) // Size of the buffer for terminal output of target, up to host (Default: 1k)
GlimwormBeacons 0:a7800e894aaf 73 #define BUFFER_SIZE_DOWN (16) // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16)
GlimwormBeacons 0:a7800e894aaf 74
GlimwormBeacons 0:a7800e894aaf 75 #define SEGGER_RTT_PRINTF_BUFFER_SIZE (64u) // Size of buffer for RTT printf to bulk-send chars via RTT (Default: 64)
GlimwormBeacons 0:a7800e894aaf 76
GlimwormBeacons 0:a7800e894aaf 77 #define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_NO_BLOCK_SKIP // Mode for pre-initialized terminal channel (buffer 0)
GlimwormBeacons 0:a7800e894aaf 78
GlimwormBeacons 0:a7800e894aaf 79 //
GlimwormBeacons 0:a7800e894aaf 80 // Target is not allowed to perform other RTT operations while string still has not been stored completely.
GlimwormBeacons 0:a7800e894aaf 81 // Otherwise we would probably end up with a mixed string in the buffer.
GlimwormBeacons 0:a7800e894aaf 82 // If using RTT from within interrupts, multiple tasks or multi processors, define the SEGGER_RTT_LOCK() and SEGGER_RTT_UNLOCK() function here.
GlimwormBeacons 0:a7800e894aaf 83 //
GlimwormBeacons 0:a7800e894aaf 84 // SEGGER_RTT_MAX_INTERRUPT_PRIORITY can be used in the sample lock routines on Cortex-M3/4.
GlimwormBeacons 0:a7800e894aaf 85 // Make sure to mask all interrupts which can send RTT data, i.e. generate SystemView events, or cause task switches.
GlimwormBeacons 0:a7800e894aaf 86 // When high-priority interrupts must not be masked while sending RTT data, SEGGER_RTT_MAX_INTERRUPT_PRIORITY needs to be adjusted accordingly.
GlimwormBeacons 0:a7800e894aaf 87 // (Higher priority = lower priority number)
GlimwormBeacons 0:a7800e894aaf 88 // Default value for embOS: 128u
GlimwormBeacons 0:a7800e894aaf 89 // Default configuration in FreeRTOS: configMAX_SYSCALL_INTERRUPT_PRIORITY: ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
GlimwormBeacons 0:a7800e894aaf 90 // In case of doubt mask all interrupts: 0u
GlimwormBeacons 0:a7800e894aaf 91 //
GlimwormBeacons 0:a7800e894aaf 92
GlimwormBeacons 0:a7800e894aaf 93 #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) // Interrupt priority to lock on SEGGER_RTT_LOCK on Cortex-M3/4 (Default: 0x20)
GlimwormBeacons 0:a7800e894aaf 94
GlimwormBeacons 0:a7800e894aaf 95 /*********************************************************************
GlimwormBeacons 0:a7800e894aaf 96 *
GlimwormBeacons 0:a7800e894aaf 97 * RTT lock configuration for SEGGER Embedded Studio,
GlimwormBeacons 0:a7800e894aaf 98 * Rowley CrossStudio and GCC
GlimwormBeacons 0:a7800e894aaf 99 */
GlimwormBeacons 0:a7800e894aaf 100 #if (defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__)
GlimwormBeacons 0:a7800e894aaf 101 #ifdef __ARM_ARCH_6M__
GlimwormBeacons 0:a7800e894aaf 102 #define SEGGER_RTT_LOCK() { \
GlimwormBeacons 0:a7800e894aaf 103 unsigned int LockState; \
GlimwormBeacons 0:a7800e894aaf 104 __asm volatile ("mrs %0, primask \n\t" \
GlimwormBeacons 0:a7800e894aaf 105 "mov r1, $1 \n\t" \
GlimwormBeacons 0:a7800e894aaf 106 "msr primask, r1 \n\t" \
GlimwormBeacons 0:a7800e894aaf 107 : "=r" (LockState) \
GlimwormBeacons 0:a7800e894aaf 108 : \
GlimwormBeacons 0:a7800e894aaf 109 : "r1" \
GlimwormBeacons 0:a7800e894aaf 110 );
GlimwormBeacons 0:a7800e894aaf 111
GlimwormBeacons 0:a7800e894aaf 112 #define SEGGER_RTT_UNLOCK() __asm volatile ("msr primask, %0 \n\t" \
GlimwormBeacons 0:a7800e894aaf 113 : \
GlimwormBeacons 0:a7800e894aaf 114 : "r" (LockState) \
GlimwormBeacons 0:a7800e894aaf 115 : \
GlimwormBeacons 0:a7800e894aaf 116 ); \
GlimwormBeacons 0:a7800e894aaf 117 }
GlimwormBeacons 0:a7800e894aaf 118
GlimwormBeacons 0:a7800e894aaf 119 #elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__))
GlimwormBeacons 0:a7800e894aaf 120 #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
GlimwormBeacons 0:a7800e894aaf 121 #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
GlimwormBeacons 0:a7800e894aaf 122 #endif
GlimwormBeacons 0:a7800e894aaf 123 #define SEGGER_RTT_LOCK() { \
GlimwormBeacons 0:a7800e894aaf 124 unsigned int LockState; \
GlimwormBeacons 0:a7800e894aaf 125 __asm volatile ("mrs %0, basepri \n\t" \
GlimwormBeacons 0:a7800e894aaf 126 "mov r1, %1 \n\t" \
GlimwormBeacons 0:a7800e894aaf 127 "msr basepri, r1 \n\t" \
GlimwormBeacons 0:a7800e894aaf 128 : "=r" (LockState) \
GlimwormBeacons 0:a7800e894aaf 129 : "i"(SEGGER_RTT_MAX_INTERRUPT_PRIORITY) \
GlimwormBeacons 0:a7800e894aaf 130 : "r1" \
GlimwormBeacons 0:a7800e894aaf 131 );
GlimwormBeacons 0:a7800e894aaf 132
GlimwormBeacons 0:a7800e894aaf 133 #define SEGGER_RTT_UNLOCK() __asm volatile ("msr basepri, %0 \n\t" \
GlimwormBeacons 0:a7800e894aaf 134 : \
GlimwormBeacons 0:a7800e894aaf 135 : "r" (LockState) \
GlimwormBeacons 0:a7800e894aaf 136 : \
GlimwormBeacons 0:a7800e894aaf 137 ); \
GlimwormBeacons 0:a7800e894aaf 138 }
GlimwormBeacons 0:a7800e894aaf 139
GlimwormBeacons 0:a7800e894aaf 140 #elif defined(__ARM_ARCH_7A__)
GlimwormBeacons 0:a7800e894aaf 141 #define SEGGER_RTT_LOCK() { \
GlimwormBeacons 0:a7800e894aaf 142 unsigned int LockState; \
GlimwormBeacons 0:a7800e894aaf 143 __asm volatile ("mrs r1, CPSR \n\t" \
GlimwormBeacons 0:a7800e894aaf 144 "mov %0, r1 \n\t" \
GlimwormBeacons 0:a7800e894aaf 145 "orr r1, r1, #0xC0 \n\t" \
GlimwormBeacons 0:a7800e894aaf 146 "msr CPSR_c, r1 \n\t" \
GlimwormBeacons 0:a7800e894aaf 147 : "=r" (LockState) \
GlimwormBeacons 0:a7800e894aaf 148 : \
GlimwormBeacons 0:a7800e894aaf 149 : "r1" \
GlimwormBeacons 0:a7800e894aaf 150 );
GlimwormBeacons 0:a7800e894aaf 151
GlimwormBeacons 0:a7800e894aaf 152 #define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t" \
GlimwormBeacons 0:a7800e894aaf 153 "mrs r1, CPSR \n\t" \
GlimwormBeacons 0:a7800e894aaf 154 "bic r1, r1, #0xC0 \n\t" \
GlimwormBeacons 0:a7800e894aaf 155 "and r0, r0, #0xC0 \n\t" \
GlimwormBeacons 0:a7800e894aaf 156 "orr r1, r1, r0 \n\t" \
GlimwormBeacons 0:a7800e894aaf 157 "msr CPSR_c, r1 \n\t" \
GlimwormBeacons 0:a7800e894aaf 158 : \
GlimwormBeacons 0:a7800e894aaf 159 : "r" (LockState) \
GlimwormBeacons 0:a7800e894aaf 160 : "r0", "r1" \
GlimwormBeacons 0:a7800e894aaf 161 ); \
GlimwormBeacons 0:a7800e894aaf 162 }
GlimwormBeacons 0:a7800e894aaf 163 #else
GlimwormBeacons 0:a7800e894aaf 164 #define SEGGER_RTT_LOCK()
GlimwormBeacons 0:a7800e894aaf 165 #define SEGGER_RTT_UNLOCK()
GlimwormBeacons 0:a7800e894aaf 166 #endif
GlimwormBeacons 0:a7800e894aaf 167 #endif
GlimwormBeacons 0:a7800e894aaf 168
GlimwormBeacons 0:a7800e894aaf 169 /*********************************************************************
GlimwormBeacons 0:a7800e894aaf 170 *
GlimwormBeacons 0:a7800e894aaf 171 * RTT lock configuration for IAR EWARM
GlimwormBeacons 0:a7800e894aaf 172 */
GlimwormBeacons 0:a7800e894aaf 173 #ifdef __ICCARM__
GlimwormBeacons 0:a7800e894aaf 174 #if (defined (__ARM6M__) && (__CORE__ == __ARM6M__))
GlimwormBeacons 0:a7800e894aaf 175 #define SEGGER_RTT_LOCK() { \
GlimwormBeacons 0:a7800e894aaf 176 unsigned int LockState; \
GlimwormBeacons 0:a7800e894aaf 177 LockState = __get_PRIMASK(); \
GlimwormBeacons 0:a7800e894aaf 178 __set_PRIMASK(1);
GlimwormBeacons 0:a7800e894aaf 179
GlimwormBeacons 0:a7800e894aaf 180 #define SEGGER_RTT_UNLOCK() __set_PRIMASK(LockState); \
GlimwormBeacons 0:a7800e894aaf 181 }
GlimwormBeacons 0:a7800e894aaf 182 #elif ((defined (__ARM7EM__) && (__CORE__ == __ARM7EM__)) || (defined (__ARM7M__) && (__CORE__ == __ARM7M__)))
GlimwormBeacons 0:a7800e894aaf 183 #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
GlimwormBeacons 0:a7800e894aaf 184 #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
GlimwormBeacons 0:a7800e894aaf 185 #endif
GlimwormBeacons 0:a7800e894aaf 186 #define SEGGER_RTT_LOCK() { \
GlimwormBeacons 0:a7800e894aaf 187 unsigned int LockState; \
GlimwormBeacons 0:a7800e894aaf 188 LockState = __get_BASEPRI(); \
GlimwormBeacons 0:a7800e894aaf 189 __set_BASEPRI(SEGGER_RTT_MAX_INTERRUPT_PRIORITY);
GlimwormBeacons 0:a7800e894aaf 190
GlimwormBeacons 0:a7800e894aaf 191 #define SEGGER_RTT_UNLOCK() __set_BASEPRI(LockState); \
GlimwormBeacons 0:a7800e894aaf 192 }
GlimwormBeacons 0:a7800e894aaf 193 #endif
GlimwormBeacons 0:a7800e894aaf 194 #endif
GlimwormBeacons 0:a7800e894aaf 195
GlimwormBeacons 0:a7800e894aaf 196 /*********************************************************************
GlimwormBeacons 0:a7800e894aaf 197 *
GlimwormBeacons 0:a7800e894aaf 198 * RTT lock configuration for KEIL ARM
GlimwormBeacons 0:a7800e894aaf 199 */
GlimwormBeacons 0:a7800e894aaf 200 #ifdef __CC_ARM
GlimwormBeacons 0:a7800e894aaf 201 #if (defined __TARGET_ARCH_6S_M)
GlimwormBeacons 0:a7800e894aaf 202 #define SEGGER_RTT_LOCK() { \
GlimwormBeacons 0:a7800e894aaf 203 unsigned int LockState; \
GlimwormBeacons 0:a7800e894aaf 204 register unsigned char PRIMASK __asm( "primask"); \
GlimwormBeacons 0:a7800e894aaf 205 LockState = PRIMASK; \
GlimwormBeacons 0:a7800e894aaf 206 PRIMASK = 1u; \
GlimwormBeacons 0:a7800e894aaf 207 __schedule_barrier();
GlimwormBeacons 0:a7800e894aaf 208
GlimwormBeacons 0:a7800e894aaf 209 #define SEGGER_RTT_UNLOCK() PRIMASK = LockState; \
GlimwormBeacons 0:a7800e894aaf 210 __schedule_barrier(); \
GlimwormBeacons 0:a7800e894aaf 211 }
GlimwormBeacons 0:a7800e894aaf 212 #elif (defined(__TARGET_ARCH_7_M) || defined(__TARGET_ARCH_7E_M))
GlimwormBeacons 0:a7800e894aaf 213 #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
GlimwormBeacons 0:a7800e894aaf 214 #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
GlimwormBeacons 0:a7800e894aaf 215 #endif
GlimwormBeacons 0:a7800e894aaf 216 #define SEGGER_RTT_LOCK() { \
GlimwormBeacons 0:a7800e894aaf 217 unsigned int LockState; \
GlimwormBeacons 0:a7800e894aaf 218 register unsigned char BASEPRI __asm( "basepri"); \
GlimwormBeacons 0:a7800e894aaf 219 LockState = BASEPRI; \
GlimwormBeacons 0:a7800e894aaf 220 BASEPRI = SEGGER_RTT_MAX_INTERRUPT_PRIORITY; \
GlimwormBeacons 0:a7800e894aaf 221 __schedule_barrier();
GlimwormBeacons 0:a7800e894aaf 222
GlimwormBeacons 0:a7800e894aaf 223 #define SEGGER_RTT_UNLOCK() BASEPRI = LockState; \
GlimwormBeacons 0:a7800e894aaf 224 __schedule_barrier(); \
GlimwormBeacons 0:a7800e894aaf 225 }
GlimwormBeacons 0:a7800e894aaf 226 #endif
GlimwormBeacons 0:a7800e894aaf 227 #endif
GlimwormBeacons 0:a7800e894aaf 228
GlimwormBeacons 0:a7800e894aaf 229 /*********************************************************************
GlimwormBeacons 0:a7800e894aaf 230 *
GlimwormBeacons 0:a7800e894aaf 231 * RTT lock configuration fallback
GlimwormBeacons 0:a7800e894aaf 232 */
GlimwormBeacons 0:a7800e894aaf 233 #ifndef SEGGER_RTT_LOCK
GlimwormBeacons 0:a7800e894aaf 234 #define SEGGER_RTT_LOCK() // Lock RTT (nestable) (i.e. disable interrupts)
GlimwormBeacons 0:a7800e894aaf 235 #endif
GlimwormBeacons 0:a7800e894aaf 236
GlimwormBeacons 0:a7800e894aaf 237 #ifndef SEGGER_RTT_UNLOCK
GlimwormBeacons 0:a7800e894aaf 238 #define SEGGER_RTT_UNLOCK() // Unlock RTT (nestable) (i.e. enable previous interrupt lock state)
GlimwormBeacons 0:a7800e894aaf 239 #endif
GlimwormBeacons 0:a7800e894aaf 240
GlimwormBeacons 0:a7800e894aaf 241 #endif
GlimwormBeacons 0:a7800e894aaf 242 /*************************** End of file ****************************/