Contiki-NG
segger-rtt.h
1 /*********************************************************************
2 * SEGGER MICROCONTROLLER GmbH & Co. KG *
3 * Solutions for real time microcontroller applications *
4 **********************************************************************
5 * *
6 * (c) 2014 - 2015 SEGGER Microcontroller GmbH & Co. KG *
7 * *
8 * www.segger.com Support: support@segger.com *
9 * *
10 **********************************************************************
11 * *
12 * All rights reserved. *
13 * *
14 * * This software may in its unmodified form be freely redistributed *
15 * in source form. *
16 * * The source code may be modified, provided the source code *
17 * retains the above copyright notice, this list of conditions and *
18 * the following disclaimer. *
19 * * Modified versions of this software in source or linkable form *
20 * may not be distributed without prior consent of SEGGER. *
21 * * This software may only be used for communication with SEGGER *
22 * J-Link debug probes. *
23 * *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
25 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
26 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
28 * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
31 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
32 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
35 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
36 * DAMAGE. *
37 * *
38 **********************************************************************
39 ---------------------------END-OF-HEADER------------------------------
40 File : SEGGER_RTT.h
41 Purpose : Implementation of SEGGER real-time transfer which allows
42  real-time communication on targets which support debugger
43  memory accesses while the CPU is running.
44 ----------------------------------------------------------------------
45 */
46 
47 #ifndef SEGGER_RTT_H
48 #define SEGGER_RTT_H
49 
50 #include "segger-rtt-conf.h"
51 
52 /*********************************************************************
53 *
54 * Defines, fixed
55 *
56 **********************************************************************
57 */
58 
59 /*********************************************************************
60 *
61 * Types
62 *
63 **********************************************************************
64 */
65 
66 //
67 // Description for a circular buffer (also called "ring buffer")
68 // which is used as up- (T->H) or down-buffer (H->T)
69 //
70 typedef struct {
71  const char* sName; // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
72  char* pBuffer; // Pointer to start of buffer
73  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.
74  volatile unsigned WrOff; // Position of next item to be written by either host (down-buffer) or target (up-buffer). Must be volatile since it may be modified by host (down-buffer)
75  volatile unsigned RdOff; // Position of next item to be read by target (down-buffer) or host (up-buffer). Must be volatile since it may be modified by host (up-buffer)
76  unsigned Flags; // Contains configuration flags
77 } SEGGER_RTT_RING_BUFFER;
78 
79 //
80 // RTT control block which describes the number of buffers available
81 // as well as the configuration for each buffer
82 //
83 //
84 typedef struct {
85  char acID[16]; // Initialized to "SEGGER RTT"
86  int MaxNumUpBuffers; // Initialized to SEGGER_RTT_MAX_NUM_UP_BUFFERS (type. 2)
87  int MaxNumDownBuffers; // Initialized to SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (type. 2)
88  SEGGER_RTT_RING_BUFFER aUp[SEGGER_RTT_MAX_NUM_UP_BUFFERS]; // Up buffers, transferring information up from target via debug probe to host
89  SEGGER_RTT_RING_BUFFER aDown[SEGGER_RTT_MAX_NUM_DOWN_BUFFERS]; // Down buffers, transferring information down from host via debug probe to target
90 } SEGGER_RTT_CB;
91 
92 /*********************************************************************
93 *
94 * Global data
95 *
96 **********************************************************************
97 */
98 extern SEGGER_RTT_CB _SEGGER_RTT;
99 
100 /*********************************************************************
101 *
102 * RTT API functions
103 *
104 **********************************************************************
105 */
106 int SEGGER_RTT_ConfigUpBuffer (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
107 int SEGGER_RTT_ConfigDownBuffer (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
108 int SEGGER_RTT_GetKey (void);
109 unsigned SEGGER_RTT_HasData (unsigned BufferIndex);
110 int SEGGER_RTT_HasKey (void);
111 void SEGGER_RTT_Init (void);
112 unsigned SEGGER_RTT_Read (unsigned BufferIndex, void* pBuffer, unsigned BufferSize);
113 unsigned SEGGER_RTT_ReadNoLock (unsigned BufferIndex, void* pData, unsigned BufferSize);
114 int SEGGER_RTT_SetNameDownBuffer(unsigned BufferIndex, const char* sName);
115 int SEGGER_RTT_SetNameUpBuffer (unsigned BufferIndex, const char* sName);
116 int SEGGER_RTT_WaitKey (void);
117 unsigned SEGGER_RTT_Write (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
118 unsigned SEGGER_RTT_WriteNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
119 unsigned SEGGER_RTT_WriteSkipNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
120 unsigned SEGGER_RTT_WriteString (unsigned BufferIndex, const char* s);
121 //
122 // Function macro for performance optimization
123 //
124 #define SEGGER_RTT_HASDATA(n) (_SEGGER_RTT.aDown[n].WrOff - _SEGGER_RTT.aDown[n].RdOff)
125 
126 /*********************************************************************
127 *
128 * RTT "Terminal" API functions
129 *
130 **********************************************************************
131 */
132 int SEGGER_RTT_SetTerminal (char TerminalId);
133 int SEGGER_RTT_TerminalOut (char TerminalId, const char* s);
134 
135 /*********************************************************************
136 *
137 * RTT printf functions (require SEGGER_RTT_printf.c)
138 *
139 **********************************************************************
140 */
141 int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...);
142 
143 /*********************************************************************
144 *
145 * Defines
146 *
147 **********************************************************************
148 */
149 
150 //
151 // Operating modes. Define behavior if buffer is full (not enough space for entire message)
152 //
153 #define SEGGER_RTT_MODE_NO_BLOCK_SKIP (0U) // Skip. Do not block, output nothing. (Default)
154 #define SEGGER_RTT_MODE_NO_BLOCK_TRIM (1U) // Trim: Do not block, output as much as fits.
155 #define SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL (2U) // Block: Wait until there is space in the buffer.
156 #define SEGGER_RTT_MODE_MASK (3U)
157 
158 //
159 // Control sequences, based on ANSI.
160 // Can be used to control color, and clear the screen
161 //
162 #define RTT_CTRL_RESET "\e[0m" // Reset to default colors
163 #define RTT_CTRL_CLEAR "\e[2J" // Clear screen, reposition cursor to top left
164 
165 #define RTT_CTRL_TEXT_BLACK "\e[2;30m"
166 #define RTT_CTRL_TEXT_RED "\e[2;31m"
167 #define RTT_CTRL_TEXT_GREEN "\e[2;32m"
168 #define RTT_CTRL_TEXT_YELLOW "\e[2;33m"
169 #define RTT_CTRL_TEXT_BLUE "\e[2;34m"
170 #define RTT_CTRL_TEXT_MAGENTA "\e[2;35m"
171 #define RTT_CTRL_TEXT_CYAN "\e[2;36m"
172 #define RTT_CTRL_TEXT_WHITE "\e[2;37m"
173 
174 #define RTT_CTRL_TEXT_BRIGHT_BLACK "\e[1;30m"
175 #define RTT_CTRL_TEXT_BRIGHT_RED "\e[1;31m"
176 #define RTT_CTRL_TEXT_BRIGHT_GREEN "\e[1;32m"
177 #define RTT_CTRL_TEXT_BRIGHT_YELLOW "\e[1;33m"
178 #define RTT_CTRL_TEXT_BRIGHT_BLUE "\e[1;34m"
179 #define RTT_CTRL_TEXT_BRIGHT_MAGENTA "\e[1;35m"
180 #define RTT_CTRL_TEXT_BRIGHT_CYAN "\e[1;36m"
181 #define RTT_CTRL_TEXT_BRIGHT_WHITE "\e[1;37m"
182 
183 #define RTT_CTRL_BG_BLACK "\e[24;40m"
184 #define RTT_CTRL_BG_RED "\e[24;41m"
185 #define RTT_CTRL_BG_GREEN "\e[24;42m"
186 #define RTT_CTRL_BG_YELLOW "\e[24;43m"
187 #define RTT_CTRL_BG_BLUE "\e[24;44m"
188 #define RTT_CTRL_BG_MAGENTA "\e[24;45m"
189 #define RTT_CTRL_BG_CYAN "\e[24;46m"
190 #define RTT_CTRL_BG_WHITE "\e[24;47m"
191 
192 #define RTT_CTRL_BG_BRIGHT_BLACK "\e[4;40m"
193 #define RTT_CTRL_BG_BRIGHT_RED "\e[4;41m"
194 #define RTT_CTRL_BG_BRIGHT_GREEN "\e[4;42m"
195 #define RTT_CTRL_BG_BRIGHT_YELLOW "\e[4;43m"
196 #define RTT_CTRL_BG_BRIGHT_BLUE "\e[4;44m"
197 #define RTT_CTRL_BG_BRIGHT_MAGENTA "\e[4;45m"
198 #define RTT_CTRL_BG_BRIGHT_CYAN "\e[4;46m"
199 #define RTT_CTRL_BG_BRIGHT_WHITE "\e[4;47m"
200 
201 
202 #endif
203 
204 /*************************** End of file ****************************/