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.h Source File

SEGGER_RTT.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.h
00060 Purpose : Implementation of SEGGER real-time transfer which allows
00061           real-time communication on targets which support debugger 
00062           memory accesses while the CPU is running.
00063 Revision: Rev: 13430
00064 ----------------------------------------------------------------------
00065 */
00066 
00067 #ifndef SEGGER_RTT_H
00068 #define SEGGER_RTT_H
00069 
00070 #include "SEGGER_RTT_Conf.h"
00071 
00072 
00073 
00074 /*********************************************************************
00075 *
00076 *       Defines, defaults
00077 *
00078 **********************************************************************
00079 */
00080 #ifndef RTT_USE_ASM
00081   #if ((defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__) || (defined __clang__)) && (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_8M_MAIN__))
00082     #define RTT_USE_ASM                           (1)
00083   #else
00084     #define RTT_USE_ASM                           (0)
00085   #endif
00086 #endif
00087 
00088 #ifndef SEGGER_RTT_ASM  // defined when SEGGER_RTT.h is included from assembly file
00089 #include <stdlib.h>
00090 #include <stdarg.h>
00091 
00092 /*********************************************************************
00093 *
00094 *       Defines, fixed
00095 *
00096 **********************************************************************
00097 */
00098 
00099 /*********************************************************************
00100 *
00101 *       Types
00102 *
00103 **********************************************************************
00104 */
00105 
00106 //
00107 // Description for a circular buffer (also called "ring buffer")
00108 // which is used as up-buffer (T->H)
00109 //
00110 typedef struct {
00111   const     char*    sName;         // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
00112             char*    pBuffer;       // Pointer to start of buffer
00113             unsigned SizeOfBuffer;  // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty.
00114             unsigned WrOff;         // Position of next item to be written by either target.
00115   volatile  unsigned RdOff;         // Position of next item to be read by host. Must be volatile since it may be modified by host.
00116             unsigned Flags;         // Contains configuration flags
00117 } SEGGER_RTT_BUFFER_UP;
00118 
00119 //
00120 // Description for a circular buffer (also called "ring buffer")
00121 // which is used as down-buffer (H->T)
00122 //
00123 typedef struct {
00124   const     char*    sName;         // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
00125             char*    pBuffer;       // Pointer to start of buffer
00126             unsigned SizeOfBuffer;  // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty.
00127   volatile  unsigned WrOff;         // Position of next item to be written by host. Must be volatile since it may be modified by host.
00128             unsigned RdOff;         // Position of next item to be read by target (down-buffer).
00129             unsigned Flags;         // Contains configuration flags
00130 } SEGGER_RTT_BUFFER_DOWN;
00131 
00132 //
00133 // RTT control block which describes the number of buffers available
00134 // as well as the configuration for each buffer
00135 //
00136 //
00137 typedef struct {
00138   char                    acID[16];                                 // Initialized to "SEGGER RTT"
00139   int                     MaxNumUpBuffers;                          // Initialized to SEGGER_RTT_MAX_NUM_UP_BUFFERS (type. 2)
00140   int                     MaxNumDownBuffers;                        // Initialized to SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (type. 2)
00141   SEGGER_RTT_BUFFER_UP    aUp[SEGGER_RTT_MAX_NUM_UP_BUFFERS];       // Up buffers, transferring information up from target via debug probe to host
00142   SEGGER_RTT_BUFFER_DOWN  aDown[SEGGER_RTT_MAX_NUM_DOWN_BUFFERS];   // Down buffers, transferring information down from host via debug probe to target
00143 } SEGGER_RTT_CB;
00144 
00145 /*********************************************************************
00146 *
00147 *       Global data
00148 *
00149 **********************************************************************
00150 */
00151 extern SEGGER_RTT_CB _SEGGER_RTT;
00152 
00153 /*********************************************************************
00154 *
00155 *       RTT API functions
00156 *
00157 **********************************************************************
00158 */
00159 #ifdef __cplusplus
00160   extern "C" {
00161 #endif
00162 int          SEGGER_RTT_AllocDownBuffer         (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
00163 int          SEGGER_RTT_AllocUpBuffer           (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
00164 int          SEGGER_RTT_ConfigUpBuffer          (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
00165 int          SEGGER_RTT_ConfigDownBuffer        (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
00166 int          SEGGER_RTT_GetKey                  (void);
00167 unsigned     SEGGER_RTT_HasData                 (unsigned BufferIndex);
00168 int          SEGGER_RTT_HasKey                  (void);
00169 unsigned     SEGGER_RTT_HasDataUp               (unsigned BufferIndex);
00170 void         SEGGER_RTT_Init                    (void);
00171 unsigned     SEGGER_RTT_Read                    (unsigned BufferIndex,       void* pBuffer, unsigned BufferSize);
00172 unsigned     SEGGER_RTT_ReadNoLock              (unsigned BufferIndex,       void* pData,   unsigned BufferSize);
00173 int          SEGGER_RTT_SetNameDownBuffer       (unsigned BufferIndex, const char* sName);
00174 int          SEGGER_RTT_SetNameUpBuffer         (unsigned BufferIndex, const char* sName);
00175 int          SEGGER_RTT_SetFlagsDownBuffer      (unsigned BufferIndex, unsigned Flags);
00176 int          SEGGER_RTT_SetFlagsUpBuffer        (unsigned BufferIndex, unsigned Flags);
00177 int          SEGGER_RTT_WaitKey                 (void);
00178 unsigned     SEGGER_RTT_Write                   (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
00179 unsigned     SEGGER_RTT_WriteNoLock             (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
00180 unsigned     SEGGER_RTT_WriteSkipNoLock         (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
00181 unsigned     SEGGER_RTT_ASM_WriteSkipNoLock     (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
00182 unsigned     SEGGER_RTT_WriteString             (unsigned BufferIndex, const char* s);
00183 void         SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
00184 unsigned     SEGGER_RTT_PutChar                 (unsigned BufferIndex, char c);
00185 unsigned     SEGGER_RTT_PutCharSkip             (unsigned BufferIndex, char c);
00186 unsigned     SEGGER_RTT_PutCharSkipNoLock       (unsigned BufferIndex, char c);
00187 //
00188 // Function macro for performance optimization
00189 //
00190 #define      SEGGER_RTT_HASDATA(n)       (_SEGGER_RTT.aDown[n].WrOff - _SEGGER_RTT.aDown[n].RdOff)
00191 
00192 #if RTT_USE_ASM
00193   #define SEGGER_RTT_WriteSkipNoLock  SEGGER_RTT_ASM_WriteSkipNoLock
00194 #endif
00195 
00196 /*********************************************************************
00197 *
00198 *       RTT "Terminal" API functions
00199 *
00200 **********************************************************************
00201 */
00202 int     SEGGER_RTT_SetTerminal        (char TerminalId);
00203 int     SEGGER_RTT_TerminalOut        (char TerminalId, const char* s);
00204 
00205 /*********************************************************************
00206 *
00207 *       RTT printf functions (require SEGGER_RTT_printf.c)
00208 *
00209 **********************************************************************
00210 */
00211 int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...);
00212 int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList);
00213 
00214 #ifdef __cplusplus
00215   }
00216 #endif
00217 
00218 #endif // ifndef(SEGGER_RTT_ASM)
00219 
00220 /*********************************************************************
00221 *
00222 *       Defines
00223 *
00224 **********************************************************************
00225 */
00226 
00227 //
00228 // Operating modes. Define behavior if buffer is full (not enough space for entire message)
00229 //
00230 #define SEGGER_RTT_MODE_NO_BLOCK_SKIP         (0)     // Skip. Do not block, output nothing. (Default)
00231 #define SEGGER_RTT_MODE_NO_BLOCK_TRIM         (1)     // Trim: Do not block, output as much as fits.
00232 #define SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL    (2)     // Block: Wait until there is space in the buffer.
00233 #define SEGGER_RTT_MODE_MASK                  (3)
00234 
00235 //
00236 // Control sequences, based on ANSI.
00237 // Can be used to control color, and clear the screen
00238 //
00239 #define RTT_CTRL_RESET                "\x1B[0m"         // Reset to default colors
00240 #define RTT_CTRL_CLEAR                "\x1B[2J"         // Clear screen, reposition cursor to top left
00241 
00242 #define RTT_CTRL_TEXT_BLACK           "\x1B[2;30m"
00243 #define RTT_CTRL_TEXT_RED             "\x1B[2;31m"
00244 #define RTT_CTRL_TEXT_GREEN           "\x1B[2;32m"
00245 #define RTT_CTRL_TEXT_YELLOW          "\x1B[2;33m"
00246 #define RTT_CTRL_TEXT_BLUE            "\x1B[2;34m"
00247 #define RTT_CTRL_TEXT_MAGENTA         "\x1B[2;35m"
00248 #define RTT_CTRL_TEXT_CYAN            "\x1B[2;36m"
00249 #define RTT_CTRL_TEXT_WHITE           "\x1B[2;37m"
00250 
00251 #define RTT_CTRL_TEXT_BRIGHT_BLACK    "\x1B[1;30m"
00252 #define RTT_CTRL_TEXT_BRIGHT_RED      "\x1B[1;31m"
00253 #define RTT_CTRL_TEXT_BRIGHT_GREEN    "\x1B[1;32m"
00254 #define RTT_CTRL_TEXT_BRIGHT_YELLOW   "\x1B[1;33m"
00255 #define RTT_CTRL_TEXT_BRIGHT_BLUE     "\x1B[1;34m"
00256 #define RTT_CTRL_TEXT_BRIGHT_MAGENTA  "\x1B[1;35m"
00257 #define RTT_CTRL_TEXT_BRIGHT_CYAN     "\x1B[1;36m"
00258 #define RTT_CTRL_TEXT_BRIGHT_WHITE    "\x1B[1;37m"
00259 
00260 #define RTT_CTRL_BG_BLACK             "\x1B[24;40m"
00261 #define RTT_CTRL_BG_RED               "\x1B[24;41m"
00262 #define RTT_CTRL_BG_GREEN             "\x1B[24;42m"
00263 #define RTT_CTRL_BG_YELLOW            "\x1B[24;43m"
00264 #define RTT_CTRL_BG_BLUE              "\x1B[24;44m"
00265 #define RTT_CTRL_BG_MAGENTA           "\x1B[24;45m"
00266 #define RTT_CTRL_BG_CYAN              "\x1B[24;46m"
00267 #define RTT_CTRL_BG_WHITE             "\x1B[24;47m"
00268 
00269 #define RTT_CTRL_BG_BRIGHT_BLACK      "\x1B[4;40m"
00270 #define RTT_CTRL_BG_BRIGHT_RED        "\x1B[4;41m"
00271 #define RTT_CTRL_BG_BRIGHT_GREEN      "\x1B[4;42m"
00272 #define RTT_CTRL_BG_BRIGHT_YELLOW     "\x1B[4;43m"
00273 #define RTT_CTRL_BG_BRIGHT_BLUE       "\x1B[4;44m"
00274 #define RTT_CTRL_BG_BRIGHT_MAGENTA    "\x1B[4;45m"
00275 #define RTT_CTRL_BG_BRIGHT_CYAN       "\x1B[4;46m"
00276 #define RTT_CTRL_BG_BRIGHT_WHITE      "\x1B[4;47m"
00277 
00278 
00279 #endif
00280 
00281 /*************************** End of file ****************************/