summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/sbc_harness/config/config.h2
-rw-r--r--libhw/w5500.c14
2 files changed, 13 insertions, 3 deletions
diff --git a/cmd/sbc_harness/config/config.h b/cmd/sbc_harness/config/config.h
index f9c7df2..0fa95ae 100644
--- a/cmd/sbc_harness/config/config.h
+++ b/cmd/sbc_harness/config/config.h
@@ -22,8 +22,8 @@
#define CONFIG_W5500_LOCAL_PORT_MIN 32768
#define CONFIG_W5500_LOCAL_PORT_MAX 60999
+#define CONFIG_W5500_VALIDATE_SPI 1 /* bool */
#define CONFIG_W5500_DEBUG 1 /* bool */
-
#define CONFIG_W5500_LL_DEBUG 0 /* bool */
/* 9P *************************************************************************/
diff --git a/libhw/w5500.c b/libhw/w5500.c
index fafc846..0f15785 100644
--- a/libhw/w5500.c
+++ b/libhw/w5500.c
@@ -96,6 +96,9 @@
#ifndef CONFIG_W5500_LOCAL_PORT_MAX
#error config.h must define CONFIG_W5500_LOCAL_PORT_MAX
#endif
+#ifndef CONFIG_W5500_VALIDATE_SPI
+ #error config.h must define CONFIG_W5500_VALIDATE_SPI
+#endif
#ifndef CONFIG_W5500_DEBUG
#error config.h must define CONFIG_W5500_DEBUG
#endif
@@ -312,14 +315,21 @@ void _w5500_init(struct w5500 *chip,
};
}
+#if CONFIG_W5500_VALIDATE_SPI
/* Validate that SPI works correctly. */
+ bool spi_ok = true;
for (uint16_t a = 0; a < 0x100; a++) {
w5500ll_write_sock_reg(chip->spidev, 0, mode, a);
uint8_t b = w5500ll_read_sock_reg(chip->spidev, 0, mode);
- if (b != a)
- errorf("SPI to W5500 does not appear to be functional: wrote:%d != read:%d", a, b);
+ if (b != a) {
+ errorf("SPI to W5500 does not appear to be functional: wrote:0x%02"PRIx16" != read:0x%02"PRIx8, a, b);
+ spi_ok = false;
+ }
}
+ if (!spi_ok)
+ __lm_abort();
w5500ll_write_sock_reg(chip->spidev, 0, mode, 0);
+#endif
/* Initialize the hardware. */
gpioirq_set_and_enable_exclusive_handler(pin_intr, GPIO_IRQ_EDGE_FALL, w5500_intrhandler, chip);