1 /********************************************************************* 2 * SEGGER Microcontroller GmbH * 3 * The Embedded Experts * 4 ********************************************************************** 5 * * 6 * (c) 1995 - 2018 SEGGER Microcontroller GmbH * 7 * * 8 * www.segger.com Support: support@segger.com * 9 * * 10 ********************************************************************** 11 * * 12 * SEGGER RTT * Real Time Transfer for embedded targets * 13 * * 14 ********************************************************************** 15 * * 16 * All rights reserved. * 17 * * 18 * SEGGER strongly recommends to not make any changes * 19 * to or modify the source code of this software in order to stay * 20 * compatible with the RTT protocol and J-Link. * 21 * * 22 * Redistribution and use in source and binary forms, with or * 23 * without modification, are permitted provided that the following * 24 * conditions are met: * 25 * * 26 * o Redistributions of source code must retain the above copyright * 27 * notice, this list of conditions and the following disclaimer. * 28 * * 29 * o Redistributions in binary form must reproduce the above * 30 * copyright notice, this list of conditions and the following * 31 * disclaimer in the documentation and/or other materials provided * 32 * with the distribution. * 33 * * 34 * o Neither the name of SEGGER Microcontroller GmbH * 35 * nor the names of its contributors may be used to endorse or * 36 * promote products derived from this software without specific * 37 * prior written permission. * 38 * * 39 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * 40 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * 41 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * 42 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * 43 * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * 44 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * 45 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * 46 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * 47 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * 48 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 49 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * 50 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 51 * DAMAGE. * 52 * * 53 ********************************************************************** 54 ---------------------------END-OF-HEADER------------------------------ 55 File : SEGGER_RTT_Conf.h 56 Purpose : Implementation of SEGGER real-time transfer (RTT) which 57 allows real-time communication on targets which support 58 debugger memory accesses while the CPU is running. 59 Revision: $Rev: 12847 $ 60 61 */ 62 63 #ifndef SEGGER_RTT_CONF_H 64 #define SEGGER_RTT_CONF_H 65 66 #ifdef __IAR_SYSTEMS_ICC__ 67 #include <intrinsics.h> 68 #endif 69 70 /********************************************************************* 71 * 72 * Defines, configurable 73 * 74 ********************************************************************** 75 */ 76 77 #define SEGGER_RTT_MAX_NUM_UP_BUFFERS (3) // Max. number of up-buffers (T->H) available on this target (Default: 3) 78 #define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (3) // Max. number of down-buffers (H->T) available on this target (Default: 3) 79 80 #define BUFFER_SIZE_UP (1024) // Size of the buffer for terminal output of target, up to host (Default: 1k) 81 #define BUFFER_SIZE_DOWN (16) // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16) 82 83 #define SEGGER_RTT_PRINTF_BUFFER_SIZE (64u) // Size of buffer for RTT printf to bulk-send chars via RTT (Default: 64) 84 85 #define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_NO_BLOCK_SKIP // Mode for pre-initialized terminal channel (buffer 0) 86 87 #define USE_RTT_ASM (0) // Use assembler version of SEGGER_RTT.c when 1 88 89 /********************************************************************* 90 * 91 * RTT memcpy configuration 92 * 93 * memcpy() is good for large amounts of data, 94 * but the overhead is big for small amounts, which are usually stored via RTT. 95 * With SEGGER_RTT_MEMCPY_USE_BYTELOOP a simple byte loop can be used instead. 96 * 97 * SEGGER_RTT_MEMCPY() can be used to replace standard memcpy() in RTT functions. 98 * This is may be required with memory access restrictions, 99 * such as on Cortex-A devices with MMU. 100 */ 101 #define SEGGER_RTT_MEMCPY_USE_BYTELOOP 0 // 0: Use memcpy/SEGGER_RTT_MEMCPY, 1: Use a simple byte-loop 102 // 103 // Example definition of SEGGER_RTT_MEMCPY to external memcpy with GCC toolchains and Cortex-A targets 104 // 105 //#if ((defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__)) && (defined (__ARM_ARCH_7A__)) 106 // #define SEGGER_RTT_MEMCPY(pDest, pSrc, NumBytes) SEGGER_memcpy((pDest), (pSrc), (NumBytes)) 107 //#endif 108 109 // 110 // Target is not allowed to perform other RTT operations while string still has not been stored completely. 111 // Otherwise we would probably end up with a mixed string in the buffer. 112 // If using RTT from within interrupts, multiple tasks or multi processors, define the SEGGER_RTT_LOCK() and SEGGER_RTT_UNLOCK() function here. 113 // 114 // SEGGER_RTT_MAX_INTERRUPT_PRIORITY can be used in the sample lock routines on Cortex-M3/4. 115 // Make sure to mask all interrupts which can send RTT data, i.e. generate SystemView events, or cause task switches. 116 // When high-priority interrupts must not be masked while sending RTT data, SEGGER_RTT_MAX_INTERRUPT_PRIORITY needs to be adjusted accordingly. 117 // (Higher priority = lower priority number) 118 // Default value for embOS: 128u 119 // Default configuration in FreeRTOS: configMAX_SYSCALL_INTERRUPT_PRIORITY: ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) 120 // In case of doubt mask all interrupts: 1 << (8 - BASEPRI_PRIO_BITS) i.e. 1 << 5 when 3 bits are implemented in NVIC 121 // or define SEGGER_RTT_LOCK() to completely disable interrupts. 122 // 123 124 #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) // Interrupt priority to lock on SEGGER_RTT_LOCK on Cortex-M3/4 (Default: 0x20) 125 126 /********************************************************************* 127 * 128 * RTT lock configuration for SEGGER Embedded Studio, 129 * Rowley CrossStudio and GCC 130 */ 131 #if (defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__) || (defined __clang__) 132 #if (defined(__ARM_ARCH_6M__) || defined(__ARM_ARCH_8M_BASE__)) 133 #define SEGGER_RTT_LOCK() { \ 134 unsigned int LockState; \ 135 __asm volatile ("mrs %0, primask \n\t" \ 136 "movs r1, $1 \n\t" \ 137 "msr primask, r1 \n\t" \ 138 : "=r" (LockState) \ 139 : \ 140 : "r1" \ 141 ); 142 143 #define SEGGER_RTT_UNLOCK() __asm volatile ("msr primask, %0 \n\t" \ 144 : \ 145 : "r" (LockState) \ 146 : \ 147 ); \ 148 } 149 #elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_8M_MAIN__)) 150 #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY 151 #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) 152 #endif 153 #define SEGGER_RTT_LOCK() { \ 154 unsigned int LockState; \ 155 __asm volatile ("mrs %0, basepri \n\t" \ 156 "mov r1, %1 \n\t" \ 157 "msr basepri, r1 \n\t" \ 158 : "=r" (LockState) \ 159 : "i"(SEGGER_RTT_MAX_INTERRUPT_PRIORITY) \ 160 : "r1" \ 161 ); 162 163 #define SEGGER_RTT_UNLOCK() __asm volatile ("msr basepri, %0 \n\t" \ 164 : \ 165 : "r" (LockState) \ 166 : \ 167 ); \ 168 } 169 170 #elif defined(__ARM_ARCH_7A__) 171 #define SEGGER_RTT_LOCK() { \ 172 unsigned int LockState; \ 173 __asm volatile ("mrs r1, CPSR \n\t" \ 174 "mov %0, r1 \n\t" \ 175 "orr r1, r1, #0xC0 \n\t" \ 176 "msr CPSR_c, r1 \n\t" \ 177 : "=r" (LockState) \ 178 : \ 179 : "r1" \ 180 ); 181 182 #define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t" \ 183 "mrs r1, CPSR \n\t" \ 184 "bic r1, r1, #0xC0 \n\t" \ 185 "and r0, r0, #0xC0 \n\t" \ 186 "orr r1, r1, r0 \n\t" \ 187 "msr CPSR_c, r1 \n\t" \ 188 : \ 189 : "r" (LockState) \ 190 : "r0", "r1" \ 191 ); \ 192 } 193 #else 194 #define SEGGER_RTT_LOCK() 195 #define SEGGER_RTT_UNLOCK() 196 #endif 197 #endif 198 199 /********************************************************************* 200 * 201 * RTT lock configuration for IAR EWARM 202 */ 203 #ifdef __ICCARM__ 204 #if (defined (__ARM6M__) && (__CORE__ == __ARM6M__)) 205 #define SEGGER_RTT_LOCK() { \ 206 unsigned int LockState; \ 207 LockState = __get_PRIMASK(); \ 208 __set_PRIMASK(1); 209 210 #define SEGGER_RTT_UNLOCK() __set_PRIMASK(LockState); \ 211 } 212 #elif ((defined (__ARM7EM__) && (__CORE__ == __ARM7EM__)) || (defined (__ARM7M__) && (__CORE__ == __ARM7M__))) 213 #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY 214 #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) 215 #endif 216 #define SEGGER_RTT_LOCK() { \ 217 unsigned int LockState; \ 218 LockState = __get_BASEPRI(); \ 219 __set_BASEPRI(SEGGER_RTT_MAX_INTERRUPT_PRIORITY); 220 221 #define SEGGER_RTT_UNLOCK() __set_BASEPRI(LockState); \ 222 } 223 #endif 224 #endif 225 226 /********************************************************************* 227 * 228 * RTT lock configuration for IAR RX 229 */ 230 #ifdef __ICCRX__ 231 #define SEGGER_RTT_LOCK() { \ 232 unsigned long LockState; \ 233 LockState = __get_interrupt_state(); \ 234 __disable_interrupt(); 235 236 #define SEGGER_RTT_UNLOCK() __set_interrupt_state(LockState); \ 237 } 238 #endif 239 240 /********************************************************************* 241 * 242 * RTT lock configuration for IAR RL78 243 */ 244 #ifdef __ICCRL78__ 245 #define SEGGER_RTT_LOCK() { \ 246 __istate_t LockState; \ 247 LockState = __get_interrupt_state(); \ 248 __disable_interrupt(); 249 250 #define SEGGER_RTT_UNLOCK() __set_interrupt_state(LockState); \ 251 } 252 #endif 253 254 /********************************************************************* 255 * 256 * RTT lock configuration for KEIL ARM 257 */ 258 #ifdef __CC_ARM 259 #if (defined __TARGET_ARCH_6S_M) 260 #define SEGGER_RTT_LOCK() { \ 261 unsigned int LockState; \ 262 register unsigned char PRIMASK __asm( "primask"); \ 263 LockState = PRIMASK; \ 264 PRIMASK = 1u; \ 265 __schedule_barrier(); 266 267 #define SEGGER_RTT_UNLOCK() PRIMASK = LockState; \ 268 __schedule_barrier(); \ 269 } 270 #elif (defined(__TARGET_ARCH_7_M) || defined(__TARGET_ARCH_7E_M)) 271 #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY 272 #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) 273 #endif 274 #define SEGGER_RTT_LOCK() { \ 275 unsigned int LockState; \ 276 register unsigned char BASEPRI __asm( "basepri"); \ 277 LockState = BASEPRI; \ 278 BASEPRI = SEGGER_RTT_MAX_INTERRUPT_PRIORITY; \ 279 __schedule_barrier(); 280 281 #define SEGGER_RTT_UNLOCK() BASEPRI = LockState; \ 282 __schedule_barrier(); \ 283 } 284 #endif 285 #endif 286 287 /********************************************************************* 288 * 289 * RTT lock configuration for TI ARM 290 */ 291 #ifdef __TI_ARM__ 292 #if defined (__TI_ARM_V6M0__) 293 #define SEGGER_RTT_LOCK() { \ 294 unsigned int LockState; \ 295 LockState = __get_PRIMASK(); \ 296 __set_PRIMASK(1); 297 298 #define SEGGER_RTT_UNLOCK() __set_PRIMASK(LockState); \ 299 } 300 #elif (defined (__TI_ARM_V7M3__) || defined (__TI_ARM_V7M4__)) 301 #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY 302 #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) 303 #endif 304 #define SEGGER_RTT_LOCK() { \ 305 unsigned int LockState; \ 306 LockState = _set_interrupt_priority(SEGGER_RTT_MAX_INTERRUPT_PRIORITY); 307 308 #define SEGGER_RTT_UNLOCK() _set_interrupt_priority(LockState); \ 309 } 310 #endif 311 #endif 312 313 /********************************************************************* 314 * 315 * RTT lock configuration for CCRX 316 */ 317 #ifdef __RX 318 #define SEGGER_RTT_LOCK() { \ 319 unsigned long LockState; \ 320 LockState = get_psw() & 0x010000; \ 321 clrpsw_i(); 322 323 #define SEGGER_RTT_UNLOCK() set_psw(get_psw() | LockState); \ 324 } 325 #endif 326 327 /********************************************************************* 328 * 329 * RTT lock configuration fallback 330 */ 331 #ifndef SEGGER_RTT_LOCK 332 #define SEGGER_RTT_LOCK() // Lock RTT (nestable) (i.e. disable interrupts) 333 #endif 334 335 #ifndef SEGGER_RTT_UNLOCK 336 #define SEGGER_RTT_UNLOCK() // Unlock RTT (nestable) (i.e. enable previous interrupt lock state) 337 #endif 338 339 #endif 340 /*************************** End of file ****************************/ 341