-
Notifications
You must be signed in to change notification settings - Fork 340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fixes and improvements from Micropython #120
Open
andrewleech
wants to merge
6
commits into
Wiznet:micropython
Choose a base branch
from
andrewleech:micropython
base: micropython
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8cbbc03
Properly fix ARP bug with W5200 chipset.
pi-anl fca54c4
Wrap exported functions in a macro to allow renaming.
pi-anl 1a272d7
Add socket_reset; fix orderly shutdown in recv.
pi-anl 009940c
Allow improvements in performance of socket ops with threading.
pi-anl 0fb14c8
Protect write_burst buffer arg as const.
pi-anl 0803fc5
w5200: Allow selecting maximum fixed buffer size for MACRAW.
pi-anl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,9 @@ | |
//! THE POSSIBILITY OF SUCH DAMAGE. | ||
// | ||
//***************************************************************************** | ||
#include <string.h> | ||
#include "socket.h" | ||
#include "wizchip_conf.h" | ||
|
||
//M20150401 : Typing Error | ||
//#define SOCK_ANY_PORT_NUM 0xC000; | ||
|
@@ -65,6 +67,7 @@ static uint16_t sock_is_sending = 0; | |
|
||
static uint16_t sock_remained_size[_WIZCHIP_SOCK_NUM_] = {0,0,}; | ||
|
||
|
||
//M20150601 : For extern decleation | ||
//static uint8_t sock_pack_info[_WIZCHIP_SOCK_NUM_] = {0,}; | ||
uint8_t sock_pack_info[_WIZCHIP_SOCK_NUM_] = {0,}; | ||
|
@@ -100,9 +103,21 @@ uint8_t sock_pack_info[_WIZCHIP_SOCK_NUM_] = {0,}; | |
if(len == 0) return SOCKERR_DATALEN; \ | ||
}while(0); \ | ||
|
||
void WIZCHIP_EXPORT(socket_reset)(void) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need to use a reset function? |
||
sock_any_port = SOCK_ANY_PORT_NUM; | ||
sock_io_mode = 0; | ||
sock_is_sending = 0; | ||
/* | ||
memset(sock_remained_size, 0, _WIZCHIP_SOCK_NUM_ * sizeof(uint16_t)); | ||
memset(sock_pack_info, 0, _WIZCHIP_SOCK_NUM_ * sizeof(uint8_t)); | ||
*/ | ||
|
||
#if _WIZCHIP_ == 5200 | ||
memset(sock_next_rd, 0, _WIZCHIP_SOCK_NUM_ * sizeof(uint16_t)); | ||
#endif | ||
} | ||
|
||
int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag) | ||
int8_t WIZCHIP_EXPORT(socket)(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag) | ||
{ | ||
CHECK_SOCKNUM(); | ||
switch(protocol) | ||
|
@@ -166,7 +181,7 @@ int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag) | |
break; | ||
} | ||
} | ||
close(sn); | ||
WIZCHIP_EXPORT(close)(sn); | ||
//M20150601 | ||
#if _WIZCHIP_ == 5300 | ||
setSn_MR(sn, ((uint16_t)(protocol | (flag & 0xF0))) | (((uint16_t)(flag & 0x02)) << 7) ); | ||
|
@@ -195,7 +210,7 @@ int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag) | |
return (int8_t)sn; | ||
} | ||
|
||
int8_t close(uint8_t sn) | ||
int8_t WIZCHIP_EXPORT(close)(uint8_t sn) | ||
{ | ||
CHECK_SOCKNUM(); | ||
//A20160426 : Applied the erratum 1 of W5300 | ||
|
@@ -238,7 +253,7 @@ int8_t close(uint8_t sn) | |
return SOCK_OK; | ||
} | ||
|
||
int8_t listen(uint8_t sn) | ||
int8_t WIZCHIP_EXPORT(listen)(uint8_t sn) | ||
{ | ||
CHECK_SOCKNUM(); | ||
CHECK_SOCKMODE(Sn_MR_TCP); | ||
|
@@ -247,14 +262,14 @@ int8_t listen(uint8_t sn) | |
while(getSn_CR(sn)); | ||
while(getSn_SR(sn) != SOCK_LISTEN) | ||
{ | ||
close(sn); | ||
WIZCHIP_EXPORT(close)(sn); | ||
return SOCKERR_SOCKCLOSED; | ||
} | ||
return SOCK_OK; | ||
} | ||
|
||
|
||
int8_t connect(uint8_t sn, uint8_t * addr, uint16_t port) | ||
int8_t WIZCHIP_EXPORT(connect)(uint8_t sn, uint8_t * addr, uint16_t port) | ||
{ | ||
CHECK_SOCKNUM(); | ||
CHECK_SOCKMODE(Sn_MR_TCP); | ||
|
@@ -274,6 +289,9 @@ int8_t connect(uint8_t sn, uint8_t * addr, uint16_t port) | |
if(port == 0) return SOCKERR_PORTZERO; | ||
setSn_DIPR(sn,addr); | ||
setSn_DPORT(sn,port); | ||
#if _WIZCHIP_ == 5200 // for w5200 ARP errata | ||
setSUBR(wizchip_getsubn()); | ||
#endif | ||
setSn_CR(sn,Sn_CR_CONNECT); | ||
while(getSn_CR(sn)); | ||
if(sock_io_mode & (1<<sn)) return SOCK_BUSY; | ||
|
@@ -282,19 +300,29 @@ int8_t connect(uint8_t sn, uint8_t * addr, uint16_t port) | |
if (getSn_IR(sn) & Sn_IR_TIMEOUT) | ||
{ | ||
setSn_IR(sn, Sn_IR_TIMEOUT); | ||
#if _WIZCHIP_ == 5200 // for w5200 ARP errata | ||
setSUBR((uint8_t*)"\x00\x00\x00\x00"); | ||
#endif | ||
return SOCKERR_TIMEOUT; | ||
} | ||
|
||
if (getSn_SR(sn) == SOCK_CLOSED) | ||
{ | ||
return SOCKERR_SOCKCLOSED; | ||
} | ||
if (getSn_SR(sn) == SOCK_CLOSED) { | ||
#if _WIZCHIP_ == 5200 // for w5200 ARP errata | ||
setSUBR((uint8_t*)"\x00\x00\x00\x00"); | ||
#endif | ||
return SOCKERR_SOCKCLOSED; | ||
} | ||
|
||
WIZCHIP_YIELD(); | ||
} | ||
#if _WIZCHIP_ == 5200 // for w5200 ARP errata | ||
setSUBR((uint8_t*)"\x00\x00\x00\x00"); | ||
#endif | ||
|
||
return SOCK_OK; | ||
} | ||
|
||
int8_t disconnect(uint8_t sn) | ||
int8_t WIZCHIP_EXPORT(disconnect)(uint8_t sn) | ||
{ | ||
CHECK_SOCKNUM(); | ||
CHECK_SOCKMODE(Sn_MR_TCP); | ||
|
@@ -307,14 +335,14 @@ int8_t disconnect(uint8_t sn) | |
{ | ||
if(getSn_IR(sn) & Sn_IR_TIMEOUT) | ||
{ | ||
close(sn); | ||
WIZCHIP_EXPORT(close)(sn); | ||
return SOCKERR_TIMEOUT; | ||
} | ||
} | ||
return SOCK_OK; | ||
} | ||
|
||
int32_t send(uint8_t sn, uint8_t * buf, uint16_t len) | ||
int32_t WIZCHIP_EXPORT(send)(uint8_t sn, uint8_t * buf, uint16_t len) | ||
{ | ||
uint8_t tmp=0; | ||
uint16_t freesize=0; | ||
|
@@ -344,7 +372,7 @@ int32_t send(uint8_t sn, uint8_t * buf, uint16_t len) | |
} | ||
else if(tmp & Sn_IR_TIMEOUT) | ||
{ | ||
close(sn); | ||
WIZCHIP_EXPORT(close)(sn); | ||
return SOCKERR_TIMEOUT; | ||
} | ||
else return SOCK_BUSY; | ||
|
@@ -357,11 +385,12 @@ int32_t send(uint8_t sn, uint8_t * buf, uint16_t len) | |
tmp = getSn_SR(sn); | ||
if ((tmp != SOCK_ESTABLISHED) && (tmp != SOCK_CLOSE_WAIT)) | ||
{ | ||
close(sn); | ||
WIZCHIP_EXPORT(close)(sn); | ||
return SOCKERR_SOCKSTATUS; | ||
} | ||
if( (sock_io_mode & (1<<sn)) && (len > freesize) ) return SOCK_BUSY; | ||
if(len <= freesize) break; | ||
WIZCHIP_YIELD(); | ||
} | ||
wiz_send_data(sn, buf, len); | ||
#if _WIZCHIP_ == 5200 | ||
|
@@ -382,7 +411,7 @@ int32_t send(uint8_t sn, uint8_t * buf, uint16_t len) | |
} | ||
|
||
|
||
int32_t recv(uint8_t sn, uint8_t * buf, uint16_t len) | ||
int32_t WIZCHIP_EXPORT(recv)(uint8_t sn, uint8_t * buf, uint16_t len) | ||
{ | ||
uint8_t tmp = 0; | ||
uint16_t recvsize = 0; | ||
|
@@ -417,18 +446,24 @@ int32_t recv(uint8_t sn, uint8_t * buf, uint16_t len) | |
if(recvsize != 0) break; | ||
else if(getSn_TX_FSR(sn) == getSn_TxMAX(sn)) | ||
{ | ||
close(sn); | ||
return SOCKERR_SOCKSTATUS; | ||
// dpgeorge: Getting here seems to be an orderly shutdown of the | ||
// socket, and trying to get POSIX behaviour we return 0 because: | ||
// "If no messages are available to be received and the peer has per? | ||
// formed an orderly shutdown, recv() shall return 0". | ||
// TODO this return value clashes with SOCK_BUSY in non-blocking mode. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please delete the comments |
||
WIZCHIP_EXPORT(close)(sn); | ||
return 0; | ||
} | ||
} | ||
else | ||
{ | ||
close(sn); | ||
WIZCHIP_EXPORT(close)(sn); | ||
return SOCKERR_SOCKSTATUS; | ||
} | ||
} | ||
if((sock_io_mode & (1<<sn)) && (recvsize == 0)) return SOCK_BUSY; | ||
if(recvsize != 0) break; | ||
WIZCHIP_YIELD(); | ||
}; | ||
#if _WIZCHIP_ == 5300 | ||
} | ||
|
@@ -487,7 +522,7 @@ int32_t recv(uint8_t sn, uint8_t * buf, uint16_t len) | |
return (int32_t)len; | ||
} | ||
|
||
int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port) | ||
int32_t WIZCHIP_EXPORT(sendto)(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port) | ||
{ | ||
uint8_t tmp = 0; | ||
uint16_t freesize = 0; | ||
|
@@ -537,6 +572,7 @@ int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_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; | ||
WIZCHIP_YIELD(); | ||
}; | ||
wiz_send_data(sn, buf, len); | ||
|
||
|
@@ -580,6 +616,7 @@ int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t | |
return SOCKERR_TIMEOUT; | ||
} | ||
//////////// | ||
WIZCHIP_YIELD(); | ||
} | ||
#if _WIZCHIP_ < 5500 //M20150401 : for WIZCHIP Errata #4, #5 (ARP errata) | ||
if(taddr) setSUBR((uint8_t*)&taddr); | ||
|
@@ -590,8 +627,7 @@ int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t | |
} | ||
|
||
|
||
|
||
int32_t recvfrom(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port) | ||
int32_t WIZCHIP_EXPORT(recvfrom)(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port) | ||
{ | ||
//M20150601 : For W5300 | ||
#if _WIZCHIP_ == 5300 | ||
|
@@ -633,6 +669,7 @@ int32_t recvfrom(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16 | |
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; | ||
WIZCHIP_YIELD(); | ||
}; | ||
} | ||
//D20150601 : Move it to bottom | ||
|
@@ -644,7 +681,7 @@ int32_t recvfrom(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16 | |
{ | ||
wiz_recv_data(sn, head, 8); | ||
setSn_CR(sn,Sn_CR_RECV); | ||
while(getSn_CR(sn)); | ||
while(getSn_CR(sn)) {} | ||
// read peer's IP address, port number & packet length | ||
//A20150601 : For W5300 | ||
#if _WIZCHIP_ == 5300 | ||
|
@@ -710,7 +747,7 @@ int32_t recvfrom(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16 | |
#endif | ||
if(sock_remained_size[sn] > 1514) | ||
{ | ||
close(sn); | ||
WIZCHIP_EXPORT(close)(sn); | ||
return SOCKFATAL_PACKLEN; | ||
} | ||
sock_pack_info[sn] = PACK_FIRST; | ||
|
@@ -773,7 +810,7 @@ int32_t recvfrom(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16 | |
} | ||
|
||
|
||
int8_t ctlsocket(uint8_t sn, ctlsock_type cstype, void* arg) | ||
int8_t WIZCHIP_EXPORT(ctlsocket)(uint8_t sn, ctlsock_type cstype, void* arg) | ||
{ | ||
uint8_t tmp = 0; | ||
CHECK_SOCKNUM(); | ||
|
@@ -819,7 +856,7 @@ int8_t ctlsocket(uint8_t sn, ctlsock_type cstype, void* arg) | |
return SOCK_OK; | ||
} | ||
|
||
int8_t setsockopt(uint8_t sn, sockopt_type sotype, void* arg) | ||
int8_t WIZCHIP_EXPORT(setsockopt)(uint8_t sn, sockopt_type sotype, void* arg) | ||
{ | ||
// M20131220 : Remove warning | ||
//uint8_t tmp; | ||
|
@@ -872,7 +909,7 @@ int8_t setsockopt(uint8_t sn, sockopt_type sotype, void* arg) | |
return SOCK_OK; | ||
} | ||
|
||
int8_t getsockopt(uint8_t sn, sockopt_type sotype, void* arg) | ||
int8_t WIZCHIP_EXPORT(getsockopt)(uint8_t sn, sockopt_type sotype, void* arg) | ||
{ | ||
CHECK_SOCKNUM(); | ||
switch(sotype) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please delete this phrase.