15
15
#include "cybt_shared_bus_driver.h"
16
16
17
17
#include "cyw43_btfw_43439.h"
18
+ #include "cybt_logging.h"
18
19
19
20
#if CYW43_USE_HEX_BTFW
20
21
extern const char brcm_patch_version [];
@@ -31,20 +32,6 @@ extern const int brcm_patch_ram_length;
31
32
#define BTSDIO_FWBUF_OPER_DELAY_US (250)
32
33
#define BTFW_WAIT_TIME_MS (150)
33
34
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
-
48
35
#define ROUNDUP (x , a ) ((((x) + ((a) - 1)) / (a)) * (a))
49
36
#define ROUNDDN (x , a ) ((x) & ~((a) - 1))
50
37
#define ISALIGNED (a , x ) (((uint32_t)(a) & ((x) - 1)) == 0)
@@ -123,17 +110,17 @@ int cyw43_btbus_init(cyw43_ll_t *self) {
123
110
124
111
ret = cybt_fw_download_prepare (& p_write_buf , & p_hex_buf );
125
112
if (CYBT_SUCCESS != ret ) {
126
- cybt_printf ("Could not allocate memory\n" );
113
+ cybt_error ("Could not allocate memory\n" );
127
114
return ret ;
128
115
}
129
116
130
117
cybt_debug ("cybt_fw_download\n" );
131
118
const uint8_t * fw_data_buf ;
132
119
uint32_t fw_data_len ;
133
120
#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" );
135
122
#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 );
137
124
#endif
138
125
fw_data_len = brcm_patch_ram_length ;
139
126
fw_data_buf = brcm_patchram_buf ;
@@ -151,7 +138,7 @@ int cyw43_btbus_init(cyw43_ll_t *self) {
151
138
cybt_fw_download_finish (p_write_buf , p_hex_buf );
152
139
153
140
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 );
155
142
return CYBT_ERR_HCI_INIT_FAILED ;
156
143
}
157
144
@@ -161,7 +148,7 @@ int cyw43_btbus_init(cyw43_ll_t *self) {
161
148
if (CYBT_SUCCESS == ret ) {
162
149
cybt_debug ("hci_open(): FW download successfully\n" );
163
150
} else {
164
- cybt_printf ("hci_open(): Failed to download FW\n" );
151
+ cybt_error ("hci_open(): Failed to download FW\n" );
165
152
return CYBT_ERR_HCI_INIT_FAILED ;
166
153
}
167
154
@@ -182,7 +169,7 @@ int cyw43_btbus_init(cyw43_ll_t *self) {
182
169
return CYBT_SUCCESS ;
183
170
}
184
171
185
- #if CYBT_VDEBUG
172
+ #if 0
186
173
static void dump_bytes (const uint8_t * bptr , uint32_t len ) {
187
174
unsigned int i = 0 ;
188
175
@@ -198,6 +185,9 @@ static void dump_bytes(const uint8_t *bptr, uint32_t len) {
198
185
}
199
186
printf ("\n" );
200
187
}
188
+ #define DUMP_BYTES dump_bytes
189
+ #else
190
+ #define DUMP_BYTES (...)
201
191
#endif
202
192
203
193
static 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)
206
196
207
197
assert (ISALIGNED (p_data , 4 ));
208
198
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" );
210
200
return CYBT_ERR_BADARG ;
211
201
}
212
202
@@ -260,7 +250,7 @@ static cybt_result_t cybt_hci_read(uint8_t *p_data, uint32_t *p_length) {
260
250
assert (ISALIGNED (p_data , 4 ));
261
251
if (!ISALIGNED (p_data , 4 )) {
262
252
assert (false);
263
- cybt_printf ("cybt_hci_read: buffer not aligned\n" );
253
+ cybt_error ("cybt_hci_read: buffer not aligned\n" );
264
254
return CYBT_ERR_BADARG ;
265
255
}
266
256
@@ -272,9 +262,9 @@ static cybt_result_t cybt_hci_read(uint8_t *p_data, uint32_t *p_length) {
272
262
cybt_debug ("cybt_hci_read: bt2host_in_val=%lu bt2host_out_val=%lu fw_b2h_buf_count=%ld\n" ,
273
263
fw_membuf_info .bt2host_in_val , fw_membuf_info .bt2host_out_val , fw_b2h_buf_count );
274
264
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 ,
276
266
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 ,
278
268
fw_membuf_info .bt2host_out_val );
279
269
panic ("cyw43 buffer overflow" );
280
270
}
@@ -355,9 +345,7 @@ int cyw43_btbus_write(uint8_t *buf, uint32_t size) {
355
345
cybt_bus_request ();
356
346
357
347
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
361
349
362
350
cybt_hci_write_buf (buf , size );
363
351
cybt_bus_release ();
@@ -376,7 +364,7 @@ static bool cybt_hci_read_packet(uint8_t *buf, uint32_t max_buf_size, uint32_t *
376
364
377
365
if (bt_result != CYBT_SUCCESS ) {
378
366
* size = 0 ;
379
- cybt_printf ("cybt_hci_read_packet: error %d" , bt_result );
367
+ cybt_error ("cybt_hci_read_packet: error %d" , bt_result );
380
368
return true;
381
369
}
382
370
@@ -390,7 +378,7 @@ static bool cybt_hci_read_packet(uint8_t *buf, uint32_t max_buf_size, uint32_t *
390
378
uint32_t hci_read_len = ((buf [2 ] << 16 ) & 0xFFFF00 ) | ((buf [1 ] << 8 ) & 0xFF00 ) | (buf [0 ] & 0xFF );
391
379
if (hci_read_len > max_buf_size - 4 ) {
392
380
* 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 );
394
382
assert (false);
395
383
return false;
396
384
}
@@ -401,7 +389,7 @@ static bool cybt_hci_read_packet(uint8_t *buf, uint32_t max_buf_size, uint32_t *
401
389
bt_result = cybt_hci_read (buf + 4 , & total_read_len );
402
390
if (bt_result != CYBT_SUCCESS ) {
403
391
* size = 0 ;
404
- cybt_printf ("cybt_hci_read_packet: read failed\n" );
392
+ cybt_error ("cybt_hci_read_packet: read failed\n" );
405
393
assert (false);
406
394
return false;
407
395
}
@@ -413,15 +401,13 @@ static bool cybt_hci_read_packet(uint8_t *buf, uint32_t max_buf_size, uint32_t *
413
401
} else {
414
402
assert (total_read_len > 0 );
415
403
* 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 );
417
405
//assert(false);
418
406
return true;
419
407
}
420
408
421
409
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 );
425
411
426
412
return true;
427
413
}
0 commit comments