10
10
#include <logging/log_output.h>
11
11
#include <SEGGER_RTT.h>
12
12
13
- #define DROP_MAX 99
13
+ #ifndef CONFIG_LOG_BACKEND_RTT_BUFFER_SIZE
14
+ #define CONFIG_LOG_BACKEND_RTT_BUFFER_SIZE 0
15
+ #endif
16
+
17
+ #ifndef CONFIG_LOG_BACKEND_RTT_MESSAGE_SIZE
18
+ #define CONFIG_LOG_BACKEND_RTT_MESSAGE_SIZE 0
19
+ #endif
20
+
21
+ #ifndef CONFIG_LOG_BACKEND_RTT_OUTPUT_BUFFER_SIZE
22
+ #define CONFIG_LOG_BACKEND_RTT_OUTPUT_BUFFER_SIZE 0
23
+ #endif
14
24
15
- #if CONFIG_LOG_BACKEND_RTT_MODE_DROP
25
+ #ifndef CONFIG_LOG_BACKEND_RTT_RETRY_DELAY_MS
26
+ /* Long enough to detect host presence */
27
+ #define CONFIG_LOG_BACKEND_RTT_RETRY_DELAY_MS 10
28
+ #endif
29
+
30
+ #ifndef CONFIG_LOG_BACKEND_RTT_RETRY_CNT
31
+ /* Big enough to detect host presence */
32
+ #define CONFIG_LOG_BACKEND_RTT_RETRY_CNT 10
33
+ #endif
34
+
35
+ #define DROP_MAX 99
16
36
17
37
#define DROP_MSG "\nmessages dropped: \r"
38
+
18
39
#define DROP_MSG_LEN (sizeof(DROP_MSG) - 1)
19
- #define MESSAGE_SIZE CONFIG_LOG_BACKEND_RTT_MESSAGE_SIZE
20
- #define CHAR_BUF_SIZE 1
21
- #define RETRY_DELAY_MS 10 /* Long enough to detect host presence */
22
- #define RETRY_CNT 10 /* Big enough to detect host presence */
23
- #else
24
40
25
- #define DROP_MSG NULL
26
- #define DROP_MSG_LEN 0
27
- #define MESSAGE_SIZE 0
28
- #define CHAR_BUF_SIZE CONFIG_LOG_BACKEND_RTT_OUTPUT_BUFFER_SIZE
29
- #define RETRY_DELAY_MS CONFIG_LOG_BACKEND_RTT_RETRY_DELAY_MS
30
- #define RETRY_CNT CONFIG_LOG_BACKEND_RTT_RETRY_CNT
31
- #endif /* CONFIG_LOG_BACKEND_RTT_MODE_DROP */
41
+ #define MESSAGE_SIZE CONFIG_LOG_BACKEND_RTT_MESSAGE_SIZE
32
42
33
- #if CONFIG_LOG_BACKEND_RTT_BUFFER > 0
43
+ #define CHAR_BUF_SIZE IS_ENABLED(CONFIG_LOG_BACKEND_RTT_MODE_BLOCK) ? \
44
+ CONFIG_LOG_BACKEND_RTT_OUTPUT_BUFFER_SIZE : 1
34
45
35
- #define RTT_LOCK ()
36
- #define RTT_UNLOCK ()
37
- #define RTT_BUFFER_SIZE CONFIG_LOG_BACKEND_RTT_BUFFER_SIZE
46
+ #define RTT_LOCK () \
47
+ COND_CODE_0(CONFIG_LOG_BACKEND_RTT_BUFFER, (SEGGER_RTT_LOCK()), ())
38
48
39
- #else
49
+ #define RTT_UNLOCK () \
50
+ COND_CODE_0(CONFIG_LOG_BACKEND_RTT_BUFFER, (SEGGER_RTT_UNLOCK()), ())
40
51
41
- #define RTT_LOCK () SEGGER_RTT_LOCK()
42
- #define RTT_UNLOCK () SEGGER_RTT_UNLOCK()
43
- #define RTT_BUFFER_SIZE 0
52
+ #define RTT_BUFFER_SIZE \
53
+ COND_CODE_0(CONFIG_LOG_BACKEND_RTT_BUFFER, \
54
+ (0), (CONFIG_LOG_BACKEND_RTT_BUFFER_SIZE))
44
55
45
- #endif /* CONFIG_LOG_BACKEND_RTT_BUFFER > 0 */
46
56
47
57
static const char * drop_msg = DROP_MSG ;
48
58
static u8_t rtt_buf [RTT_BUFFER_SIZE ];
@@ -142,9 +152,10 @@ static void on_failed_write(int retry_cnt)
142
152
if (retry_cnt == 0 ) {
143
153
host_present = false;
144
154
} else if (sync_mode ) {
145
- k_busy_wait (USEC_PER_MSEC * RETRY_DELAY_MS );
155
+ k_busy_wait (USEC_PER_MSEC *
156
+ CONFIG_LOG_BACKEND_RTT_RETRY_DELAY_MS );
146
157
} else {
147
- k_sleep (RETRY_DELAY_MS );
158
+ k_sleep (CONFIG_LOG_BACKEND_RTT_RETRY_DELAY_MS );
148
159
}
149
160
}
150
161
@@ -168,7 +179,7 @@ static void on_write(int retry_cnt)
168
179
static int data_out_block_mode (u8_t * data , size_t length , void * ctx )
169
180
{
170
181
int ret ;
171
- int retry_cnt = RETRY_CNT ;
182
+ int retry_cnt = CONFIG_LOG_BACKEND_RTT_RETRY_CNT ;
172
183
173
184
do {
174
185
if (!sync_mode ) {
0 commit comments