Add faster version code.

This commit is contained in:
Richard Barry 2008-11-16 15:13:40 +00:00
parent f7a168e184
commit 31606543da
7 changed files with 2060 additions and 1685 deletions

View File

@ -44,11 +44,11 @@
*
* $Id: timer.c,v 1.2 2006/06/12 08:00:30 adam Exp $
*/
#include "clock.h"
#include "uip_timer.h"
/*---------------------------------------------------------------------------*/
/**
* Set a timer.
*
@ -60,13 +60,14 @@
* \param interval The interval before the timer expires.
*
*/
void
timer_set(struct timer *t, clock_time_t interval)
void timer_set( struct timer *t, clock_time_t interval )
{
t->interval = interval;
t->start = clock_time();
}
/*---------------------------------------------------------------------------*/
/**
* Reset the timer with the same interval.
*
@ -80,12 +81,13 @@ timer_set(struct timer *t, clock_time_t interval)
*
* \sa timer_restart()
*/
void
timer_reset(struct timer *t)
void timer_reset( struct timer *t )
{
t->start += t->interval;
}
/*---------------------------------------------------------------------------*/
/**
* Restart the timer from the current point in time
*
@ -100,12 +102,13 @@ timer_reset(struct timer *t)
*
* \sa timer_reset()
*/
void
timer_restart(struct timer *t)
void timer_restart( struct timer *t )
{
t->start = clock_time();
}
/*---------------------------------------------------------------------------*/
/**
* Check if a timer has expired.
*
@ -117,11 +120,11 @@ timer_restart(struct timer *t)
* \return Non-zero if the timer has expired, zero otherwise.
*
*/
int
timer_expired(struct timer *t)
int timer_expired( struct timer *t )
{
return( clock_time_t ) ( clock_time() - t->start ) >= ( clock_time_t ) t->interval;
}
/*---------------------------------------------------------------------------*/
/** @} */

View File

@ -32,7 +32,6 @@
*
* $Id: uip-split.c,v 1.2 2006/06/12 08:00:30 adam Exp $
*/
#include <string.h>
#include "uip-split.h"
@ -40,25 +39,23 @@
#include "uip-fw.h"
#include "uip_arch.h"
#define BUF ( ( struct uip_tcpip_hdr * ) &uip_buf[UIP_LLH_LEN] )
/*-----------------------------------------------------------------------------*/
void
uip_split_output(void)
void uip_split_output( void )
{
u16_t tcplen, len1, len2;
/* We only try to split maximum sized TCP segments. */
if(BUF->proto == UIP_PROTO_TCP &&
uip_len == UIP_BUFSIZE - UIP_LLH_LEN) {
if( BUF->proto == UIP_PROTO_TCP && uip_len == UIP_BUFSIZE - UIP_LLH_LEN )
{
tcplen = uip_len - UIP_TCPIP_HLEN;
/* Split the segment in two. If the original packet length was
odd, we make the second packet one byte larger. */
len1 = len2 = tcplen / 2;
if(len1 + len2 < tcplen) {
if( len1 + len2 < tcplen )
{
++len2;
}
@ -66,6 +63,7 @@ uip_split_output(void)
field of the IP header and updating the checksums. */
uip_len = len1 + UIP_TCPIP_HLEN;
#if UIP_CONF_IPV6
/* For IPv6, the IP length field does not include the IPv6 IP header
length. */
BUF->len[0] = ( (uip_len - UIP_IPH_LEN) >> 8 );
@ -80,13 +78,16 @@ uip_split_output(void)
BUF->tcpchksum = ~( uip_tcpchksum() );
#if !UIP_CONF_IPV6
/* Recalculate the IP checksum. */
BUF->ipchksum = 0;
BUF->ipchksum = ~( uip_ipchksum() );
#endif /* UIP_CONF_IPV6 */
/* Transmit the first packet. */
/* uip_fw_output();*/
// tcpip_output();
/* Now, create the second packet. To do this, it is not enough to
@ -96,6 +97,7 @@ uip_split_output(void)
packet (len1). */
uip_len = len2 + UIP_TCPIP_HLEN;
#if UIP_CONF_IPV6
/* For IPv6, the IP length field does not include the IPv6 IP header
length. */
BUF->len[0] = ( (uip_len - UIP_IPH_LEN) >> 8 );
@ -119,18 +121,24 @@ uip_split_output(void)
BUF->tcpchksum = ~( uip_tcpchksum() );
#if !UIP_CONF_IPV6
/* Recalculate the IP checksum. */
BUF->ipchksum = 0;
BUF->ipchksum = ~( uip_ipchksum() );
#endif /* UIP_CONF_IPV6 */
/* Transmit the second packet. */
/* uip_fw_output();*/
// tcpip_output();
} else {
}
else
{
/* uip_fw_output();*/
// tcpip_output();
}
}
}
/*-----------------------------------------------------------------------------*/

File diff suppressed because it is too large Load Diff

View File

@ -1631,6 +1631,10 @@ u16_t uip_tcpchksum(void);
*/
u16_t uip_udpchksum(void);
/**
* Work out the fasted way of sending the data to the low level driver.
*/
int uip_fast_send( int xARP );
#endif /* __UIP_H__ */

View File

@ -57,8 +57,6 @@
* $Id: uip_arp.c,v 1.8 2006/06/02 23:36:21 adam Exp $
*
*/
#include "uip_arp.h"
#include <string.h>
@ -66,8 +64,8 @@
#ifdef __ICCARM__
#pragma pack( 1 )
#endif
struct arp_hdr {
struct arp_hdr
{
struct uip_eth_hdr ethhdr;
u16_t hwtype;
u16_t protocol;
@ -83,43 +81,35 @@ struct arp_hdr {
#ifdef __ICCARM__
#pragma pack()
#endif
#ifdef __ICCARM__
#pragma pack( 1 )
#endif
struct ethip_hdr {
struct ethip_hdr
{
struct uip_eth_hdr ethhdr;
/* IP header. */
u8_t vhl,
tos,
len[2],
ipid[2],
ipoffset[2],
ttl,
proto;
u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
u16_t ipchksum;
u16_t srcipaddr[2],
destipaddr[2];
u16_t srcipaddr[2], destipaddr[2];
} PACK_STRUCT_END;
#ifdef __ICCARM__
#pragma pack()
#endif
#define ARP_REQUEST 1
#define ARP_REPLY 2
#define ARP_HWTYPE_ETH 1
struct arp_entry {
struct arp_entry
{
u16_t ipaddr[2];
struct uip_eth_addr ethaddr;
u8_t time;
};
static const struct uip_eth_addr broadcast_ethaddr =
{{0xff,0xff,0xff,0xff,0xff,0xff}};
static const struct uip_eth_addr broadcast_ethaddr = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
static const u16_t broadcast_ipaddr[2] = { 0xffff, 0xffff };
static struct arp_entry arp_table[UIP_ARPTAB_SIZE];
@ -131,20 +121,25 @@ static u8_t tmpage;
#define BUF ( ( struct arp_hdr * ) &uip_buf[0] )
#define IPBUF ( ( struct ethip_hdr * ) &uip_buf[0] )
/*-----------------------------------------------------------------------------------*/
/**
* Initialize the ARP module.
*
*/
/*-----------------------------------------------------------------------------------*/
void
uip_arp_init(void)
void uip_arp_init( void )
{
for( i = 0; i < UIP_ARPTAB_SIZE; ++i )
{
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
memset( arp_table[i].ipaddr, 0, 4 );
}
}
/*-----------------------------------------------------------------------------------*/
/**
* Periodic ARP processing function.
*
@ -153,42 +148,42 @@ uip_arp_init(void)
* is 10 seconds between the calls.
*
*/
/*-----------------------------------------------------------------------------------*/
void
uip_arp_timer(void)
void uip_arp_timer( void )
{
struct arp_entry *tabptr;
++arptime;
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
for( i = 0; i < UIP_ARPTAB_SIZE; ++i )
{
tabptr = &arp_table[i];
if((tabptr->ipaddr[0] | tabptr->ipaddr[1]) != 0 &&
arptime - tabptr->time >= UIP_ARP_MAXAGE) {
if( (tabptr->ipaddr[0] | tabptr->ipaddr[1]) != 0 && arptime - tabptr->time >= UIP_ARP_MAXAGE )
{
memset( tabptr->ipaddr, 0, 4 );
}
}
}
/*-----------------------------------------------------------------------------------*/
static void
uip_arp_update(u16_t *ipaddr, struct uip_eth_addr *ethaddr)
static void uip_arp_update( u16_t *ipaddr, struct uip_eth_addr *ethaddr )
{
register struct arp_entry *tabptr;
/* Walk through the ARP mapping table and try to find an entry to
update. If none is found, the IP -> MAC address mapping is
inserted in the ARP table. */
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
for( i = 0; i < UIP_ARPTAB_SIZE; ++i )
{
tabptr = &arp_table[i];
/* Only check those entries that are actually in use. */
if(tabptr->ipaddr[0] != 0 &&
tabptr->ipaddr[1] != 0) {
/* Only check those entries that are actually in use. */
if( tabptr->ipaddr[0] != 0 && tabptr->ipaddr[1] != 0 )
{
/* Check if the source IP address of the incoming packet matches
the IP address in this ARP table entry. */
if(ipaddr[0] == tabptr->ipaddr[0] &&
ipaddr[1] == tabptr->ipaddr[1]) {
if( ipaddr[0] == tabptr->ipaddr[0] && ipaddr[1] == tabptr->ipaddr[1] )
{
/* An old entry found, update this and return. */
memcpy( tabptr->ethaddr.addr, ethaddr->addr, 6 );
tabptr->time = arptime;
@ -202,26 +197,31 @@ uip_arp_update(u16_t *ipaddr, struct uip_eth_addr *ethaddr)
create one. */
/* First, we try to find an unused entry in the ARP table. */
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
for( i = 0; i < UIP_ARPTAB_SIZE; ++i )
{
tabptr = &arp_table[i];
if(tabptr->ipaddr[0] == 0 &&
tabptr->ipaddr[1] == 0) {
if( tabptr->ipaddr[0] == 0 && tabptr->ipaddr[1] == 0 )
{
break;
}
}
/* If no unused entry is found, we try to find the oldest entry and
throw it away. */
if(i == UIP_ARPTAB_SIZE) {
if( i == UIP_ARPTAB_SIZE )
{
tmpage = 0;
c = 0;
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
for( i = 0; i < UIP_ARPTAB_SIZE; ++i )
{
tabptr = &arp_table[i];
if(arptime - tabptr->time > tmpage) {
if( arptime - tabptr->time > tmpage )
{
tmpage = arptime - tabptr->time;
c = i;
}
}
i = c;
tabptr = &arp_table[i];
}
@ -232,7 +232,9 @@ uip_arp_update(u16_t *ipaddr, struct uip_eth_addr *ethaddr)
memcpy( tabptr->ethaddr.addr, ethaddr->addr, 6 );
tabptr->time = arptime;
}
/*-----------------------------------------------------------------------------------*/
/**
* ARP processing for incoming IP packets
*
@ -245,29 +247,34 @@ uip_arp_update(u16_t *ipaddr, struct uip_eth_addr *ethaddr)
* in the uip_buf[] buffer, and the length of the packet in the global
* variable uip_len.
*/
/*-----------------------------------------------------------------------------------*/
#if 1
void
uip_arp_ipin(void)
void uip_arp_ipin( void )
{
uip_len -= sizeof( struct uip_eth_hdr );
/* Only insert/update an entry if the source IP address of the
incoming IP packet comes from a host on the local network. */
if((IPBUF->srcipaddr[0] & uip_netmask[0]) !=
(uip_hostaddr[0] & uip_netmask[0])) {
if( (IPBUF->srcipaddr[0] & uip_netmask[0]) != (uip_hostaddr[0] & uip_netmask[0]) )
{
return;
}
if((IPBUF->srcipaddr[1] & uip_netmask[1]) !=
(uip_hostaddr[1] & uip_netmask[1])) {
if( (IPBUF->srcipaddr[1] & uip_netmask[1]) != (uip_hostaddr[1] & uip_netmask[1]) )
{
return;
}
uip_arp_update( IPBUF->srcipaddr, &(IPBUF->ethhdr.src) );
return;
}
#endif /* 0 */
/*-----------------------------------------------------------------------------------*/
/**
* ARP processing for incoming ARP packets.
*
@ -289,22 +296,25 @@ uip_arp_ipin(void)
* header in the uip_buf[] buffer, and the length of the packet in the
* global variable uip_len.
*/
/*-----------------------------------------------------------------------------------*/
void
uip_arp_arpin(void)
{
if(uip_len < sizeof(struct arp_hdr)) {
/*-----------------------------------------------------------------------------------*/
void uip_arp_arpin( void )
{
if( uip_len < sizeof(struct arp_hdr) )
{
uip_len = 0;
return;
}
uip_len = 0;
switch(BUF->opcode) {
switch( BUF->opcode )
{
case HTONS( ARP_REQUEST ):
/* ARP request. If it asked for our address, we send out a
reply. */
if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) {
if( uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr) )
{
/* First, we register the one who made the request in our ARP
table, since it is likely that we will do more communication
with this host in the future. */
@ -326,19 +336,25 @@ uip_arp_arpin(void)
BUF->ethhdr.type = HTONS( UIP_ETHTYPE_ARP );
uip_len = sizeof( struct arp_hdr );
}
break;
case HTONS( ARP_REPLY ):
/* ARP reply. We insert or update the ARP table if it was meant
for us. */
if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) {
if( uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr) )
{
uip_arp_update( BUF->sipaddr, &BUF->shwaddr );
}
break;
}
return;
}
/*-----------------------------------------------------------------------------------*/
/**
* Prepend Ethernet header to an outbound IP packet and see if we need
* to send out an ARP request.
@ -365,9 +381,9 @@ uip_arp_arpin(void)
* buffer, and the length of the packet is in the global variable
* uip_len.
*/
/*-----------------------------------------------------------------------------------*/
void
uip_arp_out(void)
void uip_arp_out( void )
{
struct arp_entry *tabptr;
@ -379,31 +395,39 @@ uip_arp_out(void)
packet with an ARP request for the IP address. */
/* First check if destination is a local broadcast. */
if(uip_ipaddr_cmp(IPBUF->destipaddr, broadcast_ipaddr)) {
if( uip_ipaddr_cmp(IPBUF->destipaddr, broadcast_ipaddr) )
{
memcpy( IPBUF->ethhdr.dest.addr, broadcast_ethaddr.addr, 6 );
} else {
}
else
{
/* Check if the destination address is on the local network. */
if(!uip_ipaddr_maskcmp(IPBUF->destipaddr, uip_hostaddr, uip_netmask)) {
if( !uip_ipaddr_maskcmp(IPBUF->destipaddr, uip_hostaddr, uip_netmask) )
{
/* Destination address was not on the local network, so we need to
use the default router's IP address instead of the destination
address when determining the MAC address. */
uip_ipaddr_copy( ipaddr, uip_draddr );
} else {
}
else
{
/* Else, we use the destination IP address. */
uip_ipaddr_copy( ipaddr, IPBUF->destipaddr );
}
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
for( i = 0; i < UIP_ARPTAB_SIZE; ++i )
{
tabptr = &arp_table[i];
if(uip_ipaddr_cmp(ipaddr, tabptr->ipaddr)) {
if( uip_ipaddr_cmp(ipaddr, tabptr->ipaddr) )
{
break;
}
}
if(i == UIP_ARPTAB_SIZE) {
if( i == UIP_ARPTAB_SIZE )
{
/* The destination address was not in our ARP table, so we
overwrite the IP packet with an ARP request. */
memset( BUF->ethhdr.dest.addr, 0xff, 6 );
memset( BUF->dhwaddr.addr, 0x00, 6 );
memcpy( BUF->ethhdr.src.addr, uip_ethaddr.addr, 6 );
@ -427,13 +451,16 @@ uip_arp_out(void)
/* Build an ethernet header. */
memcpy( IPBUF->ethhdr.dest.addr, tabptr->ethaddr.addr, 6 );
}
memcpy( IPBUF->ethhdr.src.addr, uip_ethaddr.addr, 6 );
IPBUF->ethhdr.type = HTONS( UIP_ETHTYPE_IP );
uip_len += sizeof( struct uip_eth_hdr );
}
/*-----------------------------------------------------------------------------------*/
/** @} */
/** @} */

View File

@ -32,15 +32,11 @@
* $Id: uiplib.c,v 1.2 2006/06/12 08:00:31 adam Exp $
*
*/
#include "uip.h"
#include "uiplib.h"
/*-----------------------------------------------------------------------------------*/
unsigned char
uiplib_ipaddrconv(char *addrstr, unsigned char *ipaddr)
unsigned char uiplib_ipaddrconv( char *addrstr, unsigned char *ipaddr )
{
unsigned char tmp;
char c;
@ -48,26 +44,37 @@ uiplib_ipaddrconv(char *addrstr, unsigned char *ipaddr)
tmp = 0;
for(i = 0; i < 4; ++i) {
for( i = 0; i < 4; ++i )
{
j = 0;
do {
do
{
c = *addrstr;
++j;
if(j > 4) {
if( j > 4 )
{
return 0;
}
if(c == '.' || c == 0) {
if( c == '.' || c == 0 )
{
*ipaddr = tmp;
++ipaddr;
tmp = 0;
} else if(c >= '0' && c <= '9') {
}
else if( c >= '0' && c <= '9' )
{
tmp = ( tmp * 10 ) + ( c - '0' );
} else {
}
else
{
return 0;
}
++addrstr;
} while( c != '.' && c != 0 );
}
return 1;
}