SEGGER_RTT_Conf.h 15 KB

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