Skip to content

Commit

Permalink
Update nicdrv.c to account for socket number
Browse files Browse the repository at this point in the history
  • Loading branch information
pimvliet committed Nov 11, 2022
1 parent e427836 commit 987702b
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions oshw/STM32F746ZG/nicdrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,62 +38,62 @@
#include "socket_w5500.h"
#include "w5500.h"

int16_t sendRAW(uint8_t sn, uint8_t * buf, uint16_t len)
int16_t sendRAW(uint8_t sn, uint8_t* buf, uint16_t len)
{
while(1)
{
uint16_t freesize = getSn_TX_FSR(0);
if (getSn_SR(0) == SOCK_CLOSED)
uint16_t freesize = getSn_TX_FSR(sn);
if (getSn_SR(sn) == SOCK_CLOSED)
return -1;
if (len <= freesize)
break;
}

wiz_send_data(0, buf, len);
setSn_CR(0, Sn_CR_SEND);
wiz_send_data(sn, buf, len);
setSn_CR(sn, Sn_CR_SEND);

while(1)
{
uint8_t tmp = getSn_IR(0);
uint8_t tmp = getSn_IR(sn);
if (tmp & Sn_IR_SENDOK)
{
setSn_IR(0, Sn_IR_SENDOK);
setSn_IR(sn, Sn_IR_SENDOK);
break;
}
else if (tmp & Sn_IR_TIMEOUT)
{
setSn_IR(0, Sn_IR_TIMEOUT);
setSn_IR(sn, Sn_IR_TIMEOUT);
return -1;
}
}
return len;
}

uint16_t recvRAW(uint8_t sn, uint8_t * buf, uint16_t bufsize)
uint16_t recvRAW(uint8_t sn, uint8_t* buf, uint16_t bufsize)
{
uint16_t len = getSn_RX_RSR(0);
uint16_t len = getSn_RX_RSR(sn);

if (len > 0)
{
uint8_t head[2];
uint16_t data_len = 0;

wiz_recv_data(0, head, 2);
setSn_CR(0, Sn_CR_RECV);
wiz_recv_data(sn, head, 2);
setSn_CR(sn, Sn_CR_RECV);

data_len = head[0];
data_len = (data_len << 8) + head[1];
data_len -= 2;

if (data_len > bufsize)
{
wiz_recv_ignore(0, data_len);
setSn_CR(0, Sn_CR_RECV);
wiz_recv_ignore(sn, data_len);
setSn_CR(sn, Sn_CR_RECV);
return 0;
}

wiz_recv_data(0, buf, data_len);
setSn_CR(0, Sn_CR_RECV);
wiz_recv_data(sn, buf, data_len);
setSn_CR(sn, Sn_CR_RECV);

if ((buf[0] & 0x01) || memcpy(&buf[0], priMAC, 6) == 0)
return data_len;
Expand Down

0 comments on commit 987702b

Please sign in to comment.