Update of W5500 Interface for mbed-os
Diff: WIZnet/W5500.cpp
- Revision:
- 1:2dee44ea52a9
- Parent:
- 0:77e050d1fb12
diff -r 77e050d1fb12 -r 2dee44ea52a9 WIZnet/W5500.cpp --- a/WIZnet/W5500.cpp Fri Jun 02 22:00:49 2017 +0000 +++ b/WIZnet/W5500.cpp Thu Jun 15 20:19:23 2017 +0000 @@ -49,9 +49,7 @@ bool WIZnet_Chip::setmac() { - for (int i =0; i < 6; i++) reg_wr<uint8_t>(SHAR+i, mac[i]); - return true; } @@ -184,18 +182,24 @@ int size1, size2; // during the reading Sn_RX_RSR, it has the possible change of this register. // so read twice and get same value then use size information. - do { + while (1) { size1 = sreg<uint16_t>(socket, Sn_RX_RSR); size2 = sreg<uint16_t>(socket, Sn_RX_RSR); - printf("WIZnet_Chip::wait_readable req_size = %d, size1 = %d, size2 = %d\r\n", req_size, size1, size2); + + if (size1 == size2) { + break; + } if (wait_time_ms != (-1) && t.read_ms() > wait_time_ms) { return NSAPI_ERROR_WOULD_BLOCK; } - } while (size1 != size2); + + if (!is_connected(socket)) { + return -1; + } + } if (size1 > req_size) { - printf("WIZnet_Chip::wait_readable returning %d\r\n", size1); return size1; } if (wait_time_ms != (-1) && t.read_ms() > wait_time_ms) { @@ -307,6 +311,7 @@ void WIZnet_Chip::spi_write(uint16_t addr, uint8_t cb, const uint8_t *buf, uint16_t len) { + spi->lock(); cs = 0; spi->write(addr >> 8); spi->write(addr & 0xff); @@ -327,10 +332,13 @@ } debug("\r\n"); #endif + spi->unlock(); + } void WIZnet_Chip::spi_read(uint16_t addr, uint8_t cb, uint8_t *buf, uint16_t len) { + spi->lock(); cs = 0; spi->write(addr >> 8); spi->write(addr & 0xff); @@ -354,6 +362,7 @@ wait_ms(200); } #endif + spi->unlock(); } uint32_t str_to_ip(const char* str)