SEGGER_RTT_Conf.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /*********************************************************************
  2. * SEGGER Microcontroller GmbH & Co. KG *
  3. * The Embedded Experts *
  4. **********************************************************************
  5. * *
  6. * (c) 2015 - 2017 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. * 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 & Co. KG *
  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. * SystemView version: V2.52a *
  56. * *
  57. **********************************************************************
  58. ---------------------------END-OF-HEADER------------------------------
  59. File : SEGGER_RTT_Conf.h
  60. Purpose : Implementation of SEGGER real-time transfer (RTT) which
  61. allows real-time communication on targets which support
  62. debugger memory accesses while the CPU is running.
  63. Revision: $Rev: 7859 $
  64. */
  65. #ifndef SEGGER_RTT_CONF_H
  66. #define SEGGER_RTT_CONF_H
  67. #ifdef __IAR_SYSTEMS_ICC__
  68. #include <intrinsics.h>
  69. #endif
  70. #include "rtthread.h"
  71. /*********************************************************************
  72. *
  73. * Defines, configurable
  74. *
  75. **********************************************************************
  76. */
  77. #ifndef PKG_USING_SYSTEMVIEW
  78. #define SEGGER_RTT_MAX_NUM_UP_BUFFERS (3) // Max. number of up-buffers (T->H) available on this target (Default: 3)
  79. #define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (3) // Max. number of down-buffers (H->T) available on this target (Default: 3)
  80. #define BUFFER_SIZE_UP (1024) // Size of the buffer for terminal output of target, up to host (Default: 1k)
  81. #define BUFFER_SIZE_DOWN (16) // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16)
  82. #define SEGGER_RTT_PRINTF_BUFFER_SIZE (64u) // Size of buffer for RTT printf to bulk-send chars via RTT (Default: 64)
  83. #define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_NO_BLOCK_SKIP // Mode for pre-initialized terminal channel (buffer 0)
  84. #define USE_RTT_ASM (0) // Use assembler version of SEGGER_RTT.c when 1
  85. #else
  86. #define SEGGER_RTT_MAX_NUM_UP_BUFFERS PKG_SEGGER_RTT_MAX_NUM_UP_BUFFERS
  87. #define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS PKG_SEGGER_RTT_MAX_NUM_DOWN_BUFFERS
  88. #define BUFFER_SIZE_UP PKG_SEGGER_RTT_BUFFER_SIZE_UP
  89. #define BUFFER_SIZE_DOWN PKG_SEGGER_RTT_BUFFER_SIZE_DOWN
  90. #define SEGGER_RTT_PRINTF_BUFFER_SIZE PKG_SEGGER_RTT_PRINTF_BUFFER_SIZE
  91. #ifdef PKG_SEGGER_RTT_MODE_ENABLE_NO_BLOCK_SKIP
  92. #define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_NO_BLOCK_SKIP
  93. #endif
  94. #ifdef PKG_SEGGER_RTT_MODE_ENABLE_NO_BLOCK_TRIM
  95. #define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_NO_BLOCK_TRIM
  96. #endif
  97. #ifdef PKG_SEGGER_RTT_MODE_ENABLE_BLOCK_IF_FIFO_FULL
  98. #define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
  99. #endif
  100. #ifdef PKG_SEGGER_RTT_USE_RTT_ASM
  101. #define USE_RTT_ASM 1
  102. #endif
  103. #endif
  104. /*********************************************************************
  105. *
  106. * RTT memcpy configuration
  107. *
  108. * memcpy() is good for large amounts of data,
  109. * but the overhead is big for small amounts, which are usually stored via RTT.
  110. * With SEGGER_RTT_MEMCPY_USE_BYTELOOP a simple byte loop can be used instead.
  111. *
  112. * SEGGER_RTT_MEMCPY() can be used to replace standard memcpy() in RTT functions.
  113. * This is may be required with memory access restrictions,
  114. * such as on Cortex-A devices with MMU.
  115. */
  116. #ifndef PKG_USING_SYSTEMVIEW
  117. #define SEGGER_RTT_MEMCPY_USE_BYTELOOP 0 // 0: Use memcpy/SEGGER_RTT_MEMCPY, 1: Use a simple byte-loop
  118. #else
  119. #ifdef PKG_SEGGER_RTT_MEMCPY_USE_BYTELOOP
  120. #define SEGGER_RTT_MEMCPY_USE_BYTELOOP 1
  121. #endif
  122. #endif
  123. //
  124. // Example definition of SEGGER_RTT_MEMCPY to external memcpy with GCC toolchains and Cortex-A targets
  125. //
  126. //#if ((defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__)) && (defined (__ARM_ARCH_7A__))
  127. // #define SEGGER_RTT_MEMCPY(pDest, pSrc, NumBytes) SEGGER_memcpy((pDest), (pSrc), (NumBytes))
  128. //#endif
  129. //
  130. // Target is not allowed to perform other RTT operations while string still has not been stored completely.
  131. // Otherwise we would probably end up with a mixed string in the buffer.
  132. // If using RTT from within interrupts, multiple tasks or multi processors, define the SEGGER_RTT_LOCK() and SEGGER_RTT_UNLOCK() function here.
  133. //
  134. // SEGGER_RTT_MAX_INTERRUPT_PRIORITY can be used in the sample lock routines on Cortex-M3/4.
  135. // Make sure to mask all interrupts which can send RTT data, i.e. generate SystemView events, or cause task switches.
  136. // When high-priority interrupts must not be masked while sending RTT data, SEGGER_RTT_MAX_INTERRUPT_PRIORITY needs to be adjusted accordingly.
  137. // (Higher priority = lower priority number)
  138. // Default value for embOS: 128u
  139. // Default configuration in FreeRTOS: configMAX_SYSCALL_INTERRUPT_PRIORITY: ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
  140. // In case of doubt mask all interrupts: 1 << (8 - BASEPRI_PRIO_BITS) i.e. 1 << 5 when 3 bits are implemented in NVIC
  141. // or define SEGGER_RTT_LOCK() to completely disable interrupts.
  142. //
  143. #ifndef PKG_USING_SYSTEMVIEW
  144. #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) // Interrupt priority to lock on SEGGER_RTT_LOCK on Cortex-M3/4 (Default: 0x20)
  145. #else
  146. #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY PKG_SEGGER_RTT_MAX_INTERRUPT_PRIORITY
  147. #endif
  148. /*********************************************************************
  149. *
  150. * RTT lock configuration for SEGGER Embedded Studio,
  151. * Rowley CrossStudio and GCC
  152. */
  153. #if (defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__)
  154. #ifdef __ARM_ARCH_6M__
  155. #define SEGGER_RTT_LOCK() { \
  156. unsigned int LockState; \
  157. __asm volatile ("mrs %0, primask \n\t" \
  158. "mov r1, $1 \n\t" \
  159. "msr primask, r1 \n\t" \
  160. : "=r" (LockState) \
  161. : \
  162. : "r1" \
  163. );
  164. #define SEGGER_RTT_UNLOCK() __asm volatile ("msr primask, %0 \n\t" \
  165. : \
  166. : "r" (LockState) \
  167. : \
  168. ); \
  169. }
  170. #elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__))
  171. #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
  172. #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
  173. #endif
  174. #define SEGGER_RTT_LOCK() { \
  175. unsigned int LockState; \
  176. __asm volatile ("mrs %0, basepri \n\t" \
  177. "mov r1, %1 \n\t" \
  178. "msr basepri, r1 \n\t" \
  179. : "=r" (LockState) \
  180. : "i"(SEGGER_RTT_MAX_INTERRUPT_PRIORITY) \
  181. : "r1" \
  182. );
  183. #define SEGGER_RTT_UNLOCK() __asm volatile ("msr basepri, %0 \n\t" \
  184. : \
  185. : "r" (LockState) \
  186. : \
  187. ); \
  188. }
  189. #elif defined(__ARM_ARCH_7A__)
  190. #define SEGGER_RTT_LOCK() { \
  191. unsigned int LockState; \
  192. __asm volatile ("mrs r1, CPSR \n\t" \
  193. "mov %0, r1 \n\t" \
  194. "orr r1, r1, #0xC0 \n\t" \
  195. "msr CPSR_c, r1 \n\t" \
  196. : "=r" (LockState) \
  197. : \
  198. : "r1" \
  199. );
  200. #define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t" \
  201. "mrs r1, CPSR \n\t" \
  202. "bic r1, r1, #0xC0 \n\t" \
  203. "and r0, r0, #0xC0 \n\t" \
  204. "orr r1, r1, r0 \n\t" \
  205. "msr CPSR_c, r1 \n\t" \
  206. : \
  207. : "r" (LockState) \
  208. : "r0", "r1" \
  209. ); \
  210. }
  211. #else
  212. #define SEGGER_RTT_LOCK()
  213. #define SEGGER_RTT_UNLOCK()
  214. #endif
  215. #endif
  216. /*********************************************************************
  217. *
  218. * RTT lock configuration for IAR EWARM
  219. */
  220. #ifdef __ICCARM__
  221. #if (defined (__ARM6M__) && (__CORE__ == __ARM6M__))
  222. #define SEGGER_RTT_LOCK() { \
  223. unsigned int LockState; \
  224. LockState = __get_PRIMASK(); \
  225. __set_PRIMASK(1);
  226. #define SEGGER_RTT_UNLOCK() __set_PRIMASK(LockState); \
  227. }
  228. #elif ((defined (__ARM7EM__) && (__CORE__ == __ARM7EM__)) || (defined (__ARM7M__) && (__CORE__ == __ARM7M__)))
  229. #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
  230. #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
  231. #endif
  232. #define SEGGER_RTT_LOCK() { \
  233. unsigned int LockState; \
  234. LockState = __get_BASEPRI(); \
  235. __set_BASEPRI(SEGGER_RTT_MAX_INTERRUPT_PRIORITY);
  236. #define SEGGER_RTT_UNLOCK() __set_BASEPRI(LockState); \
  237. }
  238. #endif
  239. #endif
  240. /*********************************************************************
  241. *
  242. * RTT lock configuration for IAR RX
  243. */
  244. #ifdef __ICCRX__
  245. #define SEGGER_RTT_LOCK() { \
  246. unsigned long LockState; \
  247. LockState = __get_interrupt_state(); \
  248. __disable_interrupt();
  249. #define SEGGER_RTT_UNLOCK() __set_interrupt_state(LockState); \
  250. }
  251. #endif
  252. /*********************************************************************
  253. *
  254. * RTT lock configuration for IAR RL78
  255. */
  256. #ifdef __ICCRL78__
  257. #define SEGGER_RTT_LOCK() { \
  258. __istate_t LockState; \
  259. LockState = __get_interrupt_state(); \
  260. __disable_interrupt();
  261. #define SEGGER_RTT_UNLOCK() __set_interrupt_state(LockState); \
  262. }
  263. #endif
  264. /*********************************************************************
  265. *
  266. * RTT lock configuration for KEIL ARM
  267. */
  268. #ifdef __CC_ARM
  269. #if (defined __TARGET_ARCH_6S_M)
  270. #define SEGGER_RTT_LOCK() { \
  271. unsigned int LockState; \
  272. register unsigned char PRIMASK __asm( "primask"); \
  273. LockState = PRIMASK; \
  274. PRIMASK = 1u; \
  275. __schedule_barrier();
  276. #define SEGGER_RTT_UNLOCK() PRIMASK = LockState; \
  277. __schedule_barrier(); \
  278. }
  279. #elif (defined(__TARGET_ARCH_7_M) || defined(__TARGET_ARCH_7E_M))
  280. #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
  281. #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
  282. #endif
  283. #define SEGGER_RTT_LOCK() { \
  284. unsigned int LockState; \
  285. register unsigned char BASEPRI __asm( "basepri"); \
  286. LockState = BASEPRI; \
  287. BASEPRI = SEGGER_RTT_MAX_INTERRUPT_PRIORITY; \
  288. __schedule_barrier();
  289. #define SEGGER_RTT_UNLOCK() BASEPRI = LockState; \
  290. __schedule_barrier(); \
  291. }
  292. #endif
  293. #endif
  294. /*********************************************************************
  295. *
  296. * RTT lock configuration for TI ARM
  297. */
  298. #ifdef __TI_ARM__
  299. #if defined (__TI_ARM_V6M0__)
  300. #define SEGGER_RTT_LOCK() { \
  301. unsigned int LockState; \
  302. LockState = __get_PRIMASK(); \
  303. __set_PRIMASK(1);
  304. #define SEGGER_RTT_UNLOCK() __set_PRIMASK(LockState); \
  305. }
  306. #elif (defined (__TI_ARM_V7M3__) || defined (__TI_ARM_V7M4__))
  307. #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
  308. #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
  309. #endif
  310. #define SEGGER_RTT_LOCK() { \
  311. unsigned int LockState; \
  312. LockState = OS_GetBASEPRI(); \
  313. OS_SetBASEPRI(SEGGER_RTT_MAX_INTERRUPT_PRIORITY);
  314. #define SEGGER_RTT_UNLOCK() OS_SetBASEPRI(LockState); \
  315. }
  316. #endif
  317. #endif
  318. /*********************************************************************
  319. *
  320. * RTT lock configuration fallback
  321. */
  322. #ifndef SEGGER_RTT_LOCK
  323. #define SEGGER_RTT_LOCK() // Lock RTT (nestable) (i.e. disable interrupts)
  324. #endif
  325. #ifndef SEGGER_RTT_UNLOCK
  326. #define SEGGER_RTT_UNLOCK() // Unlock RTT (nestable) (i.e. enable previous interrupt lock state)
  327. #endif
  328. #endif
  329. /*************************** End of file ****************************/