Skip to content

Commit aa0c417

Browse files
nordic-krchgalak
authored andcommitted
logging: defines clean up
RTT backend supports two modes blocking and drop. Apparently, defines used lead to warning while clang compilation. Define that caused warning has been changed together with clean up which removed #ifdefs for definitions. Signed-off-by: Krzysztof Chruscinski <[email protected]>
1 parent 6b5bed6 commit aa0c417

File tree

1 file changed

+37
-26
lines changed

1 file changed

+37
-26
lines changed

subsys/logging/log_backend_rtt.c

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,49 @@
1010
#include <logging/log_output.h>
1111
#include <SEGGER_RTT.h>
1212

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
1424

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
1636

1737
#define DROP_MSG "\nmessages dropped: \r"
38+
1839
#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
2440

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
3242

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
3445

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()), ())
3848

39-
#else
49+
#define RTT_UNLOCK() \
50+
COND_CODE_0(CONFIG_LOG_BACKEND_RTT_BUFFER, (SEGGER_RTT_UNLOCK()), ())
4051

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))
4455

45-
#endif /* CONFIG_LOG_BACKEND_RTT_BUFFER > 0 */
4656

4757
static const char *drop_msg = DROP_MSG;
4858
static u8_t rtt_buf[RTT_BUFFER_SIZE];
@@ -142,9 +152,10 @@ static void on_failed_write(int retry_cnt)
142152
if (retry_cnt == 0) {
143153
host_present = false;
144154
} 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);
146157
} else {
147-
k_sleep(RETRY_DELAY_MS);
158+
k_sleep(CONFIG_LOG_BACKEND_RTT_RETRY_DELAY_MS);
148159
}
149160
}
150161

@@ -168,7 +179,7 @@ static void on_write(int retry_cnt)
168179
static int data_out_block_mode(u8_t *data, size_t length, void *ctx)
169180
{
170181
int ret;
171-
int retry_cnt = RETRY_CNT;
182+
int retry_cnt = CONFIG_LOG_BACKEND_RTT_RETRY_CNT;
172183

173184
do {
174185
if (!sync_mode) {

0 commit comments

Comments
 (0)