diff options
-rw-r--r-- | cmd/sbc_harness/fs_harness_flash_bin.c | 16 | ||||
-rw-r--r-- | cmd/sbc_harness/main.c | 4 | ||||
-rw-r--r-- | cmd/sbc_harness/tusb_log.c | 8 | ||||
-rw-r--r-- | lib9p/srv.c | 16 | ||||
-rw-r--r-- | libcr/coroutine.c | 34 | ||||
-rw-r--r-- | libdhcp/dhcp_client.c | 30 | ||||
-rw-r--r-- | libhw_cr/rp2040_hwspi.c | 4 | ||||
-rw-r--r-- | libhw_cr/w5500.c | 98 | ||||
-rw-r--r-- | libhw_cr/w5500_ll.h | 12 | ||||
-rw-r--r-- | libmisc/assert.c | 10 | ||||
-rw-r--r-- | libmisc/include/libmisc/log.h | 16 | ||||
-rw-r--r-- | libmisc/tests/test_log.c | 10 | ||||
-rw-r--r-- | libusb/usb_common.c | 6 |
13 files changed, 132 insertions, 132 deletions
diff --git a/cmd/sbc_harness/fs_harness_flash_bin.c b/cmd/sbc_harness/fs_harness_flash_bin.c index 5920b85..f353ddd 100644 --- a/cmd/sbc_harness/fs_harness_flash_bin.c +++ b/cmd/sbc_harness/fs_harness_flash_bin.c @@ -41,7 +41,7 @@ static_assert(DATA_HSIZE % FLASH_SECTOR_SIZE == 0); [[noreturn]] static void __no_inline_not_in_flash_func(ab_flash_finalize)(uint8_t *buf) { assert(buf); - infof("copying upper flash to lower flash..."); + log_infof("copying upper flash to lower flash..."); cr_save_and_disable_interrupts(); @@ -53,7 +53,7 @@ static_assert(DATA_HSIZE % FLASH_SECTOR_SIZE == 0); flash_range_program(off, buf, FLASH_SECTOR_SIZE); } - infof("rebooting..."); + log_infof("rebooting..."); watchdog_reboot(0, 0, 300); @@ -71,7 +71,7 @@ static void ab_flash_initialize_zero(uint8_t *buf) { memset(buf, 0, FLASH_SECTOR_SIZE); - infof("zeroing upper flash..."); + log_infof("zeroing upper flash..."); for (size_t off = DATA_HSIZE; off < DATA_SIZE; off += FLASH_SECTOR_SIZE) { if (memcmp(buf, DATA_START+off, FLASH_SECTOR_SIZE) == 0) continue; @@ -84,7 +84,7 @@ static void ab_flash_initialize_zero(uint8_t *buf) { flash_range_program(off, buf, FLASH_SECTOR_SIZE); cr_restore_interrupts(saved); } - debugf("... zeroed"); + log_debugf("... zeroed"); } /** @@ -95,7 +95,7 @@ static void ab_flash_initialize_zero(uint8_t *buf) { static void ab_flash_initialize(uint8_t *buf) { assert(buf); - infof("initializing upper flash..."); + log_infof("initializing upper flash..."); for (size_t off = 0; off < DATA_HSIZE; off += FLASH_SECTOR_SIZE) { memcpy(buf, DATA_START+off, FLASH_SECTOR_SIZE); if (memcmp(buf, DATA_START+DATA_HSIZE+off, FLASH_SECTOR_SIZE) == 0) @@ -105,7 +105,7 @@ static void ab_flash_initialize(uint8_t *buf) { flash_range_program(DATA_HSIZE+off, buf, FLASH_SECTOR_SIZE); cr_restore_interrupts(saved); } - debugf("... initialized"); + log_debugf("... initialized"); } /** @@ -123,14 +123,14 @@ static void ab_flash_write_sector(size_t pos, uint8_t *dat) { pos += DATA_HSIZE; - infof("write flash sector @ %zu...", pos); + log_infof("write flash sector @ %zu...", pos); if (memcmp(dat, DATA_START+pos, FLASH_SECTOR_SIZE) != 0) { bool saved = cr_save_and_disable_interrupts(); flash_range_erase(pos, FLASH_SECTOR_SIZE); flash_range_program(pos, dat, FLASH_SECTOR_SIZE); cr_restore_interrupts(saved); } - debugf("... written"); + log_debugf("... written"); } /* srv_file *******************************************************************/ diff --git a/cmd/sbc_harness/main.c b/cmd/sbc_harness/main.c index 5630e83..7d6c085 100644 --- a/cmd/sbc_harness/main.c +++ b/cmd/sbc_harness/main.c @@ -129,7 +129,7 @@ static COROUTINE hello_world_cr(void *_chan) { for (size_t i = 0;; i = (i+1) % strlen(msg)) { int result = usb_keyboard_rpc_send_req(chan, (uint32_t)msg[i]); if (result < 1) { - errorf("error sending rune U+%d", (uint32_t)msg[i]); + log_errorf("error sending rune U+%d", (uint32_t)msg[i]); break; } } @@ -246,7 +246,7 @@ int main() { bootclock = rp2040_hwtimer(0); stdio_uart_init(); /* char *hdr = "=" * (80-strlen("info : MAIN: ")); */ - infof("==================================================================="); + log_infof("==================================================================="); coroutine_add("init", init_cr, NULL); coroutine_main(); assert_notreached("all coroutines exited"); diff --git a/cmd/sbc_harness/tusb_log.c b/cmd/sbc_harness/tusb_log.c index 4c6b7df..fe2c688 100644 --- a/cmd/sbc_harness/tusb_log.c +++ b/cmd/sbc_harness/tusb_log.c @@ -1,6 +1,6 @@ /* sbc_harness/tusb_log.c - Logger for tusb_config.h * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later */ @@ -9,7 +9,7 @@ void _libmisc_tu_mess_failed(const char *expr, const char *file, unsigned int line, const char *func) { - errorf("%s:%u:%s(): assertion \"%s\" failed", - file, line, func, - expr); + log_errorf("%s:%u:%s(): assertion \"%s\" failed", + file, line, func, + expr); } diff --git a/lib9p/srv.c b/lib9p/srv.c index 6d9d992..ddf4834 100644 --- a/lib9p/srv.c +++ b/lib9p/srv.c @@ -54,12 +54,12 @@ void lib9p_srv_acknowledge_flush(struct lib9p_srv_ctx *ctx) { ctx->flush_acknowledged = true; } -#define req_debugf(fmt, ...) \ - debugf("cid=%zu: %s(tag=%"PRIu16"): " fmt, \ - cr_getcid(), \ - lib9p_msgtype_str(ctx->basectx.version, ctx->net_bytes[4]), \ - ctx->tag \ - __VA_OPT__(,) __VA_ARGS__) +#define req_debugf(fmt, ...) \ + log_debugf("cid=%zu: %s(tag=%"PRIu16"): " fmt, \ + cr_getcid(), \ + lib9p_msgtype_str(ctx->basectx.version, ctx->net_bytes[4]), \ + ctx->tag \ + __VA_OPT__(,) __VA_ARGS__) /* structs ********************************************************************/ @@ -361,7 +361,7 @@ static void srv_msglog(struct srv_req *req, enum lib9p_msg_type typ, void *hostm #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat" #pragma GCC diagnostic ignored "-Wformat-extra-args" - infof("%c %v", typ % 2 ? '<' : '>', lo_box_lib9p_msg_as_fmt_formatter(&req->basectx, typ, hostmsg)); + log_infof("%c %v", typ % 2 ? '<' : '>', lo_box_lib9p_msg_as_fmt_formatter(&req->basectx, typ, hostmsg)); #pragma GCC diagnostic pop } @@ -373,7 +373,7 @@ static ssize_t srv_write_Rmsg(struct srv_req *req, struct lib9p_Rmsg_send_buf *r return r; } -#define srv_nonrespond_errorf errorf +#define srv_nonrespond_errorf log_errorf static void srv_respond_error(struct srv_req *req) { #if CONFIG_9P_ENABLE_9P2000_u || CONFIG_9P_ENABLE_9P2000_L diff --git a/libcr/coroutine.c b/libcr/coroutine.c index bf44219..2c605fc 100644 --- a/libcr/coroutine.c +++ b/libcr/coroutine.c @@ -556,8 +556,8 @@ cid_t coroutine_add_with_stack_size(size_t stack_size, assert_cid_state(parent, state == CR_RUNNING); assert(stack_size); assert(fn); - debugf("coroutine_add_with_stack_size(%zu, \"%s\", %p, %p)...", - stack_size, name, fn, args); + log_debugf("coroutine_add_with_stack_size(%zu, \"%s\", %p, %p)...", + stack_size, name, fn, args); if (!coroutine_initialized) { cr_plat_init(); @@ -567,7 +567,7 @@ cid_t coroutine_add_with_stack_size(size_t stack_size, cid_t child = coroutine_allocate_cid(); if (!child) return 0; - debugf("...child=%zu", child); + log_debugf("...child=%zu", child); /* 1. state *************************************************/ coroutine_table[child-1].state = CR_INITIALIZING; @@ -580,13 +580,13 @@ cid_t coroutine_add_with_stack_size(size_t stack_size, /* 3. stack *************************************************/ coroutine_table[child-1].stack_size = stack_size + 2*CR_STACK_GUARD_SIZE; - infof("allocing \"%s\" stack with size %zu+2*%zu=%zu", - name, stack_size, CR_STACK_GUARD_SIZE, coroutine_table[child-1].stack_size); + log_infof("allocing \"%s\" stack with size %zu+2*%zu=%zu", + name, stack_size, CR_STACK_GUARD_SIZE, coroutine_table[child-1].stack_size); coroutine_table[child-1].stack = aligned_alloc(CR_PLAT_STACK_ALIGNMENT, coroutine_table[child-1].stack_size); - infof("... done, stack is [0x%p,0x%p)", - coroutine_table[child-1].stack + CR_STACK_GUARD_SIZE, - coroutine_table[child-1].stack + CR_STACK_GUARD_SIZE + stack_size); + log_infof("... done, stack is [0x%p,0x%p)", + coroutine_table[child-1].stack + CR_STACK_GUARD_SIZE, + coroutine_table[child-1].stack + CR_STACK_GUARD_SIZE + stack_size); #if CONFIG_COROUTINE_MEASURE_STACK || CONFIG_COROUTINE_PROTECT_STACK for (size_t i = 0; i < coroutine_table[child-1].stack_size; i++) ((uint8_t *)coroutine_table[child-1].stack)[i] = @@ -608,8 +608,8 @@ cid_t coroutine_add_with_stack_size(size_t stack_size, + stack_size #endif ; - debugf("...stack =%p", coroutine_table[child-1].stack); - debugf("...stack_base=%p", stack_base); + log_debugf("...stack =%p", coroutine_table[child-1].stack); + log_debugf("...stack_base=%p", stack_base); /* run until cr_begin() */ cr_plat_call_with_stack(stack_base, fn, args); assert_notreached("should cr_begin() instead of returning"); @@ -630,7 +630,7 @@ cid_t coroutine_add_with_stack_size(size_t stack_size, /* coroutine_main() ***********************************************************/ void coroutine_main(void) { - debugf("coroutine_main()"); + log_debugf("coroutine_main()"); if (!coroutine_initialized) { cr_plat_init(); coroutine_initialized = true; @@ -675,7 +675,7 @@ void coroutine_main(void) { /* cr_*() *********************************************************************/ void cr_begin(void) { - debugf("cid=%zu: cr_begin()", coroutine_running); + log_debugf("cid=%zu: cr_begin()", coroutine_running); assert_cid_state(coroutine_running, state == CR_INITIALIZING); bool saved = cr_save_and_disable_interrupts(); @@ -707,7 +707,7 @@ static inline void _cr_yield() { } void cr_yield(void) { - debugf("cid=%zu: cr_yield()", coroutine_running); + log_debugf("cid=%zu: cr_yield()", coroutine_running); assert(!cr_plat_is_in_intrhandler()); assert_cid_state(coroutine_running, state == CR_RUNNING); @@ -719,7 +719,7 @@ void cr_yield(void) { } void cr_pause_and_yield(void) { - debugf("cid=%zu: cr_pause_and_yield()", coroutine_running); + log_debugf("cid=%zu: cr_pause_and_yield()", coroutine_running); assert(!cr_plat_is_in_intrhandler()); assert_cid_state(coroutine_running, state == CR_RUNNING); @@ -730,7 +730,7 @@ void cr_pause_and_yield(void) { } [[noreturn]] void cr_exit(void) { - debugf("cid=%zu: cr_exit()", coroutine_running); + log_debugf("cid=%zu: cr_exit()", coroutine_running); assert(!cr_plat_is_in_intrhandler()); assert_cid_state(coroutine_running, state == CR_RUNNING); @@ -747,7 +747,7 @@ static void _cr_unpause(cid_t cid) { } void cr_unpause(cid_t cid) { - debugf("cr_unpause(%zu)", cid); + log_debugf("cr_unpause(%zu)", cid); assert(!cr_plat_is_in_intrhandler()); assert_cid_state(coroutine_running, state == CR_RUNNING); @@ -757,7 +757,7 @@ void cr_unpause(cid_t cid) { } void cr_unpause_from_intrhandler(cid_t cid) { - debugf("cr_unpause_from_intrhandler(%zu)", cid); + log_debugf("cr_unpause_from_intrhandler(%zu)", cid); assert(cr_plat_is_in_intrhandler()); _cr_unpause(cid); diff --git a/libdhcp/dhcp_client.c b/libdhcp/dhcp_client.c index 8ec3647..2d0ebe6 100644 --- a/libdhcp/dhcp_client.c +++ b/libdhcp/dhcp_client.c @@ -460,11 +460,11 @@ static bool dhcp_client_send(struct dhcp_client *client, uint8_t msgtyp, const c /**********************************************************************\ * Send * \**********************************************************************/ - debugf("state %s: sending DHCP %s", state_strs[client->state], dhcp_msgtyp_str(msgtyp)); + log_debugf("state %s: sending DHCP %s", state_strs[client->state], dhcp_msgtyp_str(msgtyp)); ssize_t r = LO_CALL(client->sock, sendto, scratch_msg, DHCP_MSG_BASE_SIZE + optlen, client_broadcasts ? net_ip4_addr_broadcast : client->lease_server_id, DHCP_PORT_SERVER); if (r < 0) { - debugf("error: sendto: %zd", r); + log_debugf("error: sendto: %zd", r); return true; } client->last_sent_msgtyp = msgtyp; @@ -704,7 +704,7 @@ static ssize_t dhcp_client_recv(struct dhcp_client *client, struct dhcp_recv_msg static bool dhcp_check_conflict(lo_interface net_packet_conn sock, struct net_ip4_addr addr) { assert(!LO_IS_NULL(sock)); ssize_t v = LO_CALL(sock, sendto, "CHECK_IP_CONFLICT", 17, addr, 5000); - debugf("check_ip_conflict => %zd", v); + log_debugf("check_ip_conflict => %zd", v); return v != -NET_EARP_TIMEOUT; } @@ -740,10 +740,10 @@ static void dhcp_client_take_lease(struct dhcp_client *client, struct dhcp_recv_ client->lease_time_ns_end = (dur_ns_end == DHCP_INFINITY * NS_PER_S) ? 0 : client->time_ns_init + dur_ns_end; if (ifup) { - infof("applying configuration to "PRI_net_eth_addr, ARG_net_eth_addr(client->self_eth_addr)); - infof(":: addr = "PRI_net_ip4_addr, ARG_net_ip4_addr(client->lease_client_addr)); - infof(":: gateway_addr = "PRI_net_ip4_addr, ARG_net_ip4_addr(client->lease_auxdata.gateway_addr)); - infof(":: subnet_mask = "PRI_net_ip4_addr, ARG_net_ip4_addr(client->lease_auxdata.subnet_mask)); + log_infof("applying configuration to "PRI_net_eth_addr, ARG_net_eth_addr(client->self_eth_addr)); + log_infof(":: addr = "PRI_net_ip4_addr, ARG_net_ip4_addr(client->lease_client_addr)); + log_infof(":: gateway_addr = "PRI_net_ip4_addr, ARG_net_ip4_addr(client->lease_auxdata.gateway_addr)); + log_infof(":: subnet_mask = "PRI_net_ip4_addr, ARG_net_ip4_addr(client->lease_auxdata.subnet_mask)); LO_CALL(client->iface, ifup, (struct net_iface_config){ .addr = client->lease_client_addr, .gateway_addr = client->lease_auxdata.gateway_addr, @@ -767,7 +767,7 @@ static void dhcp_client_setstate(struct dhcp_client *client, /* State transition diagram: https://datatracker.ietf.org/doc/html/rfc2131#page-35 */ for (;;) { - debugf("loop: state=%s", state_strs[client->state]); + log_debugf("loop: state=%s", state_strs[client->state]); switch (client->state) { case STATE_INIT: client->xid = rand_uint63n(UINT32_MAX); @@ -793,7 +793,7 @@ static void dhcp_client_setstate(struct dhcp_client *client, break; default: assert(r < 0); - debugf("error: recvfrom: %d", r); + log_debugf("error: recvfrom: %d", r); } break; case STATE_REQUESTING: @@ -806,8 +806,8 @@ static void dhcp_client_setstate(struct dhcp_client *client, break; case DHCP_MSGTYP_ACK: if (dhcp_check_conflict(client->sock, client->lease_client_addr)) { - debugf("IP "PRI_net_ip4_addr" is already in use", - ARG_net_ip4_addr(client->lease_client_addr)); + log_debugf("IP "PRI_net_ip4_addr" is already in use", + ARG_net_ip4_addr(client->lease_client_addr)); dhcp_client_setstate(client, STATE_INIT, DHCP_MSGTYP_DECLINE, "IP is already in use", scratch_msg); } else { dhcp_client_take_lease(client, scratch_msg, true); @@ -820,7 +820,7 @@ static void dhcp_client_setstate(struct dhcp_client *client, break; default: assert(r < 0); - debugf("error: recvfrom: %d", r); + log_debugf("error: recvfrom: %d", r); } break; case STATE_BOUND: @@ -834,7 +834,7 @@ static void dhcp_client_setstate(struct dhcp_client *client, break; default: assert(r < 0); - debugf("error: recvfrom: %d", r); + log_debugf("error: recvfrom: %d", r); } break; case STATE_RENEWING: @@ -863,7 +863,7 @@ static void dhcp_client_setstate(struct dhcp_client *client, break; default: assert(r < 0); - debugf("error: recvfrom: %d", r); + log_debugf("error: recvfrom: %d", r); } break; case STATE_REBINDING: @@ -889,7 +889,7 @@ static void dhcp_client_setstate(struct dhcp_client *client, break; default: assert(r < 0); - debugf("error: recvfrom: %d", r); + log_debugf("error: recvfrom: %d", r); } break; case STATE_INIT_REBOOT: diff --git a/libhw_cr/rp2040_hwspi.c b/libhw_cr/rp2040_hwspi.c index 29a7bac..c0b4fa4 100644 --- a/libhw_cr/rp2040_hwspi.c +++ b/libhw_cr/rp2040_hwspi.c @@ -70,7 +70,7 @@ void _rp2040_hwspi_init(struct rp2040_hwspi *self, assert(self); assert(baudrate_hz); uint32_t clk_peri_hz = clock_get_hz(clk_peri); - debugf("clk_peri = %"PRIu32"Hz", clk_peri_hz); + log_debugf("clk_peri = %"PRIu32"Hz", clk_peri_hz); assert(baudrate_hz*2 <= clk_peri_hz); assert_4distinct(pin_miso, pin_mosi, pin_clk, pin_cs); assert_4distinct(dma1, dma2, dma3, dma4); @@ -97,7 +97,7 @@ void _rp2040_hwspi_init(struct rp2040_hwspi *self, } actual_baudrate_hz = spi_init(inst, baudrate_hz); - debugf("baudrate = %uHz", actual_baudrate_hz); + log_debugf("baudrate = %uHz", actual_baudrate_hz); assert(actual_baudrate_hz == baudrate_hz); spi_set_format(inst, 8, (mode & 0b10) ? SPI_CPOL_1 : SPI_CPOL_0, diff --git a/libhw_cr/w5500.c b/libhw_cr/w5500.c index c04e344..2d6ac48 100644 --- a/libhw_cr/w5500.c +++ b/libhw_cr/w5500.c @@ -79,7 +79,7 @@ #include <libhw/generic/alarmclock.h> /* for sleep_*() */ #define LOG_NAME W5500 -#include <libmisc/log.h> /* for errorf(), debugf(), const_byte_str() */ +#include <libmisc/log.h> /* for log_errorf(), log_debugf(), const_byte_str() */ #define IMPLEMENTATION_FOR_LIBHW_W5500_H YES #include <libhw/w5500.h> @@ -187,7 +187,7 @@ static COROUTINE w5500_irq_cr(void *_chip) { bool had_intr = false; uint8_t chipintr = w5500ll_read_common_reg(chip->spidev, chip_interrupt); - n_debugf(W5500_LL, "w5500_irq_cr(): chipintr=%"PRIu8, chipintr); + log_n_debugf(W5500_LL, "w5500_irq_cr(): chipintr=%"PRIu8, chipintr); had_intr = had_intr || (chipintr != 0); if (chipintr) w5500ll_write_common_reg(chip->spidev, chip_interrupt, 0xFF); @@ -196,7 +196,7 @@ static COROUTINE w5500_irq_cr(void *_chip) { struct _w5500_socket *socket = &chip->sockets[socknum]; uint8_t sockintr = w5500ll_read_sock_reg(chip->spidev, socknum, interrupt); - n_debugf(W5500_LL, "w5500_irq_cr(): sockintr[%"PRIu8"]=%"PRIu8, socknum, sockintr); + log_n_debugf(W5500_LL, "w5500_irq_cr(): sockintr[%"PRIu8"]=%"PRIu8, socknum, sockintr); had_intr = had_intr || (sockintr != 0); switch (socket->mode) { @@ -208,15 +208,15 @@ static COROUTINE w5500_irq_cr(void *_chip) { recv_bits = sockintr & (SOCKINTR_RECV_DAT|SOCKINTR_RECV_FIN); if (listen_bits) { - debugf("w5500_irq_cr(): signal sock[%"PRIu8"]->listen_sema", socknum); + log_debugf("w5500_irq_cr(): signal sock[%"PRIu8"]->listen_sema", socknum); cr_sema_signal(&socket->listen_sema); } if (recv_bits) { - debugf("w5500_irq_cr(): signal sock[%"PRIu8"]->read_sema", socknum); + log_debugf("w5500_irq_cr(): signal sock[%"PRIu8"]->read_sema", socknum); cr_sema_signal(&socket->read_sema); } if (send_bits) { - debugf("w5500_irq_cr(): signal sock[%"PRIu8"]->write_ch", socknum); + log_debugf("w5500_irq_cr(): signal sock[%"PRIu8"]->write_ch", socknum); cr_chan_send(&socket->write_ch, send_bits); } break; @@ -228,7 +228,7 @@ static COROUTINE w5500_irq_cr(void *_chip) { cr_mutex_unlock(&chip->mu); if (!had_intr && gpio_get(chip->pin_intr)) { - debugf("w5500_irq_cr(): looks like all interrupts have been processed, sleeping..."); + log_debugf("w5500_irq_cr(): looks like all interrupts have been processed, sleeping..."); cr_sema_wait(&chip->intr); } else cr_yield(); @@ -283,7 +283,7 @@ static inline void w5500_socket_close(struct _w5500_socket *socket) { static void w5500_intrhandler(void *_chip, uint LM_UNUSED(gpio), enum gpio_irq_level LM_UNUSED(event)) { struct w5500 *chip = _chip; - debugf("w5500_intrhandler()"); + log_debugf("w5500_intrhandler()"); cr_sema_signal_from_intrhandler(&chip->intr); } @@ -322,7 +322,7 @@ void _w5500_init(struct w5500 *chip, w5500ll_write_sock_reg(chip->spidev, 0, mode, a); uint8_t b = w5500ll_read_sock_reg(chip->spidev, 0, mode); if (b != a) { - errorf("SPI to W5500 does not appear to be functional: wrote:0x%02"PRIx16" != read:0x%02"PRIx8, a, b); + log_errorf("SPI to W5500 does not appear to be functional: wrote:0x%02"PRIx16" != read:0x%02"PRIx8, a, b); spi_ok = false; } } @@ -427,15 +427,15 @@ static void _w5500_if_up(struct w5500 *chip, struct net_iface_config cfg) { } static void w5500_if_ifup(struct w5500 *chip, struct net_iface_config cfg) { - debugf("if_up()"); - debugf(":: addr = "PRI_net_ip4_addr, ARG_net_ip4_addr(cfg.addr)); - debugf(":: gateway_addr = "PRI_net_ip4_addr, ARG_net_ip4_addr(cfg.gateway_addr)); - debugf(":: subnet_mask = "PRI_net_ip4_addr, ARG_net_ip4_addr(cfg.subnet_mask)); + log_debugf("if_up()"); + log_debugf(":: addr = "PRI_net_ip4_addr, ARG_net_ip4_addr(cfg.addr)); + log_debugf(":: gateway_addr = "PRI_net_ip4_addr, ARG_net_ip4_addr(cfg.gateway_addr)); + log_debugf(":: subnet_mask = "PRI_net_ip4_addr, ARG_net_ip4_addr(cfg.subnet_mask)); _w5500_if_up(chip, cfg); } static void w5500_if_ifdown(struct w5500 *chip) { - debugf("if_down()"); + log_debugf("if_down()"); _w5500_if_up(chip, (struct net_iface_config){0}); } @@ -444,10 +444,10 @@ static lo_interface net_stream_listener w5500_if_tcp_listen(struct w5500 *chip, struct _w5500_socket *sock = w5500_alloc_socket(chip); if (!sock) { - debugf("tcp_listen() => no sock"); + log_debugf("tcp_listen() => no sock"); return LO_NULL(net_stream_listener); } - debugf("tcp_listen() => sock[%"PRIu8"]", sock->socknum); + log_debugf("tcp_listen() => sock[%"PRIu8"]", sock->socknum); if (!local_port) local_port = w5500_alloc_local_port(chip); @@ -470,11 +470,11 @@ static lo_interface net_stream_conn w5500_if_tcp_dial(struct w5500 *chip, struct _w5500_socket *socket = w5500_alloc_socket(chip); if (!socket) { - debugf("tcp_dial() => no sock"); + log_debugf("tcp_dial() => no sock"); return LO_NULL(net_stream_conn); } uint8_t socknum = socket->socknum; - debugf("tcp_dial() => sock[%"PRIu8"]", socknum); + log_debugf("tcp_dial() => sock[%"PRIu8"]", socknum); uint16_t local_port = w5500_alloc_local_port(chip); @@ -502,7 +502,7 @@ static lo_interface net_stream_conn w5500_if_tcp_dial(struct w5500 *chip, cr_mutex_unlock(&chip->mu); for (;;) { uint8_t state = w5500ll_read_sock_reg(chip->spidev, socknum, state); - debugf("tcp_dial(): state=%s", w5500_state_str(state)); + log_debugf("tcp_dial(): state=%s", w5500_state_str(state)); switch (state) { case STATE_TCP_SYNSENT: cr_yield(); @@ -520,11 +520,11 @@ static lo_interface net_packet_conn w5500_if_udp_conn(struct w5500 *chip, uint16 struct _w5500_socket *socket = w5500_alloc_socket(chip); if (!socket) { - debugf("udp_conn() => no sock"); + log_debugf("udp_conn() => no sock"); return LO_NULL(net_packet_conn); } uint8_t socknum = socket->socknum; - debugf("udp_conn() => sock[%"PRIu8"]", socknum); + log_debugf("udp_conn() => sock[%"PRIu8"]", socknum); if (!local_port) local_port = w5500_alloc_local_port(chip); @@ -554,7 +554,7 @@ static lo_interface net_stream_conn w5500_tcplist_accept(struct _w5500_socket *s restart: if (!socket->list_open) { - debugf("tcp_listener.accept() => already closed"); + log_debugf("tcp_listener.accept() => already closed"); return LO_NULL(net_stream_conn); } @@ -573,7 +573,7 @@ static lo_interface net_stream_conn w5500_tcplist_accept(struct _w5500_socket *s cr_mutex_unlock(&chip->mu); for (;;) { uint8_t state = w5500ll_read_sock_reg(chip->spidev, socknum, state); - debugf("tcp_listener.accept() => state=%s", w5500_state_str(state)); + log_debugf("tcp_listener.accept() => state=%s", w5500_state_str(state)); switch (state) { case STATE_TCP_LISTEN: case STATE_TCP_SYNRECV: @@ -592,7 +592,7 @@ static lo_interface net_stream_conn w5500_tcplist_accept(struct _w5500_socket *s } static int w5500_tcplist_close(struct _w5500_socket *socket) { - debugf("tcp_listener.close()"); + log_debugf("tcp_listener.close()"); ASSERT_SELF(stream_listener, TCP); socket->list_open = false; @@ -608,7 +608,7 @@ static ssize_t w5500_tcp_writev(struct _w5500_socket *socket, const struct iovec size_t count = 0; for (int i = 0; i < iovcnt; i++) count += iov[i].iov_len; - debugf("tcp_conn.write(%zu)", count); + log_debugf("tcp_conn.write(%zu)", count); ASSERT_SELF(stream_conn, TCP); if (count == 0) return 0; @@ -636,14 +636,14 @@ static ssize_t w5500_tcp_writev(struct _w5500_socket *socket, const struct iovec size_t done = 0; while (done < count) { if (!socket->write_open) { - debugf(" => soft closed"); + log_debugf(" => soft closed"); return -NET_ECLOSED; } cr_mutex_lock(&chip->mu); uint8_t state = w5500ll_read_sock_reg(chip->spidev, socknum, state); if (state != STATE_TCP_ESTABLISHED && state != STATE_TCP_CLOSE_WAIT) { cr_mutex_unlock(&chip->mu); - debugf(" => hard closed"); + log_debugf(" => hard closed"); return -NET_ECLOSED; } @@ -668,11 +668,11 @@ static ssize_t w5500_tcp_writev(struct _w5500_socket *socket, const struct iovec cr_mutex_unlock(&chip->mu); switch (cr_chan_recv(&socket->write_ch)) { case SOCKINTR_SEND_OK: - debugf(" => sent %zu", freesize); + log_debugf(" => sent %zu", freesize); done += freesize; break; case SOCKINTR_SEND_TIMEOUT: - debugf(" => ACK timeout"); + log_debugf(" => ACK timeout"); return -NET_EACK_TIMEOUT; case SOCKINTR_SEND_OK|SOCKINTR_SEND_TIMEOUT: assert_notreached("send both OK and timed out?"); @@ -680,12 +680,12 @@ static ssize_t w5500_tcp_writev(struct _w5500_socket *socket, const struct iovec assert_notreached("invalid write_ch bits"); } } - debugf(" => send finished"); + log_debugf(" => send finished"); return done; } static void w5500_tcp_set_read_deadline(struct _w5500_socket *socket, uint64_t ns) { - debugf("tcp_conn.set_read_deadline(%"PRIu64")", ns); + log_debugf("tcp_conn.set_read_deadline(%"PRIu64")", ns); ASSERT_SELF(stream_conn, TCP); socket->read_deadline_ns = ns; } @@ -701,7 +701,7 @@ static ssize_t w5500_tcp_readv(struct _w5500_socket *socket, const struct iovec size_t count = 0; for (int i = 0; i < iovcnt; i++) count += iov[i].iov_len; - debugf("tcp_conn.read(%zu)", count); + log_debugf("tcp_conn.read(%zu)", count); ASSERT_SELF(stream_conn, TCP); if (count == 0) return 0; @@ -718,12 +718,12 @@ static ssize_t w5500_tcp_readv(struct _w5500_socket *socket, const struct iovec for (;;) { if (!socket->read_open) { LO_CALL(bootclock, del_trigger, &trigger); - debugf(" => soft closed"); + log_debugf(" => soft closed"); return -NET_ECLOSED; } if (socket->read_deadline_ns && socket->read_deadline_ns <= LO_CALL(bootclock, get_time_ns)) { LO_CALL(bootclock, del_trigger, &trigger); - debugf(" => recv timeout"); + log_debugf(" => recv timeout"); return -NET_ERECV_TIMEOUT; } cr_mutex_lock(&chip->mu); @@ -736,7 +736,7 @@ static ssize_t w5500_tcp_readv(struct _w5500_socket *socket, const struct iovec default: LO_CALL(bootclock, del_trigger, &trigger); cr_mutex_unlock(&chip->mu); - debugf(" => hard closed"); + log_debugf(" => hard closed"); return -NET_ECLOSED; } @@ -747,7 +747,7 @@ static ssize_t w5500_tcp_readv(struct _w5500_socket *socket, const struct iovec if (state == STATE_TCP_CLOSE_WAIT) { LO_CALL(bootclock, del_trigger, &trigger); cr_mutex_unlock(&chip->mu); - debugf(" => EOF"); + log_debugf(" => EOF"); return 0; } @@ -755,7 +755,7 @@ static ssize_t w5500_tcp_readv(struct _w5500_socket *socket, const struct iovec cr_sema_wait(&socket->read_sema); } assert(avail); - debugf(" => received %"PRIu16" bytes", avail); + log_debugf(" => received %"PRIu16" bytes", avail); uint16_t ptr = uint16be_unmarshal(w5500ll_read_sock_reg(chip->spidev, socknum, rx_read_pointer)); /* Read the data. */ if ((size_t)avail > count) @@ -771,7 +771,7 @@ static ssize_t w5500_tcp_readv(struct _w5500_socket *socket, const struct iovec } static int w5500_tcp_close_inner(struct _w5500_socket *socket, bool rd, bool wr) { - debugf("tcp_conn.close(rd=%s, wr=%s)", rd ? "true" : "false", wr ? "true" : "false"); + log_debugf("tcp_conn.close(rd=%s, wr=%s)", rd ? "true" : "false", wr ? "true" : "false"); ASSERT_SELF(stream_conn, TCP); if (rd) @@ -809,14 +809,14 @@ static int w5500_tcp_close_write(struct _w5500_socket *socket) { return w5500_tc static ssize_t w5500_udp_sendto(struct _w5500_socket *socket, void *buf, size_t count, struct net_ip4_addr node, uint16_t port) { - debugf("udp_conn.sendto()"); + log_debugf("udp_conn.sendto()"); ASSERT_SELF(packet_conn, UDP); assert(buf); assert(count); uint16_t bufsize = ((uint16_t)w5500ll_read_sock_reg(chip->spidev, socknum, tx_buf_size))*1024; if (count > bufsize) { - debugf(" => msg too large"); + log_debugf(" => msg too large"); return -NET_EMSGSIZE; } @@ -825,7 +825,7 @@ static ssize_t w5500_udp_sendto(struct _w5500_socket *socket, void *buf, size_t uint8_t state = w5500ll_read_sock_reg(chip->spidev, socknum, state); if (state != STATE_UDP) { cr_mutex_unlock(&chip->mu); - debugf(" => closed"); + log_debugf(" => closed"); return -NET_ECLOSED; } @@ -855,10 +855,10 @@ static ssize_t w5500_udp_sendto(struct _w5500_socket *socket, void *buf, size_t cr_mutex_unlock(&chip->mu); switch (cr_chan_recv(&socket->write_ch)) { case SOCKINTR_SEND_OK: - debugf(" => sent"); + log_debugf(" => sent"); return count; case SOCKINTR_SEND_TIMEOUT: - debugf(" => ARP timeout"); + log_debugf(" => ARP timeout"); return -NET_EARP_TIMEOUT; case SOCKINTR_SEND_OK|SOCKINTR_SEND_TIMEOUT: assert_notreached("send both OK and timed out?"); @@ -868,7 +868,7 @@ static ssize_t w5500_udp_sendto(struct _w5500_socket *socket, void *buf, size_t } static void w5500_udp_set_recv_deadline(struct _w5500_socket *socket, uint64_t ns) { - debugf("udp_conn.set_recv_deadline(%"PRIu64")", ns); + log_debugf("udp_conn.set_recv_deadline(%"PRIu64")", ns); ASSERT_SELF(packet_conn, UDP); socket->read_deadline_ns = ns; } @@ -880,7 +880,7 @@ static void w5500_udp_alarm_handler(void *_arg) { static ssize_t w5500_udp_recvfrom(struct _w5500_socket *socket, void *buf, size_t count, struct net_ip4_addr *ret_node, uint16_t *ret_port) { - debugf("udp_conn.recvfrom()"); + log_debugf("udp_conn.recvfrom()"); ASSERT_SELF(packet_conn, UDP); assert(buf); assert(count); @@ -897,14 +897,14 @@ static ssize_t w5500_udp_recvfrom(struct _w5500_socket *socket, void *buf, size_ for (;;) { if (socket->read_deadline_ns && socket->read_deadline_ns <= LO_CALL(bootclock, get_time_ns)) { LO_CALL(bootclock, del_trigger, &trigger); - debugf(" => recv timeout"); + log_debugf(" => recv timeout"); return -NET_ERECV_TIMEOUT; } cr_mutex_lock(&chip->mu); uint8_t state = w5500ll_read_sock_reg(chip->spidev, socknum, state); if (state != STATE_UDP) { LO_CALL(bootclock, del_trigger, &trigger); - debugf(" => hard closed"); + log_debugf(" => hard closed"); return -NET_ECLOSED; } @@ -935,7 +935,7 @@ static ssize_t w5500_udp_recvfrom(struct _w5500_socket *socket, void *buf, size_ if (ret_port) *ret_port = uint16be_decode(&hdr[4]); uint16_t len = uint16be_decode(&hdr[6]); - debugf(" => received %"PRIu16" bytes%s", len, len < avail-8 ? " (plus more messages)" : ""); + log_debugf(" => received %"PRIu16" bytes%s", len, len < avail-8 ? " (plus more messages)" : ""); /* Now read the actual data. */ if (count > len) count = len; @@ -953,7 +953,7 @@ static ssize_t w5500_udp_recvfrom(struct _w5500_socket *socket, void *buf, size_ } static int w5500_udp_close(struct _w5500_socket *socket) { - debugf("udp_conn.close()"); + log_debugf("udp_conn.close()"); ASSERT_SELF(packet_conn, UDP); w5500_socket_close(socket); diff --git a/libhw_cr/w5500_ll.h b/libhw_cr/w5500_ll.h index 8b98f9d..738a7f1 100644 --- a/libhw_cr/w5500_ll.h +++ b/libhw_cr/w5500_ll.h @@ -83,9 +83,9 @@ w5500ll_writev( assert(iov); assert(iovcnt > 0); #if CONFIG_W5500_LL_DEBUG - n_debugf(W5500_LL, - "%s(): w5500ll_write(spidev, addr=%#04x, block="PRI_ctl_block", iov, iovcnt=%d)", - func, addr, ARG_ctl_block(block), iovcnt); + log_n_debugf(W5500_LL, + "%s(): w5500ll_write(spidev, addr=%#04x, block="PRI_ctl_block", iov, iovcnt=%d)", + func, addr, ARG_ctl_block(block), iovcnt); #endif uint8_t header[] = { @@ -120,9 +120,9 @@ w5500ll_readv( assert(iov); assert(iovcnt > 0); #if CONFIG_W5500_LL_DEBUG - n_debugf(W5500_LL, - "%s(): w5500ll_read(spidev, addr=%#04x, block="PRI_ctl_block", iov, iovcnt=%d)", - func, addr, ARG_ctl_block(block), iovcnt); + log_n_debugf(W5500_LL, + "%s(): w5500ll_read(spidev, addr=%#04x, block="PRI_ctl_block", iov, iovcnt=%d)", + func, addr, ARG_ctl_block(block), iovcnt); #endif uint8_t header[] = { diff --git a/libmisc/assert.c b/libmisc/assert.c index fdd8154..8bca524 100644 --- a/libmisc/assert.c +++ b/libmisc/assert.c @@ -7,7 +7,7 @@ #include <stdbool.h> /* for bool, true, false */ #define LOG_NAME ASSERT -#include <libmisc/log.h> /* for errorf() */ +#include <libmisc/log.h> /* for log_errorf() */ #include <libmisc/assert.h> @@ -19,10 +19,10 @@ void __assert_msg_fail(const char *expr, static bool in_fail = false; if (!in_fail) { in_fail = true; - errorf("%s:%u:%s(): assertion \"%s\" failed%s%s", - file, line, func, - expr, - msg ? ": " : "", msg ?: ""); + log_errorf("%s:%u:%s(): assertion \"%s\" failed%s%s", + file, line, func, + expr, + msg ? ": " : "", msg ?: ""); in_fail = false; } __lm_abort(); diff --git a/libmisc/include/libmisc/log.h b/libmisc/include/libmisc/log.h index 79c0ab6..4529946 100644 --- a/libmisc/include/libmisc/log.h +++ b/libmisc/include/libmisc/log.h @@ -20,15 +20,15 @@ const char *const_byte_str(uint8_t b); -#define n_errorf(nam, fmt, ...) do { __lm_printf("error: " LM_STR_(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) -#define n_infof(nam, fmt, ...) do { __lm_printf("info : " LM_STR_(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) -#define n_debugf(nam, fmt, ...) do { if (LM_CAT3_(CONFIG_, nam, _DEBUG) && !_LOG_NDEBUG) \ - __lm_printf("debug: " LM_STR_(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) +#define log_n_errorf(nam, fmt, ...) do { __lm_printf("error: " LM_STR_(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) +#define log_n_infof(nam, fmt, ...) do { __lm_printf("info : " LM_STR_(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) +#define log_n_debugf(nam, fmt, ...) do { if (LM_CAT3_(CONFIG_, nam, _DEBUG) && !_LOG_NDEBUG) \ + __lm_printf("debug: " LM_STR_(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) #endif /* _LIBMISC_LOG_H_ */ -#if defined(LOG_NAME) && !defined(errorf) -#define errorf(fmt, ...) n_errorf(LOG_NAME, fmt, __VA_ARGS__) -#define infof(fmt, ...) n_infof(LOG_NAME, fmt, __VA_ARGS__) -#define debugf(fmt, ...) n_debugf(LOG_NAME, fmt, __VA_ARGS__) +#if defined(LOG_NAME) && !defined(log_errorf) +#define log_errorf(fmt, ...) log_n_errorf(LOG_NAME, fmt, __VA_ARGS__) +#define log_infof(fmt, ...) log_n_infof(LOG_NAME, fmt, __VA_ARGS__) +#define log_debugf(fmt, ...) log_n_debugf(LOG_NAME, fmt, __VA_ARGS__) #endif diff --git a/libmisc/tests/test_log.c b/libmisc/tests/test_log.c index 49a76ca..02b95d6 100644 --- a/libmisc/tests/test_log.c +++ b/libmisc/tests/test_log.c @@ -1,6 +1,6 @@ /* libmisc/tests/test_log.c - Tests for <libmisc/log.h> * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later */ @@ -54,17 +54,17 @@ int __lm_printf(const char *format, ...) { int main() { should_print("error: FROBNICATE: val=42\n", - errorf("val=%d", 42)); + log_errorf("val=%d", 42)); should_print("info : FROBNICATE: val=0\n", - infof("val=%d", 0)); + log_infof("val=%d", 0)); #ifndef NDEBUG #define CONFIG_FROBNICATE_DEBUG 1 should_print("debug: FROBNICATE: val=-2\n", - debugf("val=%d", -2)); + log_debugf("val=%d", -2)); #undef CONFIG_FROBNICATE_DEBUG #define CONFIG_FROBNICATE_DEBUG 0 should_print(NULL, - debugf("val=%d", -2)); + log_debugf("val=%d", -2)); #endif return 0; } diff --git a/libusb/usb_common.c b/libusb/usb_common.c index 29dec42..efd12bc 100644 --- a/libusb/usb_common.c +++ b/libusb/usb_common.c @@ -1,6 +1,6 @@ /* libusb/usb_common.c - Common framework for implementing multiple USB devices at once * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later */ @@ -68,12 +68,12 @@ uint16_t const *tud_descriptor_string_cb(uint8_t strid, uint16_t langid) { memcpy(desc.bString, globals.serial, bytelen); break; default: - debugf("GET STRING: unknown string id=%"PRIu8, strid); + log_debugf("GET STRING: unknown string id=%"PRIu8, strid); return NULL; } break; default: - debugf("GET STRING: unknown LANGID=%"PRIx16, langid); + log_debugf("GET STRING: unknown LANGID=%"PRIx16, langid); return NULL; } } |