1 /*********************************************************************
2 *                SEGGER Microcontroller GmbH & Co. KG                *
3 *                        The Embedded Experts                        *
4 **********************************************************************
5 *                                                                    *
6 *       (c) 2015 - 2017  SEGGER Microcontroller GmbH & Co. KG        *
7 *                                                                    *
8 *       www.segger.com     Support: support@segger.com               *
9 *                                                                    *
10 **********************************************************************
11 *                                                                    *
12 *       SEGGER SystemView * Real-time application analysis           *
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 & Co. KG         *
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 *                                                                    *
55 *       SystemView version: V2.42                                    *
56 *                                                                    *
57 **********************************************************************
58 ---------------------------END-OF-HEADER------------------------------
59 File    : SEGGER_RTT.h
60 Purpose : Implementation of SEGGER real-time transfer which allows
61           real-time communication on targets which support debugger
62           memory accesses while the CPU is running.
63 Revision: $Rev: 5626 $
64 ----------------------------------------------------------------------
65 */
66 
67 #ifndef SEGGER_RTT_H
68 #define SEGGER_RTT_H
69 
70 #include "SEGGER_RTT_Conf.h"
71 
72 /*********************************************************************
73 *
74 *       Defines, fixed
75 *
76 **********************************************************************
77 */
78 
79 /*********************************************************************
80 *
81 *       Types
82 *
83 **********************************************************************
84 */
85 
86 //
87 // Description for a circular buffer (also called "ring buffer")
88 // which is used as up-buffer (T->H)
89 //
90 typedef struct {
91   const     char*    sName;         // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
92             char*    pBuffer;       // Pointer to start of buffer
93             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.
94             unsigned WrOff;         // Position of next item to be written by either target.
95   volatile  unsigned RdOff;         // Position of next item to be read by host. Must be volatile since it may be modified by host.
96             unsigned Flags;         // Contains configuration flags
97 } SEGGER_RTT_BUFFER_UP;
98 
99 //
100 // Description for a circular buffer (also called "ring buffer")
101 // which is used as down-buffer (H->T)
102 //
103 typedef struct {
104   const     char*    sName;         // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
105             char*    pBuffer;       // Pointer to start of buffer
106             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.
107   volatile  unsigned WrOff;         // Position of next item to be written by host. Must be volatile since it may be modified by host.
108             unsigned RdOff;         // Position of next item to be read by target (down-buffer).
109             unsigned Flags;         // Contains configuration flags
110 } SEGGER_RTT_BUFFER_DOWN;
111 
112 //
113 // RTT control block which describes the number of buffers available
114 // as well as the configuration for each buffer
115 //
116 //
117 typedef struct {
118   char                    acID[16];                                 // Initialized to "SEGGER RTT"
119   int                     MaxNumUpBuffers;                          // Initialized to SEGGER_RTT_MAX_NUM_UP_BUFFERS (type. 2)
120   int                     MaxNumDownBuffers;                        // Initialized to SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (type. 2)
121   SEGGER_RTT_BUFFER_UP    aUp[SEGGER_RTT_MAX_NUM_UP_BUFFERS];       // Up buffers, transferring information up from target via debug probe to host
122   SEGGER_RTT_BUFFER_DOWN  aDown[SEGGER_RTT_MAX_NUM_DOWN_BUFFERS];   // Down buffers, transferring information down from host via debug probe to target
123 } SEGGER_RTT_CB;
124 
125 /*********************************************************************
126 *
127 *       Global data
128 *
129 **********************************************************************
130 */
131 extern SEGGER_RTT_CB _SEGGER_RTT;
132 
133 /*********************************************************************
134 *
135 *       RTT API functions
136 *
137 **********************************************************************
138 */
139 #ifdef __cplusplus
140   extern "C" {
141 #endif
142 int          SEGGER_RTT_AllocDownBuffer         (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
143 int          SEGGER_RTT_AllocUpBuffer           (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
144 int          SEGGER_RTT_ConfigUpBuffer          (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
145 int          SEGGER_RTT_ConfigDownBuffer        (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
146 int          SEGGER_RTT_GetKey                  (void);
147 unsigned     SEGGER_RTT_HasData                 (unsigned BufferIndex);
148 int          SEGGER_RTT_HasKey                  (void);
149 void         SEGGER_RTT_Init                    (void);
150 unsigned     SEGGER_RTT_Read                    (unsigned BufferIndex,       void* pBuffer, unsigned BufferSize);
151 unsigned     SEGGER_RTT_ReadNoLock              (unsigned BufferIndex,       void* pData,   unsigned BufferSize);
152 int          SEGGER_RTT_SetNameDownBuffer       (unsigned BufferIndex, const char* sName);
153 int          SEGGER_RTT_SetNameUpBuffer         (unsigned BufferIndex, const char* sName);
154 int          SEGGER_RTT_SetFlagsDownBuffer      (unsigned BufferIndex, unsigned Flags);
155 int          SEGGER_RTT_SetFlagsUpBuffer        (unsigned BufferIndex, unsigned Flags);
156 int          SEGGER_RTT_WaitKey                 (void);
157 unsigned     SEGGER_RTT_Write                   (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
158 unsigned     SEGGER_RTT_WriteNoLock             (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
159 unsigned     SEGGER_RTT_WriteSkipNoLock         (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
160 unsigned     SEGGER_RTT_WriteString             (unsigned BufferIndex, const char* s);
161 void         SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
162 void         SEGGER_RTT_ESP_FlushNoLock       (unsigned long min_sz, unsigned long tmo);
163 void         SEGGER_RTT_ESP_Flush             (unsigned long min_sz, unsigned long tmo);
164 //
165 // Function macro for performance optimization
166 //
167 // @AGv: This macro is used inside SEGGER SystemView code.
168 // For ESP32 we use our own implementation of RTT, so this macro should not check SEGGER's RTT buffer state.
169 #define      SEGGER_RTT_HASDATA(n)       (1)
170 
171 /*********************************************************************
172 *
173 *       RTT "Terminal" API functions
174 *
175 **********************************************************************
176 */
177 int     SEGGER_RTT_SetTerminal        (char TerminalId);
178 int     SEGGER_RTT_TerminalOut        (char TerminalId, const char* s);
179 
180 /*********************************************************************
181 *
182 *       RTT printf functions (require SEGGER_RTT_printf.c)
183 *
184 **********************************************************************
185 */
186 int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...);
187 #ifdef __cplusplus
188   }
189 #endif
190 
191 /*********************************************************************
192 *
193 *       Defines
194 *
195 **********************************************************************
196 */
197 
198 //
199 // Operating modes. Define behavior if buffer is full (not enough space for entire message)
200 //
201 #define SEGGER_RTT_MODE_NO_BLOCK_SKIP         (0U)     // Skip. Do not block, output nothing. (Default)
202 #define SEGGER_RTT_MODE_NO_BLOCK_TRIM         (1U)     // Trim: Do not block, output as much as fits.
203 #define SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL    (2U)     // Block: Wait until there is space in the buffer.
204 #define SEGGER_RTT_MODE_MASK                  (3U)
205 
206 //
207 // Control sequences, based on ANSI.
208 // Can be used to control color, and clear the screen
209 //
210 #define RTT_CTRL_RESET                ""         // Reset to default colors
211 #define RTT_CTRL_CLEAR                ""         // Clear screen, reposition cursor to top left
212 
213 #define RTT_CTRL_TEXT_BLACK           ""
214 #define RTT_CTRL_TEXT_RED             ""
215 #define RTT_CTRL_TEXT_GREEN           ""
216 #define RTT_CTRL_TEXT_YELLOW          ""
217 #define RTT_CTRL_TEXT_BLUE            ""
218 #define RTT_CTRL_TEXT_MAGENTA         ""
219 #define RTT_CTRL_TEXT_CYAN            ""
220 #define RTT_CTRL_TEXT_WHITE           ""
221 
222 #define RTT_CTRL_TEXT_BRIGHT_BLACK    ""
223 #define RTT_CTRL_TEXT_BRIGHT_RED      ""
224 #define RTT_CTRL_TEXT_BRIGHT_GREEN    ""
225 #define RTT_CTRL_TEXT_BRIGHT_YELLOW   ""
226 #define RTT_CTRL_TEXT_BRIGHT_BLUE     ""
227 #define RTT_CTRL_TEXT_BRIGHT_MAGENTA  ""
228 #define RTT_CTRL_TEXT_BRIGHT_CYAN     ""
229 #define RTT_CTRL_TEXT_BRIGHT_WHITE    ""
230 
231 #define RTT_CTRL_BG_BLACK             ""
232 #define RTT_CTRL_BG_RED               ""
233 #define RTT_CTRL_BG_GREEN             ""
234 #define RTT_CTRL_BG_YELLOW            ""
235 #define RTT_CTRL_BG_BLUE              ""
236 #define RTT_CTRL_BG_MAGENTA           ""
237 #define RTT_CTRL_BG_CYAN              ""
238 #define RTT_CTRL_BG_WHITE             ""
239 
240 #define RTT_CTRL_BG_BRIGHT_BLACK      ""
241 #define RTT_CTRL_BG_BRIGHT_RED        ""
242 #define RTT_CTRL_BG_BRIGHT_GREEN      ""
243 #define RTT_CTRL_BG_BRIGHT_YELLOW     ""
244 #define RTT_CTRL_BG_BRIGHT_BLUE       ""
245 #define RTT_CTRL_BG_BRIGHT_MAGENTA    ""
246 #define RTT_CTRL_BG_BRIGHT_CYAN       ""
247 #define RTT_CTRL_BG_BRIGHT_WHITE      ""
248 
249 
250 #endif
251 
252 /*************************** End of file ****************************/
253