SEGGER_RTT.h 11 KB

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