Skip to content

Commit 1f0e777

Browse files
committed
Cooperative scheduling support for Ehternet library.
1 parent afc7fc6 commit 1f0e777

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

hardware/arduino/sam/cores/arduino/UARTClass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <stdlib.h>
2020
#include <stdio.h>
2121
#include <string.h>
22+
#include "Arduino.h"
2223
#include "UARTClass.h"
2324

2425
// Constructors ////////////////////////////////////////////////////////////////

hardware/arduino/sam/cores/arduino/USARTClass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <stdlib.h>
2020
#include <stdio.h>
2121
#include <string.h>
22+
#include "Arduino.h"
2223
#include "USARTClass.h"
2324

2425
// Constructors ////////////////////////////////////////////////////////////////

hardware/arduino/sam/libraries/Ethernet/utility/socket.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,24 +114,24 @@ uint16_t send(SOCKET s, const uint8_t * buf, uint16_t len)
114114
ret = 0;
115115
break;
116116
}
117+
if (freesize >= ret)
118+
break;
119+
yield();
117120
}
118-
while (freesize < ret);
121+
while (true);
119122

120123
// copy data
121124
W5100.send_data_processing(s, (uint8_t *)buf, ret);
122125
W5100.execCmdSn(s, Sock_SEND);
123126

124-
/* +2008.01 bj */
125127
while ( (W5100.readSnIR(s) & SnIR::SEND_OK) != SnIR::SEND_OK )
126128
{
127-
/* m2008.01 [bj] : reduce code */
128129
if ( W5100.readSnSR(s) == SnSR::CLOSED )
129130
{
130131
close(s);
131132
return 0;
132133
}
133134
}
134-
/* +2008.01 bj */
135135
W5100.writeSnIR(s, SnIR::SEND_OK);
136136
return ret;
137137
}

hardware/arduino/sam/libraries/Ethernet/utility/w5100.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ void W5100Class::init(void)
4040
for (int i=0; i<MAX_SOCK_NUM; i++) {
4141
SBASE[i] = TXBUF_BASE + SSIZE * i;
4242
RBASE[i] = RXBUF_BASE + RSIZE * i;
43+
44+
cmdSnTickets[i] = 0;
45+
cmdSntNext[i] = 0;
4346
}
47+
4448
}
4549

4650
uint16_t W5100Class::getTXFreeSize(SOCKET s)
@@ -175,9 +179,16 @@ uint16_t W5100Class::read(uint16_t _addr, uint8_t *_buf, uint16_t _len)
175179
}
176180

177181
void W5100Class::execCmdSn(SOCKET s, SockCMD _cmd) {
182+
uint8_t turn = cmdSnTickets[s];
183+
cmdSnTickets[s]++;
184+
while (cmdSntNext[s] != turn)
185+
yield();
186+
178187
// Send command to socket
179188
writeSnCR(s, _cmd);
180189
// Wait for command to complete
181190
while (readSnCR(s))
182-
;
191+
yield();
192+
193+
cmdSntNext[s]++;
183194
}

hardware/arduino/sam/libraries/Ethernet/utility/w5100.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ class W5100Class {
321321
uint16_t SBASE[SOCKETS]; // Tx buffer base address
322322
uint16_t RBASE[SOCKETS]; // Rx buffer base address
323323

324+
uint8_t cmdSnTickets[MAX_SOCK_NUM];
325+
uint8_t cmdSntNext[MAX_SOCK_NUM];
324326
};
325327

326328
extern W5100Class W5100;

0 commit comments

Comments
 (0)