From 73e387cff6a3e31a9ea0c300d92a1a4a62d791ef Mon Sep 17 00:00:00 2001 From: Li Weiwei Date: Tue, 10 Oct 2017 14:27:43 +0800 Subject: [PATCH] drivers/wiznet5k: Improve the performance of socket ops with threading. Use MICROPY_THREAD_YIELD() instead of HAL_Delay in busy waiting to improve the performance of connect, send, recv, sento and recvfrom. --- drivers/wiznet5k/ethernet/socket.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/wiznet5k/ethernet/socket.c b/drivers/wiznet5k/ethernet/socket.c index 129473ad4d..ec25fcc793 100644 --- a/drivers/wiznet5k/ethernet/socket.c +++ b/drivers/wiznet5k/ethernet/socket.c @@ -52,10 +52,9 @@ #include +#include "py/mpthread.h" #include "socket.h" -extern void HAL_Delay(uint32_t); - #define SOCK_ANY_PORT_NUM 0xC000; static uint16_t sock_any_port = SOCK_ANY_PORT_NUM; @@ -242,7 +241,7 @@ int8_t WIZCHIP_EXPORT(connect)(uint8_t sn, uint8_t * addr, uint16_t port) #endif return SOCKERR_TIMEOUT; } - HAL_Delay(1); + MICROPY_THREAD_YIELD(); } #if _WIZCHIP_ == 5200 // for W5200 ARP errata setSUBR((uint8_t*)"\x00\x00\x00\x00"); @@ -317,6 +316,7 @@ int32_t WIZCHIP_EXPORT(send)(uint8_t sn, uint8_t * buf, uint16_t len) } if( (sock_io_mode & (1< freesize) ) return SOCK_BUSY; if(len <= freesize) break; + MICROPY_THREAD_YIELD(); } wiz_send_data(sn, buf, len); #if _WIZCHIP_ == 5200 @@ -368,7 +368,7 @@ int32_t WIZCHIP_EXPORT(recv)(uint8_t sn, uint8_t * buf, uint16_t len) } if((sock_io_mode & (1< freesize) ) return SOCK_BUSY; if(len <= freesize) break; - HAL_Delay(1); + MICROPY_THREAD_YIELD(); }; wiz_send_data(sn, buf, len); @@ -446,7 +446,7 @@ int32_t WIZCHIP_EXPORT(sendto)(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t return SOCKERR_TIMEOUT; } //////////// - HAL_Delay(1); + MICROPY_THREAD_YIELD(); } #if _WIZCHIP_ == 5200 // for W5200 ARP errata setSUBR((uint8_t*)"\x00\x00\x00\x00"); @@ -486,6 +486,7 @@ int32_t WIZCHIP_EXPORT(recvfrom)(uint8_t sn, uint8_t * buf, uint16_t len, uint8_ if(getSn_SR(sn) == SOCK_CLOSED) return SOCKERR_SOCKCLOSED; if( (sock_io_mode & (1<