1515#include "cybt_shared_bus_driver.h"
1616
1717#include "cyw43_btfw_43439.h"
18+ #include "cybt_logging.h"
1819
1920#if CYW43_USE_HEX_BTFW
2021extern const char brcm_patch_version [];
@@ -31,20 +32,6 @@ extern const int brcm_patch_ram_length;
3132#define BTSDIO_FWBUF_OPER_DELAY_US (250)
3233#define BTFW_WAIT_TIME_MS (150)
3334
34- #define CYBT_DEBUG 0
35- #define CYBT_VDEBUG 0
36-
37- #if CYBT_DEBUG
38- #define cybt_debug (format ,args ...) printf("%d.%d: " format, (int)cyw43_hal_ticks_ms() / 1000, (int)cyw43_hal_ticks_ms() % 1000, ## args)
39- #else
40- #define cybt_debug (format , ...) ((void)0)
41- #endif
42- #ifndef NDEBUG
43- #define cybt_printf (format , args ...) printf("%d.%d: " format, (int)cyw43_hal_ticks_ms() / 1000, (int)cyw43_hal_ticks_ms() % 1000, ## args)
44- #else
45- #define cybt_printf (...)
46- #endif
47-
4835#define ROUNDUP (x , a ) ((((x) + ((a) - 1)) / (a)) * (a))
4936#define ROUNDDN (x , a ) ((x) & ~((a) - 1))
5037#define ISALIGNED (a , x ) (((uint32_t)(a) & ((x) - 1)) == 0)
@@ -123,17 +110,17 @@ int cyw43_btbus_init(cyw43_ll_t *self) {
123110
124111 ret = cybt_fw_download_prepare (& p_write_buf , & p_hex_buf );
125112 if (CYBT_SUCCESS != ret ) {
126- cybt_printf ("Could not allocate memory\n" );
113+ cybt_error ("Could not allocate memory\n" );
127114 return ret ;
128115 }
129116
130117 cybt_debug ("cybt_fw_download\n" );
131118 const uint8_t * fw_data_buf ;
132119 uint32_t fw_data_len ;
133120#if CYW43_USE_HEX_BTFW
134- cybt_printf ("CYW43_USE_HEX_BTFW is true\n" );
121+ cybt_error ("CYW43_USE_HEX_BTFW is true\n" );
135122#ifndef NDEBUG
136- cybt_printf ("BT FW download, version = %s\n" , brcm_patch_version );
123+ cybt_info ("BT FW download, version = %s\n" , brcm_patch_version );
137124#endif
138125 fw_data_len = brcm_patch_ram_length ;
139126 fw_data_buf = brcm_patchram_buf ;
@@ -151,7 +138,7 @@ int cyw43_btbus_init(cyw43_ll_t *self) {
151138 cybt_fw_download_finish (p_write_buf , p_hex_buf );
152139
153140 if (CYBT_SUCCESS != ret ) {
154- cybt_printf ("hci_open(): FW download failed (0x%x)\n" , ret );
141+ cybt_error ("hci_open(): FW download failed (0x%x)\n" , ret );
155142 return CYBT_ERR_HCI_INIT_FAILED ;
156143 }
157144
@@ -161,7 +148,7 @@ int cyw43_btbus_init(cyw43_ll_t *self) {
161148 if (CYBT_SUCCESS == ret ) {
162149 cybt_debug ("hci_open(): FW download successfully\n" );
163150 } else {
164- cybt_printf ("hci_open(): Failed to download FW\n" );
151+ cybt_error ("hci_open(): Failed to download FW\n" );
165152 return CYBT_ERR_HCI_INIT_FAILED ;
166153 }
167154
@@ -182,7 +169,7 @@ int cyw43_btbus_init(cyw43_ll_t *self) {
182169 return CYBT_SUCCESS ;
183170}
184171
185- #if CYBT_VDEBUG
172+ #if 0
186173static void dump_bytes (const uint8_t * bptr , uint32_t len ) {
187174 unsigned int i = 0 ;
188175
@@ -198,6 +185,9 @@ static void dump_bytes(const uint8_t *bptr, uint32_t len) {
198185 }
199186 printf ("\n" );
200187}
188+ #define DUMP_BYTES dump_bytes
189+ #else
190+ #define DUMP_BYTES (...)
201191#endif
202192
203193static cybt_result_t cybt_hci_write_buf (const uint8_t * p_data , uint32_t length ) {
@@ -206,7 +196,7 @@ static cybt_result_t cybt_hci_write_buf(const uint8_t *p_data, uint32_t length)
206196
207197 assert (ISALIGNED (p_data , 4 ));
208198 if (!ISALIGNED (p_data , 4 )) {
209- cybt_printf ("cybt_hci_write_hdr: buffer not aligned\n" );
199+ cybt_error ("cybt_hci_write_hdr: buffer not aligned\n" );
210200 return CYBT_ERR_BADARG ;
211201 }
212202
@@ -260,7 +250,7 @@ static cybt_result_t cybt_hci_read(uint8_t *p_data, uint32_t *p_length) {
260250 assert (ISALIGNED (p_data , 4 ));
261251 if (!ISALIGNED (p_data , 4 )) {
262252 assert (false);
263- cybt_printf ("cybt_hci_read: buffer not aligned\n" );
253+ cybt_error ("cybt_hci_read: buffer not aligned\n" );
264254 return CYBT_ERR_BADARG ;
265255 }
266256
@@ -272,9 +262,9 @@ static cybt_result_t cybt_hci_read(uint8_t *p_data, uint32_t *p_length) {
272262 cybt_debug ("cybt_hci_read: bt2host_in_val=%lu bt2host_out_val=%lu fw_b2h_buf_count=%ld\n" ,
273263 fw_membuf_info .bt2host_in_val , fw_membuf_info .bt2host_out_val , fw_b2h_buf_count );
274264 if (fw_b2h_buf_count < available ) {
275- cybt_printf ("error: cybt_hci_read buffer overflow fw_b2h_buf_count=%ld available=%lu\n" , fw_b2h_buf_count ,
265+ cybt_error ("error: cybt_hci_read buffer overflow fw_b2h_buf_count=%ld available=%lu\n" , fw_b2h_buf_count ,
276266 available );
277- cybt_printf ("error: cybt_hci_read bt2host_in_val=%lu bt2host_out_val=%lu\n" , fw_membuf_info .bt2host_in_val ,
267+ cybt_error ("error: cybt_hci_read bt2host_in_val=%lu bt2host_out_val=%lu\n" , fw_membuf_info .bt2host_in_val ,
278268 fw_membuf_info .bt2host_out_val );
279269 panic ("cyw43 buffer overflow" );
280270 }
@@ -355,9 +345,7 @@ int cyw43_btbus_write(uint8_t *buf, uint32_t size) {
355345 cybt_bus_request ();
356346
357347 cybt_debug ("cyw43_btbus_write: %d\n" , cmd_len );
358- #if CYBT_VDEBUG
359- dump_bytes (buf , size ); // dump header and data
360- #endif
348+ DUMP_BYTES (buf , size ); // dump header and data
361349
362350 cybt_hci_write_buf (buf , size );
363351 cybt_bus_release ();
@@ -376,7 +364,7 @@ static bool cybt_hci_read_packet(uint8_t *buf, uint32_t max_buf_size, uint32_t *
376364
377365 if (bt_result != CYBT_SUCCESS ) {
378366 * size = 0 ;
379- cybt_printf ("cybt_hci_read_packet: error %d" , bt_result );
367+ cybt_error ("cybt_hci_read_packet: error %d" , bt_result );
380368 return true;
381369 }
382370
@@ -390,7 +378,7 @@ static bool cybt_hci_read_packet(uint8_t *buf, uint32_t max_buf_size, uint32_t *
390378 uint32_t hci_read_len = ((buf [2 ] << 16 ) & 0xFFFF00 ) | ((buf [1 ] << 8 ) & 0xFF00 ) | (buf [0 ] & 0xFF );
391379 if (hci_read_len > max_buf_size - 4 ) {
392380 * size = 0 ;
393- cybt_printf ("cybt_hci_read_packet: too much data len %" PRId32 "\n" , hci_read_len );
381+ cybt_error ("cybt_hci_read_packet: too much data len %" PRId32 "\n" , hci_read_len );
394382 assert (false);
395383 return false;
396384 }
@@ -401,7 +389,7 @@ static bool cybt_hci_read_packet(uint8_t *buf, uint32_t max_buf_size, uint32_t *
401389 bt_result = cybt_hci_read (buf + 4 , & total_read_len );
402390 if (bt_result != CYBT_SUCCESS ) {
403391 * size = 0 ;
404- cybt_printf ("cybt_hci_read_packet: read failed\n" );
392+ cybt_error ("cybt_hci_read_packet: read failed\n" );
405393 assert (false);
406394 return false;
407395 }
@@ -413,15 +401,13 @@ static bool cybt_hci_read_packet(uint8_t *buf, uint32_t max_buf_size, uint32_t *
413401 } else {
414402 assert (total_read_len > 0 );
415403 * size = total_read_len + 4 ;
416- cybt_printf ("cybt_hci_read_packet: failed to read all data %lu < %lu\n" , total_read_len , hci_read_len );
404+ cybt_error ("cybt_hci_read_packet: failed to read all data %lu < %lu\n" , total_read_len , hci_read_len );
417405 //assert(false);
418406 return true;
419407 }
420408
421409 cybt_debug ("cybt_hci_read_packet: %ld\n" , * size );
422- #if CYBT_VDEBUG
423- dump_bytes (buf , * size );
424- #endif
410+ DUMP_BYTES (buf , * size );
425411
426412 return true;
427413}
0 commit comments