Skip to content

Commit 02e7bfd

Browse files
iabdalkaderdpgeorge
authored andcommitted
drivers/esp-hosted: Use __func__ in logging macros.
Update the logging macros to automatically include the function name using __func__, removing the need to manually specify it at each call site. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
1 parent 0d26a85 commit 02e7bfd

3 files changed

Lines changed: 40 additions & 40 deletions

File tree

drivers/esp-hosted/esp_hosted_hal.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@
5353
#endif
5454

5555
// Logging macros.
56-
#define debug_printf(...) do_printf(ANSI_C_BLUE); do_printf(__VA_ARGS__); do_printf(ANSI_C_DEFAULT);
57-
#define info_printf(...) do_printf(ANSI_C_GREEN); do_printf(__VA_ARGS__); do_printf(ANSI_C_DEFAULT);
58-
#define warn_printf(...) do_printf(ANSI_C_YELLOW); do_printf(__VA_ARGS__); do_printf(ANSI_C_DEFAULT);
59-
#define error_printf(...) do_printf(ANSI_C_RED); do_printf(__VA_ARGS__); do_printf(ANSI_C_DEFAULT);
60-
#define crit_printf(...) do_printf(ANSI_C_MAGENTA); do_printf(__VA_ARGS__); do_printf(ANSI_C_DEFAULT);
56+
#define debug_printf(fmt, ...) do { do_printf(ANSI_C_BLUE "%s() " fmt ANSI_C_DEFAULT, __func__, ##__VA_ARGS__); } while (0)
57+
#define info_printf(fmt, ...) do { do_printf(ANSI_C_GREEN "%s() " fmt ANSI_C_DEFAULT, __func__, ##__VA_ARGS__); } while (0)
58+
#define warn_printf(fmt, ...) do { do_printf(ANSI_C_YELLOW "%s() " fmt ANSI_C_DEFAULT, __func__, ##__VA_ARGS__); } while (0)
59+
#define error_printf(fmt, ...) do { do_printf(ANSI_C_RED "%s() " fmt ANSI_C_DEFAULT, __func__, ##__VA_ARGS__); } while (0)
60+
#define crit_printf(fmt, ...) do { do_printf(ANSI_C_MAGENTA "%s() " fmt ANSI_C_DEFAULT, __func__, ##__VA_ARGS__); } while (0)
6161

6262
typedef enum {
6363
ESP_HOSTED_MODE_BT,

drivers/esp-hosted/esp_hosted_netif.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static err_t netif_struct_init(struct netif *netif) {
5555
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP;
5656
esp_hosted_wifi_get_mac(netif->name[1] - '0', netif->hwaddr);
5757
netif->hwaddr_len = sizeof(netif->hwaddr);
58-
info_printf("netif_init() netif initialized\n");
58+
info_printf("netif initialized\n");
5959
return ERR_OK;
6060
}
6161

@@ -122,27 +122,27 @@ int esp_hosted_netif_input(esp_hosted_state_t *state, uint32_t itf, const void *
122122

123123
struct pbuf *p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
124124
if (p == NULL) {
125-
error_printf("esp_hosted_netif_input() failed to alloc pbuf %d\n", len);
125+
error_printf("failed to alloc pbuf %d\n", len);
126126
return -1;
127127
}
128128
// Copy buf to pbuf
129129
pbuf_take(p, buf, len);
130130

131131
if (netif->input(p, netif) != ERR_OK) {
132-
error_printf("esp_hosted_netif_input() netif input failed\n");
132+
error_printf("netif input failed\n");
133133
pbuf_free(p);
134134
return -1;
135135
}
136136

137-
debug_printf("esp_hosted_netif_input() eth frame input %d\n", len);
137+
debug_printf("eth frame input %d\n", len);
138138
return 0;
139139
}
140140

141141
err_t esp_hosted_netif_output(struct netif *netif, struct pbuf *p) {
142142
esp_hosted_state_t *state = netif->state;
143143

144144
if (p->tot_len > ESP_FRAME_MAX_PAYLOAD) {
145-
error_printf("esp_hosted_netif_output() pbuf len > SPI buf len\n");
145+
error_printf("pbuf len > SPI buf len\n");
146146
return ERR_IF;
147147
}
148148

@@ -158,10 +158,10 @@ err_t esp_hosted_netif_output(struct netif *netif, struct pbuf *p) {
158158

159159
size_t frame_size = (sizeof(esp_header_t) + esp_header->len + 3) & ~3U;
160160
if (esp_hosted_hal_spi_transfer(state->buf, NULL, frame_size) != 0) {
161-
error_printf("esp_hosted_netif_output() failed to send eth frame\n");
161+
error_printf("failed to send eth frame\n");
162162
return ERR_IF;
163163
}
164-
debug_printf("esp_hosted_netif_output() if %d pbuf len %d\n", esp_header->if_type, esp_header->len);
164+
debug_printf("if %d pbuf len %d\n", esp_header->if_type, esp_header->len);
165165
return ERR_OK;
166166
}
167167
#endif

drivers/esp-hosted/esp_hosted_wifi.c

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static int esp_hosted_request(CtrlMsgId msg_id, void *ctrl_payload) {
216216
// Pack protobuf
217217
size_t payload_size = ctrl_msg__get_packed_size(&ctrl_msg);
218218
if ((payload_size + sizeof(tlv_header_t)) > ESP_FRAME_MAX_PAYLOAD) {
219-
error_printf("esp_hosted_request() payload size > max payload %d\n", msg_id);
219+
error_printf("payload size > max payload %d\n", msg_id);
220220
return -1;
221221
}
222222

@@ -240,7 +240,7 @@ static int esp_hosted_request(CtrlMsgId msg_id, void *ctrl_payload) {
240240

241241
size_t frame_size = (sizeof(esp_header_t) + esp_header->len + 3) & ~3U;
242242
if (esp_hosted_hal_spi_transfer(esp_state.buf, NULL, frame_size) != 0) {
243-
error_printf("esp_hosted_request() request %d failed\n", msg_id);
243+
error_printf("request %d failed\n", msg_id);
244244
return -1;
245245
}
246246
return 0;
@@ -256,7 +256,7 @@ static CtrlMsg *esp_hosted_response(CtrlMsgId msg_id, uint32_t timeout) {
256256
break;
257257
}
258258

259-
debug_printf("esp_hosted_response() waiting for id %lu last id %lu\n", msg_id, ctrl_msg->msg_id);
259+
debug_printf("waiting for id %lu last id %lu\n", msg_id, ctrl_msg->msg_id);
260260
ctrl_msg = NULL;
261261
}
262262

@@ -273,7 +273,7 @@ static CtrlMsg *esp_hosted_response(CtrlMsgId msg_id, uint32_t timeout) {
273273

274274
// If message type is a response, check the response struct's return value.
275275
if (ctrl_msg->msg_type == CTRL_MSG_TYPE__Resp && esp_hosted_resp_value(ctrl_msg) != 0) {
276-
error_printf("esp_hosted_response() response %d failed %d\n", msg_id, esp_hosted_resp_value(ctrl_msg));
276+
error_printf("response %d failed %d\n", msg_id, esp_hosted_resp_value(ctrl_msg));
277277
ctrl_msg__free_unpacked(ctrl_msg, &protobuf_alloc);
278278
return NULL;
279279
}
@@ -305,41 +305,41 @@ int esp_hosted_wifi_poll(void) {
305305
esp_header_t *frag_header = (esp_header_t *)(esp_state.buf + offset);
306306
if ((ESP_STATE_BUF_SIZE - offset) < ESP_FRAME_MAX_SIZE) {
307307
// This shouldn't happen, but if it did stop polling.
308-
error_printf("esp_hosted_poll() spi buffer overflow offs %d\n", offset);
308+
error_printf("spi buffer overflow offs %d\n", offset);
309309
return -1;
310310
}
311311

312312
if (esp_hosted_hal_spi_transfer(NULL, esp_state.buf + offset, ESP_FRAME_MAX_SIZE) != 0) {
313-
error_printf("esp_hosted_poll() spi transfer failed\n");
313+
error_printf("spi transfer failed\n");
314314
return 0;
315315
}
316316

317317
if (frag_header->len == 0 ||
318318
frag_header->len > ESP_FRAME_MAX_PAYLOAD ||
319319
frag_header->offset != sizeof(esp_header_t)) {
320320
// Invalid or empty packet, just ignore it silently.
321-
warn_printf("esp_hosted_poll() invalid frame size %d offset %d\n",
321+
warn_printf("invalid frame size %d offset %d\n",
322322
esp_header->len, esp_header->offset);
323323
return 0;
324324
}
325325

326326
uint16_t checksum = frag_header->checksum;
327327
frag_header->checksum = esp_hosted_checksum(frag_header);
328328
if (frag_header->checksum != checksum) {
329-
warn_printf("esp_hosted_poll() invalid checksum, expected %d\n", checksum);
329+
warn_printf("invalid checksum, expected %d\n", checksum);
330330
return 0;
331331
}
332332

333333
if (offset) {
334334
// Combine fragmented packet
335335
if ((esp_header->seq_num + 1) != frag_header->seq_num) {
336-
error_printf("esp_hosted_poll() fragmented frame sequence mismatch\n");
336+
error_printf("fragmented frame sequence mismatch\n");
337337
return 0;
338338
}
339339
esp_header->len += frag_header->len;
340340
esp_header->seq_num = frag_header->seq_num;
341341
esp_header->flags = frag_header->flags;
342-
info_printf("esp_hosted_poll() received fragmented packet %d\n", frag_header->len);
342+
info_printf("received fragmented packet %d\n", frag_header->len);
343343
// Append the current fragment's payload to the previous one.
344344
memcpy(esp_state.buf + offset, frag_header->payload, frag_header->len);
345345
}
@@ -358,10 +358,10 @@ int esp_hosted_wifi_poll(void) {
358358
uint32_t itf = esp_header->if_type;
359359
if (netif_is_link_up(&esp_state.netif[itf])) {
360360
if (esp_hosted_netif_input(&esp_state, itf, esp_header->payload, esp_header->len) != 0) {
361-
error_printf("esp_hosted_poll() netif input failed\n");
361+
error_printf("netif input failed\n");
362362
return -1;
363363
}
364-
debug_printf("esp_hosted_poll() eth frame input %d\n", esp_header->len);
364+
debug_printf("eth frame input %d\n", esp_header->len);
365365
}
366366
return 0;
367367
}
@@ -372,15 +372,15 @@ int esp_hosted_wifi_poll(void) {
372372
esp_state.chip_id = priv_event->event_data[2];
373373
esp_state.spi_clk = priv_event->event_data[5];
374374
esp_state.chip_flags = priv_event->event_data[8];
375-
info_printf("esp_hosted_poll() chip id %d spi_mhz %d caps 0x%x\n",
375+
info_printf("chip id %d spi_mhz %d caps 0x%x\n",
376376
esp_state.chip_id, esp_state.spi_clk, esp_state.chip_flags);
377377
}
378378
return 0;
379379
}
380380
case ESP_HOSTED_HCI_IF:
381381
case ESP_HOSTED_TEST_IF:
382382
case ESP_HOSTED_MAX_IF:
383-
error_printf("esp_hosted_poll() unexpected interface type %d\n", esp_header->if_type);
383+
error_printf("unexpected interface type %d\n", esp_header->if_type);
384384
return 0;
385385
case ESP_HOSTED_SERIAL_IF:
386386
// Requires further processing
@@ -389,7 +389,7 @@ int esp_hosted_wifi_poll(void) {
389389

390390
CtrlMsg *ctrl_msg = ctrl_msg__unpack(&protobuf_alloc, tlv_header->data_length, tlv_header->data);
391391
if (ctrl_msg == NULL) {
392-
error_printf("esp_hosted_poll() failed to unpack protobuf\n");
392+
error_printf("failed to unpack protobuf\n");
393393
return 0;
394394
}
395395

@@ -400,7 +400,7 @@ int esp_hosted_wifi_poll(void) {
400400
break;
401401
case CTRL_MSG_ID__Event_Heartbeat:
402402
esp_state.last_hb_ms = mp_hal_ticks_ms();
403-
info_printf("esp_hosted_poll() heartbeat %lu\n", esp_state.last_hb_ms);
403+
info_printf("heartbeat %lu\n", esp_state.last_hb_ms);
404404
return 0;
405405
case CTRL_MSG_ID__Event_StationDisconnectFromAP:
406406
esp_state.flags &= ~ESP_HOSTED_FLAGS_STA_CONNECTED;
@@ -409,21 +409,21 @@ int esp_hosted_wifi_poll(void) {
409409
return 0;
410410
case CTRL_MSG_ID__Event_StationConnectedToAP:
411411
esp_state.flags |= ESP_HOSTED_FLAGS_STA_CONNECTED;
412-
info_printf("esp_hosted_poll() connected to AP\n");
412+
info_printf("connected to AP\n");
413413
return 0;
414414
default:
415-
error_printf("esp_hosted_poll() unexpected event %d\n", ctrl_msg->msg_id);
415+
error_printf("unexpected event %d\n", ctrl_msg->msg_id);
416416
return 0;
417417
}
418418
}
419419

420420
// A control message resp/event will be pushed on the stack for further processing.
421421
if (!esp_hosted_stack_push(&esp_state.stack, ctrl_msg)) {
422-
error_printf("esp_hosted_poll() message stack full\n");
422+
error_printf("message stack full\n");
423423
return -1;
424424
}
425425

426-
debug_printf("esp_hosted_poll() pushed msg_type %lu msg_id %lu\n", ctrl_msg->msg_type, ctrl_msg->msg_id);
426+
debug_printf("pushed msg_type %lu msg_id %lu\n", ctrl_msg->msg_type, ctrl_msg->msg_id);
427427
return 0;
428428
}
429429

@@ -435,7 +435,7 @@ int esp_hosted_wifi_init(uint32_t itf) {
435435

436436
// Low-level pins and SPI init, memory pool allocation etc...
437437
if (esp_hosted_hal_init(ESP_HOSTED_MODE_WIFI) != 0) {
438-
error_printf("esp_hosted_init() low-level error\n");
438+
error_printf("low-level error\n");
439439
return -1;
440440
}
441441

@@ -447,7 +447,7 @@ int esp_hosted_wifi_init(uint32_t itf) {
447447
// Wait for an ESPInit control event.
448448
ctrl_msg = esp_hosted_response(CTRL_MSG_ID__Event_ESPInit, ESP_SYNC_REQ_TIMEOUT);
449449
if (ctrl_msg == NULL) {
450-
error_printf("esp_hosted_init() espinit event timeout\n");
450+
error_printf("espinit event timeout\n");
451451
return -1;
452452
}
453453
ctrl_msg__free_unpacked(ctrl_msg, &protobuf_alloc);
@@ -475,18 +475,18 @@ int esp_hosted_wifi_init(uint32_t itf) {
475475
ctrl_msg__req__set_mode__init(&ctrl_payload_mode);
476476
ctrl_payload_mode.mode = CTRL__WIFI_MODE__APSTA;
477477
if (esp_hosted_ctrl(CTRL_MSG_ID__Req_SetWifiMode, &ctrl_payload_mode, &ctrl_msg) != 0) {
478-
error_printf("esp_hosted_init() failed to set WiFi mode\n");
478+
error_printf("failed to set WiFi mode\n");
479479
return -1;
480480
}
481481
ctrl_msg__free_unpacked(ctrl_msg, &protobuf_alloc);
482482

483-
info_printf("esp_hosted_init() device initialized\n");
483+
info_printf("device initialized\n");
484484
}
485485

486486
if (!netif_is_link_up(&esp_state.netif[itf])) {
487487
// Init lwip netif, and start DHCP client/server.
488488
esp_hosted_netif_init(&esp_state, itf);
489-
info_printf("esp_hosted_init() initialized itf %lu\n", itf);
489+
info_printf("initialized itf %lu\n", itf);
490490
}
491491

492492
// Re/enable IRQ pin.
@@ -505,7 +505,7 @@ int esp_hosted_wifi_disable(uint32_t itf) {
505505
esp_state.flags &= ~ESP_HOSTED_FLAGS_AP_STARTED;
506506
}
507507

508-
info_printf("esp_hosted_deinit() deinitialized itf %lu\n", itf);
508+
info_printf("deinitialized itf %lu\n", itf);
509509
return 0;
510510
}
511511

@@ -519,7 +519,7 @@ int esp_hosted_wifi_deinit(void) {
519519
memset(&esp_state, 0, sizeof(esp_hosted_state_t));
520520
esp_hosted_stack_init(&esp_state.stack);
521521

522-
info_printf("esp_hosted_deinit() deinitialized\n");
522+
info_printf("deinitialized\n");
523523
}
524524
return 0;
525525
}
@@ -535,7 +535,7 @@ int esp_hosted_wifi_get_mac(int itf, uint8_t *mac) {
535535
ctrl_payload.mode = (itf == ESP_HOSTED_STA_IF) ? CTRL__WIFI_MODE__STA : CTRL__WIFI_MODE__AP;
536536

537537
if (esp_hosted_ctrl(CTRL_MSG_ID__Req_GetMACAddress, &ctrl_payload, &ctrl_msg) != 0) {
538-
error_printf("esp_hosted_get_mac() request failed\n");
538+
error_printf("request failed\n");
539539
return -1;
540540
}
541541

0 commit comments

Comments
 (0)