source: trunk/firmware/RTT - Kopie/SEGGER_RTT.h @ 6

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