diff options
-rw-r--r-- | build-aux/measurestack/app_main.py | 1 | ||||
-rw-r--r-- | build-aux/measurestack/app_plugins.py | 7 | ||||
-rw-r--r-- | build-aux/measurestack/test_app_plugins.py | 2 | ||||
-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 | 4 | ||||
-rw-r--r-- | libcr/coroutine.c | 33 | ||||
-rw-r--r-- | libdhcp/dhcp_client.c | 29 | ||||
-rw-r--r-- | libfmt/libmisc.c | 31 | ||||
-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 | 37 | ||||
-rw-r--r-- | libhw_generic/include/libhw/generic/net.h | 16 | ||||
-rw-r--r-- | libhw_generic/net.c | 20 | ||||
-rw-r--r-- | libmisc/include/libmisc/_intercept.h | 14 | ||||
-rw-r--r-- | libmisc/include/libmisc/log.h | 10 | ||||
-rw-r--r-- | libmisc/intercept.c | 12 | ||||
-rw-r--r-- | libmisc/tests/test_log.c | 34 | ||||
-rw-r--r-- | libusb/usb_common.c | 4 |
19 files changed, 145 insertions, 231 deletions
diff --git a/build-aux/measurestack/app_main.py b/build-aux/measurestack/app_main.py index 69247ed..463447e 100644 --- a/build-aux/measurestack/app_main.py +++ b/build-aux/measurestack/app_main.py @@ -88,7 +88,6 @@ def main( def misc_filter(name: QName) -> tuple[int, bool]: if name in [ QName("__assert_msg_fail"), - QName("__lm_printf"), QName("fmt_vfctprintf"), QName("fmt_vsnprintf"), ]: diff --git a/build-aux/measurestack/app_plugins.py b/build-aux/measurestack/app_plugins.py index 26eb66d..fbe137c 100644 --- a/build-aux/measurestack/app_plugins.py +++ b/build-aux/measurestack/app_plugins.py @@ -389,13 +389,6 @@ class PicoFmtPlugin: BaseName("stdio_vprintf"): BaseName("stdio_buffered_printer"), } ) - case "host": - self.known_fct.update( - { - # libfmt - BaseName("__lm_printf"): BaseName("libfmt_libc_fct"), - } - ) self.wont_call_v = set([*self.known_fct.values(), *wont_call_v]) def is_intrhandler(self, name: QName) -> bool: diff --git a/build-aux/measurestack/test_app_plugins.py b/build-aux/measurestack/test_app_plugins.py index 3e281b7..aed0bb4 100644 --- a/build-aux/measurestack/test_app_plugins.py +++ b/build-aux/measurestack/test_app_plugins.py @@ -49,8 +49,6 @@ def test_fct() -> None: # if rp2040: # __wrap_vprintf => fct=stdio_buffered_printer # stdio_vprintf => fct=stdio_buffered_printer - # if host: - # __lm_printf => fct=libfmt_libc_fct app_plugins.PicoFmtPlugin("rp2040", []), ] diff --git a/cmd/sbc_harness/fs_harness_flash_bin.c b/cmd/sbc_harness/fs_harness_flash_bin.c index f353ddd..3c3fa16 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); - log_infof("copying upper flash to lower flash..."); + log_infoln("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); } - log_infof("rebooting..."); + log_infoln("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); - log_infof("zeroing upper flash..."); + log_infoln("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); } - log_debugf("... zeroed"); + log_debugln("... zeroed"); } /** @@ -95,7 +95,7 @@ static void ab_flash_initialize_zero(uint8_t *buf) { static void ab_flash_initialize(uint8_t *buf) { assert(buf); - log_infof("initializing upper flash..."); + log_infoln("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); } - log_debugf("... initialized"); + log_debugln("... initialized"); } /** @@ -123,14 +123,14 @@ static void ab_flash_write_sector(size_t pos, uint8_t *dat) { pos += DATA_HSIZE; - log_infof("write flash sector @ %zu...", pos); + log_infoln("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); } - log_debugf("... written"); + log_debugln("... written"); } /* srv_file *******************************************************************/ diff --git a/cmd/sbc_harness/main.c b/cmd/sbc_harness/main.c index 1fc76dc..0fb6e61 100644 --- a/cmd/sbc_harness/main.c +++ b/cmd/sbc_harness/main.c @@ -132,7 +132,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) { - log_errorf("error sending rune U+%d", (uint32_t)msg[i]); + log_errorln("error sending rune U+", msg[i]); break; } } @@ -249,7 +249,7 @@ int main() { bootclock = rp2040_hwtimer(0); stdio_uart_init(); /* char *hdr = "=" * (80-strlen("info : MAIN: ")); */ - log_infof("==================================================================="); + log_infoln("==================================================================="); 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 fe2c688..4629c04 100644 --- a/cmd/sbc_harness/tusb_log.c +++ b/cmd/sbc_harness/tusb_log.c @@ -9,7 +9,5 @@ void _libmisc_tu_mess_failed(const char *expr, const char *file, unsigned int line, const char *func) { - log_errorf("%s:%u:%s(): assertion \"%s\" failed", - file, line, func, - expr); + log_errorln(file, ":", line, ":", func, "(): assertion ", (qstr, expr), " failed"); } diff --git a/libcr/coroutine.c b/libcr/coroutine.c index 4c0b7e8..920c371 100644 --- a/libcr/coroutine.c +++ b/libcr/coroutine.c @@ -556,8 +556,7 @@ cid_t coroutine_add_with_stack_size(size_t stack_size, assert_cid_state(parent, state == CR_RUNNING); assert(stack_size); assert(fn); - log_debugf("coroutine_add_with_stack_size(%zu, \"%s\", %p, %p)...", - stack_size, name, fn, args); + log_debugln("coroutine_add_with_stack_size(", stack_size, ", ", (qstr, name), ", ", (ptr, fn), ", ", (ptr, args), ")..."); if (!coroutine_initialized) { cr_plat_init(); @@ -567,7 +566,7 @@ cid_t coroutine_add_with_stack_size(size_t stack_size, cid_t child = coroutine_allocate_cid(); if (!child) return 0; - log_debugf("...child=%zu", child); + log_debugln("...child=", child); /* 1. state *************************************************/ coroutine_table[child-1].state = CR_INITIALIZING; @@ -580,13 +579,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; - log_infof("allocing \"%s\" stack with size %zu+2*%zu=%zu", - name, stack_size, CR_STACK_GUARD_SIZE, coroutine_table[child-1].stack_size); + log_infoln("allocing ", (qstr, name), " stack with size ", + stack_size, "+2*", (base10, 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); - 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); + log_infoln("... done, stack is [", + (ptr, coroutine_table[child-1].stack + CR_STACK_GUARD_SIZE), ",", + (ptr, 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 +607,8 @@ cid_t coroutine_add_with_stack_size(size_t stack_size, + stack_size #endif ; - log_debugf("...stack =%p", coroutine_table[child-1].stack); - log_debugf("...stack_base=%p", stack_base); + log_debugln("...stack =", (ptr, coroutine_table[child-1].stack)); + log_debugln("...stack_base=", (ptr, 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 +629,7 @@ cid_t coroutine_add_with_stack_size(size_t stack_size, /* coroutine_main() ***********************************************************/ void coroutine_main(void) { - log_debugf("coroutine_main()"); + log_debugln("coroutine_main()"); if (!coroutine_initialized) { cr_plat_init(); coroutine_initialized = true; @@ -675,7 +674,7 @@ void coroutine_main(void) { /* cr_*() *********************************************************************/ void cr_begin(void) { - log_debugf("cid=%zu: cr_begin()", coroutine_running); + log_debugln("cid=", coroutine_running, ": cr_begin()"); assert_cid_state(coroutine_running, state == CR_INITIALIZING); bool saved = cr_save_and_disable_interrupts(); @@ -707,7 +706,7 @@ static inline void _cr_yield() { } void cr_yield(void) { - log_debugf("cid=%zu: cr_yield()", coroutine_running); + log_debugln("cid=", coroutine_running ,": cr_yield()"); assert(!cr_plat_is_in_intrhandler()); assert_cid_state(coroutine_running, state == CR_RUNNING); @@ -719,7 +718,7 @@ void cr_yield(void) { } void cr_pause_and_yield(void) { - log_debugf("cid=%zu: cr_pause_and_yield()", coroutine_running); + log_debugln("cid=", coroutine_running, ": cr_pause_and_yield()"); assert(!cr_plat_is_in_intrhandler()); assert_cid_state(coroutine_running, state == CR_RUNNING); @@ -730,7 +729,7 @@ void cr_pause_and_yield(void) { } [[noreturn]] void cr_exit(void) { - log_debugf("cid=%zu: cr_exit()", coroutine_running); + log_debugln("cid=", coroutine_running, ": cr_exit()"); assert(!cr_plat_is_in_intrhandler()); assert_cid_state(coroutine_running, state == CR_RUNNING); @@ -747,7 +746,7 @@ static void _cr_unpause(cid_t cid) { } void cr_unpause(cid_t cid) { - log_debugf("cr_unpause(%zu)", cid); + log_debugln("cr_unpause(", cid, ")"); assert(!cr_plat_is_in_intrhandler()); assert_cid_state(coroutine_running, state == CR_RUNNING); @@ -757,7 +756,7 @@ void cr_unpause(cid_t cid) { } void cr_unpause_from_intrhandler(cid_t cid) { - log_debugf("cr_unpause_from_intrhandler(%zu)", cid); + log_debugln("cr_unpause_from_intrhandler(", cid, ")"); assert(cr_plat_is_in_intrhandler()); _cr_unpause(cid); diff --git a/libdhcp/dhcp_client.c b/libdhcp/dhcp_client.c index a561cbf..8e8361d 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 * \**********************************************************************/ - log_debugf("state %s: sending DHCP %s", state_strs[client->state], dhcp_msgtyp_str(msgtyp)); + log_debugln("state ", state_strs[client->state], ": sending DHCP ", 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) { - log_debugf("error: sendto: %zd", r); + log_debugln("error: sendto: ", 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); - log_debugf("check_ip_conflict => %zd", v); + log_debugln("check_ip_conflict => ", 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) { - 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)); + log_infoln("applying configuration to ", (net_eth_addr, client->self_eth_addr)); + log_infoln(":: addr = ", (net_ip4_addr, client->lease_client_addr)); + log_infoln(":: gateway_addr = ", (net_ip4_addr, client->lease_auxdata.gateway_addr)); + log_infoln(":: subnet_mask = ", (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 (;;) { - log_debugf("loop: state=%s", state_strs[client->state]); + log_debugln("loop: state=", 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); - log_debugf("error: recvfrom: %d", r); + log_debugln("error: recvfrom: ", r); } break; case STATE_REQUESTING: @@ -806,8 +806,7 @@ static void dhcp_client_setstate(struct dhcp_client *client, break; case DHCP_MSGTYP_ACK: if (dhcp_check_conflict(client->sock, client->lease_client_addr)) { - log_debugf("IP "PRI_net_ip4_addr" is already in use", - ARG_net_ip4_addr(client->lease_client_addr)); + log_debugln("IP ", (net_ip4_addr, client->lease_client_addr), " is already in use"); 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 +819,7 @@ static void dhcp_client_setstate(struct dhcp_client *client, break; default: assert(r < 0); - log_debugf("error: recvfrom: %d", r); + log_debugln("error: recvfrom: ", r); } break; case STATE_BOUND: @@ -834,7 +833,7 @@ static void dhcp_client_setstate(struct dhcp_client *client, break; default: assert(r < 0); - log_debugf("error: recvfrom: %d", r); + log_debugln("error: recvfrom: ", r); } break; case STATE_RENEWING: @@ -863,7 +862,7 @@ static void dhcp_client_setstate(struct dhcp_client *client, break; default: assert(r < 0); - log_debugf("error: recvfrom: %d", r); + log_debugln("error: recvfrom: ", r); } break; case STATE_REBINDING: @@ -889,7 +888,7 @@ static void dhcp_client_setstate(struct dhcp_client *client, break; default: assert(r < 0); - log_debugf("error: recvfrom: %d", r); + log_debugln("error: recvfrom: ", r); } break; case STATE_INIT_REBOOT: diff --git a/libfmt/libmisc.c b/libfmt/libmisc.c index 552b916..4d3724b 100644 --- a/libfmt/libmisc.c +++ b/libfmt/libmisc.c @@ -4,39 +4,8 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -#include <stdarg.h> /* for va_list, va_start(), va_end() */ -#include <stdio.h> /* for vprintf(), putchar(), fflush() */ -#if LIB_PICO_STDIO -#include <pico/stdio.h> /* for stdio_putchar_raw() */ -#endif - -#include <libmisc/macro.h> /* for LM_UNUSED() */ -#include <libmisc/_intercept.h> /* for __lm_printf() */ - #include <libfmt/fmt.h> /* for fmt_vfctprintf() */ -#if !LIB_PICO_STDIO -static void libfmt_libc_fct(char character, void *LM_UNUSED(arg)) { - putchar(character); -} -#endif - -size_t __lm_printf(const char *format, ...) { - va_list va; - va_start(va, format); -#if LIB_PICO_STDIO - /* pico_stdio has already intercepted vprintf for us, and - * their stdio_buffered_printer() is better than our - * libfmt_libc_fct() because buffering. */ - size_t ret = (size_t) vprintf(format, va); -#else - size_t ret = (size_t) fmt_vfctprintf(libfmt_libc_fct, NULL, format, va); - fflush(stdout); -#endif - va_end(va); - return ret; -} - static void libfmt_conv_formatter(struct fmt_state *state) { lo_interface fmt_formatter obj = va_arg(*state->args, lo_interface fmt_formatter); LO_CALL(obj, format, state); diff --git a/libhw_cr/rp2040_hwspi.c b/libhw_cr/rp2040_hwspi.c index 3bf3f84..75acd58 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); - log_debugf("clk_peri = %"PRIu32"Hz", clk_peri_hz); + log_debugln("clk_peri = ", clk_peri_hz, "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); - log_debugf("baudrate = %uHz", actual_baudrate_hz); + log_debugln("baudrate = ", actual_baudrate_hz, "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 2893e8f..6f3f302 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 log_errorf(), log_debugf(), const_byte_str() */ +#include <libmisc/log.h> #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); - log_n_debugf(W5500_LL, "w5500_irq_cr(): chipintr=%"PRIu8, chipintr); + log_n_debugln(W5500_LL, "w5500_irq_cr(): chipintr=", 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); - log_n_debugf(W5500_LL, "w5500_irq_cr(): sockintr[%"PRIu8"]=%"PRIu8, socknum, sockintr); + log_n_debugln(W5500_LL, "w5500_irq_cr(): sockintr[", 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) { - log_debugf("w5500_irq_cr(): signal sock[%"PRIu8"]->listen_sema", socknum); + log_debugln("w5500_irq_cr(): signal sock[", socknum, "]->listen_sema"); cr_sema_signal(&socket->listen_sema); } if (recv_bits) { - log_debugf("w5500_irq_cr(): signal sock[%"PRIu8"]->read_sema", socknum); + log_debugln("w5500_irq_cr(): signal sock[", socknum, "]->read_sema"); cr_sema_signal(&socket->read_sema); } if (send_bits) { - log_debugf("w5500_irq_cr(): signal sock[%"PRIu8"]->write_ch", socknum); + log_debugln("w5500_irq_cr(): signal sock[", socknum, "]->write_ch"); 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)) { - log_debugf("w5500_irq_cr(): looks like all interrupts have been processed, sleeping..."); + log_debugln("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; - log_debugf("w5500_intrhandler()"); + log_debugln("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) { - log_errorf("SPI to W5500 does not appear to be functional: wrote:0x%02"PRIx16" != read:0x%02"PRIx8, a, b); + log_errorln("SPI to W5500 does not appear to be functional: wrote:", (base16_u8_, a), " != read:", (base16_u8_, 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) { - 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)); + log_debugln("if_up()"); + log_debugln(":: addr = ", (net_ip4_addr, cfg.addr)); + log_debugln(":: gateway_addr = ", (net_ip4_addr, cfg.gateway_addr)); + log_debugln(":: subnet_mask = ", (net_ip4_addr, cfg.subnet_mask)); _w5500_if_up(chip, cfg); } static void w5500_if_ifdown(struct w5500 *chip) { - log_debugf("if_down()"); + log_debugln("if_down()"); _w5500_if_up(chip, (struct net_iface_config){}); } @@ -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) { - log_debugf("tcp_listen() => no sock"); + log_debugln("tcp_listen() => no sock"); return LO_NULL(net_stream_listener); } - log_debugf("tcp_listen() => sock[%"PRIu8"]", sock->socknum); + log_debugln("tcp_listen() => sock[", 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) { - log_debugf("tcp_dial() => no sock"); + log_debugln("tcp_dial() => no sock"); return LO_NULL(net_stream_conn); } uint8_t socknum = socket->socknum; - log_debugf("tcp_dial() => sock[%"PRIu8"]", socknum); + log_debugln("tcp_dial() => sock[", 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); - log_debugf("tcp_dial(): state=%s", w5500_state_str(state)); + log_debugln("tcp_dial(): state=", 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) { - log_debugf("udp_conn() => no sock"); + log_debugln("udp_conn() => no sock"); return LO_NULL(net_packet_conn); } uint8_t socknum = socket->socknum; - log_debugf("udp_conn() => sock[%"PRIu8"]", socknum); + log_debugln("udp_conn() => sock[", 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) { - log_debugf("tcp_listener.accept() => already closed"); + log_debugln("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); - log_debugf("tcp_listener.accept() => state=%s", w5500_state_str(state)); + log_debugln("tcp_listener.accept() => state=", 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) { - log_debugf("tcp_listener.close()"); + log_debugln("tcp_listener.close()"); ASSERT_SELF(stream_listener, TCP); socket->list_open = false; @@ -609,7 +609,7 @@ static ssize_t w5500_tcp_writev(struct _w5500_socket *socket, const struct iovec for (int i = 0; i < iovcnt; i++) count += iov[i].iov_len; assert(count); - log_debugf("tcp_conn.write(%zu)", count); + log_debugln("tcp_conn.write(", count, ")"); ASSERT_SELF(stream_conn, TCP); /* What we really want is to pause until we receive an ACK for @@ -635,14 +635,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) { - log_debugf(" => soft closed"); + log_debugln(" => 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); - log_debugf(" => hard closed"); + log_debugln(" => hard closed"); return -NET_ECLOSED; } @@ -667,11 +667,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: - log_debugf(" => sent %zu", freesize); + log_debugln(" => sent ", freesize); done += freesize; break; case SOCKINTR_SEND_TIMEOUT: - log_debugf(" => ACK timeout"); + log_debugln(" => ACK timeout"); return -NET_EACK_TIMEOUT; case SOCKINTR_SEND_OK|SOCKINTR_SEND_TIMEOUT: assert_notreached("send both OK and timed out?"); @@ -679,12 +679,12 @@ static ssize_t w5500_tcp_writev(struct _w5500_socket *socket, const struct iovec assert_notreached("invalid write_ch bits"); } } - log_debugf(" => send finished"); + log_debugln(" => send finished"); return done; } static void w5500_tcp_set_read_deadline(struct _w5500_socket *socket, uint64_t ns) { - log_debugf("tcp_conn.set_read_deadline(%"PRIu64")", ns); + log_debugln("tcp_conn.set_read_deadline(", 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 for (int i = 0; i < iovcnt; i++) count += iov[i].iov_len; assert(count); - log_debugf("tcp_conn.read(%zu)", count); + log_debugln("tcp_conn.read(", count, ")"); ASSERT_SELF(stream_conn, TCP); struct alarmclock_trigger trigger = {}; @@ -716,12 +716,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); - log_debugf(" => soft closed"); + log_debugln(" => 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); - log_debugf(" => recv timeout"); + log_debugln(" => recv timeout"); return -NET_ERECV_TIMEOUT; } cr_mutex_lock(&chip->mu); @@ -734,7 +734,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); - log_debugf(" => hard closed"); + log_debugln(" => hard closed"); return -NET_ECLOSED; } @@ -745,7 +745,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); - log_debugf(" => EOF"); + log_debugln(" => EOF"); return 0; } @@ -753,7 +753,7 @@ static ssize_t w5500_tcp_readv(struct _w5500_socket *socket, const struct iovec cr_sema_wait(&socket->read_sema); } assert(avail); - log_debugf(" => received %"PRIu16" bytes", avail); + log_debugln(" => received ", avail, " bytes"); uint16_t ptr = uint16be_unmarshal(w5500ll_read_sock_reg(chip->spidev, socknum, rx_read_pointer)); /* Read the data. */ if ((size_t)avail > count) @@ -769,7 +769,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) { - log_debugf("tcp_conn.close(rd=%s, wr=%s)", rd ? "true" : "false", wr ? "true" : "false"); + log_debugln("tcp_conn.close(rd=", rd, ", wr=", wr, ")"); ASSERT_SELF(stream_conn, TCP); if (rd) @@ -807,14 +807,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) { - log_debugf("udp_conn.sendto()"); + log_debugln("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) { - log_debugf(" => msg too large"); + log_debugln(" => msg too large"); return -NET_EMSGSIZE; } @@ -823,7 +823,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); - log_debugf(" => closed"); + log_debugln(" => closed"); return -NET_ECLOSED; } @@ -853,10 +853,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: - log_debugf(" => sent"); + log_debugln(" => sent"); return count; case SOCKINTR_SEND_TIMEOUT: - log_debugf(" => ARP timeout"); + log_debugln(" => ARP timeout"); return -NET_EARP_TIMEOUT; case SOCKINTR_SEND_OK|SOCKINTR_SEND_TIMEOUT: assert_notreached("send both OK and timed out?"); @@ -866,7 +866,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) { - log_debugf("udp_conn.set_recv_deadline(%"PRIu64")", ns); + log_debugln("udp_conn.set_recv_deadline(", ns, ")"); ASSERT_SELF(packet_conn, UDP); socket->read_deadline_ns = ns; } @@ -878,7 +878,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) { - log_debugf("udp_conn.recvfrom()"); + log_debugln("udp_conn.recvfrom()"); ASSERT_SELF(packet_conn, UDP); assert(buf); assert(count); @@ -895,14 +895,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); - log_debugf(" => recv timeout"); + log_debugln(" => 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); - log_debugf(" => hard closed"); + log_debugln(" => hard closed"); return -NET_ECLOSED; } @@ -933,7 +933,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]); - log_debugf(" => received %"PRIu16" bytes%s", len, len < avail-8 ? " (plus more messages)" : ""); + log_debugln(" => received ", len, " bytes", len < avail-8 ? " (plus more messages)" : ""); /* Now read the actual data. */ if (count > len) count = len; @@ -951,7 +951,7 @@ static ssize_t w5500_udp_recvfrom(struct _w5500_socket *socket, void *buf, size_ } static int w5500_udp_close(struct _w5500_socket *socket) { - log_debugf("udp_conn.close()"); + log_debugln("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 738a7f1..aa41e7a 100644 --- a/libhw_cr/w5500_ll.h +++ b/libhw_cr/w5500_ll.h @@ -54,14 +54,15 @@ #define CTL_OM_FDM4 0b11 /* fixed-length data mode: 4 byte data length */ #if CONFIG_W5500_LL_DEBUG -static char *_ctl_block_part_strs[] = { - "RES", - "REG", - "TX", - "RX", -}; -#define PRI_ctl_block "CTL_BLOCK_SOCK(%d, %s)" -#define ARG_ctl_block(b) (((b)>>5) & 0b111), _ctl_block_part_strs[((b)>>3)&0b11] +static void fmt_print_ctl_block(lo_interface fmt_dest, uint8_t b) { + static char *strs[] = { + "RES", + "REG", + "TX", + "RX", + }; + fmt_print("CTL_BLOCK_SOCK(", (base10, (((b)>>5) & 0b111)), ", ", strs[((b)>>3)&0b11], ")"); +} #endif /* Even though SPI is a full-duplex protocol, the W5500's spiframe on top of it is only half-duplex. @@ -83,9 +84,13 @@ w5500ll_writev( assert(iov); assert(iovcnt > 0); #if CONFIG_W5500_LL_DEBUG - 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); + log_n_debugln(W5500_LL, + func, "(): w5500ll_write(spidev", + ", addr=", (base16_u16_, addr), + ", block=", (ctl_block, block), + ", iov", + ", iovcnt=", iovcnt, + ")"); #endif uint8_t header[] = { @@ -120,9 +125,13 @@ w5500ll_readv( assert(iov); assert(iovcnt > 0); #if CONFIG_W5500_LL_DEBUG - 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); + log_n_debugln(W5500_LL, + func, "(): w5500ll_read(spidev", + ", addr=", (base16_u16_, addr), + ", block=", (ctl_block, block), + ", iov", + ", iovcnt=", iovcnt, + ")"); #endif uint8_t header[] = { diff --git a/libhw_generic/include/libhw/generic/net.h b/libhw_generic/include/libhw/generic/net.h index 1052392..573a01f 100644 --- a/libhw_generic/include/libhw/generic/net.h +++ b/libhw_generic/include/libhw/generic/net.h @@ -12,6 +12,7 @@ #include <stdint.h> /* for uint{n}_t} */ #include <sys/types.h> /* for ssize_t */ +#include <libmisc/fmt.h> #include <libhw/generic/io.h> /* Errnos *********************************************************************/ @@ -34,24 +35,13 @@ struct net_ip4_addr { static const struct net_ip4_addr net_ip4_addr_broadcast = {{255, 255, 255, 255}}; static const struct net_ip4_addr net_ip4_addr_zero = {{0, 0, 0, 0}}; - -#define PRI_net_ip4_addr "%"PRIu8".%"PRIu8".%"PRIu8".%"PRIu8 -#define ARG_net_ip4_addr(addr) (addr).octets[0], \ - (addr).octets[1], \ - (addr).octets[2], \ - (addr).octets[3] +void fmt_print_net_ip4_addr(lo_interface fmt_dest, struct net_ip4_addr); struct net_eth_addr { unsigned char octets[6]; }; -#define PRI_net_eth_addr "%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8 -#define ARG_net_eth_addr(addr) (addr).octets[0], \ - (addr).octets[1], \ - (addr).octets[2], \ - (addr).octets[3], \ - (addr).octets[4], \ - (addr).octets[5] +void fmt_print_net_eth_addr(lo_interface fmt_dest, struct net_eth_addr); /* Streams (e.g. TCP) *********************************************************/ diff --git a/libhw_generic/net.c b/libhw_generic/net.c index e2785ae..d21626e 100644 --- a/libhw_generic/net.c +++ b/libhw_generic/net.c @@ -1,6 +1,6 @@ /* libhw_generic/net.c - Device-independent <libhw/generic/net.h> utilities * - * 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 */ @@ -29,3 +29,21 @@ const char *net_strerror(int net_errno) { assert_notreached("invalid net_errno"); } } + +void fmt_print_net_ip4_addr(lo_interface fmt_dest w, struct net_ip4_addr addr) { + fmt_print(w, + addr.octets[0], ".", + addr.octets[1], ".", + addr.octets[2], ".", + addr.octets[3]); +} + +void fmt_print_net_eth_addr(lo_interface fmt_dest w, struct net_eth_addr addr) { + fmt_print(w, + (base16_u8_, addr.octets[0]), ":", + (base16_u8_, addr.octets[1]), ":", + (base16_u8_, addr.octets[2]), ":", + (base16_u8_, addr.octets[3]), ":", + (base16_u8_, addr.octets[4]), ":", + (base16_u8_, addr.octets[5])); +} diff --git a/libmisc/include/libmisc/_intercept.h b/libmisc/include/libmisc/_intercept.h index f02244a..fa327d6 100644 --- a/libmisc/include/libmisc/_intercept.h +++ b/libmisc/include/libmisc/_intercept.h @@ -7,18 +7,12 @@ #ifndef _LIBMISC__INTERCEPT_H_ #define _LIBMISC__INTERCEPT_H_ -#include <stddef.h> /* for size_t */ - -/* pico-sdk/newlib define printf() and abort() to be [[gnu::weak]] - * already, but depending on optimization options glibc might not, and - * GCC might assume it knows what they do and optimize them out. So - * define our own `__lm_` wrappers that GCC/glibc won't interfere - * with. +/* pico-sdk/newlib defines abort() to be [[gnu::weak]] already, but + * depending on optimization options glibc might not, and GCC might + * assume it knows what it does and optimize it out. So define our + * own `__lm_` wrapper that GCC/glibc won't interfere with. */ -[[gnu::format(printf, 1, 2)]] -size_t __lm_printf(const char *format, ...); - [[noreturn]] void __lm_abort(void); /* While newlib defines putchar() to be [[gnu::weak]], pico_stdio does diff --git a/libmisc/include/libmisc/log.h b/libmisc/include/libmisc/log.h index 78ee1e7..e6dfb52 100644 --- a/libmisc/include/libmisc/log.h +++ b/libmisc/include/libmisc/log.h @@ -23,11 +23,6 @@ const char *const_byte_str(uint8_t b); extern lo_interface fmt_dest _log_dest; -#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) - #define log_n_errorln(nam, ...) fmt_print(_log_dest, "error: " LM_STR_(nam) ": ", __VA_ARGS__, "\n") #define log_n_infoln(nam, ...) fmt_print(_log_dest, "info : " LM_STR_(nam) ": ", __VA_ARGS__, "\n") #define log_n_debugln(nam, ...) do { if (LM_CAT3_(CONFIG_, nam, _DEBUG) && !_LOG_NDEBUG) \ @@ -35,10 +30,7 @@ extern lo_interface fmt_dest _log_dest; #endif /* _LIBMISC_LOG_H_ */ -#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__) +#if defined(LOG_NAME) && !defined(log_errorln) #define log_errorln(...) log_n_errorln(LOG_NAME, __VA_ARGS__) #define log_infoln(...) log_n_infoln(LOG_NAME, __VA_ARGS__) #define log_debugln(...) log_n_debugln(LOG_NAME, __VA_ARGS__) diff --git a/libmisc/intercept.c b/libmisc/intercept.c index 70671f6..30870bf 100644 --- a/libmisc/intercept.c +++ b/libmisc/intercept.c @@ -4,22 +4,12 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -#include <stdarg.h> /* for va_list, va_start(), va_end() */ -#include <stdio.h> /* for vprintf(), putchar() */ +#include <stdio.h> /* for putchar() */ #include <stdlib.h> /* for abort() */ #include <libmisc/_intercept.h> [[gnu::weak]] -size_t __lm_printf(const char *format, ...) { - va_list va; - va_start(va, format); - size_t ret = (size_t) vprintf(format, va); - va_end(va); - return ret; -} - -[[gnu::weak]] void __lm_putchar(unsigned char c) { (void) putchar(c); } diff --git a/libmisc/tests/test_log.c b/libmisc/tests/test_log.c index e5abb61..ee762e2 100644 --- a/libmisc/tests/test_log.c +++ b/libmisc/tests/test_log.c @@ -20,23 +20,6 @@ static struct fmt_buf log_output = {}; -size_t __lm_printf(const char *format, ...) { - restart: - va_list va; - va_start(va, format); - size_t ret = (size_t) vsnprintf(log_output.dat, log_output.cap, format, va); - va_end(va); - - if (ret > log_output.cap) { - log_output.cap = ret+8; - log_output.dat = realloc(log_output.dat, log_output.cap); - memset(log_output.dat, 0, log_output.cap); - goto restart; - } - log_output.len = ret; - return ret; -} - void __lm_putchar(unsigned char c) { if (log_output.len+1 >= log_output.cap) { log_output.cap += 16; @@ -74,23 +57,6 @@ static void log_output_clear(void) { } while (0) int main() { - /* printf */ - should_print("error: FROBNICATE: val=42\n", - log_errorf("val=%d", 42)); - should_print("info : FROBNICATE: val=0\n", - log_infof("val=%d", 0)); -#ifndef NDEBUG -#define CONFIG_FROBNICATE_DEBUG 1 - should_print("debug: FROBNICATE: val=-2\n", - log_debugf("val=%d", -2)); -#undef CONFIG_FROBNICATE_DEBUG -#define CONFIG_FROBNICATE_DEBUG 0 - should_print(NULL, - log_debugf("val=%d", -2)); -#undef CONFIG_FROBNICATE_DEBUG -#endif - - /* libmisc/fmt.h */ should_print("error: FROBNICATE: val=42\n", log_errorln("val=", 42)); should_print("info : FROBNICATE: val=0\n", diff --git a/libusb/usb_common.c b/libusb/usb_common.c index 88e01b4..32aa53f 100644 --- a/libusb/usb_common.c +++ b/libusb/usb_common.c @@ -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: - log_debugf("GET STRING: unknown string id=%"PRIu8, strid); + log_debugln("GET STRING: unknown string id=", strid); return NULL; } break; default: - log_debugf("GET STRING: unknown LANGID=%"PRIx16, langid); + log_debugln("GET STRING: unknown LANGID=", (base16_u16_, langid)); return NULL; } } |