0x6d61726b / mbed-os-retarget-segger-rtt

Dependents:   3_Test_AFE 1_Test_Flash_ADC_RTT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SEGGER_RTT_Conf.h Source File

SEGGER_RTT_Conf.h

00001 /*********************************************************************
00002 *                    SEGGER Microcontroller GmbH                     *
00003 *                        The Embedded Experts                        *
00004 **********************************************************************
00005 *                                                                    *
00006 *            (c) 1995 - 2019 SEGGER Microcontroller GmbH             *
00007 *                                                                    *
00008 *       www.segger.com     Support: support@segger.com               *
00009 *                                                                    *
00010 **********************************************************************
00011 *                                                                    *
00012 *       SEGGER RTT * Real Time Transfer for embedded targets         *
00013 *                                                                    *
00014 **********************************************************************
00015 *                                                                    *
00016 * All rights reserved.                                               *
00017 *                                                                    *
00018 * SEGGER strongly recommends to not make any changes                 *
00019 * to or modify the source code of this software in order to stay     *
00020 * compatible with the RTT protocol and J-Link.                       *
00021 *                                                                    *
00022 * Redistribution and use in source and binary forms, with or         *
00023 * without modification, are permitted provided that the following    *
00024 * conditions are met:                                                *
00025 *                                                                    *
00026 * o Redistributions of source code must retain the above copyright   *
00027 *   notice, this list of conditions and the following disclaimer.    *
00028 *                                                                    *
00029 * o Redistributions in binary form must reproduce the above          *
00030 *   copyright notice, this list of conditions and the following      *
00031 *   disclaimer in the documentation and/or other materials provided  *
00032 *   with the distribution.                                           *
00033 *                                                                    *
00034 * o Neither the name of SEGGER Microcontroller GmbH                  *
00035 *   nor the names of its contributors may be used to endorse or      *
00036 *   promote products derived from this software without specific     *
00037 *   prior written permission.                                        *
00038 *                                                                    *
00039 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
00040 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
00041 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
00042 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
00043 * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
00044 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
00045 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
00046 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
00047 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
00048 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
00049 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
00050 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
00051 * DAMAGE.                                                            *
00052 *                                                                    *
00053 **********************************************************************
00054 *                                                                    *
00055 *       RTT version: 6.44i                                           *
00056 *                                                                    *
00057 **********************************************************************
00058 ---------------------------END-OF-HEADER------------------------------
00059 File    : SEGGER_RTT_Conf.h
00060 Purpose : Implementation of SEGGER real-time transfer (RTT) which
00061           allows real-time communication on targets which support
00062           debugger memory accesses while the CPU is running.
00063 Revision: Rev: 13430
00064 
00065 */
00066 
00067 #ifndef SEGGER_RTT_CONF_H
00068 #define SEGGER_RTT_CONF_H
00069 
00070 /*********************************************************************
00071 *
00072 *       Defines, configurable
00073 *
00074 **********************************************************************
00075 */
00076 
00077 #define SEGGER_RTT_MAX_NUM_UP_BUFFERS             (1)     // Max. number of up-buffers (T->H) available on this target    (Default: 3)
00078 #define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS           (1)     // Max. number of down-buffers (H->T) available on this target  (Default: 3)
00079 
00080 // configure SEGGER_RTT_BUFFER_SIZE_* with compiler flags (default: see SEGGER_RTT.c)
00081 //#define BUFFER_SIZE_UP                            (1024)  // Size of the buffer for terminal output of target, up to host (Default: 1k)
00082 //#define BUFFER_SIZE_DOWN                          (16)    // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16)
00083 
00084 // configure SEGGER_RTT_PRINTF_BUFFER_SIZE with compiler flags (default: see SEGGER_RTT_printf.c)
00085 //#define SEGGER_RTT_PRINTF_BUFFER_SIZE             (64u)    // Size of buffer for RTT printf to bulk-send chars via RTT     (Default: 64)
00086 
00087 // configure SEGGER_RTT_MODE_DEFAULT with compiler flags, if needed (default: see SEGGER_RTT.c)
00088 //#define SEGGER_RTT_MODE_DEFAULT                   SEGGER_RTT_MODE_NO_BLOCK_SKIP // Mode for pre-initialized terminal channel (buffer 0)
00089 
00090 /*********************************************************************
00091 *
00092 *       RTT memcpy configuration
00093 *
00094 *       memcpy() is good for large amounts of data, 
00095 *       but the overhead is big for small amounts, which are usually stored via RTT.
00096 *       With SEGGER_RTT_MEMCPY_USE_BYTELOOP a simple byte loop can be used instead.
00097 *
00098 *       SEGGER_RTT_MEMCPY() can be used to replace standard memcpy() in RTT functions.
00099 *       This is may be required with memory access restrictions, 
00100 *       such as on Cortex-A devices with MMU.
00101 */
00102 #define SEGGER_RTT_MEMCPY_USE_BYTELOOP              0 // 0: Use memcpy/SEGGER_RTT_MEMCPY, 1: Use a simple byte-loop
00103 //
00104 // Example definition of SEGGER_RTT_MEMCPY to external memcpy with GCC toolchains and Cortex-A targets
00105 //
00106 //#if ((defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__)) && (defined (__ARM_ARCH_7A__))  
00107 //  #define SEGGER_RTT_MEMCPY(pDest, pSrc, NumBytes)      SEGGER_memcpy((pDest), (pSrc), (NumBytes))
00108 //#endif
00109 
00110 //
00111 // Target is not allowed to perform other RTT operations while string still has not been stored completely.
00112 // Otherwise we would probably end up with a mixed string in the buffer.
00113 // If using  RTT from within interrupts, multiple tasks or multi processors, define the SEGGER_RTT_LOCK() and SEGGER_RTT_UNLOCK() function here.
00114 //
00115 // SEGGER_RTT_MAX_INTERRUPT_PRIORITY can be used in the sample lock routines on Cortex-M3/4.
00116 // Make sure to mask all interrupts which can send RTT data, i.e. generate SystemView events, or cause task switches.
00117 // When high-priority interrupts must not be masked while sending RTT data, SEGGER_RTT_MAX_INTERRUPT_PRIORITY needs to be adjusted accordingly.
00118 // (Higher priority = lower priority number)
00119 // Default value for embOS: 128u
00120 // Default configuration in FreeRTOS: configMAX_SYSCALL_INTERRUPT_PRIORITY: ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
00121 // In case of doubt mask all interrupts: 1 << (8 - BASEPRI_PRIO_BITS) i.e. 1 << 5 when 3 bits are implemented in NVIC
00122 // or define SEGGER_RTT_LOCK() to completely disable interrupts.
00123 //
00124 
00125 #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY         (0x20)   // Interrupt priority to lock on SEGGER_RTT_LOCK on Cortex-M3/4 (Default: 0x20)
00126 
00127 /*********************************************************************
00128 *
00129 *       RTT lock configuration for SEGGER Embedded Studio,
00130 *       Rowley CrossStudio and GCC
00131 */
00132 #if (defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__) || (defined __clang__)
00133   #if (defined(__ARM_ARCH_6M__) || defined(__ARM_ARCH_8M_BASE__))
00134     #define SEGGER_RTT_LOCK()   {                                                                   \
00135                                     unsigned int LockState;                                         \
00136                                   __asm volatile ("mrs   %0, primask  \n\t"                         \
00137                                                   "movs  r1, $1       \n\t"                         \
00138                                                   "msr   primask, r1  \n\t"                         \
00139                                                   : "=r" (LockState)                                \
00140                                                   :                                                 \
00141                                                   : "r1"                                            \
00142                                                   );
00143 
00144     #define SEGGER_RTT_UNLOCK()   __asm volatile ("msr   primask, %0  \n\t"                         \
00145                                                   :                                                 \
00146                                                   : "r" (LockState)                                 \
00147                                                   :                                                 \
00148                                                   );                                                \
00149                                 }
00150   #elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_8M_MAIN__))
00151     #ifndef   SEGGER_RTT_MAX_INTERRUPT_PRIORITY
00152       #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY   (0x20)
00153     #endif
00154     #define SEGGER_RTT_LOCK()   {                                                                   \
00155                                     unsigned int LockState;                                         \
00156                                   __asm volatile ("mrs   %0, basepri  \n\t"                         \
00157                                                   "mov   r1, %1       \n\t"                         \
00158                                                   "msr   basepri, r1  \n\t"                         \
00159                                                   : "=r" (LockState)                                \
00160                                                   : "i"(SEGGER_RTT_MAX_INTERRUPT_PRIORITY)          \
00161                                                   : "r1"                                            \
00162                                                   );
00163 
00164     #define SEGGER_RTT_UNLOCK()   __asm volatile ("msr   basepri, %0  \n\t"                         \
00165                                                   :                                                 \
00166                                                   : "r" (LockState)                                 \
00167                                                   :                                                 \
00168                                                   );                                                \
00169                                 }
00170 
00171   #elif defined(__ARM_ARCH_7A__)
00172     #define SEGGER_RTT_LOCK() {                                                \
00173                                  unsigned int LockState;                       \
00174                                  __asm volatile ("mrs r1, CPSR \n\t"           \
00175                                                  "mov %0, r1 \n\t"             \
00176                                                  "orr r1, r1, #0xC0 \n\t"      \
00177                                                  "msr CPSR_c, r1 \n\t"         \
00178                                                  : "=r" (LockState)            \
00179                                                  :                             \
00180                                                  : "r1"                        \
00181                                                  );
00182 
00183     #define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t"              \
00184                                                 "mrs r1, CPSR \n\t"            \
00185                                                 "bic r1, r1, #0xC0 \n\t"       \
00186                                                 "and r0, r0, #0xC0 \n\t"       \
00187                                                 "orr r1, r1, r0 \n\t"          \
00188                                                 "msr CPSR_c, r1 \n\t"          \
00189                                                 :                              \
00190                                                 : "r" (LockState)              \
00191                                                 : "r0", "r1"                   \
00192                                                 );                             \
00193                             }
00194 #else
00195     #define SEGGER_RTT_LOCK()
00196     #define SEGGER_RTT_UNLOCK()
00197   #endif
00198 #endif
00199 
00200 /*********************************************************************
00201 *
00202 *       RTT lock configuration fallback
00203 */
00204 #ifndef   SEGGER_RTT_LOCK
00205   #define SEGGER_RTT_LOCK()                // Lock RTT (nestable)   (i.e. disable interrupts)
00206 #endif
00207 
00208 #ifndef   SEGGER_RTT_UNLOCK
00209   #define SEGGER_RTT_UNLOCK()              // Unlock RTT (nestable) (i.e. enable previous interrupt lock state)
00210 #endif
00211 
00212 #endif
00213 /*************************** End of file ****************************/