SEGGER_RTT.h 23 KB

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