diff --git a/src/shared/drivers/WIZ5500/WIZ5500.cpp b/src/shared/drivers/WIZ5500/WIZ5500.cpp index 3cac50057b4c1c143305c1da837db560feeff508..6b4176df291a6abb4f0c76573b05be7a299dbb9b 100644 --- a/src/shared/drivers/WIZ5500/WIZ5500.cpp +++ b/src/shared/drivers/WIZ5500/WIZ5500.cpp @@ -82,6 +82,13 @@ void Wiz5500::setOnDestUnreachable(OnDestUnreachableCb cb) on_dest_unreachable = cb; } +bool Wiz5500::checkVersion() +{ + Lock<FastMutex> l(mutex); + + return spiRead8(0, Wiz::Common::REG_VERSIONR) == Wiz::VERSION; +} + Wiz5500::PhyState Wiz5500::getPhyState() { Lock<FastMutex> l(mutex); @@ -94,16 +101,10 @@ Wiz5500::PhyState Wiz5500::getPhyState() return {full_duplex, based_100mbps, link_up}; } -bool Wiz5500::reset() +void Wiz5500::reset() { Lock<FastMutex> l(mutex); - // First check that the device is actually present - if (spiRead8(0, Wiz::Common::REG_VERSIONR) != Wiz::VERSION) - { - return false; - } - // Perform a software reset spiWrite8(0, Wiz::Common::REG_MR, 1 << 7); // Enable all socket interrupts @@ -115,8 +116,6 @@ bool Wiz5500::reset() { spiWrite8(Wiz::getSocketRegBlock(i), Wiz::Socket::REG_MR, 0); } - - return true; } void Wiz5500::handleINTn() diff --git a/src/shared/drivers/WIZ5500/WIZ5500.h b/src/shared/drivers/WIZ5500/WIZ5500.h index 50053ca4bbcad12151f933758be6dbb7920d656a..9d76cec260142ac5f2a61527584a5dbc19257f40 100644 --- a/src/shared/drivers/WIZ5500/WIZ5500.h +++ b/src/shared/drivers/WIZ5500/WIZ5500.h @@ -110,6 +110,15 @@ public: */ void setOnDestUnreachable(OnDestUnreachableCb cb); + /** + * @brief Checks the VERSION register. + * Can be used to detect device presence. + * + * @returns False if the device is not connected properly (SPI comunication + * failure). + */ + bool checkVersion(); + /** * @brief Get current PHY state, can be used to poll link status, and wait * for link up. @@ -121,12 +130,9 @@ public: /** * @brief Resets the device. * Performs a software resets, resetting all registers and closing all - * sockets. Also checks for hardware presence. - * - * @returns False if the device is not connected properly (SPI comunication - * failure). + * sockets. */ - bool reset(); + void reset(); /** * @brief Handle an interrupt from INTn. diff --git a/src/tests/drivers/test-wiz5500.cpp b/src/tests/drivers/test-wiz5500.cpp index a5064910aae9c66dab399e604fda3da30ad045bf..0fb14ebddece5e0f6abefca82e1ed2420bdf4ffd 100644 --- a/src/tests/drivers/test-wiz5500.cpp +++ b/src/tests/drivers/test-wiz5500.cpp @@ -270,13 +270,15 @@ int main() SPI::ClockDivider::DIV_64); // Start the driver - if (!wiz->reset()) + if (!wiz->checkVersion()) { printf("[wiz5500] Wiz failed to start!\n"); while (1) ; } + wiz->reset(); + wiz->setOnDestUnreachable( [](WizIp ip, uint16_t port) {