Segger rtt lib

Dependents:   acnSensa_LIS acd52832_Indoor_Posit_Peripheral acd52832_Indoor_Posit_Central iBeacon acnsensa ... more

Committer:
jurica238814
Date:
Thu May 31 13:03:29 2018 +0000
Revision:
2:abdc4190029b
Parent:
0:e61e7fc7cfe1
_write function definition removed.

Who changed what in which revision?

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