Fixing w5500.

This commit is contained in:
TXuian 2022-12-10 14:16:38 +08:00
parent ecc0be0e66
commit 5bc1bf98b2
1 changed files with 13 additions and 13 deletions

View File

@ -22,7 +22,7 @@ extern void spi_select_cs(void);
extern void spi_deselete_cs(void); extern void spi_deselete_cs(void);
// global configurations for w5500 tcp connection // global configurations for w5500 tcp connection
const uint32_t socket_tcp = 0; // const uint32_t sn = 0;
const uint32_t g_wiznet_buf_size = 256; const uint32_t g_wiznet_buf_size = 256;
static wiz_NetInfo g_wiz_netinfo = {.mac = {0x00, 0x08, 0xdc, 0x11, 0x11, 0x11}, static wiz_NetInfo g_wiz_netinfo = {.mac = {0x00, 0x08, 0xdc, 0x11, 0x11, 0x11},
@ -269,27 +269,27 @@ uint32_t wiz_client_op(uint8_t sn, uint8_t *buf, uint32_t buf_size,
enum TCP_OPTION opt) { enum TCP_OPTION opt) {
// assert(buf_size <= g_wiznet_buf_size); // assert(buf_size <= g_wiznet_buf_size);
int32_t ret; int32_t ret;
switch (getSn_SR(socket_tcp)) { switch (getSn_SR(sn)) {
case SOCK_CLOSE_WAIT: case SOCK_CLOSE_WAIT:
wiz_sock_disconnect(socket_tcp); wiz_sock_disconnect(sn);
break; break;
case SOCK_CLOSED: case SOCK_CLOSED:
wiz_socket(socket_tcp, Sn_MR_TCP, 5000, 0x00); wiz_socket(sn, Sn_MR_TCP, 5000, 0x00);
break; break;
case SOCK_INIT: case SOCK_INIT:
KPrintf("[SOCKET CLIENT] sock init.\n"); KPrintf("[SOCKET CLIENT] sock init.\n");
wiz_sock_connect(socket_tcp, dst_ip, dst_port); wiz_sock_connect(sn, dst_ip, dst_port);
break; break;
case SOCK_ESTABLISHED: case SOCK_ESTABLISHED:
if (getSn_IR(socket_tcp) & Sn_IR_CON) { if (getSn_IR(sn) & Sn_IR_CON) {
printf("[SOCKET CLIENT] %d:Connected\r\n", socket_tcp); printf("[SOCKET CLIENT] %d:Connected\r\n", sn);
setSn_IR(socket_tcp, Sn_IR_CON); setSn_IR(sn, Sn_IR_CON);
} }
if (opt == SEND_DATA) { if (opt == SEND_DATA) {
uint32_t sent_size = 0; uint32_t sent_size = 0;
ret = wiz_sock_send(socket_tcp, buf, buf_size); ret = wiz_sock_send(sn, buf, buf_size);
if (ret < 0) { if (ret < 0) {
wiz_sock_close(socket_tcp); wiz_sock_close(sn);
return ret; return ret;
} }
} else if (opt == RECV_DATA) { } else if (opt == RECV_DATA) {
@ -299,7 +299,7 @@ uint32_t wiz_client_op(uint8_t sn, uint8_t *buf, uint32_t buf_size,
if (size > buf_size) size = buf_size; if (size > buf_size) size = buf_size;
ret = wiz_sock_recv(sn, buf, size); ret = wiz_sock_recv(sn, buf, size);
if (ret <= 0) { if (ret <= 0) {
wiz_sock_close(socket_tcp); wiz_sock_close(sn);
return ret; return ret;
} }
} }
@ -366,9 +366,9 @@ int32_t wiz_server_op(uint8_t sn, uint8_t *buf, uint32_t buf_size,
} }
if (opt == SEND_DATA) { if (opt == SEND_DATA) {
uint32_t sent_size = 0; uint32_t sent_size = 0;
ret = wiz_sock_send(socket_tcp, buf, buf_size); ret = wiz_sock_send(sn, buf, buf_size);
if (ret < 0) { if (ret < 0) {
wiz_sock_close(socket_tcp); wiz_sock_close(sn);
return ret; return ret;
} }
} else if (opt == RECV_DATA) { } else if (opt == RECV_DATA) {