SEGGER_RTT_Conf.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2017 SEGGER Microcontroller GmbH & Co. KG
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. /*********************************************************************
  7. * SEGGER Microcontroller GmbH & Co. KG *
  8. * The Embedded Experts *
  9. **********************************************************************
  10. * *
  11. * (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG *
  12. * *
  13. * www.segger.com Support: support@segger.com *
  14. * *
  15. **********************************************************************
  16. * *
  17. * SEGGER SystemView * Real-time application analysis *
  18. * *
  19. **********************************************************************
  20. * *
  21. * All rights reserved. *
  22. * *
  23. * SEGGER strongly recommends to not make any changes *
  24. * to or modify the source code of this software in order to stay *
  25. * compatible with the RTT protocol and J-Link. *
  26. * *
  27. * Redistribution and use in source and binary forms, with or *
  28. * without modification, are permitted provided that the following *
  29. * conditions are met: *
  30. * *
  31. * o Redistributions of source code must retain the above copyright *
  32. * notice, this list of conditions and the following disclaimer. *
  33. * *
  34. * o Redistributions in binary form must reproduce the above *
  35. * copyright notice, this list of conditions and the following *
  36. * disclaimer in the documentation and/or other materials provided *
  37. * with the distribution. *
  38. * *
  39. * o Neither the name of SEGGER Microcontroller GmbH & Co. KG *
  40. * nor the names of its contributors may be used to endorse or *
  41. * promote products derived from this software without specific *
  42. * prior written permission. *
  43. * *
  44. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
  45. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
  46. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
  47. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
  48. * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
  49. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
  50. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
  51. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
  52. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
  53. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
  54. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
  55. * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
  56. * DAMAGE. *
  57. * *
  58. **********************************************************************
  59. * *
  60. * SystemView version: V2.42 *
  61. * *
  62. **********************************************************************
  63. ---------------------------END-OF-HEADER------------------------------
  64. File : SEGGER_RTT_Conf.h
  65. Purpose : Implementation of SEGGER real-time transfer (RTT) which
  66. allows real-time communication on targets which support
  67. debugger memory accesses while the CPU is running.
  68. Revision: $Rev: 5626 $
  69. */
  70. #ifndef SEGGER_RTT_CONF_H
  71. #define SEGGER_RTT_CONF_H
  72. #ifdef __IAR_SYSTEMS_ICC__
  73. #include <intrinsics.h>
  74. #endif
  75. /*********************************************************************
  76. *
  77. * Defines, configurable
  78. *
  79. **********************************************************************
  80. */
  81. #define SEGGER_RTT_MAX_NUM_UP_BUFFERS (3) // Max. number of up-buffers (T->H) available on this target (Default: 3)
  82. #define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (3) // Max. number of down-buffers (H->T) available on this target (Default: 3)
  83. #define BUFFER_SIZE_UP (1024) // Size of the buffer for terminal output of target, up to host (Default: 1k)
  84. #define BUFFER_SIZE_DOWN (16) // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16)
  85. #define SEGGER_RTT_PRINTF_BUFFER_SIZE (64u) // Size of buffer for RTT printf to bulk-send chars via RTT (Default: 64)
  86. #define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_NO_BLOCK_SKIP // Mode for pre-initialized terminal channel (buffer 0)
  87. //
  88. // Target is not allowed to perform other RTT operations while string still has not been stored completely.
  89. // Otherwise we would probably end up with a mixed string in the buffer.
  90. // If using RTT from within interrupts, multiple tasks or multi processors, define the SEGGER_RTT_LOCK() and SEGGER_RTT_UNLOCK() function here.
  91. //
  92. // SEGGER_RTT_MAX_INTERRUPT_PRIORITY can be used in the sample lock routines on Cortex-M3/4.
  93. // Make sure to mask all interrupts which can send RTT data, i.e. generate SystemView events, or cause task switches.
  94. // When high-priority interrupts must not be masked while sending RTT data, SEGGER_RTT_MAX_INTERRUPT_PRIORITY needs to be adjusted accordingly.
  95. // (Higher priority = lower priority number)
  96. // Default value for embOS: 128u
  97. // Default configuration in FreeRTOS: configMAX_SYSCALL_INTERRUPT_PRIORITY: ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
  98. // In case of doubt mask all interrupts: 1 << (8 - BASEPRI_PRIO_BITS) i.e. 1 << 5 when 3 bits are implemented in NVIC
  99. // or define SEGGER_RTT_LOCK() to completely disable interrupts.
  100. //
  101. #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) // Interrupt priority to lock on SEGGER_RTT_LOCK on Cortex-M3/4 (Default: 0x20)
  102. /*********************************************************************
  103. *
  104. * RTT lock configuration for SEGGER Embedded Studio,
  105. * Rowley CrossStudio and GCC
  106. */
  107. #if (defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__)
  108. #ifdef __ARM_ARCH_6M__
  109. #define SEGGER_RTT_LOCK() { \
  110. unsigned int LockState; \
  111. __asm volatile ("mrs %0, primask \n\t" \
  112. "mov r1, $1 \n\t" \
  113. "msr primask, r1 \n\t" \
  114. : "=r" (LockState) \
  115. : \
  116. : "r1" \
  117. );
  118. #define SEGGER_RTT_UNLOCK() __asm volatile ("msr primask, %0 \n\t" \
  119. : \
  120. : "r" (LockState) \
  121. : \
  122. ); \
  123. }
  124. #elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__))
  125. #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
  126. #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
  127. #endif
  128. #define SEGGER_RTT_LOCK() { \
  129. unsigned int LockState; \
  130. __asm volatile ("mrs %0, basepri \n\t" \
  131. "mov r1, %1 \n\t" \
  132. "msr basepri, r1 \n\t" \
  133. : "=r" (LockState) \
  134. : "i"(SEGGER_RTT_MAX_INTERRUPT_PRIORITY) \
  135. : "r1" \
  136. );
  137. #define SEGGER_RTT_UNLOCK() __asm volatile ("msr basepri, %0 \n\t" \
  138. : \
  139. : "r" (LockState) \
  140. : \
  141. ); \
  142. }
  143. #elif defined(__ARM_ARCH_7A__)
  144. #define SEGGER_RTT_LOCK() { \
  145. unsigned int LockState; \
  146. __asm volatile ("mrs r1, CPSR \n\t" \
  147. "mov %0, r1 \n\t" \
  148. "orr r1, r1, #0xC0 \n\t" \
  149. "msr CPSR_c, r1 \n\t" \
  150. : "=r" (LockState) \
  151. : \
  152. : "r1" \
  153. );
  154. #define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t" \
  155. "mrs r1, CPSR \n\t" \
  156. "bic r1, r1, #0xC0 \n\t" \
  157. "and r0, r0, #0xC0 \n\t" \
  158. "orr r1, r1, r0 \n\t" \
  159. "msr CPSR_c, r1 \n\t" \
  160. : \
  161. : "r" (LockState) \
  162. : "r0", "r1" \
  163. ); \
  164. }
  165. #else
  166. #define SEGGER_RTT_LOCK()
  167. #define SEGGER_RTT_UNLOCK()
  168. #endif
  169. #endif
  170. /*********************************************************************
  171. *
  172. * RTT lock configuration for IAR EWARM
  173. */
  174. #ifdef __ICCARM__
  175. #if (defined (__ARM6M__) && (__CORE__ == __ARM6M__))
  176. #define SEGGER_RTT_LOCK() { \
  177. unsigned int LockState; \
  178. LockState = __get_PRIMASK(); \
  179. __set_PRIMASK(1);
  180. #define SEGGER_RTT_UNLOCK() __set_PRIMASK(LockState); \
  181. }
  182. #elif ((defined (__ARM7EM__) && (__CORE__ == __ARM7EM__)) || (defined (__ARM7M__) && (__CORE__ == __ARM7M__)))
  183. #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
  184. #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
  185. #endif
  186. #define SEGGER_RTT_LOCK() { \
  187. unsigned int LockState; \
  188. LockState = __get_BASEPRI(); \
  189. __set_BASEPRI(SEGGER_RTT_MAX_INTERRUPT_PRIORITY);
  190. #define SEGGER_RTT_UNLOCK() __set_BASEPRI(LockState); \
  191. }
  192. #endif
  193. #endif
  194. /*********************************************************************
  195. *
  196. * RTT lock configuration for IAR RX
  197. */
  198. #ifdef __ICCRX__
  199. #define SEGGER_RTT_LOCK() { \
  200. unsigned long LockState; \
  201. LockState = __get_interrupt_state(); \
  202. __disable_interrupt();
  203. #define SEGGER_RTT_UNLOCK() __set_interrupt_state(LockState); \
  204. }
  205. #endif
  206. /*********************************************************************
  207. *
  208. * RTT lock configuration for KEIL ARM
  209. */
  210. #ifdef __CC_ARM
  211. #if (defined __TARGET_ARCH_6S_M)
  212. #define SEGGER_RTT_LOCK() { \
  213. unsigned int LockState; \
  214. register unsigned char PRIMASK __asm( "primask"); \
  215. LockState = PRIMASK; \
  216. PRIMASK = 1u; \
  217. __schedule_barrier();
  218. #define SEGGER_RTT_UNLOCK() PRIMASK = LockState; \
  219. __schedule_barrier(); \
  220. }
  221. #elif (defined(__TARGET_ARCH_7_M) || defined(__TARGET_ARCH_7E_M))
  222. #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
  223. #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
  224. #endif
  225. #define SEGGER_RTT_LOCK() { \
  226. unsigned int LockState; \
  227. register unsigned char BASEPRI __asm( "basepri"); \
  228. LockState = BASEPRI; \
  229. BASEPRI = SEGGER_RTT_MAX_INTERRUPT_PRIORITY; \
  230. __schedule_barrier();
  231. #define SEGGER_RTT_UNLOCK() BASEPRI = LockState; \
  232. __schedule_barrier(); \
  233. }
  234. #endif
  235. #endif
  236. /*********************************************************************
  237. *
  238. * RTT lock configuration for TI ARM
  239. */
  240. #ifdef __TI_ARM__
  241. #if defined (__TI_ARM_V6M0__)
  242. #define SEGGER_RTT_LOCK() { \
  243. unsigned int LockState; \
  244. LockState = __get_PRIMASK(); \
  245. __set_PRIMASK(1);
  246. #define SEGGER_RTT_UNLOCK() __set_PRIMASK(LockState); \
  247. }
  248. #elif (defined (__TI_ARM_V7M3__) || defined (__TI_ARM_V7M4__))
  249. #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
  250. #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
  251. #endif
  252. #define SEGGER_RTT_LOCK() { \
  253. unsigned int LockState; \
  254. LockState = OS_GetBASEPRI(); \
  255. OS_SetBASEPRI(SEGGER_RTT_MAX_INTERRUPT_PRIORITY);
  256. #define SEGGER_RTT_UNLOCK() OS_SetBASEPRI(LockState); \
  257. }
  258. #endif
  259. #endif
  260. /*********************************************************************
  261. *
  262. * RTT lock configuration fallback
  263. */
  264. #ifndef SEGGER_RTT_LOCK
  265. void SEGGER_SYSVIEW_X_RTT_Lock(void);
  266. #define SEGGER_RTT_LOCK() SEGGER_SYSVIEW_X_RTT_Lock() // Lock RTT (nestable) (i.e. disable interrupts)
  267. #endif
  268. #ifndef SEGGER_RTT_UNLOCK
  269. void SEGGER_SYSVIEW_X_RTT_Unlock(void);
  270. #define SEGGER_RTT_UNLOCK() SEGGER_SYSVIEW_X_RTT_Unlock() // Unlock RTT (nestable) (i.e. enable previous interrupt lock state)
  271. #endif
  272. #endif
  273. /*************************** End of file ****************************/