Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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