Skip to content

Commit 0ff16ea

Browse files
committed
save another 658 bytes of flash by using all static access in network and mempool
1 parent 0a281a3 commit 0ff16ea

11 files changed

+137
-157
lines changed

UIPClient.cpp

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ UIPClient::_write(uip_userdata_t* u, const uint8_t *buf, size_t size)
171171
if (u->packets_out[p] == NOBLOCK)
172172
{
173173
newpacket:
174-
u->packets_out[p] = UIPEthernetClass::network.allocBlock(UIP_SOCKET_DATALEN);
174+
u->packets_out[p] = Enc28J60Network::allocBlock(UIP_SOCKET_DATALEN);
175175
if (u->packets_out[p] == NOBLOCK)
176176
{
177177
#if UIP_ATTEMPTS_ON_WRITE > 0
@@ -197,7 +197,7 @@ UIPClient::_write(uip_userdata_t* u, const uint8_t *buf, size_t size)
197197
Serial.write((uint8_t*)buf+size-remain,remain);
198198
Serial.println(F("'"));
199199
#endif
200-
written = UIPEthernetClass::network.writePacket(u->packets_out[p],u->out_pos,(uint8_t*)buf+size-remain,remain);
200+
written = Enc28J60Network::writePacket(u->packets_out[p],u->out_pos,(uint8_t*)buf+size-remain,remain);
201201
remain -= written;
202202
u->out_pos+=written;
203203
if (remain > 0)
@@ -235,7 +235,7 @@ UIPClient::_available(uip_userdata_t *u)
235235
int len = 0;
236236
for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS; i++)
237237
{
238-
len += UIPEthernetClass::network.blockSize(u->packets_in[i]);
238+
len += Enc28J60Network::blockSize(u->packets_in[i]);
239239
}
240240
return len;
241241
}
@@ -251,8 +251,8 @@ UIPClient::read(uint8_t *buf, size_t size)
251251
uint16_t read;
252252
do
253253
{
254-
read = UIPEthernetClass::network.readPacket(data->packets_in[0],0,buf+size-remain,remain);
255-
if (read == UIPEthernetClass::network.blockSize(data->packets_in[0]))
254+
read = Enc28J60Network::readPacket(data->packets_in[0],0,buf+size-remain,remain);
255+
if (read == Enc28J60Network::blockSize(data->packets_in[0]))
256256
{
257257
remain -= read;
258258
_eatBlock(&data->packets_in[0]);
@@ -270,7 +270,7 @@ UIPClient::read(uint8_t *buf, size_t size)
270270
}
271271
else
272272
{
273-
UIPEthernetClass::network.resizeBlock(data->packets_in[0],read);
273+
Enc28J60Network::resizeBlock(data->packets_in[0],read);
274274
break;
275275
}
276276
}
@@ -297,7 +297,7 @@ UIPClient::peek()
297297
if (data->packets_in[0] != NOBLOCK)
298298
{
299299
uint8_t c;
300-
UIPEthernetClass::network.readPacket(data->packets_in[0],0,&c,1);
300+
Enc28J60Network::readPacket(data->packets_in[0],0,&c,1);
301301
return c;
302302
}
303303
}
@@ -315,12 +315,6 @@ UIPClient::flush()
315315

316316
void
317317
uipclient_appcall(void)
318-
{
319-
UIPClient::uip_callback();
320-
}
321-
322-
void
323-
UIPClient::uip_callback()
324318
{
325319
uip_userdata_t *u = (uip_userdata_t*)uip_conn->appstate;
326320
if (!u && uip_connected())
@@ -329,7 +323,7 @@ UIPClient::uip_callback()
329323
Serial.println(F("UIPClient uip_connected"));
330324
_dumpAllData();
331325
#endif
332-
u = (uip_userdata_t*) _allocateData();
326+
u = (uip_userdata_t*) UIPClient::_allocateData();
333327
if (u)
334328
{
335329
uip_conn->appstate = u;
@@ -353,7 +347,7 @@ UIPClient::uip_callback()
353347
#endif
354348
if (uip_len && !(u->state & (UIP_CLIENT_CLOSE | UIP_CLIENT_REMOTECLOSED)))
355349
{
356-
memhandle newPacket = UIPEthernetClass::network.allocBlock(uip_len);
350+
memhandle newPacket = Enc28J60Network::allocBlock(uip_len);
357351
if (newPacket != NOBLOCK)
358352
{
359353
for (uint8_t i=0; i < UIP_SOCKET_NUMPACKETS; i++)
@@ -362,7 +356,7 @@ UIPClient::uip_callback()
362356
{
363357
if (i == UIP_SOCKET_NUMPACKETS-1)
364358
uip_stop();
365-
UIPEthernetClass::network.copyPacket(newPacket,0,UIPEthernetClass::in_packet,((uint8_t*)uip_appdata)-uip_buf,uip_len);
359+
Enc28J60Network::copyPacket(newPacket,0,UIPEthernetClass::in_packet,((uint8_t*)uip_appdata)-uip_buf,uip_len);
366360
u->packets_in[i] = newPacket;
367361
goto finish_newdata;
368362
}
@@ -386,7 +380,7 @@ UIPClient::uip_callback()
386380
_dumpAllData();
387381
#endif
388382
// drop outgoing packets not sent yet:
389-
_flushBlocks(&u->packets_out[0]);
383+
UIPClient::_flushBlocks(&u->packets_out[0]);
390384
if (u->packets_in[0] != NOBLOCK)
391385
{
392386
((uip_userdata_closed_t *)u)->lport = uip_conn->lport;
@@ -407,7 +401,7 @@ UIPClient::uip_callback()
407401
#ifdef UIPETHERNET_DEBUG_CLIENT
408402
Serial.println(F("UIPClient uip_acked"));
409403
#endif
410-
_eatBlock(&u->packets_out[0]);
404+
UIPClient::_eatBlock(&u->packets_out[0]);
411405
}
412406
if (uip_poll() || uip_rexmit())
413407
{
@@ -421,18 +415,18 @@ UIPClient::uip_callback()
421415
uip_len = u->out_pos;
422416
if (uip_len > 0)
423417
{
424-
UIPEthernetClass::network.resizeBlock(u->packets_out[0],0,uip_len);
418+
Enc28J60Network::resizeBlock(u->packets_out[0],0,uip_len);
425419
}
426420
}
427421
else
428-
uip_len = UIPEthernetClass::network.blockSize(u->packets_out[0]);
422+
uip_len = Enc28J60Network::blockSize(u->packets_out[0]);
429423
if (uip_len > 0)
430424
{
431425
UIPEthernetClass::uip_hdrlen = ((uint8_t*)uip_appdata)-uip_buf;
432-
UIPEthernetClass::uip_packet = UIPEthernetClass::network.allocBlock(UIPEthernetClass::uip_hdrlen+uip_len);
426+
UIPEthernetClass::uip_packet = Enc28J60Network::allocBlock(UIPEthernetClass::uip_hdrlen+uip_len);
433427
if (UIPEthernetClass::uip_packet != NOBLOCK)
434428
{
435-
UIPEthernetClass::network.copyPacket(UIPEthernetClass::uip_packet,UIPEthernetClass::uip_hdrlen,u->packets_out[0],0,uip_len);
429+
Enc28J60Network::copyPacket(UIPEthernetClass::uip_packet,UIPEthernetClass::uip_hdrlen,u->packets_out[0],0,uip_len);
436430
UIPEthernetClass::packetstate |= UIPETHERNET_SENDPACKET;
437431
uip_send(uip_appdata,uip_len);
438432
}
@@ -513,7 +507,7 @@ UIPClient::_eatBlock(memhandle* block)
513507
}
514508
Serial.print(F("-> "));
515509
#endif
516-
UIPEthernetClass::network.freeBlock(block[0]);
510+
Enc28J60Network::freeBlock(block[0]);
517511
for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS-1; i++)
518512
{
519513
block[i] = block[i+1];
@@ -534,7 +528,7 @@ UIPClient::_flushBlocks(memhandle* block)
534528
{
535529
for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS; i++)
536530
{
537-
UIPEthernetClass::network.freeBlock(block[i]);
531+
Enc28J60Network::freeBlock(block[i]);
538532
}
539533
}
540534

UIPClient.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ class UIPClient : public Client {
101101

102102
friend void uipclient_appcall(void);
103103

104-
static void uip_callback();
105104
};
106105

107106
#endif

UIPEthernet.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ DhcpClass* UIPEthernetClass::_dhcp(NULL);
4747

4848
struct uip_timer UIPEthernetClass::periodic_timer;
4949

50-
Enc28J60Network UIPEthernetClass::network;
51-
5250
// Because uIP isn't encapsulated within a class we have to use global
5351
// variables, so we can only have one TCP/IP stack per program.
5452

@@ -167,7 +165,7 @@ UIPEthernetClass::tick()
167165
{
168166
if (in_packet == NOBLOCK)
169167
{
170-
in_packet = network.receivePacket();
168+
in_packet = Enc28J60Network::receivePacket();
171169
#ifdef UIPETHERNET_DEBUG
172170
if (in_packet != NOBLOCK)
173171
{
@@ -179,10 +177,10 @@ UIPEthernetClass::tick()
179177
if (in_packet != NOBLOCK)
180178
{
181179
packetstate = UIPETHERNET_FREEPACKET;
182-
uip_len = network.blockSize(in_packet);
180+
uip_len = Enc28J60Network::blockSize(in_packet);
183181
if (uip_len > 0)
184182
{
185-
network.readPacket(in_packet,0,(uint8_t*)uip_buf,UIP_BUFSIZE);
183+
Enc28J60Network::readPacket(in_packet,0,(uint8_t*)uip_buf,UIP_BUFSIZE);
186184
if (ETH_HDR ->type == HTONS(UIP_ETHTYPE_IP))
187185
{
188186
uip_packet = in_packet;
@@ -217,7 +215,7 @@ UIPEthernetClass::tick()
217215
Serial.print(F("freeing packet: "));
218216
Serial.println(in_packet);
219217
#endif
220-
network.freePacket();
218+
Enc28J60Network::freePacket();
221219
in_packet = NOBLOCK;
222220
}
223221
}
@@ -229,7 +227,7 @@ UIPEthernetClass::tick()
229227
{
230228
uip_periodic(i);
231229
// If the above function invocation resulted in data that
232-
// should be sent out on the network, the global variable
230+
// should be sent out on the Enc28J60Network, the global variable
233231
// uip_len is set to a value > 0.
234232
if (uip_len > 0)
235233
{
@@ -243,7 +241,7 @@ UIPEthernetClass::tick()
243241
{
244242
uip_udp_periodic(i);
245243
// If the above function invocation resulted in data that
246-
// should be sent out on the network, the global variable
244+
// should be sent out on the Enc28J60Network, the global variable
247245
// uip_len is set to a value > 0. */
248246
if (uip_len > 0)
249247
{
@@ -259,38 +257,38 @@ boolean UIPEthernetClass::network_send()
259257
if (packetstate & UIPETHERNET_SENDPACKET)
260258
{
261259
#ifdef UIPETHERNET_DEBUG
262-
Serial.print(F("network_send uip_packet: "));
260+
Serial.print(F("Enc28J60Network_send uip_packet: "));
263261
Serial.print(uip_packet);
264262
Serial.print(F(", hdrlen: "));
265263
Serial.println(uip_hdrlen);
266264
#endif
267-
network.writePacket(uip_packet,0,uip_buf,uip_hdrlen);
265+
Enc28J60Network::writePacket(uip_packet,0,uip_buf,uip_hdrlen);
268266
goto sendandfree;
269267
}
270-
uip_packet = network.allocBlock(uip_len);
268+
uip_packet = Enc28J60Network::allocBlock(uip_len);
271269
if (uip_packet != NOBLOCK)
272270
{
273271
#ifdef UIPETHERNET_DEBUG
274-
Serial.print(F("network_send uip_buf (uip_len): "));
272+
Serial.print(F("Enc28J60Network_send uip_buf (uip_len): "));
275273
Serial.print(uip_len);
276274
Serial.print(F(", packet: "));
277275
Serial.println(uip_packet);
278276
#endif
279-
network.writePacket(uip_packet,0,uip_buf,uip_len);
277+
Enc28J60Network::writePacket(uip_packet,0,uip_buf,uip_len);
280278
goto sendandfree;
281279
}
282280
return false;
283281
sendandfree:
284-
network.sendPacket(uip_packet);
285-
network.freeBlock(uip_packet);
282+
Enc28J60Network::sendPacket(uip_packet);
283+
Enc28J60Network::freeBlock(uip_packet);
286284
uip_packet = NOBLOCK;
287285
return true;
288286
}
289287

290288
void UIPEthernetClass::init(const uint8_t* mac) {
291289
uip_timer_set(&periodic_timer, CLOCK_SECOND / 4);
292290

293-
network.init((uint8_t*)mac);
291+
Enc28J60Network::init((uint8_t*)mac);
294292
uip_seteth_addr(mac);
295293

296294
uip_init();
@@ -415,7 +413,7 @@ uip_tcpchksum(void)
415413
#endif
416414
if (upper_layer_memlen < upper_layer_len)
417415
{
418-
sum = UIPEthernetClass::network.chksum(
416+
sum = Enc28J60Network::chksum(
419417
sum,
420418
UIPEthernetClass::uip_packet,
421419
UIP_IPH_LEN + UIP_LLH_LEN + upper_layer_memlen,

UIPEthernet.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ class UIPEthernetClass
9292

9393
static struct uip_timer periodic_timer;
9494

95-
static Enc28J60Network network;
96-
9795
static void init(const uint8_t* mac);
9896
static void configure(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet);
9997

@@ -116,6 +114,9 @@ class UIPEthernetClass
116114
friend uint16_t uip_tcpchksum(void);
117115
friend uint16_t uip_udpchksum(void);
118116

117+
friend void uipclient_appcall(void);
118+
friend void uipudp_appcall(void);
119+
119120
#if UIP_CONF_IPV6
120121
uint16_t uip_icmp6chksum(void);
121122
#endif /* UIP_CONF_IPV6 */

0 commit comments

Comments
 (0)