Update UIPEthernet library

This commit is contained in:
Henrik Ekblad
2014-10-21 23:44:52 +02:00
parent f71ed97aaa
commit d5ca838371
8 changed files with 106 additions and 48 deletions
+44 -15
View File
@@ -45,7 +45,7 @@ uint8_t UIPEthernetClass::packetstate(0);
IPAddress UIPEthernetClass::_dnsServerAddress;
DhcpClass* UIPEthernetClass::_dhcp(NULL);
struct uip_timer UIPEthernetClass::periodic_timer;
unsigned long UIPEthernetClass::periodic_timer;
// Because uIP isn't encapsulated within a class we have to use global
// variables, so we can only have one TCP/IP stack per program.
@@ -183,7 +183,7 @@ UIPEthernetClass::tick()
Enc28J60Network::readPacket(in_packet,0,(uint8_t*)uip_buf,UIP_BUFSIZE);
if (ETH_HDR ->type == HTONS(UIP_ETHTYPE_IP))
{
uip_packet = in_packet;
uip_packet = in_packet; //required for upper_layer_checksum of in_packet!
#ifdef UIPETHERNET_DEBUG
Serial.print(F("readPacket type IP, uip_len: "));
Serial.println(uip_len);
@@ -220,22 +220,50 @@ UIPEthernetClass::tick()
}
}
if (uip_timer_expired(&periodic_timer))
unsigned long now = millis();
#if UIP_CLIENT_TIMER >= 0
boolean periodic = (long)( now - periodic_timer ) >= 0;
for (int i = 0; i < UIP_CONNS; i++)
{
uip_timer_restart(&periodic_timer);
#else
if ((long)( now - periodic_timer ) >= 0)
{
periodic_timer = now + UIP_PERIODIC_TIMER;
for (int i = 0; i < UIP_CONNS; i++)
{
uip_periodic(i);
// If the above function invocation resulted in data that
// should be sent out on the Enc28J60Network, the global variable
// uip_len is set to a value > 0.
if (uip_len > 0)
{
uip_arp_out();
network_send();
}
#endif
uip_conn = &uip_conns[i];
#if UIP_CLIENT_TIMER >= 0
if (periodic)
{
#endif
uip_process(UIP_TIMER);
#if UIP_CLIENT_TIMER >= 0
}
else
{
if ((long)( now - ((uip_userdata_t*)uip_conn->appstate)->timer) >= 0)
uip_process(UIP_POLL_REQUEST);
else
continue;
}
#endif
// If the above function invocation resulted in data that
// should be sent out on the Enc28J60Network, the global variable
// uip_len is set to a value > 0.
if (uip_len > 0)
{
uip_arp_out();
network_send();
}
}
#if UIP_CLIENT_TIMER >= 0
if (periodic)
{
periodic_timer = now + UIP_PERIODIC_TIMER;
#endif
#if UIP_UDP
for (int i = 0; i < UIP_UDP_CONNS; i++)
{
@@ -263,6 +291,7 @@ boolean UIPEthernetClass::network_send()
Serial.println(uip_hdrlen);
#endif
Enc28J60Network::writePacket(uip_packet,0,uip_buf,uip_hdrlen);
packetstate &= ~ UIPETHERNET_SENDPACKET;
goto sendandfree;
}
uip_packet = Enc28J60Network::allocBlock(uip_len);
@@ -286,7 +315,7 @@ sendandfree:
}
void UIPEthernetClass::init(const uint8_t* mac) {
uip_timer_set(&periodic_timer, CLOCK_SECOND / 4);
periodic_timer = millis() + UIP_PERIODIC_TIMER;
Enc28J60Network::init((uint8_t*)mac);
uip_seteth_addr(mac);