|
27 | 27 |
|
28 | 28 | #include "monitor.h" |
29 | 29 |
|
30 | | -#ifdef CONFIG_BT_DEBUG_MONITOR_RTT |
31 | | -#include <SEGGER_RTT.h> |
32 | | - |
33 | | -#define RTT_BUFFER_NAME CONFIG_BT_DEBUG_MONITOR_RTT_BUFFER_NAME |
34 | | -#define RTT_BUF_SIZE CONFIG_BT_DEBUG_MONITOR_RTT_BUFFER_SIZE |
35 | | -static uint8_t rtt_buf[RTT_BUF_SIZE]; |
36 | | -#elif CONFIG_BT_DEBUG_MONITOR_UART |
37 | | -static const struct device *monitor_dev; |
38 | | -#endif |
39 | | - |
40 | 30 | /* This is the same default priority as for other console handlers, |
41 | 31 | * except that we're not exporting it as a Kconfig variable until a |
42 | 32 | * clear need arises. |
@@ -74,18 +64,40 @@ static struct { |
74 | 64 | atomic_t other; |
75 | 65 | } drops; |
76 | 66 |
|
| 67 | +#if defined(CONFIG_BT_DEBUG_MONITOR_RTT) |
| 68 | +#include <SEGGER_RTT.h> |
| 69 | + |
| 70 | +#define RTT_BUFFER_NAME CONFIG_BT_DEBUG_MONITOR_RTT_BUFFER_NAME |
| 71 | +#define RTT_BUF_SIZE CONFIG_BT_DEBUG_MONITOR_RTT_BUFFER_SIZE |
| 72 | + |
| 73 | +static uint8_t rtt_buf[RTT_BUF_SIZE]; |
| 74 | + |
77 | 75 | static void monitor_send(const void *data, size_t len) |
78 | 76 | { |
79 | | -#ifdef CONFIG_BT_DEBUG_MONITOR_RTT |
80 | 77 | SEGGER_RTT_Write(CONFIG_BT_DEBUG_MONITOR_RTT_BUFFER, data, len); |
81 | | -#elif CONFIG_BT_DEBUG_MONITOR_UART |
| 78 | +} |
| 79 | + |
| 80 | +static void poll_out(char c) |
| 81 | +{ |
| 82 | + monitor_send(&c, sizeof(c)); |
| 83 | +} |
| 84 | +#elif defined(CONFIG_BT_DEBUG_MONITOR_UART) |
| 85 | +static const struct device *monitor_dev; |
| 86 | + |
| 87 | +static void poll_out(char c) |
| 88 | +{ |
| 89 | + uart_poll_out(monitor_dev, c); |
| 90 | +} |
| 91 | + |
| 92 | +static void monitor_send(const void *data, size_t len) |
| 93 | +{ |
82 | 94 | const uint8_t *buf = data; |
83 | 95 |
|
84 | 96 | while (len--) { |
85 | | - uart_poll_out(monitor_dev, *buf++); |
| 97 | + poll_out(*buf++); |
86 | 98 | } |
87 | | -#endif |
88 | 99 | } |
| 100 | +#endif /* CONFIG_BT_DEBUG_MONITOR_UART */ |
89 | 101 |
|
90 | 102 | static void encode_drops(struct bt_monitor_hdr *hdr, uint8_t type, |
91 | 103 | atomic_t *val) |
@@ -191,19 +203,7 @@ void bt_monitor_new_index(uint8_t type, uint8_t bus, bt_addr_t *addr, |
191 | 203 | bt_monitor_send(BT_MONITOR_NEW_INDEX, &pkt, sizeof(pkt)); |
192 | 204 | } |
193 | 205 |
|
194 | | -#ifdef CONFIG_BT_DEBUG_MONITOR_RTT |
195 | | -static int bt_monitor_init(const struct device *d) |
196 | | -{ |
197 | | - ARG_UNUSED(d); |
198 | | - |
199 | | - SEGGER_RTT_ConfigUpBuffer(CONFIG_BT_DEBUG_MONITOR_RTT_BUFFER, |
200 | | - RTT_BUFFER_NAME, rtt_buf, RTT_BUF_SIZE, |
201 | | - SEGGER_RTT_MODE_NO_BLOCK_SKIP); |
202 | | - return 0; |
203 | | -} |
204 | | -#elif CONFIG_BT_DEBUG_MONITOR_UART |
205 | | - |
206 | | -#if !defined(CONFIG_UART_CONSOLE) && !defined(CONFIG_LOG_PRINTK) |
| 206 | +#if !defined(CONFIG_UART_CONSOLE) && !defined(CONFIG_RTT_CONSOLE) && !defined(CONFIG_LOG_PRINTK) |
207 | 207 | static int monitor_console_out(int c) |
208 | 208 | { |
209 | 209 | static char buf[MONITOR_MSG_MAX]; |
@@ -231,7 +231,7 @@ static int monitor_console_out(int c) |
231 | 231 |
|
232 | 232 | extern void __printk_hook_install(int (*fn)(int)); |
233 | 233 | extern void __stdout_hook_install(int (*fn)(int)); |
234 | | -#endif /* !CONFIG_UART_CONSOLE */ |
| 234 | +#endif /* !CONFIG_UART_CONSOLE && !CONFIG_RTT_CONSOLE && !CONFIG_LOG_PRINTK */ |
235 | 235 |
|
236 | 236 | #ifndef CONFIG_LOG_MODE_MINIMAL |
237 | 237 | struct monitor_log_ctx { |
@@ -316,7 +316,7 @@ static void monitor_log_put(const struct log_backend *const backend, |
316 | 316 | monitor_send(ctx.msg, ctx.total_len); |
317 | 317 |
|
318 | 318 | /* Terminate the string with null */ |
319 | | - uart_poll_out(monitor_dev, '\0'); |
| 319 | + poll_out('\0'); |
320 | 320 |
|
321 | 321 | atomic_clear_bit(&flags, BT_LOG_BUSY); |
322 | 322 | } |
@@ -353,7 +353,7 @@ static void monitor_log_process(const struct log_backend *const backend, |
353 | 353 | monitor_send(ctx.msg, ctx.total_len); |
354 | 354 |
|
355 | 355 | /* Terminate the string with null */ |
356 | | - uart_poll_out(monitor_dev, '\0'); |
| 356 | + poll_out('\0'); |
357 | 357 |
|
358 | 358 | atomic_clear_bit(&flags, BT_LOG_BUSY); |
359 | 359 | } |
@@ -381,22 +381,27 @@ static int bt_monitor_init(const struct device *d) |
381 | 381 | { |
382 | 382 | ARG_UNUSED(d); |
383 | 383 |
|
| 384 | +#if defined(CONFIG_BT_DEBUG_MONITOR_RTT) |
| 385 | + SEGGER_RTT_ConfigUpBuffer(CONFIG_BT_DEBUG_MONITOR_RTT_BUFFER, |
| 386 | + RTT_BUFFER_NAME, rtt_buf, RTT_BUF_SIZE, |
| 387 | + SEGGER_RTT_MODE_NO_BLOCK_SKIP); |
| 388 | +#elif defined(CONFIG_BT_DEBUG_MONITOR_UART) |
384 | 389 | monitor_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_bt_mon_uart)); |
385 | 390 |
|
386 | 391 | __ASSERT_NO_MSG(device_is_ready(monitor_dev)); |
387 | 392 |
|
388 | 393 | #if defined(CONFIG_UART_INTERRUPT_DRIVEN) |
389 | 394 | uart_irq_rx_disable(monitor_dev); |
390 | 395 | uart_irq_tx_disable(monitor_dev); |
391 | | -#endif |
| 396 | +#endif /* CONFIG_UART_INTERRUPT_DRIVEN */ |
| 397 | +#endif /* CONFIG_BT_DEBUG_MONITOR_UART */ |
392 | 398 |
|
393 | | -#if !defined(CONFIG_UART_CONSOLE) && !defined(CONFIG_LOG_PRINTK) |
| 399 | +#if !defined(CONFIG_UART_CONSOLE) && !defined(CONFIG_RTT_CONSOLE) && !defined(CONFIG_LOG_PRINTK) |
394 | 400 | __printk_hook_install(monitor_console_out); |
395 | 401 | __stdout_hook_install(monitor_console_out); |
396 | | -#endif |
| 402 | +#endif /* !CONFIG_UART_CONSOLE && !CONFIG_RTT_CONSOLE && !CONFIG_LOG_PRINTK */ |
397 | 403 |
|
398 | 404 | return 0; |
399 | 405 | } |
400 | | -#endif /* CONFIG_BT_DEBUG_MONITOR_UART */ |
401 | 406 |
|
402 | 407 | SYS_INIT(bt_monitor_init, PRE_KERNEL_1, MONITOR_INIT_PRIORITY); |
0 commit comments