Skip to content

Commit 7459fdf

Browse files
committed
Merge branch 'timer' into Arduino_1.5.5
2 parents bfd8ce2 + 38c5e7e commit 7459fdf

File tree

5 files changed

+58
-16
lines changed

5 files changed

+58
-16
lines changed

UIPEthernet/src/UIPClient.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ UIPClient::_write(uip_userdata_t* u, const uint8_t *buf, size_t size)
226226
goto newpacket;
227227
}
228228
ready:
229+
#if UIP_CLIENT_TIMER >= 0
230+
u->timer = millis()+UIP_CLIENT_TIMER;
231+
#endif
229232
return size-remain;
230233
}
231234
return -1;

UIPEthernet/src/UIPClient.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ typedef struct {
5555
memhandle packets_in[UIP_SOCKET_NUMPACKETS];
5656
memhandle packets_out[UIP_SOCKET_NUMPACKETS];
5757
memaddress out_pos;
58+
#if UIP_CLIENT_TIMER >= 0
59+
unsigned long timer;
60+
#endif
5861
} uip_userdata_t;
5962

6063
class UIPClient : public Client {

UIPEthernet/src/UIPEthernet.cpp

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ uint8_t UIPEthernetClass::packetstate(0);
4545
IPAddress UIPEthernetClass::_dnsServerAddress;
4646
DhcpClass* UIPEthernetClass::_dhcp(NULL);
4747

48-
struct uip_timer UIPEthernetClass::periodic_timer;
48+
unsigned long UIPEthernetClass::periodic_timer;
4949

5050
// Because uIP isn't encapsulated within a class we have to use global
5151
// variables, so we can only have one TCP/IP stack per program.
@@ -220,22 +220,50 @@ UIPEthernetClass::tick()
220220
}
221221
}
222222

223-
if (uip_timer_expired(&periodic_timer))
223+
unsigned long now = millis();
224+
225+
#if UIP_CLIENT_TIMER >= 0
226+
boolean periodic = (long)( now - periodic_timer ) >= 0;
227+
for (int i = 0; i < UIP_CONNS; i++)
228+
{
229+
#else
230+
if ((long)( now - periodic_timer ) >= 0)
224231
{
225-
uip_timer_restart(&periodic_timer);
232+
periodic_timer = now + UIP_PERIODIC_TIMER;
233+
226234
for (int i = 0; i < UIP_CONNS; i++)
227235
{
228-
uip_periodic(i);
229-
// If the above function invocation resulted in data that
230-
// should be sent out on the Enc28J60Network, the global variable
231-
// uip_len is set to a value > 0.
232-
if (uip_len > 0)
233-
{
234-
uip_arp_out();
235-
network_send();
236-
}
236+
#endif
237+
uip_conn = &uip_conns[i];
238+
#if UIP_CLIENT_TIMER >= 0
239+
if (periodic)
240+
{
241+
#endif
242+
uip_process(UIP_TIMER);
243+
#if UIP_CLIENT_TIMER >= 0
237244
}
238-
245+
else
246+
{
247+
if ((long)( now - ((uip_userdata_t*)uip_conn->appstate)->timer) >= 0)
248+
uip_process(UIP_POLL_REQUEST);
249+
else
250+
continue;
251+
}
252+
#endif
253+
// If the above function invocation resulted in data that
254+
// should be sent out on the Enc28J60Network, the global variable
255+
// uip_len is set to a value > 0.
256+
if (uip_len > 0)
257+
{
258+
uip_arp_out();
259+
network_send();
260+
}
261+
}
262+
#if UIP_CLIENT_TIMER >= 0
263+
if (periodic)
264+
{
265+
periodic_timer = now + UIP_PERIODIC_TIMER;
266+
#endif
239267
#if UIP_UDP
240268
for (int i = 0; i < UIP_UDP_CONNS; i++)
241269
{
@@ -286,7 +314,7 @@ boolean UIPEthernetClass::network_send()
286314
}
287315

288316
void UIPEthernetClass::init(const uint8_t* mac) {
289-
uip_timer_set(&periodic_timer, CLOCK_SECOND / 4);
317+
periodic_timer = millis() + UIP_PERIODIC_TIMER;
290318

291319
Enc28J60Network::init((uint8_t*)mac);
292320
uip_seteth_addr(mac);

UIPEthernet/src/UIPEthernet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class UIPEthernetClass
9090
static IPAddress _dnsServerAddress;
9191
static DhcpClass* _dhcp;
9292

93-
static struct uip_timer periodic_timer;
93+
static unsigned long periodic_timer;
9494

9595
static void init(const uint8_t* mac);
9696
static void configure(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet);

UIPEthernet/src/utility/uipethernet-conf.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#define UIP_SOCKET_NUMPACKETS 5
66
#define UIP_CONF_MAX_CONNECTIONS 4
77

8-
/* for UDP */
8+
/* for UDP
9+
* set UIP_CONF_UDP to 0 to disable UDP (saves aprox. 5kb flash) */
910
#define UIP_CONF_UDP 1
1011
#define UIP_CONF_BROADCAST 1
1112
#define UIP_CONF_UDP_CONNS 4
@@ -18,4 +19,11 @@
1819
* if set to a number <= 0 connect will timeout when uIP does (which might be longer than you expect...) */
1920
#define UIP_CONNECT_TIMEOUT -1
2021

22+
/* periodic timer for uip (in ms) */
23+
#define UIP_PERIODIC_TIMER 250
24+
25+
/* timer to poll client for data after last write (in ms)
26+
* set to -1 to disable fast polling and rely on periodic only (saves 100 bytes flash) */
27+
#define UIP_CLIENT_TIMER 10
28+
2129
#endif

0 commit comments

Comments
 (0)