17dc86dfdSMatthias Ringwald /********************************************************************* 2779af47bSMatthias Ringwald * SEGGER Microcontroller GmbH * 3779af47bSMatthias Ringwald * The Embedded Experts * 47dc86dfdSMatthias Ringwald ********************************************************************** 57dc86dfdSMatthias Ringwald * * 6*ce6f85e7SMatthias Ringwald * (c) 1995 - 2020 SEGGER Microcontroller GmbH * 77dc86dfdSMatthias Ringwald * * 87dc86dfdSMatthias Ringwald * www.segger.com Support: [email protected] * 97dc86dfdSMatthias Ringwald * * 107dc86dfdSMatthias Ringwald ********************************************************************** 117dc86dfdSMatthias Ringwald * * 127dc86dfdSMatthias Ringwald * SEGGER RTT * Real Time Transfer for embedded targets * 137dc86dfdSMatthias Ringwald * * 147dc86dfdSMatthias Ringwald ********************************************************************** 157dc86dfdSMatthias Ringwald * * 167dc86dfdSMatthias Ringwald * All rights reserved. * 177dc86dfdSMatthias Ringwald * * 187dc86dfdSMatthias Ringwald * SEGGER strongly recommends to not make any changes * 197dc86dfdSMatthias Ringwald * to or modify the source code of this software in order to stay * 207dc86dfdSMatthias Ringwald * compatible with the RTT protocol and J-Link. * 217dc86dfdSMatthias Ringwald * * 227dc86dfdSMatthias Ringwald * Redistribution and use in source and binary forms, with or * 237dc86dfdSMatthias Ringwald * without modification, are permitted provided that the following * 24*ce6f85e7SMatthias Ringwald * condition is met: * 257dc86dfdSMatthias Ringwald * * 267dc86dfdSMatthias Ringwald * o Redistributions of source code must retain the above copyright * 27*ce6f85e7SMatthias Ringwald * notice, this condition and the following disclaimer. * 287dc86dfdSMatthias Ringwald * * 297dc86dfdSMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * 307dc86dfdSMatthias Ringwald * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * 317dc86dfdSMatthias Ringwald * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * 327dc86dfdSMatthias Ringwald * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * 337dc86dfdSMatthias Ringwald * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * 347dc86dfdSMatthias Ringwald * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * 357dc86dfdSMatthias Ringwald * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * 367dc86dfdSMatthias Ringwald * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * 377dc86dfdSMatthias Ringwald * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * 387dc86dfdSMatthias Ringwald * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 397dc86dfdSMatthias Ringwald * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * 407dc86dfdSMatthias Ringwald * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 417dc86dfdSMatthias Ringwald * DAMAGE. * 427dc86dfdSMatthias Ringwald * * 437dc86dfdSMatthias Ringwald ********************************************************************** 447dc86dfdSMatthias Ringwald ---------------------------END-OF-HEADER------------------------------ 457dc86dfdSMatthias Ringwald File : SEGGER_RTT_Conf.h 467dc86dfdSMatthias Ringwald Purpose : Implementation of SEGGER real-time transfer (RTT) which 477dc86dfdSMatthias Ringwald allows real-time communication on targets which support 487dc86dfdSMatthias Ringwald debugger memory accesses while the CPU is running. 49*ce6f85e7SMatthias Ringwald Revision: $Rev: 24316 $ 507dc86dfdSMatthias Ringwald 517dc86dfdSMatthias Ringwald */ 527dc86dfdSMatthias Ringwald 537dc86dfdSMatthias Ringwald #ifndef SEGGER_RTT_CONF_H 547dc86dfdSMatthias Ringwald #define SEGGER_RTT_CONF_H 557dc86dfdSMatthias Ringwald 567dc86dfdSMatthias Ringwald #ifdef __IAR_SYSTEMS_ICC__ 577dc86dfdSMatthias Ringwald #include <intrinsics.h> 587dc86dfdSMatthias Ringwald #endif 597dc86dfdSMatthias Ringwald 607dc86dfdSMatthias Ringwald /********************************************************************* 617dc86dfdSMatthias Ringwald * 627dc86dfdSMatthias Ringwald * Defines, configurable 637dc86dfdSMatthias Ringwald * 647dc86dfdSMatthias Ringwald ********************************************************************** 657dc86dfdSMatthias Ringwald */ 667dc86dfdSMatthias Ringwald 67*ce6f85e7SMatthias Ringwald // 68*ce6f85e7SMatthias Ringwald // Take in and set to correct values for Cortex-A systems with CPU cache 69*ce6f85e7SMatthias Ringwald // 70*ce6f85e7SMatthias Ringwald //#define SEGGER_RTT_CPU_CACHE_LINE_SIZE (32) // Largest cache line size (in bytes) in the current system 71*ce6f85e7SMatthias Ringwald //#define SEGGER_RTT_UNCACHED_OFF (0xFB000000) // Address alias where RTT CB and buffers can be accessed uncached 72*ce6f85e7SMatthias Ringwald // 73*ce6f85e7SMatthias Ringwald // Most common case: 74*ce6f85e7SMatthias Ringwald // Up-channel 0: RTT 75*ce6f85e7SMatthias Ringwald // Up-channel 1: SystemView 76*ce6f85e7SMatthias Ringwald // 77*ce6f85e7SMatthias Ringwald #ifndef SEGGER_RTT_MAX_NUM_UP_BUFFERS 787dc86dfdSMatthias Ringwald #define SEGGER_RTT_MAX_NUM_UP_BUFFERS (3) // Max. number of up-buffers (T->H) available on this target (Default: 3) 79*ce6f85e7SMatthias Ringwald #endif 80*ce6f85e7SMatthias Ringwald // 81*ce6f85e7SMatthias Ringwald // Most common case: 82*ce6f85e7SMatthias Ringwald // Down-channel 0: RTT 83*ce6f85e7SMatthias Ringwald // Down-channel 1: SystemView 84*ce6f85e7SMatthias Ringwald // 85*ce6f85e7SMatthias Ringwald #ifndef SEGGER_RTT_MAX_NUM_DOWN_BUFFERS 867dc86dfdSMatthias Ringwald #define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (3) // Max. number of down-buffers (H->T) available on this target (Default: 3) 87*ce6f85e7SMatthias Ringwald #endif 887dc86dfdSMatthias Ringwald 89*ce6f85e7SMatthias Ringwald #ifndef BUFFER_SIZE_UP 907dc86dfdSMatthias Ringwald #define BUFFER_SIZE_UP (1024) // Size of the buffer for terminal output of target, up to host (Default: 1k) 91*ce6f85e7SMatthias Ringwald #endif 92*ce6f85e7SMatthias Ringwald 93*ce6f85e7SMatthias Ringwald #ifndef BUFFER_SIZE_DOWN 947dc86dfdSMatthias Ringwald #define BUFFER_SIZE_DOWN (16) // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16) 95*ce6f85e7SMatthias Ringwald #endif 967dc86dfdSMatthias Ringwald 97*ce6f85e7SMatthias Ringwald #ifndef SEGGER_RTT_PRINTF_BUFFER_SIZE 987dc86dfdSMatthias Ringwald #define SEGGER_RTT_PRINTF_BUFFER_SIZE (64u) // Size of buffer for RTT printf to bulk-send chars via RTT (Default: 64) 99*ce6f85e7SMatthias Ringwald #endif 1007dc86dfdSMatthias Ringwald 101*ce6f85e7SMatthias Ringwald #ifndef SEGGER_RTT_MODE_DEFAULT 102043de24aSMatthias Ringwald #define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_NO_BLOCK_SKIP // Mode for pre-initialized terminal channel (buffer 0) 103*ce6f85e7SMatthias Ringwald #endif 1047dc86dfdSMatthias Ringwald 1057dc86dfdSMatthias Ringwald /********************************************************************* 1067dc86dfdSMatthias Ringwald * 1077dc86dfdSMatthias Ringwald * RTT memcpy configuration 1087dc86dfdSMatthias Ringwald * 1097dc86dfdSMatthias Ringwald * memcpy() is good for large amounts of data, 1107dc86dfdSMatthias Ringwald * but the overhead is big for small amounts, which are usually stored via RTT. 1117dc86dfdSMatthias Ringwald * With SEGGER_RTT_MEMCPY_USE_BYTELOOP a simple byte loop can be used instead. 1127dc86dfdSMatthias Ringwald * 1137dc86dfdSMatthias Ringwald * SEGGER_RTT_MEMCPY() can be used to replace standard memcpy() in RTT functions. 1147dc86dfdSMatthias Ringwald * This is may be required with memory access restrictions, 1157dc86dfdSMatthias Ringwald * such as on Cortex-A devices with MMU. 1167dc86dfdSMatthias Ringwald */ 117*ce6f85e7SMatthias Ringwald #ifndef SEGGER_RTT_MEMCPY_USE_BYTELOOP 1187dc86dfdSMatthias Ringwald #define SEGGER_RTT_MEMCPY_USE_BYTELOOP 0 // 0: Use memcpy/SEGGER_RTT_MEMCPY, 1: Use a simple byte-loop 119*ce6f85e7SMatthias Ringwald #endif 1207dc86dfdSMatthias Ringwald // 1217dc86dfdSMatthias Ringwald // Example definition of SEGGER_RTT_MEMCPY to external memcpy with GCC toolchains and Cortex-A targets 1227dc86dfdSMatthias Ringwald // 1237dc86dfdSMatthias Ringwald //#if ((defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__)) && (defined (__ARM_ARCH_7A__)) 1247dc86dfdSMatthias Ringwald // #define SEGGER_RTT_MEMCPY(pDest, pSrc, NumBytes) SEGGER_memcpy((pDest), (pSrc), (NumBytes)) 1257dc86dfdSMatthias Ringwald //#endif 1267dc86dfdSMatthias Ringwald 1277dc86dfdSMatthias Ringwald // 1287dc86dfdSMatthias Ringwald // Target is not allowed to perform other RTT operations while string still has not been stored completely. 1297dc86dfdSMatthias Ringwald // Otherwise we would probably end up with a mixed string in the buffer. 1307dc86dfdSMatthias Ringwald // If using RTT from within interrupts, multiple tasks or multi processors, define the SEGGER_RTT_LOCK() and SEGGER_RTT_UNLOCK() function here. 1317dc86dfdSMatthias Ringwald // 1327dc86dfdSMatthias Ringwald // SEGGER_RTT_MAX_INTERRUPT_PRIORITY can be used in the sample lock routines on Cortex-M3/4. 1337dc86dfdSMatthias Ringwald // Make sure to mask all interrupts which can send RTT data, i.e. generate SystemView events, or cause task switches. 1347dc86dfdSMatthias Ringwald // When high-priority interrupts must not be masked while sending RTT data, SEGGER_RTT_MAX_INTERRUPT_PRIORITY needs to be adjusted accordingly. 1357dc86dfdSMatthias Ringwald // (Higher priority = lower priority number) 1367dc86dfdSMatthias Ringwald // Default value for embOS: 128u 1377dc86dfdSMatthias Ringwald // Default configuration in FreeRTOS: configMAX_SYSCALL_INTERRUPT_PRIORITY: ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) 1387dc86dfdSMatthias Ringwald // In case of doubt mask all interrupts: 1 << (8 - BASEPRI_PRIO_BITS) i.e. 1 << 5 when 3 bits are implemented in NVIC 1397dc86dfdSMatthias Ringwald // or define SEGGER_RTT_LOCK() to completely disable interrupts. 1407dc86dfdSMatthias Ringwald // 141*ce6f85e7SMatthias Ringwald #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY 1427dc86dfdSMatthias Ringwald #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) // Interrupt priority to lock on SEGGER_RTT_LOCK on Cortex-M3/4 (Default: 0x20) 143*ce6f85e7SMatthias Ringwald #endif 1447dc86dfdSMatthias Ringwald 1457dc86dfdSMatthias Ringwald /********************************************************************* 1467dc86dfdSMatthias Ringwald * 1477dc86dfdSMatthias Ringwald * RTT lock configuration for SEGGER Embedded Studio, 1487dc86dfdSMatthias Ringwald * Rowley CrossStudio and GCC 1497dc86dfdSMatthias Ringwald */ 150*ce6f85e7SMatthias Ringwald #if ((defined(__SES_ARM) || defined(__SES_RISCV) || defined(__CROSSWORKS_ARM) || defined(__GNUC__) || defined(__clang__)) && !defined (__CC_ARM) && !defined(WIN32)) 151779af47bSMatthias Ringwald #if (defined(__ARM_ARCH_6M__) || defined(__ARM_ARCH_8M_BASE__)) 1527dc86dfdSMatthias Ringwald #define SEGGER_RTT_LOCK() { \ 153*ce6f85e7SMatthias Ringwald unsigned int _SEGGER_RTT__LockState; \ 1547dc86dfdSMatthias Ringwald __asm volatile ("mrs %0, primask \n\t" \ 155*ce6f85e7SMatthias Ringwald "movs r1, #1 \n\t" \ 1567dc86dfdSMatthias Ringwald "msr primask, r1 \n\t" \ 157*ce6f85e7SMatthias Ringwald : "=r" (_SEGGER_RTT__LockState) \ 1587dc86dfdSMatthias Ringwald : \ 159*ce6f85e7SMatthias Ringwald : "r1", "cc" \ 1607dc86dfdSMatthias Ringwald ); 1617dc86dfdSMatthias Ringwald 1627dc86dfdSMatthias Ringwald #define SEGGER_RTT_UNLOCK() __asm volatile ("msr primask, %0 \n\t" \ 1637dc86dfdSMatthias Ringwald : \ 164*ce6f85e7SMatthias Ringwald : "r" (_SEGGER_RTT__LockState) \ 1657dc86dfdSMatthias Ringwald : \ 1667dc86dfdSMatthias Ringwald ); \ 1677dc86dfdSMatthias Ringwald } 168779af47bSMatthias Ringwald #elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_8M_MAIN__)) 1697dc86dfdSMatthias Ringwald #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY 1707dc86dfdSMatthias Ringwald #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) 1717dc86dfdSMatthias Ringwald #endif 1727dc86dfdSMatthias Ringwald #define SEGGER_RTT_LOCK() { \ 173*ce6f85e7SMatthias Ringwald unsigned int _SEGGER_RTT__LockState; \ 1747dc86dfdSMatthias Ringwald __asm volatile ("mrs %0, basepri \n\t" \ 1757dc86dfdSMatthias Ringwald "mov r1, %1 \n\t" \ 1767dc86dfdSMatthias Ringwald "msr basepri, r1 \n\t" \ 177*ce6f85e7SMatthias Ringwald : "=r" (_SEGGER_RTT__LockState) \ 1787dc86dfdSMatthias Ringwald : "i"(SEGGER_RTT_MAX_INTERRUPT_PRIORITY) \ 179*ce6f85e7SMatthias Ringwald : "r1", "cc" \ 1807dc86dfdSMatthias Ringwald ); 1817dc86dfdSMatthias Ringwald 1827dc86dfdSMatthias Ringwald #define SEGGER_RTT_UNLOCK() __asm volatile ("msr basepri, %0 \n\t" \ 1837dc86dfdSMatthias Ringwald : \ 184*ce6f85e7SMatthias Ringwald : "r" (_SEGGER_RTT__LockState) \ 1857dc86dfdSMatthias Ringwald : \ 1867dc86dfdSMatthias Ringwald ); \ 1877dc86dfdSMatthias Ringwald } 1887dc86dfdSMatthias Ringwald 189*ce6f85e7SMatthias Ringwald #elif (defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__)) 1907dc86dfdSMatthias Ringwald #define SEGGER_RTT_LOCK() { \ 191*ce6f85e7SMatthias Ringwald unsigned int _SEGGER_RTT__LockState; \ 1927dc86dfdSMatthias Ringwald __asm volatile ("mrs r1, CPSR \n\t" \ 1937dc86dfdSMatthias Ringwald "mov %0, r1 \n\t" \ 1947dc86dfdSMatthias Ringwald "orr r1, r1, #0xC0 \n\t" \ 1957dc86dfdSMatthias Ringwald "msr CPSR_c, r1 \n\t" \ 196*ce6f85e7SMatthias Ringwald : "=r" (_SEGGER_RTT__LockState) \ 1977dc86dfdSMatthias Ringwald : \ 198*ce6f85e7SMatthias Ringwald : "r1", "cc" \ 1997dc86dfdSMatthias Ringwald ); 2007dc86dfdSMatthias Ringwald 2017dc86dfdSMatthias Ringwald #define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t" \ 2027dc86dfdSMatthias Ringwald "mrs r1, CPSR \n\t" \ 2037dc86dfdSMatthias Ringwald "bic r1, r1, #0xC0 \n\t" \ 2047dc86dfdSMatthias Ringwald "and r0, r0, #0xC0 \n\t" \ 2057dc86dfdSMatthias Ringwald "orr r1, r1, r0 \n\t" \ 2067dc86dfdSMatthias Ringwald "msr CPSR_c, r1 \n\t" \ 2077dc86dfdSMatthias Ringwald : \ 208*ce6f85e7SMatthias Ringwald : "r" (_SEGGER_RTT__LockState) \ 209*ce6f85e7SMatthias Ringwald : "r0", "r1", "cc" \ 2107dc86dfdSMatthias Ringwald ); \ 2117dc86dfdSMatthias Ringwald } 212*ce6f85e7SMatthias Ringwald #elif defined(__riscv) || defined(__riscv_xlen) 213*ce6f85e7SMatthias Ringwald #define SEGGER_RTT_LOCK() { \ 214*ce6f85e7SMatthias Ringwald unsigned int _SEGGER_RTT__LockState; \ 215*ce6f85e7SMatthias Ringwald __asm volatile ("csrr %0, mstatus \n\t" \ 216*ce6f85e7SMatthias Ringwald "csrci mstatus, 8 \n\t" \ 217*ce6f85e7SMatthias Ringwald "andi %0, %0, 8 \n\t" \ 218*ce6f85e7SMatthias Ringwald : "=r" (_SEGGER_RTT__LockState) \ 219*ce6f85e7SMatthias Ringwald : \ 220*ce6f85e7SMatthias Ringwald : \ 221*ce6f85e7SMatthias Ringwald ); 222*ce6f85e7SMatthias Ringwald 223*ce6f85e7SMatthias Ringwald #define SEGGER_RTT_UNLOCK() __asm volatile ("csrr a1, mstatus \n\t" \ 224*ce6f85e7SMatthias Ringwald "or %0, %0, a1 \n\t" \ 225*ce6f85e7SMatthias Ringwald "csrs mstatus, %0 \n\t" \ 226*ce6f85e7SMatthias Ringwald : \ 227*ce6f85e7SMatthias Ringwald : "r" (_SEGGER_RTT__LockState) \ 228*ce6f85e7SMatthias Ringwald : "a1" \ 229*ce6f85e7SMatthias Ringwald ); \ 230*ce6f85e7SMatthias Ringwald } 231*ce6f85e7SMatthias Ringwald #else 232*ce6f85e7SMatthias Ringwald #define SEGGER_RTT_LOCK() 233*ce6f85e7SMatthias Ringwald #define SEGGER_RTT_UNLOCK() 2347dc86dfdSMatthias Ringwald #endif 2357dc86dfdSMatthias Ringwald #endif 2367dc86dfdSMatthias Ringwald 2377dc86dfdSMatthias Ringwald /********************************************************************* 2387dc86dfdSMatthias Ringwald * 2397dc86dfdSMatthias Ringwald * RTT lock configuration for IAR EWARM 2407dc86dfdSMatthias Ringwald */ 2417dc86dfdSMatthias Ringwald #ifdef __ICCARM__ 242*ce6f85e7SMatthias Ringwald #if (defined (__ARM6M__) && (__CORE__ == __ARM6M__)) || \ 243*ce6f85e7SMatthias Ringwald (defined (__ARM8M_BASELINE__) && (__CORE__ == __ARM8M_BASELINE__)) 2447dc86dfdSMatthias Ringwald #define SEGGER_RTT_LOCK() { \ 245*ce6f85e7SMatthias Ringwald unsigned int _SEGGER_RTT__LockState; \ 246*ce6f85e7SMatthias Ringwald _SEGGER_RTT__LockState = __get_PRIMASK(); \ 2477dc86dfdSMatthias Ringwald __set_PRIMASK(1); 2487dc86dfdSMatthias Ringwald 249*ce6f85e7SMatthias Ringwald #define SEGGER_RTT_UNLOCK() __set_PRIMASK(_SEGGER_RTT__LockState); \ 2507dc86dfdSMatthias Ringwald } 251*ce6f85e7SMatthias Ringwald #elif (defined (__ARM7EM__) && (__CORE__ == __ARM7EM__)) || \ 252*ce6f85e7SMatthias Ringwald (defined (__ARM7M__) && (__CORE__ == __ARM7M__)) || \ 253*ce6f85e7SMatthias Ringwald (defined (__ARM8M_MAINLINE__) && (__CORE__ == __ARM8M_MAINLINE__)) || \ 254*ce6f85e7SMatthias Ringwald (defined (__ARM8M_MAINLINE__) && (__CORE__ == __ARM8M_MAINLINE__)) 2557dc86dfdSMatthias Ringwald #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY 2567dc86dfdSMatthias Ringwald #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) 2577dc86dfdSMatthias Ringwald #endif 2587dc86dfdSMatthias Ringwald #define SEGGER_RTT_LOCK() { \ 259*ce6f85e7SMatthias Ringwald unsigned int _SEGGER_RTT__LockState; \ 260*ce6f85e7SMatthias Ringwald _SEGGER_RTT__LockState = __get_BASEPRI(); \ 2617dc86dfdSMatthias Ringwald __set_BASEPRI(SEGGER_RTT_MAX_INTERRUPT_PRIORITY); 2627dc86dfdSMatthias Ringwald 263*ce6f85e7SMatthias Ringwald #define SEGGER_RTT_UNLOCK() __set_BASEPRI(_SEGGER_RTT__LockState); \ 264*ce6f85e7SMatthias Ringwald } 265*ce6f85e7SMatthias Ringwald #elif (defined (__ARM7A__) && (__CORE__ == __ARM7A__)) || \ 266*ce6f85e7SMatthias Ringwald (defined (__ARM7R__) && (__CORE__ == __ARM7R__)) 267*ce6f85e7SMatthias Ringwald #define SEGGER_RTT_LOCK() { \ 268*ce6f85e7SMatthias Ringwald unsigned int _SEGGER_RTT__LockState; \ 269*ce6f85e7SMatthias Ringwald __asm volatile ("mrs r1, CPSR \n\t" \ 270*ce6f85e7SMatthias Ringwald "mov %0, r1 \n\t" \ 271*ce6f85e7SMatthias Ringwald "orr r1, r1, #0xC0 \n\t" \ 272*ce6f85e7SMatthias Ringwald "msr CPSR_c, r1 \n\t" \ 273*ce6f85e7SMatthias Ringwald : "=r" (_SEGGER_RTT__LockState) \ 274*ce6f85e7SMatthias Ringwald : \ 275*ce6f85e7SMatthias Ringwald : "r1", "cc" \ 276*ce6f85e7SMatthias Ringwald ); 277*ce6f85e7SMatthias Ringwald 278*ce6f85e7SMatthias Ringwald #define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t" \ 279*ce6f85e7SMatthias Ringwald "mrs r1, CPSR \n\t" \ 280*ce6f85e7SMatthias Ringwald "bic r1, r1, #0xC0 \n\t" \ 281*ce6f85e7SMatthias Ringwald "and r0, r0, #0xC0 \n\t" \ 282*ce6f85e7SMatthias Ringwald "orr r1, r1, r0 \n\t" \ 283*ce6f85e7SMatthias Ringwald "msr CPSR_c, r1 \n\t" \ 284*ce6f85e7SMatthias Ringwald : \ 285*ce6f85e7SMatthias Ringwald : "r" (_SEGGER_RTT__LockState) \ 286*ce6f85e7SMatthias Ringwald : "r0", "r1", "cc" \ 287*ce6f85e7SMatthias Ringwald ); \ 2887dc86dfdSMatthias Ringwald } 2897dc86dfdSMatthias Ringwald #endif 2907dc86dfdSMatthias Ringwald #endif 2917dc86dfdSMatthias Ringwald 2927dc86dfdSMatthias Ringwald /********************************************************************* 2937dc86dfdSMatthias Ringwald * 2947dc86dfdSMatthias Ringwald * RTT lock configuration for IAR RX 2957dc86dfdSMatthias Ringwald */ 2967dc86dfdSMatthias Ringwald #ifdef __ICCRX__ 2977dc86dfdSMatthias Ringwald #define SEGGER_RTT_LOCK() { \ 298*ce6f85e7SMatthias Ringwald unsigned long _SEGGER_RTT__LockState; \ 299*ce6f85e7SMatthias Ringwald _SEGGER_RTT__LockState = __get_interrupt_state(); \ 3007dc86dfdSMatthias Ringwald __disable_interrupt(); 3017dc86dfdSMatthias Ringwald 302*ce6f85e7SMatthias Ringwald #define SEGGER_RTT_UNLOCK() __set_interrupt_state(_SEGGER_RTT__LockState); \ 3037dc86dfdSMatthias Ringwald } 3047dc86dfdSMatthias Ringwald #endif 3057dc86dfdSMatthias Ringwald 3067dc86dfdSMatthias Ringwald /********************************************************************* 3077dc86dfdSMatthias Ringwald * 3087dc86dfdSMatthias Ringwald * RTT lock configuration for IAR RL78 3097dc86dfdSMatthias Ringwald */ 3107dc86dfdSMatthias Ringwald #ifdef __ICCRL78__ 3117dc86dfdSMatthias Ringwald #define SEGGER_RTT_LOCK() { \ 312*ce6f85e7SMatthias Ringwald __istate_t _SEGGER_RTT__LockState; \ 313*ce6f85e7SMatthias Ringwald _SEGGER_RTT__LockState = __get_interrupt_state(); \ 3147dc86dfdSMatthias Ringwald __disable_interrupt(); 3157dc86dfdSMatthias Ringwald 316*ce6f85e7SMatthias Ringwald #define SEGGER_RTT_UNLOCK() __set_interrupt_state(_SEGGER_RTT__LockState); \ 3177dc86dfdSMatthias Ringwald } 3187dc86dfdSMatthias Ringwald #endif 3197dc86dfdSMatthias Ringwald 3207dc86dfdSMatthias Ringwald /********************************************************************* 3217dc86dfdSMatthias Ringwald * 3227dc86dfdSMatthias Ringwald * RTT lock configuration for KEIL ARM 3237dc86dfdSMatthias Ringwald */ 3247dc86dfdSMatthias Ringwald #ifdef __CC_ARM 3257dc86dfdSMatthias Ringwald #if (defined __TARGET_ARCH_6S_M) 3267dc86dfdSMatthias Ringwald #define SEGGER_RTT_LOCK() { \ 327*ce6f85e7SMatthias Ringwald unsigned int _SEGGER_RTT__LockState; \ 328*ce6f85e7SMatthias Ringwald register unsigned char _SEGGER_RTT__PRIMASK __asm( "primask"); \ 329*ce6f85e7SMatthias Ringwald _SEGGER_RTT__LockState = _SEGGER_RTT__PRIMASK; \ 330*ce6f85e7SMatthias Ringwald _SEGGER_RTT__PRIMASK = 1u; \ 3317dc86dfdSMatthias Ringwald __schedule_barrier(); 3327dc86dfdSMatthias Ringwald 333*ce6f85e7SMatthias Ringwald #define SEGGER_RTT_UNLOCK() _SEGGER_RTT__PRIMASK = _SEGGER_RTT__LockState; \ 3347dc86dfdSMatthias Ringwald __schedule_barrier(); \ 3357dc86dfdSMatthias Ringwald } 3367dc86dfdSMatthias Ringwald #elif (defined(__TARGET_ARCH_7_M) || defined(__TARGET_ARCH_7E_M)) 3377dc86dfdSMatthias Ringwald #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY 3387dc86dfdSMatthias Ringwald #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) 3397dc86dfdSMatthias Ringwald #endif 3407dc86dfdSMatthias Ringwald #define SEGGER_RTT_LOCK() { \ 341*ce6f85e7SMatthias Ringwald unsigned int _SEGGER_RTT__LockState; \ 3427dc86dfdSMatthias Ringwald register unsigned char BASEPRI __asm( "basepri"); \ 343*ce6f85e7SMatthias Ringwald _SEGGER_RTT__LockState = BASEPRI; \ 3447dc86dfdSMatthias Ringwald BASEPRI = SEGGER_RTT_MAX_INTERRUPT_PRIORITY; \ 3457dc86dfdSMatthias Ringwald __schedule_barrier(); 3467dc86dfdSMatthias Ringwald 347*ce6f85e7SMatthias Ringwald #define SEGGER_RTT_UNLOCK() BASEPRI = _SEGGER_RTT__LockState; \ 3487dc86dfdSMatthias Ringwald __schedule_barrier(); \ 3497dc86dfdSMatthias Ringwald } 3507dc86dfdSMatthias Ringwald #endif 3517dc86dfdSMatthias Ringwald #endif 3527dc86dfdSMatthias Ringwald 3537dc86dfdSMatthias Ringwald /********************************************************************* 3547dc86dfdSMatthias Ringwald * 3557dc86dfdSMatthias Ringwald * RTT lock configuration for TI ARM 3567dc86dfdSMatthias Ringwald */ 3577dc86dfdSMatthias Ringwald #ifdef __TI_ARM__ 3587dc86dfdSMatthias Ringwald #if defined (__TI_ARM_V6M0__) 3597dc86dfdSMatthias Ringwald #define SEGGER_RTT_LOCK() { \ 360*ce6f85e7SMatthias Ringwald unsigned int _SEGGER_RTT__LockState; \ 361*ce6f85e7SMatthias Ringwald _SEGGER_RTT__LockState = __get_PRIMASK(); \ 3627dc86dfdSMatthias Ringwald __set_PRIMASK(1); 3637dc86dfdSMatthias Ringwald 364*ce6f85e7SMatthias Ringwald #define SEGGER_RTT_UNLOCK() __set_PRIMASK(_SEGGER_RTT__LockState); \ 3657dc86dfdSMatthias Ringwald } 3667dc86dfdSMatthias Ringwald #elif (defined (__TI_ARM_V7M3__) || defined (__TI_ARM_V7M4__)) 3677dc86dfdSMatthias Ringwald #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY 3687dc86dfdSMatthias Ringwald #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) 3697dc86dfdSMatthias Ringwald #endif 3707dc86dfdSMatthias Ringwald #define SEGGER_RTT_LOCK() { \ 371*ce6f85e7SMatthias Ringwald unsigned int _SEGGER_RTT__LockState; \ 372*ce6f85e7SMatthias Ringwald _SEGGER_RTT__LockState = _set_interrupt_priority(SEGGER_RTT_MAX_INTERRUPT_PRIORITY); 3737dc86dfdSMatthias Ringwald 374*ce6f85e7SMatthias Ringwald #define SEGGER_RTT_UNLOCK() _set_interrupt_priority(_SEGGER_RTT__LockState); \ 3757dc86dfdSMatthias Ringwald } 3767dc86dfdSMatthias Ringwald #endif 3777dc86dfdSMatthias Ringwald #endif 3787dc86dfdSMatthias Ringwald 3797dc86dfdSMatthias Ringwald /********************************************************************* 3807dc86dfdSMatthias Ringwald * 381779af47bSMatthias Ringwald * RTT lock configuration for CCRX 382779af47bSMatthias Ringwald */ 383779af47bSMatthias Ringwald #ifdef __RX 384*ce6f85e7SMatthias Ringwald #include <machine.h> 385779af47bSMatthias Ringwald #define SEGGER_RTT_LOCK() { \ 386*ce6f85e7SMatthias Ringwald unsigned long _SEGGER_RTT__LockState; \ 387*ce6f85e7SMatthias Ringwald _SEGGER_RTT__LockState = get_psw() & 0x010000; \ 388779af47bSMatthias Ringwald clrpsw_i(); 389779af47bSMatthias Ringwald 390*ce6f85e7SMatthias Ringwald #define SEGGER_RTT_UNLOCK() set_psw(get_psw() | _SEGGER_RTT__LockState); \ 391*ce6f85e7SMatthias Ringwald } 392*ce6f85e7SMatthias Ringwald #endif 393*ce6f85e7SMatthias Ringwald 394*ce6f85e7SMatthias Ringwald /********************************************************************* 395*ce6f85e7SMatthias Ringwald * 396*ce6f85e7SMatthias Ringwald * RTT lock configuration for embOS Simulation on Windows 397*ce6f85e7SMatthias Ringwald * (Can also be used for generic RTT locking with embOS) 398*ce6f85e7SMatthias Ringwald */ 399*ce6f85e7SMatthias Ringwald #if defined(WIN32) || defined(SEGGER_RTT_LOCK_EMBOS) 400*ce6f85e7SMatthias Ringwald 401*ce6f85e7SMatthias Ringwald void OS_SIM_EnterCriticalSection(void); 402*ce6f85e7SMatthias Ringwald void OS_SIM_LeaveCriticalSection(void); 403*ce6f85e7SMatthias Ringwald 404*ce6f85e7SMatthias Ringwald #define SEGGER_RTT_LOCK() { \ 405*ce6f85e7SMatthias Ringwald OS_SIM_EnterCriticalSection(); 406*ce6f85e7SMatthias Ringwald 407*ce6f85e7SMatthias Ringwald #define SEGGER_RTT_UNLOCK() OS_SIM_LeaveCriticalSection(); \ 408779af47bSMatthias Ringwald } 409779af47bSMatthias Ringwald #endif 410779af47bSMatthias Ringwald 411779af47bSMatthias Ringwald /********************************************************************* 412779af47bSMatthias Ringwald * 4137dc86dfdSMatthias Ringwald * RTT lock configuration fallback 4147dc86dfdSMatthias Ringwald */ 4157dc86dfdSMatthias Ringwald #ifndef SEGGER_RTT_LOCK 4167dc86dfdSMatthias Ringwald #define SEGGER_RTT_LOCK() // Lock RTT (nestable) (i.e. disable interrupts) 4177dc86dfdSMatthias Ringwald #endif 4187dc86dfdSMatthias Ringwald 4197dc86dfdSMatthias Ringwald #ifndef SEGGER_RTT_UNLOCK 4207dc86dfdSMatthias Ringwald #define SEGGER_RTT_UNLOCK() // Unlock RTT (nestable) (i.e. enable previous interrupt lock state) 4217dc86dfdSMatthias Ringwald #endif 4227dc86dfdSMatthias Ringwald 4237dc86dfdSMatthias Ringwald #endif 4247dc86dfdSMatthias Ringwald /*************************** End of file ****************************/ 425