Skip to content

Commit 0f67ca8

Browse files
committed
pbdrv/bluetooth: Debugging changes for virtualhub.
- Implements HCI logging in bluetooth BTStack. - Adds a stderr version of uart_debug_first_port. - (Revert?) Enables debug logging for virtualhub bluetooth.
1 parent a404a3b commit 0f67ca8

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

lib/pbio/drv/bluetooth/bluetooth_btstack.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,27 @@
5454
#define HUB_VARIANT 0x0000
5555
#endif
5656

57-
#define DEBUG 0
57+
#define DEBUG 1
5858

5959
#if DEBUG
6060
#include <pbdrv/../../drv/uart/uart_debug_first_port.h>
6161
#define DEBUG_PRINT pbdrv_uart_debug_printf
62+
#include <pbdrv/../../drv/uart/uart_debug_first_port.h>
63+
#define DEBUG_PRINT pbdrv_uart_debug_printf
64+
static void pbdrv_hci_dump_reset(void) {
65+
}
66+
static void pbdrv_hci_dump_log_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t len) {
67+
pbdrv_uart_debug_printf("HCI %s packet type: %02x, len: %u\n", in ? "in" : "out", packet_type, len);
68+
}
69+
static void pbdrv_hci_dump_log_message(int log_level, const char *format, va_list argptr) {
70+
pbdrv_uart_debug_vprintf(format, argptr);
71+
pbdrv_uart_debug_printf("\n");
72+
}
73+
static const hci_dump_t bluetooth_btstack_classic_hci_dump = {
74+
.reset = pbdrv_hci_dump_reset,
75+
.log_packet = pbdrv_hci_dump_log_packet,
76+
.log_message = pbdrv_hci_dump_log_message,
77+
};
6278
#else
6379
#define DEBUG_PRINT(...)
6480
#endif
@@ -1143,6 +1159,15 @@ void pbdrv_bluetooth_init_hci(void) {
11431159
btstack_run_loop_init(&bluetooth_btstack_run_loop);
11441160

11451161
hci_init(pdata->transport_instance(), pdata->transport_config());
1162+
1163+
#if DEBUG
1164+
hci_dump_init(&bluetooth_btstack_classic_hci_dump);
1165+
hci_dump_enable_log_level(HCI_DUMP_LOG_LEVEL_INFO, true);
1166+
hci_dump_enable_log_level(HCI_DUMP_LOG_LEVEL_ERROR, true);
1167+
hci_dump_enable_log_level(HCI_DUMP_LOG_LEVEL_DEBUG, true);
1168+
hci_dump_enable_packet_log(true);
1169+
#endif
1170+
11461171
if (pdata->chipset_instance != NULL) {
11471172
hci_set_chipset(pdata->chipset_instance());
11481173
}

lib/pbio/drv/uart/uart_debug_first_port.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,20 @@ void pbdrv_uart_debug_init(void);
2121

2222
#else // PBDRV_CONFIG_UART_DEBUG_FIRST_PORT
2323

24+
#if PBDRV_CONFIG_UART_DEBUG_FIRST_PORT_IS_STDERR
25+
26+
#include <stdio.h>
27+
28+
#define pbdrv_uart_debug_printf(...) fprintf(stderr, __VA_ARGS__)
29+
#define pbdrv_uart_debug_vprintf(format, argptr) vfprintf(stderr, format, argptr)
30+
31+
#else
32+
2433
#define pbdrv_uart_debug_printf(...)
2534
#define pbdrv_uart_debug_vprintf(format, argptr)
2635

36+
#endif // PBDRV_CONFIG_UART_DEBUG_FIRST_PORT_IS_STDERR
37+
2738
#define pbdrv_uart_debug_is_done() (true)
2839

2940
#define pbdrv_uart_debug_init()

lib/pbio/platform/virtual_hub/pbdrvconfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#define PBDRV_CONFIG_MOTOR_DRIVER_NUM_DEV (6)
4242
#define PBDRV_CONFIG_MOTOR_DRIVER_VIRTUAL_SIMULATION (1)
4343

44+
#define PBDRV_CONFIG_UART_DEBUG_FIRST_PORT_IS_STDERR (1)
45+
4446
#define PBDRV_CONFIG_HAS_PORT_A (1)
4547
#define PBDRV_CONFIG_HAS_PORT_B (1)
4648
#define PBDRV_CONFIG_HAS_PORT_C (1)

0 commit comments

Comments
 (0)