From d2ce652dff3fe8e358f1c013ac79a954f4d3862b Mon Sep 17 00:00:00 2001 From: Bas Stottelaar Date: Fri, 23 Oct 2020 14:34:16 +0200 Subject: [PATCH 01/13] drivers/*: remove unneeded ENABLE_DEBUG --- drivers/apds99xx/apds99xx.c | 8 -------- drivers/hmc5883l/hmc5883l.c | 8 -------- 2 files changed, 16 deletions(-) diff --git a/drivers/apds99xx/apds99xx.c b/drivers/apds99xx/apds99xx.c index 1f2e4d2facbb..8f2fd3e49caa 100644 --- a/drivers/apds99xx/apds99xx.c +++ b/drivers/apds99xx/apds99xx.c @@ -28,18 +28,10 @@ #define ENABLE_DEBUG 0 #include "debug.h" -#if ENABLE_DEBUG - #define DEBUG_DEV(f, d, ...) \ DEBUG("[apds99xx] %s i2c dev=%d addr=%02x: " f "\n", \ __func__, d->params.dev, APDS99XX_I2C_ADDRESS, ## __VA_ARGS__); -#else /* ENABLE_DEBUG */ - -#define DEBUG_DEV(f, d, ...) - -#endif /* ENABLE_DEBUG */ - #define ERROR_DEV(f, d, ...) \ LOG_ERROR("[apds99xx] %s i2c dev=%d addr=%02x: " f "\n", \ __func__, d->params.dev, APDS99XX_I2C_ADDRESS, ## __VA_ARGS__); diff --git a/drivers/hmc5883l/hmc5883l.c b/drivers/hmc5883l/hmc5883l.c index 688cae1d495a..1388d0caeb0a 100644 --- a/drivers/hmc5883l/hmc5883l.c +++ b/drivers/hmc5883l/hmc5883l.c @@ -27,18 +27,10 @@ #define ENABLE_DEBUG 0 #include "debug.h" -#if ENABLE_DEBUG - #define DEBUG_DEV(f, d, ...) \ DEBUG("[hmc5883l] %s i2c dev=%d addr=%02x: " f "\n", \ __func__, d->dev, HMC5883L_I2C_ADDRESS, ## __VA_ARGS__); -#else /* ENABLE_DEBUG */ - -#define DEBUG_DEV(f, d, ...) - -#endif /* ENABLE_DEBUG */ - #define ERROR_DEV(f, d, ...) \ LOG_ERROR("[hmc5883l] %s i2c dev=%d addr=%02x: " f "\n", \ __func__, d->dev, HMC5883L_I2C_ADDRESS, ## __VA_ARGS__); From 27a684aa60711514b70f520af2049e97fae73fe2 Mon Sep 17 00:00:00 2001 From: Bas Stottelaar Date: Fri, 23 Oct 2020 14:35:13 +0200 Subject: [PATCH 02/13] sys/*: remove unneeded ENABLE_DEBUG --- sys/net/gnrc/network_layer/ipv6/nib/_nib-internal.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/sys/net/gnrc/network_layer/ipv6/nib/_nib-internal.c b/sys/net/gnrc/network_layer/ipv6/nib/_nib-internal.c index c15d6ef41497..5d774118a4bb 100644 --- a/sys/net/gnrc/network_layer/ipv6/nib/_nib-internal.c +++ b/sys/net/gnrc/network_layer/ipv6/nib/_nib-internal.c @@ -703,11 +703,9 @@ _nib_abr_entry_t *_nib_abr_add(const ipv6_addr_t *addr) DEBUG(" using %p\n", (void *)abr); memcpy(&abr->addr, addr, sizeof(abr->addr)); } -#if ENABLE_DEBUG else { DEBUG(" NIB full\n"); } -#endif /* ENABLE_DEBUG */ return abr; } From 2d3d047fd6d092f81bea71d9f454cba873abf9ad Mon Sep 17 00:00:00 2001 From: Bas Stottelaar Date: Wed, 28 Oct 2020 17:20:10 +0100 Subject: [PATCH 03/13] core/*: replace #if ENABLE_DEBUG with IS_ACTIVE --- core/priority_queue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/priority_queue.c b/core/priority_queue.c index 3a2027f900a9..c7f734cc7a3f 100644 --- a/core/priority_queue.c +++ b/core/priority_queue.c @@ -72,7 +72,7 @@ void priority_queue_add(priority_queue_t *root, priority_queue_node_t *new_obj) new_obj->next = NULL; } -#if ENABLE_DEBUG +#if IS_ACTIVE(ENABLE_DEBUG) void priority_queue_print(priority_queue_t *root) { printf("queue:\n"); From 94171b73894922729dc6c584b88cd4fc04175d9d Mon Sep 17 00:00:00 2001 From: Bas Stottelaar Date: Fri, 23 Oct 2020 00:39:57 +0200 Subject: [PATCH 04/13] cpu/*: replace #if ENABLE_DEBUG with IS_ACTIVE --- cpu/esp32/esp-eth/esp_eth_netdev.c | 14 ++++---- cpu/esp32/periph/timer.c | 15 ++++---- cpu/esp32/startup.c | 36 +++++++++---------- .../vendor/esp-idf/heap/src/esp_heap_caps.c | 2 +- cpu/esp_common/esp-now/esp_now_netdev.c | 12 +++---- cpu/esp_common/esp-wifi/esp_wifi_netdev.c | 29 +++++++-------- cpu/esp_common/periph/spi.c | 28 +++++++-------- cpu/native/periph/eeprom.c | 4 +-- cpu/native/periph/uart.c | 2 +- cpu/native/socket_zep/socket_zep.c | 14 ++++---- cpu/native/syscalls.c | 17 +++++---- 11 files changed, 87 insertions(+), 86 deletions(-) diff --git a/cpu/esp32/esp-eth/esp_eth_netdev.c b/cpu/esp32/esp-eth/esp_eth_netdev.c index 679af9a44cdb..3e0c1cbaf7bd 100644 --- a/cpu/esp32/esp-eth/esp_eth_netdev.c +++ b/cpu/esp32/esp-eth/esp_eth_netdev.c @@ -203,10 +203,10 @@ static int _esp_eth_send(netdev_t *netdev, const iolist_t *iolist) } } - #if ENABLE_DEBUG - printf ("%s: send %d byte\n", __func__, dev->tx_len); - /* esp_hexdump (dev->tx_buf, dev->tx_len, 'b', 16); */ - #endif + if (IS_ACTIVE(ENABLE_DEBUG)) { + printf ("%s: send %d byte\n", __func__, dev->tx_len); + /* esp_hexdump (dev->tx_buf, dev->tx_len, 'b', 16); */ + } int ret = 0; @@ -253,9 +253,9 @@ static int _esp_eth_recv(netdev_t *netdev, void *buf, size_t len, void *info) return -ENOBUFS; } - #if ENABLE_DEBUG - /* esp_hexdump (dev->rx_buf, dev->rx_len, 'b', 16); */ - #endif + if (IS_ACTIVE(ENABLE_DEBUG)) { + esp_hexdump (dev->rx_buf, dev->rx_len, 'b', 16); + } /* copy received date and reset the receive length */ memcpy(buf, dev->rx_buf, dev->rx_len); diff --git a/cpu/esp32/periph/timer.c b/cpu/esp32/periph/timer.c index 78254612e27b..ad26b29678ef 100644 --- a/cpu/esp32/periph/timer.c +++ b/cpu/esp32/periph/timer.c @@ -316,13 +316,14 @@ unsigned int IRAM timer_read(tim_t dev) { CHECK_PARAM_RET (dev < HW_TIMER_NUMOF, -1); - #if ENABLE_DEBUG - uint32_t count_lo = timer_get_counter_lo(dev); - DEBUG("%s %u\n", __func__, count_lo); - return count_lo; - #else - return timer_get_counter_lo(dev); - #endif + if (IS_ACTIVE(ENABLE_DEBUG)) { + uint32_t count_lo = timer_get_counter_lo(dev); + DEBUG("%s %u\n", __func__, count_lo); + return count_lo; + } + else { + return timer_get_counter_lo(dev); + } } void IRAM timer_start(tim_t dev) diff --git a/cpu/esp32/startup.c b/cpu/esp32/startup.c index 16697b5041f3..be7b0de13dc6 100644 --- a/cpu/esp32/startup.c +++ b/cpu/esp32/startup.c @@ -167,30 +167,30 @@ NORETURN void IRAM call_start_cpu0 (void) rtc_clk_apb_freq_get(), rtc_clk_xtal_freq_get()*MHZ, rtc_clk_slow_freq_get_hz()); - #if ENABLE_DEBUG - ets_printf("reset reason: %d\n", reset_reason); - ets_printf("_stack %p\n", sp); - ets_printf("_bss_start %p\n", &_bss_start); - ets_printf("_bss_end %p\n", &_bss_end); - #ifndef MODULE_ESP_IDF_HEAP - ets_printf("_heap_start %p\n", &_sheap); - ets_printf("_heap_end %p\n", &_eheap); - ets_printf("_heap_free %u\n", get_free_heap_size()); - #endif /* MODULE_ESP_IDF_HEAP */ - #endif /* ENABLE_DEBUG */ + if (IS_ACTIVE(ENABLE_DEBUG)) { + ets_printf("reset reason: %d\n", reset_reason); + ets_printf("_stack %p\n", sp); + ets_printf("_bss_start %p\n", &_bss_start); + ets_printf("_bss_end %p\n", &_bss_end); + if (!IS_ACTIVE(MODULE_ESP_IDF_HEAP)) { + ets_printf("_heap_start %p\n", &_sheap); + ets_printf("_heap_end %p\n", &_eheap); + ets_printf("_heap_free %u\n", get_free_heap_size()); + } + } LOG_STARTUP("PRO cpu is up (single core mode, only PRO cpu is used)\n"); /* disable APP cpu */ DPORT_CLEAR_PERI_REG_MASK(DPORT_APPCPU_CTRL_B_REG, DPORT_APPCPU_CLKGATE_EN); - #ifdef MODULE_ESP_IDF_HEAP - /* init heap */ - heap_caps_init(); - #if ENABLE_DEBUG - ets_printf("Heap free: %u byte\n", get_free_heap_size()); - #endif /* ENABLE_DEBUG */ - #endif /* MODULE_ESP_IDF_HEAP */ + if (IS_ACTIVE(MODULE_ESP_IDF_HEAP)) { + /* init heap */ + heap_caps_init(); + if (IS_ACTIVE(ENABLE_DEBUG)) { + ets_printf("Heap free: %u byte\n", get_free_heap_size()); + } + } /* init SPI RAM if enabled */ #if CONFIG_SPIRAM_SUPPORT && CONFIG_SPIRAM_BOOT_INIT diff --git a/cpu/esp8266/vendor/esp-idf/heap/src/esp_heap_caps.c b/cpu/esp8266/vendor/esp-idf/heap/src/esp_heap_caps.c index 0ef0c111601f..8b43375a37d3 100644 --- a/cpu/esp8266/vendor/esp-idf/heap/src/esp_heap_caps.c +++ b/cpu/esp8266/vendor/esp-idf/heap/src/esp_heap_caps.c @@ -24,7 +24,7 @@ #include "esp_heap_trace.h" #include "priv/esp_heap_caps_priv.h" -#if ENABLE_DEBUG +#if IS_ACTIVE(ENABLE_DEBUG) #define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE #endif diff --git a/cpu/esp_common/esp-now/esp_now_netdev.c b/cpu/esp_common/esp-now/esp_now_netdev.c index c116a3264124..833934749e9e 100644 --- a/cpu/esp_common/esp-now/esp_now_netdev.c +++ b/cpu/esp_common/esp-now/esp_now_netdev.c @@ -154,12 +154,12 @@ static void IRAM_ATTR esp_now_scan_peers_done(void) critical_exit_var(state); } -#if ENABLE_DEBUG - esp_now_peer_num_t peer_num; - esp_now_get_peer_num(&peer_num); - DEBUG("associated peers total=%d, encrypted=%d\n", - peer_num.total_num, peer_num.encrypt_num); -#endif /* ENABLE_DEBUG */ + if (IS_ACTIVE(ENABLE_DEBUG)) { + esp_now_peer_num_t peer_num; + esp_now_get_peer_num(&peer_num); + DEBUG("associated peers total=%d, encrypted=%d\n", + peer_num.total_num, peer_num.encrypt_num); + } _esp_now_scan_peers_done = true; diff --git a/cpu/esp_common/esp-wifi/esp_wifi_netdev.c b/cpu/esp_common/esp-wifi/esp_wifi_netdev.c index 292f6c0fc874..ebf68dc2a3a3 100644 --- a/cpu/esp_common/esp-wifi/esp_wifi_netdev.c +++ b/cpu/esp_common/esp-wifi/esp_wifi_netdev.c @@ -594,12 +594,13 @@ static int _esp_wifi_send(netdev_t *netdev, const iolist_t *iolist) } } -#if ENABLE_DEBUG - ESP_WIFI_DEBUG("send %d byte", dev->tx_len); -#if MODULE_OD && ENABLE_DEBUG_HEXDUMP - od_hex_dump(dev->tx_buf, dev->tx_len, OD_WIDTH_DEFAULT); -#endif /* MODULE_OD && ENABLE_DEBUG_HEXDUMP */ -#endif + if (IS_ACTIVE(ENABLE_DEBUG)) { + ESP_WIFI_DEBUG("send %d byte", dev->tx_len); + if (IS_ACTIVE(ENABLE_DEBUG_HEXDUMP) && IS_USED(MODULE_OD)) { + od_hex_dump(dev->tx_buf, dev->tx_len, OD_WIDTH_DEFAULT); + } + } + critical_exit(); #ifdef MODULE_ESP_WIFI_AP @@ -665,15 +666,15 @@ static int _esp_wifi_recv(netdev_t *netdev, void *buf, size_t len, void *info) ringbuffer_remove(&dev->rx_buf, sizeof(uint16_t)); ringbuffer_get(&dev->rx_buf, buf, size); -#if ENABLE_DEBUG - ethernet_hdr_t *hdr = (ethernet_hdr_t *)buf; + if (IS_ACTIVE(ENABLE_DEBUG)) { + ethernet_hdr_t *hdr = (ethernet_hdr_t *)buf; + ESP_WIFI_DEBUG("received %u byte from addr " MAC_STR, + size, MAC_STR_ARG(hdr->src)); - ESP_WIFI_DEBUG("received %u byte from addr " MAC_STR, - size, MAC_STR_ARG(hdr->src)); -#if MODULE_OD && ENABLE_DEBUG_HEXDUMP - od_hex_dump(buf, size, OD_WIDTH_DEFAULT); -#endif /* MODULE_OD && ENABLE_DEBUG_HEXDUMP */ -#endif /* ENABLE_DEBUG */ + if (IS_ACTIVE(ENABLE_DEBUG_HEXDUMP) && IS_USED(MODULE_OD)) { + od_hex_dump(buf, size, OD_WIDTH_DEFAULT); + } + } critical_exit(); return size; diff --git a/cpu/esp_common/periph/spi.c b/cpu/esp_common/periph/spi.c index f43106be7bd4..388f5d3d08b4 100644 --- a/cpu/esp_common/periph/spi.c +++ b/cpu/esp_common/periph/spi.c @@ -488,15 +488,15 @@ void IRAM_ATTR spi_transfer_bytes(spi_t bus, spi_cs_t cs, bool cont, return; } - #if ENABLE_DEBUG - if (out) { - DEBUG("out = "); - for (size_t i = 0; i < len; i++) { - DEBUG("%02x ", ((const uint8_t *)out)[i]); + if (IS_ACTIVE(ENABLE_DEBUG)) { + if (out) { + DEBUG("out = "); + for (size_t i = 0; i < len; i++) { + DEBUG("%02x ", ((const uint8_t *)out)[i]); + } + DEBUG("\n"); } - DEBUG("\n"); } - #endif if (cs != SPI_CS_UNDEF) { gpio_clear(cs); @@ -524,13 +524,13 @@ void IRAM_ATTR spi_transfer_bytes(spi_t bus, spi_cs_t cs, bool cont, gpio_set (cs); } - #if ENABLE_DEBUG - if (in) { - DEBUG("in = "); - for (size_t i = 0; i < len; i++) { - DEBUG("%02x ", ((const uint8_t *)in)[i]); + if (IS_ACTIVE(ENABLE_DEBUG)) { + if (in) { + DEBUG("in = "); + for (size_t i = 0; i < len; i++) { + DEBUG("%02x ", ((const uint8_t *)in)[i]); + } + DEBUG("\n"); } - DEBUG("\n"); } - #endif } diff --git a/cpu/native/periph/eeprom.c b/cpu/native/periph/eeprom.c index 654b47692c97..797db72f864e 100644 --- a/cpu/native/periph/eeprom.c +++ b/cpu/native/periph/eeprom.c @@ -48,7 +48,7 @@ static inline void eeprom_native_write(void) DEBUG("Writing data to EEPROM file %s:\n", eeprom_file); fwrite(_eeprom_buf, 1, ARRAY_SIZE(_eeprom_buf), fp); - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { for (size_t i = 0; i < ARRAY_SIZE(_eeprom_buf); i++) { DEBUG("0x%02X ", _eeprom_buf[i]); if ((i + 1) % 16 == 0) { @@ -69,7 +69,7 @@ void eeprom_native_read(void) DEBUG("Reading data from EEPROM file %s:\n", eeprom_file); fread(_eeprom_buf, 1, ARRAY_SIZE(_eeprom_buf), fp); - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { for (size_t i = 0; i < ARRAY_SIZE(_eeprom_buf); i++) { DEBUG("0x%02X ", _eeprom_buf[i]); if ((i + 1) % 16 == 0) { diff --git a/cpu/native/periph/uart.c b/cpu/native/periph/uart.c index 4db0da2548cc..5584ba5c474b 100644 --- a/cpu/native/periph/uart.c +++ b/cpu/native/periph/uart.c @@ -164,7 +164,7 @@ void uart_write(uart_t uart, const uint8_t *data, size_t len) { DEBUG("writing to serial port "); - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { for (size_t i = 0; i < len; i++) { DEBUG("%02x ", (unsigned char) data[i]); } diff --git a/cpu/native/socket_zep/socket_zep.c b/cpu/native/socket_zep/socket_zep.c index 487a14539308..ced2089c921a 100644 --- a/cpu/native/socket_zep/socket_zep.c +++ b/cpu/native/socket_zep/socket_zep.c @@ -183,14 +183,14 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info) (unsigned)len, (void *)info); if ((buf == NULL) || (len == 0)) { int res = real_ioctl(dev->sock_fd, FIONREAD, &size); -#if ENABLE_DEBUG - if (res < 0) { - DEBUG("socket_zep::recv: error reading FIONREAD: %s", - strerror(errno)); + + if (IS_ACTIVE(ENABLE_DEBUG)) { + if (res < 0) { + DEBUG("socket_zep::recv: error reading FIONREAD: %s", + strerror(errno)); + } } -#else - (void)res; -#endif + return size; } else if (len > 0) { diff --git a/cpu/native/syscalls.c b/cpu/native/syscalls.c index 4962a6a43145..98d301972707 100644 --- a/cpu/native/syscalls.c +++ b/cpu/native/syscalls.c @@ -44,9 +44,6 @@ #include "native_internal.h" #define ENABLE_DEBUG 0 -#if ENABLE_DEBUG -#define LOCAL_DEBUG (1) -#endif #include "debug.h" ssize_t (*real_read)(int fd, void *buf, size_t count); @@ -109,16 +106,18 @@ int (*real_clock_gettime)(clockid_t clk_id, struct timespec *tp); void _native_syscall_enter(void) { _native_in_syscall++; -#if LOCAL_DEBUG - real_write(STDERR_FILENO, "> _native_in_syscall\n", 21); -#endif + + if (IS_ACTIVE(ENABLE_DEBUG)) { + real_write(STDERR_FILENO, "> _native_in_syscall\n", 21); + } } void _native_syscall_leave(void) { -#if LOCAL_DEBUG - real_write(STDERR_FILENO, "< _native_in_syscall\n", 21); -#endif + if (IS_ACTIVE(ENABLE_DEBUG)) { + real_write(STDERR_FILENO, "< _native_in_syscall\n", 21); + } + _native_in_syscall--; if ( (_native_sigpend > 0) From 62994dfb16089658de496372c2550194bfd76c79 Mon Sep 17 00:00:00 2001 From: Bas Stottelaar Date: Fri, 23 Oct 2020 00:40:33 +0200 Subject: [PATCH 05/13] drivers/*: replace #if ENABLE_DEBUG with IS_ACTIVE --- drivers/adt7310/adt7310.c | 18 +++---- drivers/apds99xx/apds99xx.c | 4 +- drivers/ata8520e/ata8520e.c | 4 +- drivers/atwinc15x0/atwinc15x0_netdev.c | 37 +++++++------ drivers/ccs811/ccs811.c | 4 +- drivers/ds3234/ds3234.c | 2 +- drivers/hmc5883l/hmc5883l.c | 4 +- drivers/kw2xrf/kw2xrf_netdev.c | 2 +- drivers/lsm303dlhc/lsm303dlhc.c | 2 +- drivers/mtd_mci/mtd_mci.c | 2 +- drivers/mtd_spi_nor/mtd_spi_nor.c | 23 ++++---- drivers/pn532/pn532.c | 2 +- drivers/rn2xx3/rn2xx3_internal.c | 2 +- drivers/sht3x/sht3x.c | 15 +++--- drivers/sx127x/sx127x_getset.c | 72 +++++++++++++------------- drivers/tsl2561/tsl2561.c | 40 +++++++------- 16 files changed, 118 insertions(+), 115 deletions(-) diff --git a/drivers/adt7310/adt7310.c b/drivers/adt7310/adt7310.c index c29ad6f6682d..54607d6bc318 100644 --- a/drivers/adt7310/adt7310.c +++ b/drivers/adt7310/adt7310.c @@ -144,17 +144,17 @@ int adt7310_init(adt7310_t *dev, spi_t spi, spi_clk_t clk, gpio_t cs) /* CS */ spi_init_cs(dev->spi, dev->cs); -#if ENABLE_DEBUG - for (int i = 0; i < 8; ++i) { - uint16_t dbg_reg = 0; - status = adt7310_read_reg(dev, i, sizeof(dbg_reg), (uint8_t *)&dbg_reg); - if (status != 0) { - printf("Error reading address 0x%02x", i); + if (IS_ACTIVE(ENABLE_DEBUG)) { + for (int i = 0; i < 8; ++i) { + uint16_t dbg_reg = 0; + status = adt7310_read_reg(dev, i, sizeof(dbg_reg), (uint8_t *)&dbg_reg); + if (status != 0) { + printf("Error reading address 0x%02x", i); + } + dbg_reg = htons(dbg_reg); + printf("%02x: %04" PRIx16 "\n", i, dbg_reg); } - dbg_reg = htons(dbg_reg); - printf("%02x: %04" PRIx16 "\n", i, dbg_reg); } -#endif /* Read ID register from device */ status = adt7310_read_reg(dev, ADT7310_REG_ID, ADT7310_REG_SIZE_ID, ®); diff --git a/drivers/apds99xx/apds99xx.c b/drivers/apds99xx/apds99xx.c index 8f2fd3e49caa..e06f965fcc33 100644 --- a/drivers/apds99xx/apds99xx.c +++ b/drivers/apds99xx/apds99xx.c @@ -480,7 +480,7 @@ static int _reg_read(const apds99xx_t *dev, uint8_t reg, uint8_t *data, uint16_t return -APDS99XX_ERROR_I2C; } - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { printf("[apds99xx] %s i2c dev=%d addr=%02x: read from reg 0x%02x: ", __func__, dev->params.dev, APDS99XX_I2C_ADDRESS, reg); for (uint16_t i = 0; i < len; i++) { @@ -496,7 +496,7 @@ static int _reg_write(const apds99xx_t *dev, uint8_t reg, uint8_t *data, uint16_ { assert(dev != NULL); - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { printf("[apds99xx] %s i2c dev=%d addr=%02x: write to reg 0x%02x: ", __func__, dev->params.dev, APDS99XX_I2C_ADDRESS, reg); for (uint16_t i = 0; i < len; i++) { diff --git a/drivers/ata8520e/ata8520e.c b/drivers/ata8520e/ata8520e.c index 0d7ec4beafa6..a4eeb05e318d 100644 --- a/drivers/ata8520e/ata8520e.c +++ b/drivers/ata8520e/ata8520e.c @@ -205,7 +205,7 @@ static void _status(const ata8520e_t *dev) uint8_t sigfox2 = spi_transfer_byte(SPIDEV, CSPIN, false, 0); spi_release(SPIDEV); - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { _print_atmel_status(atmel); _print_sigfox_status(sigfox); _print_sigfox_status(sigfox2); @@ -272,7 +272,7 @@ int ata8520e_init(ata8520e_t *dev, const ata8520e_params_t *params) xtimer_usleep(100 * US_PER_MS); /* 100 ms */ - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { char sigfox_id[SIGFOX_ID_LENGTH + 1]; ata8520e_read_id(dev, sigfox_id); diff --git a/drivers/atwinc15x0/atwinc15x0_netdev.c b/drivers/atwinc15x0/atwinc15x0_netdev.c index 2daf2b779ef4..3c212cdf8024 100644 --- a/drivers/atwinc15x0/atwinc15x0_netdev.c +++ b/drivers/atwinc15x0/atwinc15x0_netdev.c @@ -103,9 +103,10 @@ static void _atwinc15x0_eth_cb(uint8_t type, void *msg, void *ctrl_buf) DEBUG("%s type=%u msg=%p len=%d remaining=%d\n", __func__, type, msg, ctrl->u16DataSize, ctrl->u16RemainigDataSize); -#if MODULE_OD && ENABLE_DEBUG_DUMP - od_hex_dump(msg, ctrl->u16DataSize, 16); -#endif + + if (IS_ACTIVE(ENABLE_DEBUG) && IS_USED(MODULE_OD)) { + od_hex_dump(msg, ctrl->u16DataSize, 16); + } /* the buffer shouldn't be used here */ assert(atwinc15x0->rx_buf == NULL); @@ -258,12 +259,13 @@ static int _atwinc15x0_send(netdev_t *netdev, const iolist_t *iolist) } } -#if ENABLE_DEBUG - DEBUG("%s send %d byte", __func__, tx_len); -#if MODULE_OD && ENABLE_DEBUG_DUMP - od_hex_dump(dev->tx_buf, dev->tx_len, OD_WIDTH_DEFAULT); -#endif /* MODULE_OD && ENABLE_DEBUG_HEXDUMP */ -#endif + if (IS_ACTIVE(ENABLE_DEBUG)) { + DEBUG("%s send %d byte", __func__, tx_len); + if (IS_ACTIVE(ENABLE_DEBUG_DUMP) && IS_USED(MODULE_OD)) { + od_hex_dump(atwinc15x0_eth_buf, tx_len, OD_WIDTH_DEFAULT); + } + } + irq_restore(state); /* send the the packet */ @@ -320,14 +322,15 @@ static int _atwinc15x0_recv(netdev_t *netdev, void *buf, size_t len, void *info) dev->rx_len = 0; dev->rx_buf = NULL; -#if ENABLE_DEBUG - ethernet_hdr_t *hdr = (ethernet_hdr_t *)buf; - DEBUG("%s received %u byte from addr " ATWINC15X0_MAC_STR "\n", - __func__, rx_size, ATWINC15X0_MAC_STR_ARG(hdr->src)); -#if MODULE_OD && ENABLE_DEBUG_DUMP - od_hex_dump(buf, rx_size, OD_WIDTH_DEFAULT); -#endif /* MODULE_OD && ENABLE_DEBUG_HEXDUMP */ -#endif /* ENABLE_DEBUG */ + if (IS_ACTIVE(ENABLE_DEBUG)) { + ethernet_hdr_t *hdr = (ethernet_hdr_t *)buf; + DEBUG("%s received %u byte from addr " ATWINC15X0_MAC_STR "\n", + __func__, rx_size, ATWINC15X0_MAC_STR_ARG(hdr->src)); + + if (IS_ACTIVE(ENABLE_DEBUG_DUMP) && IS_USED(MODULE_OD)) { + od_hex_dump(buf, rx_size, OD_WIDTH_DEFAULT); + } + } irq_restore(state); diff --git a/drivers/ccs811/ccs811.c b/drivers/ccs811/ccs811.c index d066a38ef0d4..03e20247188d 100644 --- a/drivers/ccs811/ccs811.c +++ b/drivers/ccs811/ccs811.c @@ -512,7 +512,7 @@ static int _reg_read(const ccs811_t *dev, uint8_t reg, uint8_t *data, uint32_t l #endif if (res == CCS811_OK) { - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { printf("[ccs811] %s dev=%d addr=%02x: read following bytes: ", __func__, dev->params.i2c_dev, dev->params.i2c_addr); for (unsigned i = 0; i < len; i++) { @@ -537,7 +537,7 @@ static int _reg_write(const ccs811_t *dev, uint8_t reg, uint8_t *data, uint32_t int res = CCS811_OK; - if (ENABLE_DEBUG && data && len) { + if (IS_ACTIVE(ENABLE_DEBUG) && data && len) { printf("[css811] %s dev=%d addr=%02x: write following bytes: ", __func__, dev->params.i2c_dev, dev->params.i2c_addr); for (unsigned i = 0; i < len; i++) { diff --git a/drivers/ds3234/ds3234.c b/drivers/ds3234/ds3234.c index 8055a2687f5e..c3ecb633fdbc 100644 --- a/drivers/ds3234/ds3234.c +++ b/drivers/ds3234/ds3234.c @@ -79,7 +79,7 @@ int ds3234_pps_init(const ds3234_params_t *dev) } DEBUG("ds3234: init on SPI_DEV(%u)\n", dev->spi); - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { for (int k = 0; k <= 0x19; ++k) { uint8_t dbg_reg = 0; ds3234_read_reg(dev, k, 1, &dbg_reg); diff --git a/drivers/hmc5883l/hmc5883l.c b/drivers/hmc5883l/hmc5883l.c index 1388d0caeb0a..b84c2656c40c 100644 --- a/drivers/hmc5883l/hmc5883l.c +++ b/drivers/hmc5883l/hmc5883l.c @@ -243,7 +243,7 @@ static int _reg_read(const hmc5883l_t *dev, uint8_t reg, uint8_t *data, uint16_t i2c_release(dev->dev); if (res == 0) { - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { printf("[hmc5883l] %s i2c dev=%d addr=%02x: read following bytes: ", __func__, dev->dev, HMC5883L_I2C_ADDRESS); for (unsigned i = 0; i < len; i++) { @@ -268,7 +268,7 @@ static int _reg_write(const hmc5883l_t *dev, uint8_t reg, uint8_t data) DEBUG_DEV("write register 0x%02x", dev, reg); - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { printf("[hmc5883l] %s i2c dev=%d addr=%02x: write following bytes: ", __func__, dev->dev, HMC5883L_I2C_ADDRESS); printf("%02x ", data); diff --git a/drivers/kw2xrf/kw2xrf_netdev.c b/drivers/kw2xrf/kw2xrf_netdev.c index ab470228ba77..4ee4b17ec091 100644 --- a/drivers/kw2xrf/kw2xrf_netdev.c +++ b/drivers/kw2xrf/kw2xrf_netdev.c @@ -798,7 +798,7 @@ static void _isr(netdev_t *netdev) } kw2xrf_write_dreg(dev, MKW2XDM_IRQSTS2, irqsts2); - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { /* for debugging only */ kw2xrf_read_dregs(dev, MKW2XDM_IRQSTS1, dregs, MKW2XDM_IRQSTS1 + 3); if (dregs[MKW2XDM_IRQSTS1] & 0x7f) { diff --git a/drivers/lsm303dlhc/lsm303dlhc.c b/drivers/lsm303dlhc/lsm303dlhc.c index 338ec62d0e2e..06e7eba2fb86 100644 --- a/drivers/lsm303dlhc/lsm303dlhc.c +++ b/drivers/lsm303dlhc/lsm303dlhc.c @@ -82,7 +82,7 @@ int lsm303dlhc_init(lsm303dlhc_t *dev, const lsm303dlhc_params_t *params) i2c_release(DEV_I2C); /* configure mag data ready pin */ gpio_init(DEV_MAG_PIN, GPIO_IN); - if (ENABLE_DEBUG && res == 0) { + if (IS_ACTIVE(ENABLE_DEBUG) && res == 0) { DEBUG("[OK]\n"); } else { diff --git a/drivers/mtd_mci/mtd_mci.c b/drivers/mtd_mci/mtd_mci.c index 1e0c5791072c..a1cf1941027a 100644 --- a/drivers/mtd_mci/mtd_mci.c +++ b/drivers/mtd_mci/mtd_mci.c @@ -40,7 +40,7 @@ static int mtd_mci_init(mtd_dev_t *dev) return -EIO; } - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { uint32_t block_size; mci_ioctl(GET_BLOCK_SIZE, &block_size); DEBUG("block size: %lu\n", block_size); diff --git a/drivers/mtd_spi_nor/mtd_spi_nor.c b/drivers/mtd_spi_nor/mtd_spi_nor.c index f7ff1b72ef7d..85a7854fa13d 100644 --- a/drivers/mtd_spi_nor/mtd_spi_nor.c +++ b/drivers/mtd_spi_nor/mtd_spi_nor.c @@ -26,12 +26,8 @@ #include #include "mtd.h" -#if MODULE_XTIMER #include "xtimer.h" -#include "timex.h" -#else #include "thread.h" -#endif #include "byteorder.h" #include "mtd_spi_nor.h" @@ -110,7 +106,7 @@ static void mtd_spi_cmd_addr_read(const mtd_spi_nor_t *dev, uint8_t opcode, uint8_t *addr_buf = _be_addr(dev, &addr); - if (ENABLE_TRACE) { + if (IS_ACTIVE(ENABLE_TRACE)) { TRACE("mtd_spi_cmd_addr_read: addr:"); for (unsigned int i = 0; i < dev->params->addr_width; ++i) { TRACE(" %02x", addr_buf[i]); @@ -146,7 +142,7 @@ static void mtd_spi_cmd_addr_write(const mtd_spi_nor_t *dev, uint8_t opcode, uint8_t *addr_buf = _be_addr(dev, &addr); - if (ENABLE_TRACE) { + if (IS_ACTIVE(ENABLE_TRACE)) { TRACE("mtd_spi_cmd_addr_write: addr:"); for (unsigned int i = 0; i < dev->params->addr_width; ++i) { TRACE(" %02x", addr_buf[i]); @@ -313,9 +309,10 @@ static inline void wait_for_write_complete(const mtd_spi_nor_t *dev, uint32_t us { unsigned i = 0, j = 0; uint32_t div = 2; -#if ENABLE_DEBUG && defined(MODULE_XTIMER) - uint32_t diff = xtimer_now_usec(); -#endif + uint32_t diff = 0; + if (IS_ACTIVE(ENABLE_DEBUG) && IS_USED(MODULE_XTIMER)) { + diff = xtimer_now_usec(); + } do { uint8_t status; mtd_spi_cmd_read(dev, dev->params->opcode->rdsr, &status, sizeof(status)); @@ -349,10 +346,10 @@ static inline void wait_for_write_complete(const mtd_spi_nor_t *dev, uint32_t us #endif } while (1); DEBUG("wait loop %u times, yield %u times", i, j); -#if ENABLE_DEBUG && defined(MODULE_XTIMER) - diff = xtimer_now_usec() - diff; - DEBUG(", total wait %"PRIu32"us", diff); -#endif + if (IS_ACTIVE(ENABLE_DEBUG) && IS_ACTIVE(MODULE_XTIMER)) { + diff = xtimer_now_usec() - diff; + DEBUG(", total wait %"PRIu32"us", diff); + } DEBUG("\n"); } diff --git a/drivers/pn532/pn532.c b/drivers/pn532/pn532.c index ce976dd984c1..f50658e29243 100644 --- a/drivers/pn532/pn532.c +++ b/drivers/pn532/pn532.c @@ -78,7 +78,7 @@ /* Length for passive listings */ #define LIST_PASSIVE_LEN_14443(num) (num * 20) -#if ENABLE_DEBUG +#if IS_ACTIVE(ENABLE_DEBUG) #define PRINTBUFF printbuff static void printbuff(uint8_t *buff, unsigned len) { diff --git a/drivers/rn2xx3/rn2xx3_internal.c b/drivers/rn2xx3/rn2xx3_internal.c index c3993a8fa56c..a0556e2d0de2 100644 --- a/drivers/rn2xx3/rn2xx3_internal.c +++ b/drivers/rn2xx3/rn2xx3_internal.c @@ -100,7 +100,7 @@ void rn2xx3_set_internal_state(rn2xx3_t *dev, uint8_t state) return; } - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { printf("[rn2xx3] new state: "); switch(state) { case RN2XX3_INT_STATE_CMD: diff --git a/drivers/sht3x/sht3x.c b/drivers/sht3x/sht3x.c index 9b21fd833822..7a9bcc5ccea8 100644 --- a/drivers/sht3x/sht3x.c +++ b/drivers/sht3x/sht3x.c @@ -322,13 +322,14 @@ static int _read_data(sht3x_dev_t* dev, uint8_t *data, uint8_t len) i2c_release(dev->i2c_dev); if (res == 0) { -#if ENABLE_DEBUG - printf("[sht3x] %s bus=%d addr=%02x: read following bytes: ", - __func__, dev->i2c_dev, dev->i2c_addr); - for (int i=0; i < len; i++) - printf("%02x ", data[i]); - printf("\n"); -#endif /* ENABLE_DEBUG */ + if (IS_ACTIVE(ENABLE_DEBUG)) { + printf("[sht3x] %s bus=%d addr=%02x: read following bytes: ", + __func__, dev->i2c_dev, dev->i2c_addr); + for (int i=0; i < len; i++) { + printf("%02x ", data[i]); + } + printf("\n"); + } } else { DEBUG_DEV("could not read %d bytes from sensor, reason %d", diff --git a/drivers/sx127x/sx127x_getset.c b/drivers/sx127x/sx127x_getset.c index 39f2c50a1be2..371ce746bebc 100644 --- a/drivers/sx127x/sx127x_getset.c +++ b/drivers/sx127x/sx127x_getset.c @@ -44,22 +44,22 @@ uint8_t sx127x_get_state(const sx127x_t *dev) void sx127x_set_state(sx127x_t *dev, uint8_t state) { -#if ENABLE_DEBUG - switch (state) { - case SX127X_RF_IDLE: - DEBUG("[sx127x] Change state: IDLE\n"); - break; - case SX127X_RF_RX_RUNNING: - DEBUG("[sx127x] Change state: RX\n"); - break; - case SX127X_RF_TX_RUNNING: - DEBUG("[sx127x] Change state: TX\n"); - break; - default: - DEBUG("[sx127x] Change state: UNKNOWN\n"); - break; + if (IS_ACTIVE(ENABLE_DEBUG)) { + switch (state) { + case SX127X_RF_IDLE: + DEBUG("[sx127x] Change state: IDLE\n"); + break; + case SX127X_RF_RX_RUNNING: + DEBUG("[sx127x] Change state: RX\n"); + break; + case SX127X_RF_TX_RUNNING: + DEBUG("[sx127x] Change state: TX\n"); + break; + default: + DEBUG("[sx127x] Change state: UNKNOWN\n"); + break; + } } -#endif dev->settings.state = state; } @@ -440,28 +440,28 @@ uint8_t sx127x_get_op_mode(const sx127x_t *dev) void sx127x_set_op_mode(const sx127x_t *dev, uint8_t op_mode) { -#if ENABLE_DEBUG - switch(op_mode) { - case SX127X_RF_OPMODE_SLEEP: - DEBUG("[sx127x] Set op mode: SLEEP\n"); - break; - case SX127X_RF_OPMODE_STANDBY: - DEBUG("[sx127x] Set op mode: STANDBY\n"); - break; - case SX127X_RF_OPMODE_RECEIVER_SINGLE: - DEBUG("[sx127x] Set op mode: RECEIVER SINGLE\n"); - break; - case SX127X_RF_OPMODE_RECEIVER: - DEBUG("[sx127x] Set op mode: RECEIVER\n"); - break; - case SX127X_RF_OPMODE_TRANSMITTER: - DEBUG("[sx127x] Set op mode: TRANSMITTER\n"); - break; - default: - DEBUG("[sx127x] Set op mode: UNKNOWN (%d)\n", op_mode); - break; + if (IS_ACTIVE(ENABLE_DEBUG)) { + switch(op_mode) { + case SX127X_RF_OPMODE_SLEEP: + DEBUG("[sx127x] Set op mode: SLEEP\n"); + break; + case SX127X_RF_OPMODE_STANDBY: + DEBUG("[sx127x] Set op mode: STANDBY\n"); + break; + case SX127X_RF_OPMODE_RECEIVER_SINGLE: + DEBUG("[sx127x] Set op mode: RECEIVER SINGLE\n"); + break; + case SX127X_RF_OPMODE_RECEIVER: + DEBUG("[sx127x] Set op mode: RECEIVER\n"); + break; + case SX127X_RF_OPMODE_TRANSMITTER: + DEBUG("[sx127x] Set op mode: TRANSMITTER\n"); + break; + default: + DEBUG("[sx127x] Set op mode: UNKNOWN (%d)\n", op_mode); + break; + } } -#endif /* Replace previous mode value and setup new mode value */ sx127x_reg_write(dev, SX127X_REG_OPMODE, diff --git a/drivers/tsl2561/tsl2561.c b/drivers/tsl2561/tsl2561.c index a0d4523c6ca8..546ba0533147 100644 --- a/drivers/tsl2561/tsl2561.c +++ b/drivers/tsl2561/tsl2561.c @@ -75,13 +75,14 @@ int tsl2561_init(tsl2561_t *dev, const tsl2561_params_t *params) TSL2561_COMMAND_MODE | TSL2561_REGISTER_TIMING, DEV_INTEGRATION | DEV_GAIN, 0); -#if ENABLE_DEBUG - uint8_t timing; - i2c_read_reg(DEV_I2C, DEV_ADDR, - TSL2561_COMMAND_MODE | TSL2561_REGISTER_TIMING, &timing, 0); - DEBUG("[Info] Timing ? %d (expected: %d)\n", - timing, DEV_INTEGRATION | DEV_GAIN); -#endif + if (IS_ACTIVE(ENABLE_DEBUG)) { + uint8_t timing; + i2c_read_reg(DEV_I2C, DEV_ADDR, + TSL2561_COMMAND_MODE | TSL2561_REGISTER_TIMING, + &timing, 0); + DEBUG("[Info] Timing ? %d (expected: %d)\n", + timing, DEV_INTEGRATION | DEV_GAIN); + } _disable(dev); i2c_release(DEV_I2C); @@ -187,12 +188,13 @@ static void _enable(const tsl2561_t *dev) i2c_write_reg(DEV_I2C, DEV_ADDR, TSL2561_COMMAND_MODE | TSL2561_REGISTER_CONTROL, TSL2561_CONTROL_POWERON, 0); -#if ENABLE_DEBUG - uint8_t en; - i2c_read_reg(DEV_I2C, DEV_ADDR, - TSL2561_COMMAND_MODE | TSL2561_REGISTER_CONTROL, &en, 0); - DEBUG("[Info] Enabled ? %s\n", en == 3 ? "true" : "false"); -#endif + + if (IS_ACTIVE(ENABLE_DEBUG)) { + uint8_t en; + i2c_read_reg(DEV_I2C, DEV_ADDR, + TSL2561_COMMAND_MODE | TSL2561_REGISTER_CONTROL, &en, 0); + DEBUG("[Info] Enabled ? %s\n", en == 3 ? "true" : "false"); + } } @@ -203,12 +205,12 @@ static void _disable(const tsl2561_t *dev) TSL2561_COMMAND_MODE | TSL2561_REGISTER_CONTROL, TSL2561_CONTROL_POWEROFF, 0); -#if ENABLE_DEBUG - uint8_t dis; - i2c_read_reg(DEV_I2C, DEV_ADDR, - TSL2561_COMMAND_MODE | TSL2561_REGISTER_CONTROL, &dis, 0); - DEBUG("[Info] Disabled ? %s\n", dis == 0 ? "true": "false"); -#endif + if (IS_ACTIVE(ENABLE_DEBUG)) { + uint8_t dis; + i2c_read_reg(DEV_I2C, DEV_ADDR, + TSL2561_COMMAND_MODE | TSL2561_REGISTER_CONTROL, &dis, 0); + DEBUG("[Info] Disabled ? %s\n", dis == 0 ? "true": "false"); + } } static void _read_data(const tsl2561_t *dev, uint16_t *full, uint16_t *ir) From bf88a24fb4c8fdea1bdd838b0d33e0413dad9301 Mon Sep 17 00:00:00 2001 From: Bas Stottelaar Date: Fri, 23 Oct 2020 14:39:16 +0200 Subject: [PATCH 06/13] examples/*: replace #if ENABLE_DEBUG with IS_ACTIVE --- examples/dtls-echo/dtls-client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/dtls-echo/dtls-client.c b/examples/dtls-echo/dtls-client.c index e1ef30516bb1..e9668b9020c2 100644 --- a/examples/dtls-echo/dtls-client.c +++ b/examples/dtls-echo/dtls-client.c @@ -131,7 +131,7 @@ static int dtls_handle_read(dtls_context_t *ctx) memcpy(&session.addr, &remote.addr.ipv6, sizeof(session.addr)); - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { DEBUG("DBG-Client: Msg received from \n\t Addr Src: ["); ipv6_addr_print(&session.addr); DEBUG("]:%u\n", remote.port); From 9dd3b7a3ecd7cf6a71486e32f98f9a71076e66ca Mon Sep 17 00:00:00 2001 From: Bas Stottelaar Date: Fri, 23 Oct 2020 00:40:45 +0200 Subject: [PATCH 07/13] pkg/*: replace #if ENABLE_DEBUG with IS_ACTIVE --- pkg/nimble/autoconn/nimble_autoconn.c | 22 +++++++---------- .../contrib/platform_functions_wrapper.c | 16 +++++-------- pkg/openthread/contrib/platform_radio.c | 6 ++--- pkg/paho-mqtt/contrib/riot_iface.c | 4 +--- pkg/semtech-loramac/contrib/semtech_loramac.c | 4 ++-- pkg/tinydtls/contrib/sock_dtls.c | 24 +++++++++---------- 6 files changed, 33 insertions(+), 43 deletions(-) diff --git a/pkg/nimble/autoconn/nimble_autoconn.c b/pkg/nimble/autoconn/nimble_autoconn.c index f9cee1841ad8..b75469b4744a 100644 --- a/pkg/nimble/autoconn/nimble_autoconn.c +++ b/pkg/nimble/autoconn/nimble_autoconn.c @@ -164,20 +164,16 @@ static void _on_scan_evt(uint8_t type, const ble_addr_t *addr, int8_t rssi, static void _evt_dbg(const char *msg, int handle, const uint8_t *addr) { -#if ENABLE_DEBUG - printf("[autoconn] %s (%i|", msg, handle); - if (addr) { - bluetil_addr_print(addr); - } - else { - printf("n/a"); + if (IS_ACTIVE(ENABLE_DEBUG)) { + printf("[autoconn] %s (%i|", msg, handle); + if (addr) { + bluetil_addr_print(addr); + } + else { + printf("n/a"); + } + puts(")"); } - puts(")"); -#else - (void)msg; - (void)handle; - (void)addr; -#endif } static void _on_netif_evt(int handle, nimble_netif_event_t event, diff --git a/pkg/openthread/contrib/platform_functions_wrapper.c b/pkg/openthread/contrib/platform_functions_wrapper.c index d1f2b435a2b6..4d4ef5e8a3da 100644 --- a/pkg/openthread/contrib/platform_functions_wrapper.c +++ b/pkg/openthread/contrib/platform_functions_wrapper.c @@ -110,17 +110,13 @@ uint8_t ot_call_command(char* command, void *arg, void* answer) void output_bytes(const char* name, const uint8_t *aBytes, uint8_t aLength) { -#if ENABLE_DEBUG - DEBUG("%s: ", name); - for (int i = 0; i < aLength; i++) { - DEBUG("%02x", aBytes[i]); + if (IS_ACTIVE(ENABLE_DEBUG)) { + DEBUG("%s: ", name); + for (int i = 0; i < aLength; i++) { + DEBUG("%02x", aBytes[i]); + } + DEBUG("\n"); } - DEBUG("\n"); -#else - (void)name; - (void)aBytes; - (void)aLength; -#endif } OT_COMMAND ot_channel(otInstance* ot_instance, void* arg, void* answer) { diff --git a/pkg/openthread/contrib/platform_radio.c b/pkg/openthread/contrib/platform_radio.c index 4f8f4a51b582..a91a1419cc20 100644 --- a/pkg/openthread/contrib/platform_radio.c +++ b/pkg/openthread/contrib/platform_radio.c @@ -159,7 +159,7 @@ void recv_pkt(otInstance *aInstance, netdev_t *dev) /* Get RSSI from a radio driver. RSSI should be in [dBm] */ Rssi = (int8_t)rx_info.rssi; - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { DEBUG("Received message: len %d\n", (int) sReceiveFrame.mLength); for (int i = 0; i < sReceiveFrame.mLength; ++i) { DEBUG("%x ", sReceiveFrame.mPsdu[i]); @@ -216,7 +216,7 @@ void otPlatRadioSetExtendedAddress(otInstance *aInstance, const otExtAddress *aE for (unsigned i = 0; i < IEEE802154_LONG_ADDRESS_LEN; i++) { reversed_addr[i] = (uint8_t) ((uint8_t *)aExtAddress)[IEEE802154_LONG_ADDRESS_LEN - 1 - i]; } - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { for (unsigned i = 0; i < IEEE802154_LONG_ADDRESS_LEN; ++i) { DEBUG("%x ", (uint8_t) ((uint8_t *)reversed_addr)[i]); } @@ -344,7 +344,7 @@ otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aPacket) }; /*Set channel and power based on transmit frame */ - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { DEBUG("otPlatRadioTransmit->channel: %i, length %d\n", (int) aPacket->mChannel, (int)aPacket->mLength); for (size_t i = 0; i < aPacket->mLength; ++i) { diff --git a/pkg/paho-mqtt/contrib/riot_iface.c b/pkg/paho-mqtt/contrib/riot_iface.c index 8c18e84abdfd..90f1cddcc6b6 100644 --- a/pkg/paho-mqtt/contrib/riot_iface.c +++ b/pkg/paho-mqtt/contrib/riot_iface.c @@ -88,8 +88,7 @@ static int mqtt_read(struct Network *n, unsigned char *buf, int len, } } while (rc < len && xtimer_now64().ticks64 < send_tick && rc >= 0); -#ifdef ENABLE_DEBUG - if (IS_USED(MODULE_LWIP) && rc > 0) { + if (IS_ACTIVE(ENABLE_DEBUG) && IS_USED(MODULE_LWIP) && rc > 0) { DEBUG("MQTT buf asked for %d, available to read %d\n", rc, tsrb_avail(&tsrb_lwip_tcp)); for (int i = 0; i < rc; i++) { @@ -97,7 +96,6 @@ static int mqtt_read(struct Network *n, unsigned char *buf, int len, } DEBUG("\n"); } -#endif return rc; } diff --git a/pkg/semtech-loramac/contrib/semtech_loramac.c b/pkg/semtech-loramac/contrib/semtech_loramac.c index c5d12c743ef8..4b42ee2ffcf5 100644 --- a/pkg/semtech-loramac/contrib/semtech_loramac.c +++ b/pkg/semtech-loramac/contrib/semtech_loramac.c @@ -712,7 +712,7 @@ void *_semtech_loramac_event_loop(void *arg) /* save the uplink counter */ _save_uplink_counter(mac); #endif - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { switch (confirm->McpsRequest) { case MCPS_UNCONFIRMED: { @@ -755,7 +755,7 @@ void *_semtech_loramac_event_loop(void *arg) break; } - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { switch (indication->McpsIndication) { case MCPS_UNCONFIRMED: DEBUG("[semtech-loramac] MCPS indication Unconfirmed\n"); diff --git a/pkg/tinydtls/contrib/sock_dtls.c b/pkg/tinydtls/contrib/sock_dtls.c index 1eb6bff70ca3..0d9fd8cc3d9f 100644 --- a/pkg/tinydtls/contrib/sock_dtls.c +++ b/pkg/tinydtls/contrib/sock_dtls.c @@ -117,19 +117,19 @@ static int _event(struct dtls_context_t *ctx, session_t *session, sock_dtls_t *sock = dtls_get_app_data(ctx); msg_t msg = { .type = code, .content.ptr = session }; -#ifdef ENABLE_DEBUG - switch (code) { - case DTLS_EVENT_CONNECT: - DEBUG("sock_dtls: event connect\n"); - break; - case DTLS_EVENT_CONNECTED: - DEBUG("sock_dtls: event connected\n"); - break; - case DTLS_EVENT_RENEGOTIATE: - DEBUG("sock_dtls: event renegotiate\n"); - break; + if (IS_ACTIVE(ENABLE_DEBUG)) { + switch (code) { + case DTLS_EVENT_CONNECT: + DEBUG("sock_dtls: event connect\n"); + break; + case DTLS_EVENT_CONNECTED: + DEBUG("sock_dtls: event connected\n"); + break; + case DTLS_EVENT_RENEGOTIATE: + DEBUG("sock_dtls: event renegotiate\n"); + break; + } } -#endif /* ENABLE_DEBUG */ if (!level && (code != DTLS_EVENT_CONNECT)) { mbox_put(&sock->mbox, &msg); } From 922e2ac1c9046d0bd6ef46c3ce50766751550f17 Mon Sep 17 00:00:00 2001 From: Bas Stottelaar Date: Fri, 23 Oct 2020 00:40:57 +0200 Subject: [PATCH 08/13] sys/*: replace #if ENABLE_DEBUG with IS_ACTIVE --- sys/can/isotp/isotp.c | 48 ++++---- sys/can/router.c | 52 +++++---- sys/ecc/golay2412.c | 107 ++++++++---------- sys/net/application_layer/dhcpv6/client.c | 43 +++---- sys/net/crosslayer/inet_csum/inet_csum.c | 17 +-- sys/net/gnrc/link_layer/lwmac/lwmac.c | 31 +++-- .../netif/ieee802154/gnrc_netif_ieee802154.c | 27 ++--- sys/net/gnrc/network_layer/ipv6/nib/nib.c | 2 +- .../sixlowpan/ctx/gnrc_sixlowpan_ctx.c | 16 +-- .../sixlowpan/iphc/gnrc_sixlowpan_iphc.c | 16 +-- .../gnrc/routing/rpl/gnrc_rpl_validation.c | 2 +- sys/net/gnrc/routing/rpl/p2p/gnrc_rpl_p2p.c | 2 +- sys/net/network_layer/fib/fib.c | 26 ++--- sys/posix/pthread/pthread.c | 2 +- sys/timex/timex.c | 32 +++--- sys/vfs/vfs.c | 3 +- sys/ztimer/core.c | 4 +- 17 files changed, 208 insertions(+), 222 deletions(-) diff --git a/sys/can/isotp/isotp.c b/sys/can/isotp/isotp.c index 5142acfe8c84..070b9c21f971 100644 --- a/sys/can/isotp/isotp.c +++ b/sys/can/isotp/isotp.c @@ -312,13 +312,13 @@ static int _isotp_rcv_ff(struct isotp *isotp, struct can_frame *frame, int ae) ((uint8_t *)isotp->rx.snip->data)[isotp->rx.idx++] = frame->data[i]; } -#if ENABLE_DEBUG - DEBUG("_isotp_rcv_ff: rx.buf="); - for (unsigned i = 0; i < isotp->rx.idx; i++) { - DEBUG("%02hhx", ((uint8_t *)isotp->rx.snip->data)[i]); + if (IS_ACTIVE(ENABLE_DEBUG)) { + DEBUG("_isotp_rcv_ff: rx.buf="); + for (unsigned i = 0; i < isotp->rx.idx; i++) { + DEBUG("%02hhx", ((uint8_t *)isotp->rx.snip->data)[i]); + } + DEBUG("\n"); } - DEBUG("\n"); -#endif isotp->rx.sn = 1; @@ -360,13 +360,13 @@ static int _isotp_rcv_cf(struct isotp *isotp, struct can_frame *frame, int ae) } } -#if ENABLE_DEBUG - DEBUG("_isotp_rcv_cf: rx.buf="); - for (unsigned i = 0; i < isotp->rx.idx; i++) { - DEBUG("%02hhx", ((uint8_t *)isotp->rx.snip->data)[i]); + if (IS_ACTIVE(ENABLE_DEBUG)) { + DEBUG("_isotp_rcv_cf: rx.buf="); + for (unsigned i = 0; i < isotp->rx.idx; i++) { + DEBUG("%02hhx", ((uint8_t *)isotp->rx.snip->data)[i]); + } + DEBUG("\n"); } - DEBUG("\n"); -#endif if (isotp->rx.idx >= isotp->rx.snip->size) { isotp->rx.state = ISOTP_IDLE; @@ -392,13 +392,13 @@ static int _isotp_rcv(struct isotp *isotp, struct can_frame *frame) int ae = (isotp->opt.flags & CAN_ISOTP_EXTEND_ADDR) ? 1 : 0; uint8_t n_pci_type; -#if ENABLE_DEBUG - DEBUG("_isotp_rcv: id=%" PRIx32 " data=", frame->can_id); - for (int i = 0; i < frame->can_dlc; i++) { - DEBUG("%02hhx", frame->data[i]); + if (IS_ACTIVE(ENABLE_DEBUG)) { + DEBUG("_isotp_rcv: id=%" PRIx32 " data=", frame->can_id); + for (int i = 0; i < frame->can_dlc; i++) { + DEBUG("%02hhx", frame->data[i]); + } + DEBUG("\n"); } - DEBUG("\n"); -#endif if (ae && frame->data[0] != isotp->opt.rx_ext_address) { return 1; @@ -448,13 +448,13 @@ static int _isotp_send_fc(struct isotp *isotp, int ae, uint8_t status) isotp->rx.bs = 0; -#if ENABLE_DEBUG - DEBUG("_isotp_send_fc: id=%" PRIx32 " data=", fc.can_id); - for (int i = 0; i < fc.can_dlc; i++) { - DEBUG("%02hhx", fc.data[i]); + if (IS_ACTIVE(ENABLE_DEBUG)) { + DEBUG("_isotp_send_fc: id=%" PRIx32 " data=", fc.can_id); + for (int i = 0; i < fc.can_dlc; i++) { + DEBUG("%02hhx", fc.data[i]); + } + DEBUG("\n"); } - DEBUG("\n"); -#endif xtimer_set(&isotp->rx_timer, CAN_ISOTP_TIMEOUT_N_Ar); isotp->rx.tx_handle = raw_can_send(isotp->entry.ifnum, &fc, isotp_pid); diff --git a/sys/can/router.c b/sys/can/router.c index 316b87f1b8a4..227c8760e43e 100644 --- a/sys/can/router.c +++ b/sys/can/router.c @@ -30,9 +30,7 @@ #include "assert.h" #include "memarray.h" -#ifdef MODULE_CAN_MBOX #include "mbox.h" -#endif #define ENABLE_DEBUG 0 #include "debug.h" @@ -71,7 +69,7 @@ static void _insert_to_list(can_reg_entry_t **list, filter_el_t *el); static filter_el_t *_find_filter_el(can_reg_entry_t *list, can_reg_entry_t *entry, canid_t can_id, canid_t mask, void *data); static int _filter_is_used(unsigned int ifnum, canid_t can_id, canid_t mask); -#if ENABLE_DEBUG +#if IS_ACTIVE(ENABLE_DEBUG) static void _print_filters(void) { for (int i = 0; i < (int)CAN_DLL_NUMOF; i++) { @@ -84,7 +82,6 @@ static void _print_filters(void) } } } - #define PRINT_FILTERS() _print_filters() #else #define PRINT_FILTERS() @@ -214,13 +211,15 @@ int can_router_register(can_reg_entry_t *entry, canid_t can_id, canid_t mask, vo filter_el_t *filter; int ret; -#if ENABLE_DEBUG - if (entry->type == CAN_TYPE_DEFAULT) { - DEBUG("can_router_register: ifnum=%d, pid=%" PRIkernel_pid ", can_id=0x%" PRIx32 - ", mask=0x%" PRIx32 ", data=%p\n", entry->ifnum, entry->target.pid, can_id, mask, param); - } else if (entry->type == CAN_TYPE_MBOX) { - DEBUG("can_router_register: ifnum=%d, mbox=%p, can_id=0x%" PRIx32 - ", mask=0x%" PRIx32 ", data=%p\n", entry->ifnum, (void *)entry->target.mbox, can_id, mask, param); +#ifdef MODULE_CAN_MBOX + if (IS_ACTIVE(ENABLE_DEBUG)) { + if (entry->type == CAN_TYPE_DEFAULT) { + DEBUG("can_router_register: ifnum=%d, pid=%" PRIkernel_pid ", can_id=0x%" PRIx32 + ", mask=0x%" PRIx32 ", data=%p\n", entry->ifnum, entry->target.pid, can_id, mask, param); + } else if (entry->type == CAN_TYPE_MBOX) { + DEBUG("can_router_register: ifnum=%d, mbox=%p, can_id=0x%" PRIx32 + ", mask=0x%" PRIx32 ", data=%p\n", entry->ifnum, (void *)entry->target.mbox, can_id, mask, param); + } } #endif @@ -263,13 +262,15 @@ int can_router_unregister(can_reg_entry_t *entry, canid_t can_id, filter_el_t *el; int ret; -#if ENABLE_DEBUG - if (entry->type == CAN_TYPE_DEFAULT) { - DEBUG("can_router_unregister: ifnum=%d, pid=%" PRIkernel_pid ", can_id=0x%" PRIx32 - ", mask=0x%" PRIx32 ", data=%p", entry->ifnum, entry->target.pid, can_id, mask, param); - } else if (entry->type == CAN_TYPE_MBOX) { - DEBUG("can_router_unregister: ifnum=%d, mbox=%p, can_id=0x%" PRIx32 - ", mask=0x%" PRIx32 ", data=%p\n", entry->ifnum, (void *)entry->target.mbox, can_id, mask, param); +#ifdef MODULE_CAN_MBOX + if (IS_ACTIVE(ENABLE_DEBUG)) { + if (entry->type == CAN_TYPE_DEFAULT) { + DEBUG("can_router_unregister: ifnum=%d, pid=%" PRIkernel_pid ", can_id=0x%" PRIx32 + ", mask=0x%" PRIx32 ", data=%p", entry->ifnum, entry->target.pid, can_id, mask, param); + } else if (entry->type == CAN_TYPE_MBOX) { + DEBUG("can_router_unregister: ifnum=%d, mbox=%p, can_id=0x%" PRIx32 + ", mask=0x%" PRIx32 ", data=%p\n", entry->ifnum, (void *)entry->target.mbox, can_id, mask, param); + } } #endif @@ -317,9 +318,8 @@ int can_router_dispatch_rx_indic(can_pkt_t *pkt) int res = 0; msg_t msg; msg.type = CAN_MSG_RX_INDICATION; -#if ENABLE_DEBUG int msg_cnt = 0; -#endif + DEBUG("can_router_dispatch_rx_indic: pkt=%p, ifnum=%d, can_id=%" PRIx32 "\n", (void *)pkt, pkt->entry.ifnum, pkt->frame.can_id); @@ -335,9 +335,11 @@ int can_router_dispatch_rx_indic(can_pkt_t *pkt) PRIkernel_pid "\n", entry->target.pid); atomic_fetch_add(&pkt->ref_count, 1); msg.content.ptr = can_pkt_alloc_rx_data(&pkt->frame, sizeof(pkt->frame), el->data); -#if ENABLE_DEBUG - msg_cnt++; -#endif + + if (IS_ACTIVE(ENABLE_DEBUG)) { + msg_cnt++; + } + if (!msg.content.ptr || (_send_msg(&msg, entry) <= 0)) { can_pkt_free_rx_data(msg.content.ptr); atomic_fetch_sub(&pkt->ref_count, 1); @@ -349,9 +351,9 @@ int can_router_dispatch_rx_indic(can_pkt_t *pkt) } } mutex_unlock(&lock); -#if ENABLE_DEBUG + DEBUG("can_router_dispatch_rx: msg send to %d threads\n", msg_cnt); -#endif + if (atomic_load(&pkt->ref_count) == 0) { can_pkt_free(pkt); } diff --git a/sys/ecc/golay2412.c b/sys/ecc/golay2412.c index 320a9fdd928d..8ea526e469dc 100644 --- a/sys/ecc/golay2412.c +++ b/sys/ecc/golay2412.c @@ -45,15 +45,9 @@ #include "bitarithm.h" #include "ecc/golay2412.h" -#define ENABLE_DEBUG 0 +#define ENABLE_DEBUG 0 #include "debug.h" -#if ENABLE_DEBUG -#define DEBUG_FEC_GOLAY2412 (1) -#else -#define DEBUG_FEC_GOLAY2412 (0) -#endif - /* generator matrix transposed [24 x 12] */ static const uint32_t golay2412_Gt[24] = { 0x08ed, 0x01db, 0x03b5, 0x0769, 0x0ed1, 0x0da3, 0x0b47, 0x068f, @@ -75,7 +69,6 @@ static const uint32_t golay2412_H[12] = { 0x00008d1d, 0x00004a3b, 0x00002477, 0x00001ffe }; -#if DEBUG_FEC_GOLAY2412 /* print string of bits to standard output */ static inline void liquid_print_bitstring(uint32_t _x, uint32_t _n) @@ -86,7 +79,6 @@ static inline void liquid_print_bitstring(uint32_t _x, printf("%" PRIu32, (_x >> (_n - i - 1)) & 1); } } -#endif #ifndef NDEBUG static uint32_t block_get_enc_msg_len(uint32_t _dec_msg_len, @@ -107,16 +99,15 @@ static uint32_t block_get_enc_msg_len(uint32_t _dec_msg_len, /* compute total number of bytes out: ceil(num_bits_out/8) */ uint32_t num_bytes_out = num_bits_out / 8 + ((num_bits_out % 8) ? 1 : 0); -#if DEBUG_FEC_GOLAY2412 - printf("block_get_enc_msg_len(%" PRIu32 ",%" PRIu32 ",%" PRIu32 ")\n", _dec_msg_len, _m, _k); - printf(" dec msg len : %" PRIu32 " bytes\n", _dec_msg_len); - printf(" m : %" PRIu32 " bits\n", _m); - printf(" k : %" PRIu32 " bits\n", _k); - printf(" num bits in : %" PRIu32 " bits\n", num_bits_in); - printf(" num blocks : %" PRIu32 "\n", num_blocks); - printf(" num bits out: %" PRIu32 " bits\n", num_bits_out); - printf(" enc msg len : %" PRIu32 " bytes\n", num_bytes_out); -#endif + DEBUG("block_get_enc_msg_len(%" PRIu32 ",%" PRIu32 ",%" PRIu32 ")\n", + _dec_msg_len, _m, _k); + DEBUG(" dec msg len : %" PRIu32 " bytes\n", _dec_msg_len); + DEBUG(" m : %" PRIu32 " bits\n", _m); + DEBUG(" k : %" PRIu32 " bits\n", _k); + DEBUG(" num bits in : %" PRIu32 " bits\n", num_bits_in); + DEBUG(" num blocks : %" PRIu32 "\n", num_blocks); + DEBUG(" num bits out: %" PRIu32 " bits\n", num_bits_out); + DEBUG(" enc msg len : %" PRIu32 " bytes\n", num_bytes_out); return num_bytes_out; } @@ -187,84 +178,75 @@ static uint32_t golay2412_decode_symbol(uint32_t _sym_enc, /* compute syndrome vector, s = r*H^T = ( H*r^T )^T */ s = golay2412_matrix_mul(_sym_enc, _B, 12); -#if DEBUG_FEC_GOLAY2412 - printf("s (syndrome vector): "); liquid_print_bitstring(s, 12); printf("\n"); -#endif + if (IS_ACTIVE(ENABLE_DEBUG)) { + printf("s (syndrome vector): "); + liquid_print_bitstring(s, 12); + printf("\n"); + } /* compute weight of s (12 bits) */ uint8_t ws = bitarithm_bits_set_u32(s & 0x00000fff); -#if DEBUG_FEC_GOLAY2412 - printf("w(s) = %u\n", ws); -#endif + DEBUG("w(s) = %u\n", ws); /* step 2: */ e_hat = 0; if (ws <= 3) { -#if DEBUG_FEC_GOLAY2412 - printf(" w(s) <= 3: estimating error vector as [s, 0(12)]\n"); -#endif + DEBUG(" w(s) <= 3: estimating error vector as [s, 0(12)]\n"); /* set e_hat = [s 0(12)] */ e_hat = (s << 12) & 0xfff000; } else { /* step 3: search for p[i] s.t. w(s+p[i]) <= 2 */ -#if DEBUG_FEC_GOLAY2412 - printf(" searching for w(s + p_i) <= 2...\n"); -#endif + DEBUG(" searching for w(s + p_i) <= 2...\n"); int8_t s_index = golay2412_parity_search(s, _A); if (s_index >= 0) { /* vector found! */ -#if DEBUG_FEC_GOLAY2412 - printf(" w(s + p[%2i]) <= 2: estimating error vector as [s+p[%2i]," - "u[%2i]]\n", s_index, s_index, s_index); -#endif + DEBUG(" w(s + p[%2i]) <= 2: estimating error vector as " + "[s+p[%2i],u[%2i]]\n", s_index, s_index, s_index); + /* NOTE : uj = 1 << (12-j-1) */ e_hat = ((s ^ _A[s_index]) << 12) | (1 << (11 - s_index)); } else { /* step 4: compute s*P */ uint32_t sP = golay2412_matrix_mul(s, _A, 12); -#if DEBUG_FEC_GOLAY2412 - printf("s*P: "); liquid_print_bitstring(sP, 12); printf("\n"); -#endif + + if (IS_ACTIVE(ENABLE_DEBUG)) { + printf("s*P: "); + liquid_print_bitstring(sP, 12); + printf("\n"); + } /* compute weight of sP (12 bits) */ uint8_t wsP = bitarithm_bits_set_u32(sP & 0x00000fff); -#if DEBUG_FEC_GOLAY2412 - printf("w(s*P) = %u\n", wsP); -#endif + DEBUG("w(s*P) = %u\n", wsP); if (wsP == 2 || wsP == 3) { /* step 5: set e = [0, s*P] */ -#if DEBUG_FEC_GOLAY2412 - printf(" w(s*P) in [2,3]: estimating error vector as [0(12), s*P]\n"); -#endif + DEBUG(" w(s*P) in [2,3]: estimating error vector as " + "[0(12), s*P]\n"); e_hat = sP; } else { /* step 6: search for p[i] s.t. w(s*P + p[i]) == 2... */ + DEBUG(" searching for w(s*P + p_i) == 2...\n"); -#if DEBUG_FEC_GOLAY2412 - printf(" searching for w(s*P + p_i) == 2...\n"); -#endif int8_t sP_index = golay2412_parity_search(sP, _A); if (sP_index >= 0) { /* vector found! */ -#if DEBUG_FEC_GOLAY2412 - printf(" w(s*P + p[%2i]) == 2: estimating error vector as [u[%2i]," - "s*P+p[%2i]]\n", sP_index, sP_index, sP_index); -#endif + DEBUG(" w(s*P + p[%2i]) == 2: estimating error vector " + "as [u[%2i],s*P+p[%2i]]\n", + sP_index, sP_index, sP_index); + /* NOTE : uj = 1 << (12-j-1) * [ uj << 1 2 ] [ sP + p[j] ] */ e_hat = (1L << (23 - sP_index)) | (sP ^ _A[sP_index]); } else { /* step 7: decoding error */ -#if DEBUG_FEC_GOLAY2412 - printf(" **** decoding error\n"); -#endif + DEBUG(" **** decoding error\n"); } } } @@ -272,14 +254,15 @@ static uint32_t golay2412_decode_symbol(uint32_t _sym_enc, /* step 8: compute estimated transmitted message: v_hat = r + e_hat */ v_hat = _sym_enc ^ e_hat; -#if DEBUG_FEC_GOLAY2412 - printf("r (received vector): "); - liquid_print_bitstring(_sym_enc, 24); printf("\n"); - printf("e-hat (estimated error vector): "); - liquid_print_bitstring(e_hat, 24); printf("\n"); - printf("v-hat (estimated tx vector): "); - liquid_print_bitstring(v_hat, 24); printf("\n"); -#endif + + if (IS_ACTIVE(ENABLE_DEBUG)) { + printf("r (received vector): "); + liquid_print_bitstring(_sym_enc, 24); printf("\n"); + printf("e-hat (estimated error vector): "); + liquid_print_bitstring(e_hat, 24); printf("\n"); + printf("v-hat (estimated tx vector): "); + liquid_print_bitstring(v_hat, 24); printf("\n"); + } /* compute estimated original message: (last 12 bits of encoded message) */ m_hat = v_hat & 0x0fff; diff --git a/sys/net/application_layer/dhcpv6/client.c b/sys/net/application_layer/dhcpv6/client.c index 763f4908256b..7551491057f5 100644 --- a/sys/net/application_layer/dhcpv6/client.c +++ b/sys/net/application_layer/dhcpv6/client.c @@ -332,40 +332,43 @@ static inline dhcpv6_opt_t *_opt_next(dhcpv6_opt_t *opt) static bool _check_status_opt(dhcpv6_opt_status_t *status) { - /* DHCPV6_STATUS_SUCCESS is 0, so we don't need to fix byte order */ -#if ENABLE_DEBUG - if ((status != NULL) && (status->code.u16 != DHCPV6_STATUS_SUCCESS)) { - size_t msg_len = byteorder_ntohs(status->len); - char msg[msg_len - 1]; - - strncpy(msg, status->msg, msg_len - 2); - DEBUG("DHCPv6 client: server returned error (%u) \"%s\"\n", - byteorder_ntohs(status->code), msg); + if (IS_ACTIVE(ENABLE_DEBUG)) { + if ((status != NULL) && (status->code.u16 != DHCPV6_STATUS_SUCCESS)) { + size_t msg_len = byteorder_ntohs(status->len); + char msg[msg_len - 1]; + + strncpy(msg, status->msg, msg_len - 2); + DEBUG("DHCPv6 client: server returned error (%u) \"%s\"\n", + byteorder_ntohs(status->code), msg); + } } -#endif + + /* DHCPV6_STATUS_SUCCESS is 0, so we don't need to fix byte order */ return (status == NULL) || (status->code.u16 == DHCPV6_STATUS_SUCCESS); } static bool _check_cid_opt(dhcpv6_opt_duid_t *cid) { -#if ENABLE_DEBUG - if ((byteorder_ntohs(cid->len) != duid_len) || - (memcmp(cid->duid, duid, duid_len) != 0)) { - DEBUG("DHCPv6 client: message is not for me\n"); + if (IS_ACTIVE(ENABLE_DEBUG)) { + if ((byteorder_ntohs(cid->len) != duid_len) || + (memcmp(cid->duid, duid, duid_len) != 0)) { + DEBUG("DHCPv6 client: message is not for me\n"); + } } -#endif + return ((byteorder_ntohs(cid->len) == duid_len) && (memcmp(cid->duid, duid, duid_len) == 0)); } static bool _check_sid_opt(dhcpv6_opt_duid_t *sid) { -#if ENABLE_DEBUG - if ((byteorder_ntohs(sid->len) != server.duid_len) || - (memcmp(sid->duid, server.duid.u8, server.duid_len) != 0)) { - DEBUG("DHCPv6 client: message is not from my server\n"); + if (IS_ACTIVE(ENABLE_DEBUG)) { + if ((byteorder_ntohs(sid->len) != server.duid_len) || + (memcmp(sid->duid, server.duid.u8, server.duid_len) != 0)) { + DEBUG("DHCPv6 client: message is not from my server\n"); + } } -#endif + return ((byteorder_ntohs(sid->len) == server.duid_len) && (memcmp(sid->duid, server.duid.u8, server.duid_len) == 0)); } diff --git a/sys/net/crosslayer/inet_csum/inet_csum.c b/sys/net/crosslayer/inet_csum/inet_csum.c index 7e474554506b..abeda848a8bb 100644 --- a/sys/net/crosslayer/inet_csum/inet_csum.c +++ b/sys/net/crosslayer/inet_csum/inet_csum.c @@ -25,14 +25,15 @@ uint16_t inet_csum_slice(uint16_t sum, const uint8_t *buf, uint16_t len, size_t uint32_t csum = sum; DEBUG("inet_sum: sum = 0x%04" PRIx16 ", len = %" PRIu16, sum, len); -#if ENABLE_DEBUG -#ifdef MODULE_OD - DEBUG(", buf:\n"); - od_hex_dump(buf, len, OD_WIDTH_DEFAULT); -#else - DEBUG(", buf output only with od module\n"); -#endif -#endif + + if (IS_ACTIVE(ENABLE_DEBUG)) { + if (IS_USED(MODULE_OD)) { + DEBUG(", buf:\n"); + od_hex_dump(buf, len, OD_WIDTH_DEFAULT); + } else { + DEBUG(", buf output only with od module\n"); + } + } if (len == 0) return csum; diff --git a/sys/net/gnrc/link_layer/lwmac/lwmac.c b/sys/net/gnrc/link_layer/lwmac/lwmac.c index df9bec45dd69..443c600f47ee 100644 --- a/sys/net/gnrc/link_layer/lwmac/lwmac.c +++ b/sys/net/gnrc/link_layer/lwmac/lwmac.c @@ -25,6 +25,7 @@ #include #include +#include "od.h" #include "timex.h" #include "random.h" #include "periph/rtt.h" @@ -166,9 +167,6 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif) if (!(state->flags & NETDEV_IEEE802154_RAW)) { gnrc_pktsnip_t *ieee802154_hdr, *netif_hdr; gnrc_netif_hdr_t *hdr; -#if ENABLE_DEBUG - char src_str[GNRC_NETIF_HDR_L2ADDR_PRINT_LEN]; -#endif size_t mhr_len = ieee802154_get_frame_hdr_len(pkt->data); if (mhr_len == 0) { @@ -207,16 +205,19 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif) hdr->rssi = rx_info.rssi; gnrc_netif_hdr_set_netif(hdr, netif); pkt->type = state->proto; -#if ENABLE_DEBUG - DEBUG("_recv_ieee802154: received packet from %s of length %u\n", - gnrc_netif_addr_to_str(src_str, sizeof(src_str), - gnrc_netif_hdr_get_src_addr(hdr), - hdr->src_l2addr_len), - nread); -#if defined(MODULE_OD) - od_hex_dump(pkt->data, nread, OD_WIDTH_DEFAULT); -#endif -#endif + if (IS_ACTIVE(ENABLE_DEBUG)) { + char src_str[GNRC_NETIF_HDR_L2ADDR_PRINT_LEN]; + + DEBUG("_recv_ieee802154: received packet from %s of length %u\n", + gnrc_netif_addr_to_str(gnrc_netif_hdr_get_src_addr(hdr), + hdr->src_l2addr_len, + src_str), + nread); + + if (IS_USED(MODULE_OD)) { + od_hex_dump(pkt->data, nread, OD_WIDTH_DEFAULT); + } + } gnrc_pktbuf_remove_snip(pkt, ieee802154_hdr); pkt = gnrc_pkt_append(pkt, netif_hdr); } @@ -923,10 +924,8 @@ static void _lwmac_msg_handler(gnrc_netif_t *netif, msg_t *msg) } #endif default: { -#if ENABLE_DEBUG - DEBUG("[LWMAC]: unknown message type 0x%04x" + DEBUG("[LWMAC]: unknown message type 0x%04x " "(no message handler defined)\n", msg->type); -#endif break; } } diff --git a/sys/net/gnrc/netif/ieee802154/gnrc_netif_ieee802154.c b/sys/net/gnrc/netif/ieee802154/gnrc_netif_ieee802154.c index c8ea5b6fef60..8a53aeba130c 100644 --- a/sys/net/gnrc/netif/ieee802154/gnrc_netif_ieee802154.c +++ b/sys/net/gnrc/netif/ieee802154/gnrc_netif_ieee802154.c @@ -24,9 +24,7 @@ #define ENABLE_DEBUG 0 #include "debug.h" -#if defined(MODULE_OD) && ENABLE_DEBUG #include "od.h" -#endif static int _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt); static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif); @@ -138,9 +136,6 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif) /* Normal mode, try to parse the frame according to IEEE 802.15.4 */ gnrc_pktsnip_t *ieee802154_hdr, *netif_hdr; gnrc_netif_hdr_t *hdr; -#if ENABLE_DEBUG - char src_str[GNRC_NETIF_HDR_L2ADDR_PRINT_LEN]; -#endif size_t mhr_len = ieee802154_get_frame_hdr_len(pkt->data); /* nread was checked for <= 0 before so we can safely cast it to @@ -193,16 +188,18 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif) hdr->rssi = rx_info.rssi; gnrc_netif_hdr_set_netif(hdr, netif); dev->driver->get(dev, NETOPT_PROTO, &pkt->type, sizeof(pkt->type)); -#if ENABLE_DEBUG - DEBUG("_recv_ieee802154: received packet from %s of length %u\n", - gnrc_netif_addr_to_str(gnrc_netif_hdr_get_src_addr(hdr), - hdr->src_l2addr_len, - src_str), - nread); -#if defined(MODULE_OD) - od_hex_dump(pkt->data, nread, OD_WIDTH_DEFAULT); -#endif -#endif + if (IS_ACTIVE(ENABLE_DEBUG)) { + char src_str[GNRC_NETIF_HDR_L2ADDR_PRINT_LEN]; + + DEBUG("_recv_ieee802154: received packet from %s of length %u\n", + gnrc_netif_addr_to_str(gnrc_netif_hdr_get_src_addr(hdr), + hdr->src_l2addr_len, + src_str), + nread); + if (IS_USED(MODULE_OD)) { + od_hex_dump(pkt->data, nread, OD_WIDTH_DEFAULT); + } + } gnrc_pktbuf_remove_snip(pkt, ieee802154_hdr); pkt = gnrc_pkt_append(pkt, netif_hdr); } diff --git a/sys/net/gnrc/network_layer/ipv6/nib/nib.c b/sys/net/gnrc/network_layer/ipv6/nib/nib.c index 7120423969c5..d95502be62ca 100644 --- a/sys/net/gnrc/network_layer/ipv6/nib/nib.c +++ b/sys/net/gnrc/network_layer/ipv6/nib/nib.c @@ -43,7 +43,7 @@ #define ENABLE_DEBUG 0 #include "debug.h" -#if ENABLE_DEBUG +#if IS_ACTIVE(ENABLE_DEBUG) #include "evtimer.h" #endif diff --git a/sys/net/gnrc/network_layer/sixlowpan/ctx/gnrc_sixlowpan_ctx.c b/sys/net/gnrc/network_layer/sixlowpan/ctx/gnrc_sixlowpan_ctx.c index 4c3b8962826f..cb9db5ad432f 100644 --- a/sys/net/gnrc/network_layer/sixlowpan/ctx/gnrc_sixlowpan_ctx.c +++ b/sys/net/gnrc/network_layer/sixlowpan/ctx/gnrc_sixlowpan_ctx.c @@ -57,15 +57,15 @@ gnrc_sixlowpan_ctx_t *gnrc_sixlowpan_ctx_lookup_addr(const ipv6_addr_t *addr) mutex_unlock(&_ctx_mutex); -#if ENABLE_DEBUG - if (res != NULL) { - DEBUG("6lo ctx: found context (%u, %s/%" PRIu8 ") ", - (res->flags_id & GNRC_SIXLOWPAN_CTX_FLAGS_CID_MASK), - ipv6_addr_to_str(ipv6str, &res->prefix, sizeof(ipv6str)), - res->prefix_len); - DEBUG("for address %s\n", ipv6_addr_to_str(ipv6str, addr, sizeof(ipv6str))); + if (IS_ACTIVE(ENABLE_DEBUG)) { + if (res != NULL) { + DEBUG("6lo ctx: found context (%u, %s/%" PRIu8 ") ", + (res->flags_id & GNRC_SIXLOWPAN_CTX_FLAGS_CID_MASK), + ipv6_addr_to_str(ipv6str, &res->prefix, sizeof(ipv6str)), + res->prefix_len); + DEBUG("for address %s\n", ipv6_addr_to_str(ipv6str, addr, sizeof(ipv6str))); + } } -#endif return res; } diff --git a/sys/net/gnrc/network_layer/sixlowpan/iphc/gnrc_sixlowpan_iphc.c b/sys/net/gnrc/network_layer/sixlowpan/iphc/gnrc_sixlowpan_iphc.c index bfe6fe7fc412..918a13d7395c 100644 --- a/sys/net/gnrc/network_layer/sixlowpan/iphc/gnrc_sixlowpan_iphc.c +++ b/sys/net/gnrc/network_layer/sixlowpan/iphc/gnrc_sixlowpan_iphc.c @@ -923,16 +923,16 @@ static int _forward_frag(gnrc_pktsnip_t *pkt, gnrc_pktsnip_t *frag_hdr, DEBUG("to (%s, %u)\n", gnrc_netif_addr_to_str(vrbe->super.dst, vrbe->super.dst_len, addr_str), vrbe->out_tag); -#if ENABLE_DEBUG && defined(MODULE_OD) - DEBUG("Original fragmentation header:\n"); - od_hex_dump(frag_hdr->data, frag_hdr->size, OD_WIDTH_DEFAULT); - DEBUG("IPHC headers + payload:\n"); - frag_hdr = pkt; - while (frag_hdr) { + if (IS_ACTIVE(ENABLE_DEBUG) && IS_USED(MODULE_OD)) { + DEBUG("Original fragmentation header:\n"); od_hex_dump(frag_hdr->data, frag_hdr->size, OD_WIDTH_DEFAULT); - frag_hdr = frag_hdr->next; + DEBUG("IPHC headers + payload:\n"); + frag_hdr = pkt; + while (frag_hdr) { + od_hex_dump(frag_hdr->data, frag_hdr->size, OD_WIDTH_DEFAULT); + frag_hdr = frag_hdr->next; + } } -#endif gnrc_pktbuf_release(pkt); (void)frag_hdr; (void)page; diff --git a/sys/net/gnrc/routing/rpl/gnrc_rpl_validation.c b/sys/net/gnrc/routing/rpl/gnrc_rpl_validation.c index 3ce6616e8714..3170ce8f861a 100644 --- a/sys/net/gnrc/routing/rpl/gnrc_rpl_validation.c +++ b/sys/net/gnrc/routing/rpl/gnrc_rpl_validation.c @@ -23,7 +23,7 @@ #define ENABLE_DEBUG 0 #include "debug.h" -#if ENABLE_DEBUG +#if IS_ACTIVE(ENABLE_DEBUG) static char addr_str[IPV6_ADDR_MAX_STR_LEN]; #endif diff --git a/sys/net/gnrc/routing/rpl/p2p/gnrc_rpl_p2p.c b/sys/net/gnrc/routing/rpl/p2p/gnrc_rpl_p2p.c index f28d5fb76edf..0fa00b89deef 100644 --- a/sys/net/gnrc/routing/rpl/p2p/gnrc_rpl_p2p.c +++ b/sys/net/gnrc/routing/rpl/p2p/gnrc_rpl_p2p.c @@ -30,7 +30,7 @@ #define ENABLE_DEBUG 0 #include "debug.h" -#if ENABLE_DEBUG +#if IS_ACTIVE(ENABLE_DEBUG) static char addr_str[IPV6_ADDR_MAX_STR_LEN]; #endif diff --git a/sys/net/network_layer/fib/fib.c b/sys/net/network_layer/fib/fib.c index f0f370b62766..66f537f9a6be 100644 --- a/sys/net/network_layer/fib/fib.c +++ b/sys/net/network_layer/fib/fib.c @@ -89,13 +89,13 @@ static int fib_find_entry(fib_table_t *table, uint8_t *dst, size_t dst_size, int ret = -EHOSTUNREACH; bool is_all_zeros_addr = true; -#if ENABLE_DEBUG - DEBUG("[fib_find_entry] dst ="); - for (size_t i = 0; i < dst_size; i++) { - DEBUG(" %02x", dst[i]); + if (IS_ACTIVE(ENABLE_DEBUG)) { + DEBUG("[fib_find_entry] dst ="); + for (size_t i = 0; i < dst_size; i++) { + DEBUG(" %02x", dst[i]); + } + DEBUG("\n"); } - DEBUG("\n"); -#endif for (size_t i = 0; i < dst_size; ++i) { if (dst[i] != 0) { @@ -175,15 +175,15 @@ static int fib_find_entry(fib_table_t *table, uint8_t *dst, size_t dst_size, } } -#if ENABLE_DEBUG - if (count > 0) { - DEBUG("[fib_find_entry] found prefix on interface %d:", entry_arr[0]->iface_id); - for (size_t i = 0; i < entry_arr[0]->global->address_size; i++) { - DEBUG(" %02x", entry_arr[0]->global->address[i]); + if (IS_ACTIVE(ENABLE_DEBUG)) { + if (count > 0) { + DEBUG("[fib_find_entry] found prefix on interface %d:", entry_arr[0]->iface_id); + for (size_t i = 0; i < entry_arr[0]->global->address_size; i++) { + DEBUG(" %02x", entry_arr[0]->global->address[i]); + } + DEBUG("\n"); } - DEBUG("\n"); } -#endif *entry_arr_size = count; return ret; diff --git a/sys/posix/pthread/pthread.c b/sys/posix/pthread/pthread.c index b78a4bade1c0..1abfdd86cec1 100644 --- a/sys/posix/pthread/pthread.c +++ b/sys/posix/pthread/pthread.c @@ -41,7 +41,7 @@ #define CONFIG_PTHREAD_REAPER_BASE_STACKSIZE (THREAD_STACKSIZE_IDLE) #endif -#if ENABLE_DEBUG +#if IS_ACTIVE(ENABLE_DEBUG) # define PTHREAD_REAPER_STACKSIZE ((CONFIG_PTHREAD_REAPER_BASE_STACKSIZE) + THREAD_EXTRA_STACKSIZE_PRINTF) # define PTHREAD_STACKSIZE THREAD_STACKSIZE_MAIN #else diff --git a/sys/timex/timex.c b/sys/timex/timex.c index 3c768f807ab9..85505ad9edc7 100644 --- a/sys/timex/timex.c +++ b/sys/timex/timex.c @@ -28,11 +28,11 @@ timex_t timex_add(const timex_t a, const timex_t b) { -#if ENABLE_DEBUG - if (!timex_isnormalized(&a) || !timex_isnormalized(&b)) { - puts("timex_add on denormalized value"); + if (IS_ACTIVE(ENABLE_DEBUG)) { + if (!timex_isnormalized(&a) || !timex_isnormalized(&b)) { + puts("timex_add on denormalized value"); + } } -#endif timex_t result; result.seconds = a.seconds + b.seconds; @@ -52,22 +52,22 @@ timex_t timex_set(uint32_t seconds, uint32_t microseconds) result.seconds = seconds; result.microseconds = microseconds; -#if ENABLE_DEBUG - if (!timex_isnormalized(&result)) { - puts("timex_set on denormalized value"); + if (IS_ACTIVE(ENABLE_DEBUG)) { + if (!timex_isnormalized(&result)) { + puts("timex_set on denormalized value"); + } } -#endif return result; } timex_t timex_sub(const timex_t a, const timex_t b) { -#if ENABLE_DEBUG - if (!timex_isnormalized(&a) || !timex_isnormalized(&b)) { - puts("timex_sub on denormalized value"); + if (IS_ACTIVE(ENABLE_DEBUG)) { + if (!timex_isnormalized(&a) || !timex_isnormalized(&b)) { + puts("timex_sub on denormalized value"); + } } -#endif timex_t result; @@ -85,11 +85,11 @@ timex_t timex_sub(const timex_t a, const timex_t b) int timex_cmp(const timex_t a, const timex_t b) { -#if ENABLE_DEBUG - if (!timex_isnormalized(&a) || !timex_isnormalized(&b)) { - puts("timex_cmp on denormalized value"); + if (IS_ACTIVE(ENABLE_DEBUG)) { + if (!timex_isnormalized(&a) || !timex_isnormalized(&b)) { + puts("timex_cmp on denormalized value"); + } } -#endif if (a.seconds < b.seconds) { return -1; diff --git a/sys/vfs/vfs.c b/sys/vfs/vfs.c index e0db65ec6807..b0dd00b62d79 100644 --- a/sys/vfs/vfs.c +++ b/sys/vfs/vfs.c @@ -31,7 +31,8 @@ #define ENABLE_DEBUG 0 #include "debug.h" -#if ENABLE_DEBUG + +#if IS_ACTIVE(ENABLE_DEBUG) /* Since some of these functions are called by printf, we can't really call * printf from our functions or we end up in an infinite recursion. */ #include /* for STDOUT_FILENO */ diff --git a/sys/ztimer/core.c b/sys/ztimer/core.c index 15ddd7908074..ccc75da72742 100644 --- a/sys/ztimer/core.c +++ b/sys/ztimer/core.c @@ -311,7 +311,7 @@ void ztimer_handler(ztimer_clock_t *clock) { DEBUG("ztimer_handler(): %p now=%" PRIu32 "\n", (void *)clock, clock->ops->now( clock)); - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { _ztimer_print(clock); } @@ -364,7 +364,7 @@ void ztimer_handler(ztimer_clock_t *clock) _ztimer_update(clock); - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { _ztimer_print(clock); } DEBUG("ztimer_handler(): %p done.\n", (void *)clock); From 53c1392d4d4fe116a7703e9f89d201796bdeda4e Mon Sep 17 00:00:00 2001 From: Bas Stottelaar Date: Fri, 23 Oct 2020 00:41:04 +0200 Subject: [PATCH 09/13] tests/*: replace #if ENABLE_DEBUG with IS_ACTIVE --- tests/driver_sdcard_spi/main.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/driver_sdcard_spi/main.c b/tests/driver_sdcard_spi/main.c index acc093510cac..dc495013563c 100644 --- a/tests/driver_sdcard_spi/main.c +++ b/tests/driver_sdcard_spi/main.c @@ -50,9 +50,7 @@ static int _init(int argc, char **argv) if (sdcard_spi_init(card, &sdcard_spi_params[0]) != 0) { puts("[FAILED]"); - #if ENABLE_DEBUG != 1 - puts("enable debugging in sdcard_spi.c for further information!"); - #endif + puts("enable debugging in sdcard_spi.c for more information!"); return -2; } puts("[OK]"); From 28ae0c97cdaad9a9ecf11daea53e77d978848e23 Mon Sep 17 00:00:00 2001 From: Bas Stottelaar Date: Fri, 23 Oct 2020 00:35:37 +0200 Subject: [PATCH 10/13] sys/*: use DEBUG_EXTRA_STACKSIZE for debug stacks --- sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c | 8 ++------ sys/net/gnrc/network_layer/sixlowpan/gnrc_sixlowpan.c | 7 +------ sys/net/gnrc/transport_layer/tcp/gnrc_tcp_eventloop.c | 6 +----- sys/net/gnrc/transport_layer/udp/gnrc_udp.c | 6 +----- 4 files changed, 5 insertions(+), 22 deletions(-) diff --git a/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c b/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c index c8b424230dc9..c6ba081b0c47 100644 --- a/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c +++ b/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c @@ -47,14 +47,10 @@ #define ENABLE_DEBUG 0 #include "debug.h" -#if ENABLE_DEBUG -static char _stack[GNRC_IPV6_STACK_SIZE + THREAD_EXTRA_STACKSIZE_PRINTF]; -#else -static char _stack[GNRC_IPV6_STACK_SIZE]; -#endif - #define _MAX_L2_ADDR_LEN (8U) +static char _stack[GNRC_IPV6_STACK_SIZE + DEBUG_EXTRA_STACKSIZE]; + #ifdef MODULE_FIB /** * @brief buffer to store the entries in the IPv6 forwarding table diff --git a/sys/net/gnrc/network_layer/sixlowpan/gnrc_sixlowpan.c b/sys/net/gnrc/network_layer/sixlowpan/gnrc_sixlowpan.c index e4649a5de714..adb0c69b5ef5 100644 --- a/sys/net/gnrc/network_layer/sixlowpan/gnrc_sixlowpan.c +++ b/sys/net/gnrc/network_layer/sixlowpan/gnrc_sixlowpan.c @@ -32,12 +32,7 @@ static kernel_pid_t _pid = KERNEL_PID_UNDEF; -#if ENABLE_DEBUG -static char _stack[GNRC_SIXLOWPAN_STACK_SIZE + THREAD_EXTRA_STACKSIZE_PRINTF]; -#else -static char _stack[GNRC_SIXLOWPAN_STACK_SIZE]; -#endif - +static char _stack[GNRC_SIXLOWPAN_STACK_SIZE + DEBUG_EXTRA_STACKSIZE]; /* handles GNRC_NETAPI_MSG_TYPE_RCV commands */ static void _receive(gnrc_pktsnip_t *pkt); diff --git a/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_eventloop.c b/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_eventloop.c index 6f601e18fefb..9ea4b58d6dae 100644 --- a/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_eventloop.c +++ b/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_eventloop.c @@ -42,11 +42,7 @@ static msg_t _eventloop_msg_queue[TCP_EVENTLOOP_MSG_QUEUE_SIZE]; /** * @brief Allocate memory for GNRC TCP thread stack. */ -#if ENABLE_DEBUG -static char _stack[TCP_EVENTLOOP_STACK_SIZE + THREAD_EXTRA_STACKSIZE_PRINTF]; -#else -static char _stack[TCP_EVENTLOOP_STACK_SIZE]; -#endif +static char _stack[TCP_EVENTLOOP_STACK_SIZE + DEBUG_EXTRA_STACKSIZE]; /** * @brief Central evtimer for gnrc_tcp event loop diff --git a/sys/net/gnrc/transport_layer/udp/gnrc_udp.c b/sys/net/gnrc/transport_layer/udp/gnrc_udp.c index ae24f7993f0c..ddf3423e3275 100644 --- a/sys/net/gnrc/transport_layer/udp/gnrc_udp.c +++ b/sys/net/gnrc/transport_layer/udp/gnrc_udp.c @@ -42,11 +42,7 @@ static kernel_pid_t _pid = KERNEL_PID_UNDEF; /** * @brief Allocate memory for the UDP thread's stack */ -#if ENABLE_DEBUG -static char _stack[GNRC_UDP_STACK_SIZE + THREAD_EXTRA_STACKSIZE_PRINTF]; -#else -static char _stack[GNRC_UDP_STACK_SIZE]; -#endif +static char _stack[GNRC_UDP_STACK_SIZE + DEBUG_EXTRA_STACKSIZE]; /** * @brief Calculate the UDP checksum dependent on the network protocol From cc2e6b08d1e6f5393d5043ae87cb77cc5d8d292b Mon Sep 17 00:00:00 2001 From: Bas Stottelaar Date: Fri, 23 Oct 2020 14:37:01 +0200 Subject: [PATCH 11/13] core/*: ENABLE_DEBUG not needed for inttypes.h --- core/sched.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/core/sched.c b/core/sched.c index 8ef0f06ba78b..50254a63c228 100644 --- a/core/sched.c +++ b/core/sched.c @@ -20,6 +20,7 @@ */ #include +#include #include "sched.h" #include "clist.h" @@ -35,11 +36,6 @@ #define ENABLE_DEBUG 0 #include "debug.h" -#if ENABLE_DEBUG -/* For PRIu16 etc. */ -#include -#endif - #ifdef PICOLIBC_TLS #include #endif From a76cb4ea2f001036c8d144d830b88aa4f18922ec Mon Sep 17 00:00:00 2001 From: Bas Stottelaar Date: Fri, 23 Oct 2020 14:36:53 +0200 Subject: [PATCH 12/13] sys/*: ENABLE_DEBUG not needed for inttypes.h --- sys/can/router.c | 6 +----- .../gnrc/network_layer/icmpv6/echo/gnrc_icmpv6_echo.c | 7 ++----- sys/net/gnrc/network_layer/ndp/gnrc_ndp.c | 4 +--- .../sixlowpan/frag/gnrc_sixlowpan_frag.c | 11 +++-------- sys/net/link_layer/csma_sender/csma_sender.c | 6 +----- 5 files changed, 8 insertions(+), 26 deletions(-) diff --git a/sys/can/router.c b/sys/can/router.c index 227c8760e43e..e7eae1b276a8 100644 --- a/sys/can/router.c +++ b/sys/can/router.c @@ -19,6 +19,7 @@ #include #include +#include #include "kernel_defines.h" @@ -35,11 +36,6 @@ #define ENABLE_DEBUG 0 #include "debug.h" -#if ENABLE_DEBUG -/* For PRIu16 etc. */ -#include -#endif - /** * This is a can_id element */ diff --git a/sys/net/gnrc/network_layer/icmpv6/echo/gnrc_icmpv6_echo.c b/sys/net/gnrc/network_layer/icmpv6/echo/gnrc_icmpv6_echo.c index ef4e1ae4c68c..a20a18955900 100644 --- a/sys/net/gnrc/network_layer/icmpv6/echo/gnrc_icmpv6_echo.c +++ b/sys/net/gnrc/network_layer/icmpv6/echo/gnrc_icmpv6_echo.c @@ -12,6 +12,8 @@ * @file */ +#include + #include "net/gnrc.h" #include "od.h" @@ -23,11 +25,6 @@ #define ENABLE_DEBUG 0 #include "debug.h" -#if ENABLE_DEBUG -/* For PRIu16 etc. */ -#include -#endif - gnrc_pktsnip_t *gnrc_icmpv6_echo_build(uint8_t type, uint16_t id, uint16_t seq, uint8_t *data, size_t data_len) { diff --git a/sys/net/gnrc/network_layer/ndp/gnrc_ndp.c b/sys/net/gnrc/network_layer/ndp/gnrc_ndp.c index f25da7a9d8e9..2fc4d1643764 100644 --- a/sys/net/gnrc/network_layer/ndp/gnrc_ndp.c +++ b/sys/net/gnrc/network_layer/ndp/gnrc_ndp.c @@ -15,6 +15,7 @@ #include #include +#include #include "net/gnrc/icmpv6.h" #include "net/gnrc/ipv6.h" @@ -31,9 +32,6 @@ #define ENABLE_DEBUG 0 #include "debug.h" -/* For PRIu8 etc. */ -#include - static char addr_str[IPV6_ADDR_MAX_STR_LEN]; gnrc_pktsnip_t *gnrc_ndp_nbr_sol_build(const ipv6_addr_t *tgt, diff --git a/sys/net/gnrc/network_layer/sixlowpan/frag/gnrc_sixlowpan_frag.c b/sys/net/gnrc/network_layer/sixlowpan/frag/gnrc_sixlowpan_frag.c index 454dd4d12b00..b6c663ec609a 100644 --- a/sys/net/gnrc/network_layer/sixlowpan/frag/gnrc_sixlowpan_frag.c +++ b/sys/net/gnrc/network_layer/sixlowpan/frag/gnrc_sixlowpan_frag.c @@ -16,6 +16,9 @@ * @author Peter Kietzmann */ +#include +#include + #include "kernel_types.h" #include "net/gnrc/pktbuf.h" #include "net/gnrc/netapi.h" @@ -30,14 +33,6 @@ #define ENABLE_DEBUG 0 #include "debug.h" -#if ENABLE_DEBUG -/* For PRIu16 etc. */ - -#include -#include -#endif - - static inline uint16_t _floor8(uint16_t length) { return length & 0xfff8U; diff --git a/sys/net/link_layer/csma_sender/csma_sender.c b/sys/net/link_layer/csma_sender/csma_sender.c index bf43528675fd..33b50875c5a1 100644 --- a/sys/net/link_layer/csma_sender/csma_sender.c +++ b/sys/net/link_layer/csma_sender/csma_sender.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "xtimer.h" #include "random.h" @@ -32,11 +33,6 @@ #define ENABLE_DEBUG 0 #include "debug.h" -#if ENABLE_DEBUG -/* For PRIu16 etc. */ -#include -#endif - const csma_sender_conf_t CSMA_SENDER_CONF_DEFAULT = { CONFIG_CSMA_SENDER_MIN_BE_DEFAULT, CONFIG_CSMA_SENDER_MAX_BE_DEFAULT, From 0c8df9bb3cac82b7889ff6c6f582aba37f7cb0c5 Mon Sep 17 00:00:00 2001 From: Bas Stottelaar Date: Mon, 26 Oct 2020 00:18:39 +0100 Subject: [PATCH 13/13] dist/coccinelle: adapt rules for ENABLE_DEBUG --- dist/tools/coccinelle/warn/enable_debug.cocci | 16 ++++++++++++++++ .../coccinelle/warn/enable_debug_false.cocci | 5 ----- 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 dist/tools/coccinelle/warn/enable_debug.cocci delete mode 100644 dist/tools/coccinelle/warn/enable_debug_false.cocci diff --git a/dist/tools/coccinelle/warn/enable_debug.cocci b/dist/tools/coccinelle/warn/enable_debug.cocci new file mode 100644 index 000000000000..0e8aed8e19cf --- /dev/null +++ b/dist/tools/coccinelle/warn/enable_debug.cocci @@ -0,0 +1,16 @@ +// ENABLE_DEBUG must not use parenthesis to be compatible with IS_ACTIVE + +@@ +constant C; +@@ + +- #define ENABLE_DEBUG (C) ++ #define ENABLE_DEBUG C + +// make sure that ENABLE_DEBUG is zero + +@@ +@@ + +- #define ENABLE_DEBUG 1 ++ #define ENABLE_DEBUG 0 diff --git a/dist/tools/coccinelle/warn/enable_debug_false.cocci b/dist/tools/coccinelle/warn/enable_debug_false.cocci deleted file mode 100644 index 9742f5bf375a..000000000000 --- a/dist/tools/coccinelle/warn/enable_debug_false.cocci +++ /dev/null @@ -1,5 +0,0 @@ -@@ -@@ - -- #define ENABLE_DEBUG (1) -+ #define ENABLE_DEBUG (0)