diff options
-rw-r--r-- | cmd/sbc_harness/config/config.h | 2 | ||||
-rw-r--r-- | libhw/w5500_ll.h | 36 | ||||
-rw-r--r-- | libmisc/include/libmisc/log.h | 12 |
3 files changed, 38 insertions, 12 deletions
diff --git a/cmd/sbc_harness/config/config.h b/cmd/sbc_harness/config/config.h index daa01dd..bad0dc4 100644 --- a/cmd/sbc_harness/config/config.h +++ b/cmd/sbc_harness/config/config.h @@ -27,6 +27,8 @@ #define CONFIG_W5500_DEBUG 1 /* bool */ +#define CONFIG_W5500_LL_DEBUG 1 /* bool */ + /* 9P *************************************************************************/ #define CONFIG_9P_PORT 564 diff --git a/libhw/w5500_ll.h b/libhw/w5500_ll.h index 827d60f..25aa6b5 100644 --- a/libhw/w5500_ll.h +++ b/libhw/w5500_ll.h @@ -24,8 +24,8 @@ #include "config.h" -#ifndef CONFIG_W5500_DEBUG - #error config.h must define CONFIG_W5500_DEBUG +#ifndef CONFIG_W5500_LL_DEBUG + #error config.h must define CONFIG_W5500_LL_DEBUG #endif /* Low-level protocol built on SPI frames. ***********************************/ @@ -53,6 +53,7 @@ #define CTL_OM_FDM2 0b10 /* fixed-length data mode: 2 byte data length */ #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", @@ -61,18 +62,28 @@ static char *_ctl_block_part_strs[] = { }; #define PRI_ctl_block "CTL_BLOCK_SOCK(%d, %s)" #define ARG_ctl_block(b) (((b)>>5) & 0b111), _ctl_block_part_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. * Lame. */ static inline void -w5500ll_write(implements_spi *spidev, uint16_t addr, uint8_t block, void *data, size_t data_len) { +#if CONFIG_W5500_LL_DEBUG +#define w5500ll_write(...) _w5500ll_write(__func__, __VA_ARGS__) +_w5500ll_write(const char *func, +#else +w5500ll_write( +#endif + implements_spi *spidev, uint16_t addr, uint8_t block, void *data, size_t data_len) { assert(spidev); assert((block & ~CTL_MASK_BLOCK) == 0); assert(data); assert(data_len); - debugf("w5500ll_write(spidev, addr=%#04x, block="PRI_ctl_block", data, data_len=%zu)", - addr, ARG_ctl_block(block), data_len); +#if CONFIG_W5500_LL_DEBUG + n_debugf(W5500_LL, + "%s(): w5500ll_write(spidev, addr=%#04x, block="PRI_ctl_block", data, data_len=%zu)", + func, addr, ARG_ctl_block(block), data_len); +#endif uint8_t header[3] = { (uint8_t)((addr >> 8) & 0xFF), @@ -87,13 +98,22 @@ w5500ll_write(implements_spi *spidev, uint16_t addr, uint8_t block, void *data, } static inline void -w5500ll_read(implements_spi *spidev, uint16_t addr, uint8_t block, void *data, size_t data_len) { +#if CONFIG_W5500_LL_DEBUG +#define w5500ll_read(...) _w5500ll_read(__func__, __VA_ARGS__) +_w5500ll_read(const char *func, +#else +w5500ll_read( +#endif + implements_spi *spidev, uint16_t addr, uint8_t block, void *data, size_t data_len) { assert(spidev); assert((block & ~CTL_MASK_BLOCK) == 0); assert(data); assert(data_len); - debugf("w5500ll_read(spidev, addr=%#04x, block="PRI_ctl_block", data, data_len=%zu)", - addr, ARG_ctl_block(block), data_len); +#if CONFIG_W5500_LL_DEBUG + n_debugf(W5500_LL, + "%s(): w5500ll_read(spidev, addr=%#04x, block="PRI_ctl_block", data, data_len=%zu)", + func, addr, ARG_ctl_block(block), data_len); +#endif uint8_t header[3] = { (uint8_t)((addr >> 8) & 0xFF), diff --git a/libmisc/include/libmisc/log.h b/libmisc/include/libmisc/log.h index c1e4a05..b4f5461 100644 --- a/libmisc/include/libmisc/log.h +++ b/libmisc/include/libmisc/log.h @@ -25,10 +25,14 @@ [[format(printf, 1, 2)]] int _log_printf(const char *format, ...); -#define errorf(fmt, ...) do { _log_printf("error: " _LOG_STR(LOG_NAME) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) -#define infof(fmt, ...) do { _log_printf("info : " _LOG_STR(LOG_NAME) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) -#define debugf(fmt, ...) do { if (_LOG_CAT3(CONFIG_, LOG_NAME, _DEBUG) && !_LOG_NDEBUG) \ - _log_printf("debug: " _LOG_STR(LOG_NAME) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) +#define n_errorf(nam, fmt, ...) do { _log_printf("error: " _LOG_STR(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) +#define n_infof(nam, fmt, ...) do { _log_printf("info : " _LOG_STR(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) +#define n_debugf(nam, fmt, ...) do { if (_LOG_CAT3(CONFIG_, nam, _DEBUG) && !_LOG_NDEBUG) \ + _log_printf("debug: " _LOG_STR(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) + +#define errorf(fmt, ...) n_errorf(LOG_NAME, fmt, __VA_ARGS__) +#define infof(fmt, ...) n_infof(LOG_NAME, fmt, __VA_ARGS__) +#define debugf(fmt, ...) n_debugf(LOG_NAME, fmt, __VA_ARGS__) const char *const_byte_str(uint8_t b); |