SEGGER_RTT.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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. * condition is met: *
  25. * *
  26. * o Redistributions of source code must retain the above copyright *
  27. * notice, this condition and the following disclaimer. *
  28. * *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
  32. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
  33. * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
  34. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
  35. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
  36. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
  37. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
  38. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
  39. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
  40. * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
  41. * DAMAGE. *
  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: 25842 $
  50. ----------------------------------------------------------------------
  51. */
  52. #ifndef SEGGER_RTT_H
  53. #define SEGGER_RTT_H
  54. #include "SEGGER_RTT_Conf.h"
  55. /*********************************************************************
  56. *
  57. * Defines, defaults
  58. *
  59. **********************************************************************
  60. */
  61. #ifndef RTT_USE_ASM
  62. //
  63. // Some cores support out-of-order memory accesses (reordering of memory accesses in the core)
  64. // For such cores, we need to define a memory barrier to guarantee the order of certain accesses to the RTT ring buffers.
  65. // Needed for:
  66. // Cortex-M7 (ARMv7-M)
  67. // Cortex-M23 (ARM-v8M)
  68. // Cortex-M33 (ARM-v8M)
  69. // Cortex-A/R (ARM-v7A/R)
  70. //
  71. // We do not explicitly check for "Embedded Studio" as the compiler in use determines what we support.
  72. // You can use an external toolchain like IAR inside ES. So there is no point in checking for "Embedded Studio"
  73. //
  74. #if (defined __CROSSWORKS_ARM) // Rowley Crossworks
  75. #define _CC_HAS_RTT_ASM_SUPPORT 1
  76. #if (defined __ARM_ARCH_7M__) // Cortex-M3
  77. #define _CORE_HAS_RTT_ASM_SUPPORT 1
  78. #elif (defined __ARM_ARCH_7EM__) // Cortex-M4/M7
  79. #define _CORE_HAS_RTT_ASM_SUPPORT 1
  80. #define _CORE_NEEDS_DMB 1
  81. #define RTT__DMB() __asm volatile ("dmb\n" : : :);
  82. #elif (defined __ARM_ARCH_8M_BASE__) // Cortex-M23
  83. #define _CORE_HAS_RTT_ASM_SUPPORT 0
  84. #define _CORE_NEEDS_DMB 1
  85. #define RTT__DMB() __asm volatile ("dmb\n" : : :);
  86. #elif (defined __ARM_ARCH_8M_MAIN__) // Cortex-M33
  87. #define _CORE_HAS_RTT_ASM_SUPPORT 1
  88. #define _CORE_NEEDS_DMB 1
  89. #define RTT__DMB() __asm volatile ("dmb\n" : : :);
  90. #else
  91. #define _CORE_HAS_RTT_ASM_SUPPORT 0
  92. #endif
  93. #elif (defined __ARMCC_VERSION)
  94. //
  95. // ARM compiler
  96. // ARM compiler V6.0 and later is clang based.
  97. // Our ASM part is compatible to clang.
  98. //
  99. #if (__ARMCC_VERSION >= 6000000)
  100. #define _CC_HAS_RTT_ASM_SUPPORT 1
  101. #else
  102. #define _CC_HAS_RTT_ASM_SUPPORT 0
  103. #endif
  104. #if (defined __ARM_ARCH_6M__) // Cortex-M0 / M1
  105. #define _CORE_HAS_RTT_ASM_SUPPORT 0 // No ASM support for this architecture
  106. #elif (defined __ARM_ARCH_7M__) // Cortex-M3
  107. #define _CORE_HAS_RTT_ASM_SUPPORT 1
  108. #elif (defined __ARM_ARCH_7EM__) // Cortex-M4/M7
  109. #define _CORE_HAS_RTT_ASM_SUPPORT 1
  110. #define _CORE_NEEDS_DMB 1
  111. #define RTT__DMB() __asm volatile ("dmb\n" : : :);
  112. #elif (defined __ARM_ARCH_8M_BASE__) // Cortex-M23
  113. #define _CORE_HAS_RTT_ASM_SUPPORT 0
  114. #define _CORE_NEEDS_DMB 1
  115. #define RTT__DMB() __asm volatile ("dmb\n" : : :);
  116. #elif (defined __ARM_ARCH_8M_MAIN__) // Cortex-M33
  117. #define _CORE_HAS_RTT_ASM_SUPPORT 1
  118. #define _CORE_NEEDS_DMB 1
  119. #define RTT__DMB() __asm volatile ("dmb\n" : : :);
  120. #elif ((defined __ARM_ARCH_7A__) || (defined __ARM_ARCH_7R__)) // Cortex-A/R 32-bit ARMv7-A/R
  121. #define _CORE_NEEDS_DMB 1
  122. #define RTT__DMB() __asm volatile ("dmb\n" : : :);
  123. #else
  124. #define _CORE_HAS_RTT_ASM_SUPPORT 0
  125. #endif
  126. #elif ((defined __GNUC__) || (defined __clang__))
  127. //
  128. // GCC / Clang
  129. //
  130. #define _CC_HAS_RTT_ASM_SUPPORT 1
  131. // ARM 7/9: __ARM_ARCH_5__ / __ARM_ARCH_5E__ / __ARM_ARCH_5T__ / __ARM_ARCH_5T__ / __ARM_ARCH_5TE__
  132. #if (defined __ARM_ARCH_7M__) // Cortex-M3
  133. #define _CORE_HAS_RTT_ASM_SUPPORT 1
  134. #elif (defined __ARM_ARCH_7EM__) // Cortex-M4/M7
  135. #define _CORE_HAS_RTT_ASM_SUPPORT 1
  136. #define _CORE_NEEDS_DMB 1 // Only Cortex-M7 needs a DMB but we cannot distinguish M4 and M7 here...
  137. #define RTT__DMB() __asm volatile ("dmb\n" : : :);
  138. #elif (defined __ARM_ARCH_8M_BASE__) // Cortex-M23
  139. #define _CORE_HAS_RTT_ASM_SUPPORT 0
  140. #define _CORE_NEEDS_DMB 1
  141. #define RTT__DMB() __asm volatile ("dmb\n" : : :);
  142. #elif (defined __ARM_ARCH_8M_MAIN__) // Cortex-M33
  143. #define _CORE_HAS_RTT_ASM_SUPPORT 1
  144. #define _CORE_NEEDS_DMB 1
  145. #define RTT__DMB() __asm volatile ("dmb\n" : : :);
  146. #elif ((defined __ARM_ARCH_7A__) || (defined __ARM_ARCH_7R__)) // Cortex-A/R 32-bit ARMv7-A/R
  147. #define _CORE_NEEDS_DMB 1
  148. #define RTT__DMB() __asm volatile ("dmb\n" : : :);
  149. #else
  150. #define _CORE_HAS_RTT_ASM_SUPPORT 0
  151. #endif
  152. #elif ((defined __IASMARM__) || (defined __ICCARM__))
  153. //
  154. // IAR assembler/compiler
  155. //
  156. #define _CC_HAS_RTT_ASM_SUPPORT 1
  157. #if (__VER__ < 6300000)
  158. #define VOLATILE
  159. #else
  160. #define VOLATILE volatile
  161. #endif
  162. #if (defined __ARM7M__) // Needed for old versions that do not know the define yet
  163. #if (__CORE__ == __ARM7M__) // Cortex-M3
  164. #define _CORE_HAS_RTT_ASM_SUPPORT 1
  165. #endif
  166. #endif
  167. #if (defined __ARM7EM__)
  168. #if (__CORE__ == __ARM7EM__) // Cortex-M4/M7
  169. #define _CORE_HAS_RTT_ASM_SUPPORT 1
  170. #define _CORE_NEEDS_DMB 1
  171. #define RTT__DMB() asm VOLATILE ("DMB");
  172. #endif
  173. #endif
  174. #if (defined __ARM8M_BASELINE__)
  175. #if (__CORE__ == __ARM8M_BASELINE__) // Cortex-M23
  176. #define _CORE_HAS_RTT_ASM_SUPPORT 0
  177. #define _CORE_NEEDS_DMB 1
  178. #define RTT__DMB() asm VOLATILE ("DMB");
  179. #endif
  180. #endif
  181. #if (defined __ARM8M_MAINLINE__)
  182. #if (__CORE__ == __ARM8M_MAINLINE__) // Cortex-M33
  183. #define _CORE_HAS_RTT_ASM_SUPPORT 1
  184. #define _CORE_NEEDS_DMB 1
  185. #define RTT__DMB() asm VOLATILE ("DMB");
  186. #endif
  187. #endif
  188. #if (defined __ARM8EM_MAINLINE__)
  189. #if (__CORE__ == __ARM8EM_MAINLINE__) // Cortex-???
  190. #define _CORE_HAS_RTT_ASM_SUPPORT 1
  191. #define _CORE_NEEDS_DMB 1
  192. #define RTT__DMB() asm VOLATILE ("DMB");
  193. #endif
  194. #endif
  195. #if (defined __ARM7A__)
  196. #if (__CORE__ == __ARM7A__) // Cortex-A 32-bit ARMv7-A
  197. #define _CORE_NEEDS_DMB 1
  198. #define RTT__DMB() asm VOLATILE ("DMB");
  199. #endif
  200. #endif
  201. #if (defined __ARM7R__)
  202. #if (__CORE__ == __ARM7R__) // Cortex-R 32-bit ARMv7-R
  203. #define _CORE_NEEDS_DMB 1
  204. #define RTT__DMB() asm VOLATILE ("DMB");
  205. #endif
  206. #endif
  207. // TBD: __ARM8A__ => Cortex-A 64-bit ARMv8-A
  208. // TBD: __ARM8R__ => Cortex-R 64-bit ARMv8-R
  209. #else
  210. //
  211. // Other compilers
  212. //
  213. #define _CC_HAS_RTT_ASM_SUPPORT 0
  214. #define _CORE_HAS_RTT_ASM_SUPPORT 0
  215. #endif
  216. //
  217. // If IDE and core support the ASM version, enable ASM version by default
  218. //
  219. #ifndef _CORE_HAS_RTT_ASM_SUPPORT
  220. #define _CORE_HAS_RTT_ASM_SUPPORT 0 // Default for unknown cores
  221. #endif
  222. #if (_CC_HAS_RTT_ASM_SUPPORT && _CORE_HAS_RTT_ASM_SUPPORT)
  223. #define RTT_USE_ASM (1)
  224. #else
  225. #define RTT_USE_ASM (0)
  226. #endif
  227. #endif
  228. #ifndef _CORE_NEEDS_DMB
  229. #define _CORE_NEEDS_DMB 0
  230. #endif
  231. #ifndef RTT__DMB
  232. #if _CORE_NEEDS_DMB
  233. #error "Don't know how to place inline assembly for DMB"
  234. #else
  235. #define RTT__DMB()
  236. #endif
  237. #endif
  238. #ifndef SEGGER_RTT_CPU_CACHE_LINE_SIZE
  239. #define SEGGER_RTT_CPU_CACHE_LINE_SIZE (0) // On most target systems where RTT is used, we do not have a CPU cache, therefore 0 is a good default here
  240. #endif
  241. #ifndef SEGGER_RTT_UNCACHED_OFF
  242. #if SEGGER_RTT_CPU_CACHE_LINE_SIZE
  243. #error "SEGGER_RTT_UNCACHED_OFF must be defined when setting SEGGER_RTT_CPU_CACHE_LINE_SIZE != 0"
  244. #else
  245. #define SEGGER_RTT_UNCACHED_OFF (0)
  246. #endif
  247. #endif
  248. #if RTT_USE_ASM
  249. #if SEGGER_RTT_CPU_CACHE_LINE_SIZE
  250. #error "RTT_USE_ASM is not available if SEGGER_RTT_CPU_CACHE_LINE_SIZE != 0"
  251. #endif
  252. #endif
  253. #ifndef SEGGER_RTT_ASM // defined when SEGGER_RTT.h is included from assembly file
  254. #include <stdlib.h>
  255. #include <stdarg.h>
  256. /*********************************************************************
  257. *
  258. * Defines, fixed
  259. *
  260. **********************************************************************
  261. */
  262. //
  263. // Determine how much we must pad the control block to make it a multiple of a cache line in size
  264. // Assuming: U8 = 1B
  265. // U16 = 2B
  266. // U32 = 4B
  267. // U8/U16/U32* = 4B
  268. //
  269. #if SEGGER_RTT_CPU_CACHE_LINE_SIZE // Avoid division by zero in case we do not have any cache
  270. #define SEGGER_RTT__ROUND_UP_2_CACHE_LINE_SIZE(NumBytes) (((NumBytes + SEGGER_RTT_CPU_CACHE_LINE_SIZE - 1) / SEGGER_RTT_CPU_CACHE_LINE_SIZE) * SEGGER_RTT_CPU_CACHE_LINE_SIZE)
  271. #else
  272. #define SEGGER_RTT__ROUND_UP_2_CACHE_LINE_SIZE(NumBytes) (NumBytes)
  273. #endif
  274. #define SEGGER_RTT__CB_SIZE (16 + 4 + 4 + (SEGGER_RTT_MAX_NUM_UP_BUFFERS * 24) + (SEGGER_RTT_MAX_NUM_DOWN_BUFFERS * 24))
  275. #define SEGGER_RTT__CB_PADDING (SEGGER_RTT__ROUND_UP_2_CACHE_LINE_SIZE(SEGGER_RTT__CB_SIZE) - SEGGER_RTT__CB_SIZE)
  276. /*********************************************************************
  277. *
  278. * Types
  279. *
  280. **********************************************************************
  281. */
  282. //
  283. // Description for a circular buffer (also called "ring buffer")
  284. // which is used as up-buffer (T->H)
  285. //
  286. typedef struct {
  287. const char* sName; // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
  288. char* pBuffer; // Pointer to start of buffer
  289. 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.
  290. unsigned WrOff; // Position of next item to be written by either target.
  291. volatile unsigned RdOff; // Position of next item to be read by host. Must be volatile since it may be modified by host.
  292. unsigned Flags; // Contains configuration flags. Flags[31:24] are used for validity check and must be zero. Flags[23:2] are reserved for future use. Flags[1:0] = RTT operating mode.
  293. } SEGGER_RTT_BUFFER_UP;
  294. //
  295. // Description for a circular buffer (also called "ring buffer")
  296. // which is used as down-buffer (H->T)
  297. //
  298. typedef struct {
  299. const char* sName; // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
  300. char* pBuffer; // Pointer to start of buffer
  301. 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.
  302. volatile unsigned WrOff; // Position of next item to be written by host. Must be volatile since it may be modified by host.
  303. unsigned RdOff; // Position of next item to be read by target (down-buffer).
  304. unsigned Flags; // Contains configuration flags. Flags[31:24] are used for validity check and must be zero. Flags[23:2] are reserved for future use. Flags[1:0] = RTT operating mode.
  305. } SEGGER_RTT_BUFFER_DOWN;
  306. //
  307. // RTT control block which describes the number of buffers available
  308. // as well as the configuration for each buffer
  309. //
  310. //
  311. typedef struct {
  312. char acID[16]; // Initialized to "SEGGER RTT"
  313. int MaxNumUpBuffers; // Initialized to SEGGER_RTT_MAX_NUM_UP_BUFFERS (type. 2)
  314. int MaxNumDownBuffers; // Initialized to SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (type. 2)
  315. SEGGER_RTT_BUFFER_UP aUp[SEGGER_RTT_MAX_NUM_UP_BUFFERS]; // Up buffers, transferring information up from target via debug probe to host
  316. SEGGER_RTT_BUFFER_DOWN aDown[SEGGER_RTT_MAX_NUM_DOWN_BUFFERS]; // Down buffers, transferring information down from host via debug probe to target
  317. #if SEGGER_RTT__CB_PADDING
  318. unsigned char aDummy[SEGGER_RTT__CB_PADDING];
  319. #endif
  320. } SEGGER_RTT_CB;
  321. /*********************************************************************
  322. *
  323. * Global data
  324. *
  325. **********************************************************************
  326. */
  327. extern SEGGER_RTT_CB _SEGGER_RTT;
  328. /*********************************************************************
  329. *
  330. * RTT API functions
  331. *
  332. **********************************************************************
  333. */
  334. #ifdef __cplusplus
  335. extern "C" {
  336. #endif
  337. int SEGGER_RTT_AllocDownBuffer (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
  338. int SEGGER_RTT_AllocUpBuffer (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
  339. int SEGGER_RTT_ConfigUpBuffer (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
  340. int SEGGER_RTT_ConfigDownBuffer (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
  341. int SEGGER_RTT_GetKey (void);
  342. unsigned SEGGER_RTT_HasData (unsigned BufferIndex);
  343. int SEGGER_RTT_HasKey (void);
  344. unsigned SEGGER_RTT_HasDataUp (unsigned BufferIndex);
  345. void SEGGER_RTT_Init (void);
  346. unsigned SEGGER_RTT_Read (unsigned BufferIndex, void* pBuffer, unsigned BufferSize);
  347. unsigned SEGGER_RTT_ReadNoLock (unsigned BufferIndex, void* pData, unsigned BufferSize);
  348. int SEGGER_RTT_SetNameDownBuffer (unsigned BufferIndex, const char* sName);
  349. int SEGGER_RTT_SetNameUpBuffer (unsigned BufferIndex, const char* sName);
  350. int SEGGER_RTT_SetFlagsDownBuffer (unsigned BufferIndex, unsigned Flags);
  351. int SEGGER_RTT_SetFlagsUpBuffer (unsigned BufferIndex, unsigned Flags);
  352. int SEGGER_RTT_WaitKey (void);
  353. unsigned SEGGER_RTT_Write (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
  354. unsigned SEGGER_RTT_WriteNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
  355. unsigned SEGGER_RTT_WriteSkipNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
  356. unsigned SEGGER_RTT_ASM_WriteSkipNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
  357. unsigned SEGGER_RTT_WriteString (unsigned BufferIndex, const char* s);
  358. void SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
  359. unsigned SEGGER_RTT_PutChar (unsigned BufferIndex, char c);
  360. unsigned SEGGER_RTT_PutCharSkip (unsigned BufferIndex, char c);
  361. unsigned SEGGER_RTT_PutCharSkipNoLock (unsigned BufferIndex, char c);
  362. unsigned SEGGER_RTT_GetAvailWriteSpace (unsigned BufferIndex);
  363. unsigned SEGGER_RTT_GetBytesInBuffer (unsigned BufferIndex);
  364. //
  365. // Function macro for performance optimization
  366. //
  367. #define SEGGER_RTT_HASDATA(n) (((SEGGER_RTT_BUFFER_DOWN*)((char*)&_SEGGER_RTT.aDown[n] + SEGGER_RTT_UNCACHED_OFF))->WrOff - ((SEGGER_RTT_BUFFER_DOWN*)((char*)&_SEGGER_RTT.aDown[n] + SEGGER_RTT_UNCACHED_OFF))->RdOff)
  368. #if RTT_USE_ASM
  369. #define SEGGER_RTT_WriteSkipNoLock SEGGER_RTT_ASM_WriteSkipNoLock
  370. #endif
  371. /*********************************************************************
  372. *
  373. * RTT transfer functions to send RTT data via other channels.
  374. *
  375. **********************************************************************
  376. */
  377. unsigned SEGGER_RTT_ReadUpBuffer (unsigned BufferIndex, void* pBuffer, unsigned BufferSize);
  378. unsigned SEGGER_RTT_ReadUpBufferNoLock (unsigned BufferIndex, void* pData, unsigned BufferSize);
  379. unsigned SEGGER_RTT_WriteDownBuffer (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
  380. unsigned SEGGER_RTT_WriteDownBufferNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
  381. #define SEGGER_RTT_HASDATA_UP(n) (((SEGGER_RTT_BUFFER_UP*)((char*)&_SEGGER_RTT.aUp[n] + SEGGER_RTT_UNCACHED_OFF))->WrOff - ((SEGGER_RTT_BUFFER_UP*)((char*)&_SEGGER_RTT.aUp[n] + SEGGER_RTT_UNCACHED_OFF))->RdOff) // Access uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly
  382. /*********************************************************************
  383. *
  384. * RTT "Terminal" API functions
  385. *
  386. **********************************************************************
  387. */
  388. int SEGGER_RTT_SetTerminal (unsigned char TerminalId);
  389. int SEGGER_RTT_TerminalOut (unsigned char TerminalId, const char* s);
  390. /*********************************************************************
  391. *
  392. * RTT printf functions (require SEGGER_RTT_printf.c)
  393. *
  394. **********************************************************************
  395. */
  396. int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...);
  397. int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList);
  398. #ifdef __cplusplus
  399. }
  400. #endif
  401. #endif // ifndef(SEGGER_RTT_ASM)
  402. /*********************************************************************
  403. *
  404. * Defines
  405. *
  406. **********************************************************************
  407. */
  408. //
  409. // Operating modes. Define behavior if buffer is full (not enough space for entire message)
  410. //
  411. #define SEGGER_RTT_MODE_NO_BLOCK_SKIP (0) // Skip. Do not block, output nothing. (Default)
  412. #define SEGGER_RTT_MODE_NO_BLOCK_TRIM (1) // Trim: Do not block, output as much as fits.
  413. #define SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL (2) // Block: Wait until there is space in the buffer.
  414. #define SEGGER_RTT_MODE_MASK (3)
  415. //
  416. // Control sequences, based on ANSI.
  417. // Can be used to control color, and clear the screen
  418. //
  419. #define RTT_CTRL_RESET "\x1B[0m" // Reset to default colors
  420. #define RTT_CTRL_CLEAR "\x1B[2J" // Clear screen, reposition cursor to top left
  421. #define RTT_CTRL_TEXT_BLACK "\x1B[2;30m"
  422. #define RTT_CTRL_TEXT_RED "\x1B[2;31m"
  423. #define RTT_CTRL_TEXT_GREEN "\x1B[2;32m"
  424. #define RTT_CTRL_TEXT_YELLOW "\x1B[2;33m"
  425. #define RTT_CTRL_TEXT_BLUE "\x1B[2;34m"
  426. #define RTT_CTRL_TEXT_MAGENTA "\x1B[2;35m"
  427. #define RTT_CTRL_TEXT_CYAN "\x1B[2;36m"
  428. #define RTT_CTRL_TEXT_WHITE "\x1B[2;37m"
  429. #define RTT_CTRL_TEXT_BRIGHT_BLACK "\x1B[1;30m"
  430. #define RTT_CTRL_TEXT_BRIGHT_RED "\x1B[1;31m"
  431. #define RTT_CTRL_TEXT_BRIGHT_GREEN "\x1B[1;32m"
  432. #define RTT_CTRL_TEXT_BRIGHT_YELLOW "\x1B[1;33m"
  433. #define RTT_CTRL_TEXT_BRIGHT_BLUE "\x1B[1;34m"
  434. #define RTT_CTRL_TEXT_BRIGHT_MAGENTA "\x1B[1;35m"
  435. #define RTT_CTRL_TEXT_BRIGHT_CYAN "\x1B[1;36m"
  436. #define RTT_CTRL_TEXT_BRIGHT_WHITE "\x1B[1;37m"
  437. #define RTT_CTRL_BG_BLACK "\x1B[24;40m"
  438. #define RTT_CTRL_BG_RED "\x1B[24;41m"
  439. #define RTT_CTRL_BG_GREEN "\x1B[24;42m"
  440. #define RTT_CTRL_BG_YELLOW "\x1B[24;43m"
  441. #define RTT_CTRL_BG_BLUE "\x1B[24;44m"
  442. #define RTT_CTRL_BG_MAGENTA "\x1B[24;45m"
  443. #define RTT_CTRL_BG_CYAN "\x1B[24;46m"
  444. #define RTT_CTRL_BG_WHITE "\x1B[24;47m"
  445. #define RTT_CTRL_BG_BRIGHT_BLACK "\x1B[4;40m"
  446. #define RTT_CTRL_BG_BRIGHT_RED "\x1B[4;41m"
  447. #define RTT_CTRL_BG_BRIGHT_GREEN "\x1B[4;42m"
  448. #define RTT_CTRL_BG_BRIGHT_YELLOW "\x1B[4;43m"
  449. #define RTT_CTRL_BG_BRIGHT_BLUE "\x1B[4;44m"
  450. #define RTT_CTRL_BG_BRIGHT_MAGENTA "\x1B[4;45m"
  451. #define RTT_CTRL_BG_BRIGHT_CYAN "\x1B[4;46m"
  452. #define RTT_CTRL_BG_BRIGHT_WHITE "\x1B[4;47m"
  453. #endif
  454. /*************************** End of file ****************************/