Skip to content

Commit

Permalink
drivers/wiznet5k: Improve the performance of socket ops with threading.
Browse files Browse the repository at this point in the history
Use MICROPY_THREAD_YIELD() instead of HAL_Delay in busy waiting to improve
the performance of connect, send, recv, sento and recvfrom.
  • Loading branch information
Li-Weiwei authored and dpgeorge committed Oct 16, 2017
1 parent 5c43796 commit 73e387c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions drivers/wiznet5k/ethernet/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@

#include <string.h>

#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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -317,6 +316,7 @@ int32_t WIZCHIP_EXPORT(send)(uint8_t sn, uint8_t * buf, uint16_t len)
}
if( (sock_io_mode & (1<<sn)) && (len > freesize) ) return SOCK_BUSY;
if(len <= freesize) break;
MICROPY_THREAD_YIELD();
}
wiz_send_data(sn, buf, len);
#if _WIZCHIP_ == 5200
Expand Down Expand Up @@ -368,7 +368,7 @@ int32_t WIZCHIP_EXPORT(recv)(uint8_t sn, uint8_t * buf, uint16_t len)
}
if((sock_io_mode & (1<<sn)) && (recvsize == 0)) return SOCK_BUSY;
if(recvsize != 0) break;
HAL_Delay(1);
MICROPY_THREAD_YIELD();
};
if(recvsize < len) len = recvsize;
wiz_recv_data(sn, buf, len);
Expand Down Expand Up @@ -416,7 +416,7 @@ int32_t WIZCHIP_EXPORT(sendto)(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t
if(getSn_SR(sn) == SOCK_CLOSED) return SOCKERR_SOCKCLOSED;
if( (sock_io_mode & (1<<sn)) && (len > freesize) ) return SOCK_BUSY;
if(len <= freesize) break;
HAL_Delay(1);
MICROPY_THREAD_YIELD();
};
wiz_send_data(sn, buf, len);

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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<<sn)) && (pack_len == 0) ) return SOCK_BUSY;
if(pack_len != 0) break;
MICROPY_THREAD_YIELD();
};
}
sock_pack_info[sn] = PACK_COMPLETED;
Expand Down

0 comments on commit 73e387c

Please sign in to comment.