@@ -12,6 +12,7 @@ uint8_t socket(SOCKET s, uint8_t protocol, uint16_t port, uint8_t flag)
12
12
if ((protocol == SnMR::TCP) || (protocol == SnMR::UDP) || (protocol == SnMR::IPRAW) || (protocol == SnMR::MACRAW) || (protocol == SnMR::PPPOE))
13
13
{
14
14
close (s);
15
+ SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
15
16
W5100.writeSnMR (s, protocol | flag);
16
17
if (port != 0 ) {
17
18
W5100.writeSnPORT (s, port);
@@ -22,7 +23,7 @@ uint8_t socket(SOCKET s, uint8_t protocol, uint16_t port, uint8_t flag)
22
23
}
23
24
24
25
W5100.execCmdSn (s, Sock_OPEN);
25
-
26
+ SPI. endTransaction ();
26
27
return 1 ;
27
28
}
28
29
@@ -32,7 +33,10 @@ uint8_t socket(SOCKET s, uint8_t protocol, uint16_t port, uint8_t flag)
32
33
33
34
uint8_t socketStatus (SOCKET s)
34
35
{
35
- return W5100.readSnSR (s);
36
+ SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
37
+ uint8_t status = W5100.readSnSR (s);
38
+ SPI.endTransaction ();
39
+ return status;
36
40
}
37
41
38
42
@@ -41,8 +45,10 @@ uint8_t socketStatus(SOCKET s)
41
45
*/
42
46
void close (SOCKET s)
43
47
{
48
+ SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
44
49
W5100.execCmdSn (s, Sock_CLOSE);
45
50
W5100.writeSnIR (s, 0xFF );
51
+ SPI.endTransaction ();
46
52
}
47
53
48
54
@@ -52,9 +58,13 @@ void close(SOCKET s)
52
58
*/
53
59
uint8_t listen (SOCKET s)
54
60
{
55
- if (W5100.readSnSR (s) != SnSR::INIT)
61
+ SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
62
+ if (W5100.readSnSR (s) != SnSR::INIT) {
63
+ SPI.endTransaction ();
56
64
return 0 ;
65
+ }
57
66
W5100.execCmdSn (s, Sock_LISTEN);
67
+ SPI.endTransaction ();
58
68
return 1 ;
59
69
}
60
70
@@ -76,9 +86,11 @@ uint8_t connect(SOCKET s, uint8_t * addr, uint16_t port)
76
86
return 0 ;
77
87
78
88
// set destination IP
89
+ SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
79
90
W5100.writeSnDIPR (s, addr);
80
91
W5100.writeSnDPORT (s, port);
81
92
W5100.execCmdSn (s, Sock_CONNECT);
93
+ SPI.endTransaction ();
82
94
83
95
return 1 ;
84
96
}
@@ -91,7 +103,9 @@ uint8_t connect(SOCKET s, uint8_t * addr, uint16_t port)
91
103
*/
92
104
void disconnect (SOCKET s)
93
105
{
106
+ SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
94
107
W5100.execCmdSn (s, Sock_DISCON);
108
+ SPI.endTransaction ();
95
109
}
96
110
97
111
@@ -113,17 +127,21 @@ uint16_t send(SOCKET s, const uint8_t * buf, uint16_t len)
113
127
// if freebuf is available, start.
114
128
do
115
129
{
130
+ SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
116
131
freesize = W5100.getTXFreeSize (s);
117
132
status = W5100.readSnSR (s);
133
+ SPI.endTransaction ();
118
134
if ((status != SnSR::ESTABLISHED) && (status != SnSR::CLOSE_WAIT))
119
135
{
120
136
ret = 0 ;
121
137
break ;
122
138
}
139
+ yield ();
123
140
}
124
141
while (freesize < ret);
125
142
126
143
// copy data
144
+ SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
127
145
W5100.send_data_processing (s, (uint8_t *)buf, ret);
128
146
W5100.execCmdSn (s, Sock_SEND);
129
147
@@ -133,12 +151,17 @@ uint16_t send(SOCKET s, const uint8_t * buf, uint16_t len)
133
151
/* m2008.01 [bj] : reduce code */
134
152
if ( W5100.readSnSR (s) == SnSR::CLOSED )
135
153
{
154
+ SPI.endTransaction ();
136
155
close (s);
137
156
return 0 ;
138
157
}
158
+ SPI.endTransaction ();
159
+ yield ();
160
+ SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
139
161
}
140
162
/* +2008.01 bj */
141
163
W5100.writeSnIR (s, SnIR::SEND_OK);
164
+ SPI.endTransaction ();
142
165
return ret;
143
166
}
144
167
@@ -152,6 +175,7 @@ uint16_t send(SOCKET s, const uint8_t * buf, uint16_t len)
152
175
int16_t recv (SOCKET s, uint8_t *buf, int16_t len)
153
176
{
154
177
// Check how much data is available
178
+ SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
155
179
int16_t ret = W5100.getRXReceivedSize (s);
156
180
if ( ret == 0 )
157
181
{
@@ -178,13 +202,17 @@ int16_t recv(SOCKET s, uint8_t *buf, int16_t len)
178
202
W5100.recv_data_processing (s, buf, ret);
179
203
W5100.execCmdSn (s, Sock_RECV);
180
204
}
205
+ SPI.endTransaction ();
181
206
return ret;
182
207
}
183
208
184
209
185
210
int16_t recvAvailable (SOCKET s)
186
211
{
187
- return W5100.getRXReceivedSize (s);
212
+ SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
213
+ int16_t ret = W5100.getRXReceivedSize (s);
214
+ SPI.endTransaction ();
215
+ return ret;
188
216
}
189
217
190
218
@@ -195,8 +223,9 @@ int16_t recvAvailable(SOCKET s)
195
223
*/
196
224
uint16_t peek (SOCKET s, uint8_t *buf)
197
225
{
226
+ SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
198
227
W5100.recv_data_processing (s, buf, 1 , 1 );
199
-
228
+ SPI. endTransaction ();
200
229
return 1 ;
201
230
}
202
231
@@ -225,6 +254,7 @@ uint16_t sendto(SOCKET s, const uint8_t *buf, uint16_t len, uint8_t *addr, uint1
225
254
}
226
255
else
227
256
{
257
+ SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
228
258
W5100.writeSnDIPR (s, addr);
229
259
W5100.writeSnDPORT (s, port);
230
260
@@ -239,12 +269,17 @@ uint16_t sendto(SOCKET s, const uint8_t *buf, uint16_t len, uint8_t *addr, uint1
239
269
{
240
270
/* +2008.01 [bj]: clear interrupt */
241
271
W5100.writeSnIR (s, (SnIR::SEND_OK | SnIR::TIMEOUT)); /* clear SEND_OK & TIMEOUT */
272
+ SPI.endTransaction ();
242
273
return 0 ;
243
274
}
275
+ SPI.endTransaction ();
276
+ yield ();
277
+ SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
244
278
}
245
279
246
280
/* +2008.01 bj */
247
281
W5100.writeSnIR (s, SnIR::SEND_OK);
282
+ SPI.endTransaction ();
248
283
}
249
284
return ret;
250
285
}
@@ -264,6 +299,7 @@ uint16_t recvfrom(SOCKET s, uint8_t *buf, uint16_t len, uint8_t *addr, uint16_t
264
299
265
300
if ( len > 0 )
266
301
{
302
+ SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
267
303
ptr = W5100.readSnRX_RD (s);
268
304
switch (W5100.readSnMR (s) & 0x07 )
269
305
{
@@ -318,6 +354,7 @@ uint16_t recvfrom(SOCKET s, uint8_t *buf, uint16_t len, uint8_t *addr, uint16_t
318
354
break ;
319
355
}
320
356
W5100.execCmdSn (s, Sock_RECV);
357
+ SPI.endTransaction ();
321
358
}
322
359
return data_len;
323
360
}
@@ -341,6 +378,7 @@ uint16_t igmpsend(SOCKET s, const uint8_t * buf, uint16_t len)
341
378
if (ret == 0 )
342
379
return 0 ;
343
380
381
+ SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
344
382
W5100.send_data_processing (s, (uint8_t *)buf, ret);
345
383
W5100.execCmdSn (s, Sock_SEND);
346
384
@@ -350,18 +388,24 @@ uint16_t igmpsend(SOCKET s, const uint8_t * buf, uint16_t len)
350
388
{
351
389
/* in case of igmp, if send fails, then socket closed */
352
390
/* if you want change, remove this code. */
391
+ SPI.endTransaction ();
353
392
close (s);
354
393
return 0 ;
355
394
}
395
+ SPI.endTransaction ();
396
+ yield ();
397
+ SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
356
398
}
357
399
358
400
W5100.writeSnIR (s, SnIR::SEND_OK);
401
+ SPI.endTransaction ();
359
402
return ret;
360
403
}
361
404
362
405
uint16_t bufferData (SOCKET s, uint16_t offset, const uint8_t * buf, uint16_t len)
363
406
{
364
407
uint16_t ret =0 ;
408
+ SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
365
409
if (len > W5100.getTXFreeSize (s))
366
410
{
367
411
ret = W5100.getTXFreeSize (s); // check size not to exceed MAX size.
@@ -371,6 +415,7 @@ uint16_t bufferData(SOCKET s, uint16_t offset, const uint8_t* buf, uint16_t len)
371
415
ret = len;
372
416
}
373
417
W5100.send_data_processing_offset (s, offset, buf, ret);
418
+ SPI.endTransaction ();
374
419
return ret;
375
420
}
376
421
@@ -386,14 +431,17 @@ int startUDP(SOCKET s, uint8_t* addr, uint16_t port)
386
431
}
387
432
else
388
433
{
434
+ SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
389
435
W5100.writeSnDIPR (s, addr);
390
436
W5100.writeSnDPORT (s, port);
437
+ SPI.endTransaction ();
391
438
return 1 ;
392
439
}
393
440
}
394
441
395
442
int sendUDP (SOCKET s)
396
443
{
444
+ SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
397
445
W5100.execCmdSn (s, Sock_SEND);
398
446
399
447
/* +2008.01 bj */
@@ -403,12 +451,17 @@ int sendUDP(SOCKET s)
403
451
{
404
452
/* +2008.01 [bj]: clear interrupt */
405
453
W5100.writeSnIR (s, (SnIR::SEND_OK|SnIR::TIMEOUT));
454
+ SPI.endTransaction ();
406
455
return 0 ;
407
456
}
457
+ SPI.endTransaction ();
458
+ yield ();
459
+ SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
408
460
}
409
461
410
462
/* +2008.01 bj */
411
463
W5100.writeSnIR (s, SnIR::SEND_OK);
464
+ SPI.endTransaction ();
412
465
413
466
/* Sent ok */
414
467
return 1 ;
0 commit comments