Appiko
SEGGER_RTT_Conf.h
1 /*********************************************************************
2 * SEGGER MICROCONTROLLER GmbH & Co. KG *
3 * Solutions for real time microcontroller applications *
4 **********************************************************************
5 * *
6 * (c) 2014 - 2016 SEGGER Microcontroller GmbH & Co. KG *
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 * 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 ---------------------------END-OF-HEADER------------------------------
55 File : SEGGER_RTT_Conf.h
56 Purpose : Implementation of SEGGER real-time transfer (RTT) which
57  allows real-time communication on targets which support
58  debugger memory accesses while the CPU is running.
59 Revision: $Rev: 4351 $
60 ----------------------------------------------------------------------
61 */
62 
63 #ifndef SEGGER_RTT_CONF_H
64 #define SEGGER_RTT_CONF_H
65 
66 #ifdef __IAR_SYSTEMS_ICC__
67  #include <intrinsics.h>
68 #endif
69 
70 /*********************************************************************
71 *
72 * Defines, configurable
73 *
74 **********************************************************************
75 */
76 
77 #define SEGGER_RTT_MAX_NUM_UP_BUFFERS (3) // Max. number of up-buffers (T->H) available on this target (Default: 3)
78 #define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (3) // Max. number of down-buffers (H->T) available on this target (Default: 3)
79 
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 
83 #define SEGGER_RTT_PRINTF_BUFFER_SIZE (64u) // Size of buffer for RTT printf to bulk-send chars via RTT (Default: 64)
84 
85 #define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_NO_BLOCK_SKIP // Mode for pre-initialized terminal channel (buffer 0)
86 
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 
102 #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) // Interrupt priority to lock on SEGGER_RTT_LOCK on Cortex-M3/4 (Default: 0x20)
103 
104 /*********************************************************************
105 *
106 * RTT lock configuration for SEGGER Embedded Studio,
107 * Rowley CrossStudio and GCC
108 */
109 #if (defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__)
110  #ifdef __ARM_ARCH_6M__
111  #define SEGGER_RTT_LOCK() { \
112  unsigned int LockState; \
113  __asm volatile ("mrs %0, primask \n\t" \
114  "mov r1, $1 \n\t" \
115  "msr primask, r1 \n\t" \
116  : "=r" (LockState) \
117  : \
118  : "r1" \
119  );
120 
121  #define SEGGER_RTT_UNLOCK() __asm volatile ("msr primask, %0 \n\t" \
122  : \
123  : "r" (LockState) \
124  : \
125  ); \
126  }
127 
128  #elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__))
129  #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
130  #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
131  #endif
132  #define SEGGER_RTT_LOCK() { \
133  unsigned int LockState; \
134  __asm volatile ("mrs %0, basepri \n\t" \
135  "mov r1, %1 \n\t" \
136  "msr basepri, r1 \n\t" \
137  : "=r" (LockState) \
138  : "i"(SEGGER_RTT_MAX_INTERRUPT_PRIORITY) \
139  : "r1" \
140  );
141 
142  #define SEGGER_RTT_UNLOCK() __asm volatile ("msr basepri, %0 \n\t" \
143  : \
144  : "r" (LockState) \
145  : \
146  ); \
147  }
148 
149  #elif defined(__ARM_ARCH_7A__)
150  #define SEGGER_RTT_LOCK() { \
151  unsigned int LockState; \
152  __asm volatile ("mrs r1, CPSR \n\t" \
153  "mov %0, r1 \n\t" \
154  "orr r1, r1, #0xC0 \n\t" \
155  "msr CPSR_c, r1 \n\t" \
156  : "=r" (LockState) \
157  : \
158  : "r1" \
159  );
160 
161  #define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t" \
162  "mrs r1, CPSR \n\t" \
163  "bic r1, r1, #0xC0 \n\t" \
164  "and r0, r0, #0xC0 \n\t" \
165  "orr r1, r1, r0 \n\t" \
166  "msr CPSR_c, r1 \n\t" \
167  : \
168  : "r" (LockState) \
169  : "r0", "r1" \
170  ); \
171  }
172 #else
173  #define SEGGER_RTT_LOCK()
174  #define SEGGER_RTT_UNLOCK()
175  #endif
176 #endif
177 
178 /*********************************************************************
179 *
180 * RTT lock configuration for IAR EWARM
181 */
182 #ifdef __ICCARM__
183  #if (defined (__ARM6M__) && (__CORE__ == __ARM6M__))
184  #define SEGGER_RTT_LOCK() { \
185  unsigned int LockState; \
186  LockState = __get_PRIMASK(); \
187  __set_PRIMASK(1);
188 
189  #define SEGGER_RTT_UNLOCK() __set_PRIMASK(LockState); \
190  }
191  #elif ((defined (__ARM7EM__) && (__CORE__ == __ARM7EM__)) || (defined (__ARM7M__) && (__CORE__ == __ARM7M__)))
192  #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
193  #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
194  #endif
195  #define SEGGER_RTT_LOCK() { \
196  unsigned int LockState; \
197  LockState = __get_BASEPRI(); \
198  __set_BASEPRI(SEGGER_RTT_MAX_INTERRUPT_PRIORITY);
199 
200  #define SEGGER_RTT_UNLOCK() __set_BASEPRI(LockState); \
201  }
202  #endif
203 #endif
204 
205 /*********************************************************************
206 *
207 * RTT lock configuration for IAR RX
208 */
209 #ifdef __ICCRX__
210  #define SEGGER_RTT_LOCK() { \
211  unsigned long LockState; \
212  LockState = __get_interrupt_state(); \
213  __disable_interrupt();
214 
215  #define SEGGER_RTT_UNLOCK() __set_interrupt_state(LockState); \
216  }
217 #endif
218 
219 /*********************************************************************
220 *
221 * RTT lock configuration for KEIL ARM
222 */
223 #ifdef __CC_ARM
224  #if (defined __TARGET_ARCH_6S_M)
225  #define SEGGER_RTT_LOCK() { \
226  unsigned int LockState; \
227  register unsigned char PRIMASK __asm( "primask"); \
228  LockState = PRIMASK; \
229  PRIMASK = 1u; \
230  __schedule_barrier();
231 
232  #define SEGGER_RTT_UNLOCK() PRIMASK = LockState; \
233  __schedule_barrier(); \
234  }
235  #elif (defined(__TARGET_ARCH_7_M) || defined(__TARGET_ARCH_7E_M))
236  #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
237  #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
238  #endif
239  #define SEGGER_RTT_LOCK() { \
240  unsigned int LockState; \
241  register unsigned char BASEPRI __asm( "basepri"); \
242  LockState = BASEPRI; \
243  BASEPRI = SEGGER_RTT_MAX_INTERRUPT_PRIORITY; \
244  __schedule_barrier();
245 
246  #define SEGGER_RTT_UNLOCK() BASEPRI = LockState; \
247  __schedule_barrier(); \
248  }
249  #endif
250 #endif
251 
252 /*********************************************************************
253 *
254 * RTT lock configuration fallback
255 */
256 #ifndef SEGGER_RTT_LOCK
257  #define SEGGER_RTT_LOCK() // Lock RTT (nestable) (i.e. disable interrupts)
258 #endif
259 
260 #ifndef SEGGER_RTT_UNLOCK
261  #define SEGGER_RTT_UNLOCK() // Unlock RTT (nestable) (i.e. enable previous interrupt lock state)
262 #endif
263 
264 #endif
265 /*************************** End of file ****************************/