diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-11-07 22:54:51 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-11-07 22:54:51 +0000 |
commit | fae6085d5734cb000bcd6a40eb0b5bd369772d4f (patch) | |
tree | 22b9afe6128acf0e2e33e1ce70f10724e7cc914c /nuttx/net | |
parent | a97e1cc4d1195f56bc10acbcd469bb71e016476c (diff) | |
download | px4-nuttx-fae6085d5734cb000bcd6a40eb0b5bd369772d4f.tar.gz px4-nuttx-fae6085d5734cb000bcd6a40eb0b5bd369772d4f.tar.bz2 px4-nuttx-fae6085d5734cb000bcd6a40eb0b5bd369772d4f.zip |
Handle varialble length polling intervals; fix bug of last checkin
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@376 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/net')
-rw-r--r-- | nuttx/net/net-arptimer.c | 2 | ||||
-rw-r--r-- | nuttx/net/uip/uip-initialize.c | 2 | ||||
-rw-r--r-- | nuttx/net/uip/uip-input.c | 6 | ||||
-rw-r--r-- | nuttx/net/uip/uip-internal.h | 4 | ||||
-rw-r--r-- | nuttx/net/uip/uip-poll.c | 225 | ||||
-rw-r--r-- | nuttx/net/uip/uip-tcppoll.c | 3 | ||||
-rw-r--r-- | nuttx/net/uip/uip-tcptimer.c | 51 | ||||
-rw-r--r-- | nuttx/net/uip/uip-udppoll.c | 1 |
8 files changed, 217 insertions, 77 deletions
diff --git a/nuttx/net/net-arptimer.c b/nuttx/net/net-arptimer.c index a83406905..bbb4ef6cb 100644 --- a/nuttx/net/net-arptimer.c +++ b/nuttx/net/net-arptimer.c @@ -87,8 +87,6 @@ static WDOG_ID g_arptimer; /* ARP timer */ static void arptimer_poll(int argc, uint32 arg, ...) { - dbg("ARP timer expiration\n"); - /* Call the ARP timer function every 10 seconds. */ uip_arp_timer(); diff --git a/nuttx/net/uip/uip-initialize.c b/nuttx/net/uip/uip-initialize.c index 00a01ef6a..42778d2c1 100644 --- a/nuttx/net/uip/uip-initialize.c +++ b/nuttx/net/uip/uip-initialize.c @@ -98,6 +98,8 @@ const uip_ipaddr_t all_zeroes_addr = {0x00000000}; #endif +/* Reassembly timer (units: deci-seconds) */ + #if UIP_REASSEMBLY && !defined(CONFIG_NET_IPv6) uint8 uip_reasstmr; #endif diff --git a/nuttx/net/uip/uip-input.c b/nuttx/net/uip/uip-input.c index de8223640..660927d38 100644 --- a/nuttx/net/uip/uip-input.c +++ b/nuttx/net/uip/uip-input.c @@ -147,15 +147,15 @@ static uint8 uip_reass(void) uint16 offset, len; uint16 i; - /* If ip_reasstmr is zero, no packet is present in the buffer, so we + /* If uip_reasstmr is zero, no packet is present in the buffer, so we * write the IP header of the fragment into the reassembly * buffer. The timer is updated with the maximum age. */ - if (uip_reasstmr == 0) + if (!uip_reasstmr) { memcpy(uip_reassbuf, &BUF->vhl, UIP_IPH_LEN); - uip_reasstmr = UIP_REASS_MAXAGE; + uip_reasstmr = UIP_REASS_MAXAGE; uip_reassflags = 0; /* Clear the bitmap. */ diff --git a/nuttx/net/uip/uip-internal.h b/nuttx/net/uip/uip-internal.h index d1f141a30..c463d6ae0 100644 --- a/nuttx/net/uip/uip-internal.h +++ b/nuttx/net/uip/uip-internal.h @@ -101,6 +101,8 @@ extern const uip_ipaddr_t all_zeroes_addr; extern uint16 g_ipid; +/* Reassembly timer (units: deci-seconds) */ + #if UIP_REASSEMBLY && !defined(CONFIG_NET_IPv6) extern uint8 uip_reasstmr; #endif @@ -131,7 +133,7 @@ EXTERN void uip_tcppoll(struct uip_driver_s *dev, struct uip_conn *conn); /* Defined in uip-udptimer.c ************************************************/ -EXTERN void uip_udptimer(struct uip_driver_s *dev, struct uip_conn *conn); +EXTERN void uip_tcptimer(struct uip_driver_s *dev, struct uip_conn *conn, int hsec); /* Defined in uip_listen.c **************************************************/ diff --git a/nuttx/net/uip/uip-poll.c b/nuttx/net/uip/uip-poll.c index 0ac8fac97..d80b77995 100644 --- a/nuttx/net/uip/uip-poll.c +++ b/nuttx/net/uip/uip-poll.c @@ -59,6 +59,119 @@ ****************************************************************************/ /**************************************************************************** + * Function: uip_polludpconnections + * + * Description: + * Poll all UDP connections for available packets to send. + * + * Assumptions: + * This function is called from the CAN device driver and may be called from + * the timer interrupt/watchdog handle level. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_UDP +static int uip_polludpconnections(struct uip_driver_s *dev, + uip_poll_callback_t callback) +{ + struct uip_udp_conn *udp_conn = NULL; + int bstop = 0; + + /* Traverse all of the allocated UDP connections and perform the poll action */ + + while (!bstop && (udp_conn = uip_nextudpconn(udp_conn))) + { + /* Perform the UDP TX poll */ + + uip_udp_conn = udp_conn; + uip_udppoll(dev, udp_conn); + + /* Call back into the driver */ + + bstop = callback(dev); + } + + uip_udp_conn = NULL; + return bstop; +} +#else +# define uip_polludpconnections(dev,callback) (0) +#endif /* CONFIG_NET_UDP */ + +/**************************************************************************** + * Function: uip_polltcpconnections + * + * Description: + * Poll all UDP connections for available packets to send. + * + * Assumptions: + * This function is called from the CAN device driver and may be called from + * the timer interrupt/watchdog handle level. + * + ****************************************************************************/ + +static inline int uip_polltcpconnections(struct uip_driver_s *dev, + uip_poll_callback_t callback) +{ + struct uip_conn *conn = NULL; + int bstop = 0; + + /* Traverse all of the active TCP connections and perform the poll action */ + + while (!bstop && (conn = uip_nexttcpconn(conn))) + { + /* Perform the TCP TX poll */ + + uip_conn = conn; + uip_tcppoll(dev, conn); + + /* Call back into the driver */ + + bstop = callback(dev); + } + + uip_conn = NULL; + return bstop; +} + +/**************************************************************************** + * Function: uip_polltcptimer + * + * Description: + * The TCP timer has expired. Update TCP timing state in each active, + * TCP connection. + * + * Assumptions: + * This function is called from the CAN device driver and may be called from + * the timer interrupt/watchdog handle level. + * + ****************************************************************************/ + +static inline int uip_polltcptimer(struct uip_driver_s *dev, + uip_poll_callback_t callback, int hsec) +{ + struct uip_conn *conn = NULL; + int bstop = 0; + + /* Traverse all of the active TCP connections and perform the poll action */ + + while (!bstop && (conn = uip_nexttcpconn(conn))) + { + /* Perform the TCP timer poll */ + + uip_conn = conn; + uip_tcptimer(dev, conn, hsec); + + /* Call back into the driver */ + + bstop = callback(dev); + } + + uip_conn = NULL; + return bstop; +} + +/**************************************************************************** * Public Functions ****************************************************************************/ @@ -67,21 +180,18 @@ * * Description: * This function will traverse each active uIP connection structure and - * perform uip_interrupt with the specified event. After each polling each - * active uIP connection structure, this function will call the provided - * callback function if the poll resulted in new data to be send. The poll - * will continue until all connections have been polled or until the user- - * suplied function returns a non-zero value (which is would do only if - * it cannot accept further write data). + * will perform TCP and UDP polling operations. uip_poll() may be called + * asychronously with the network drvier can accept another outgoing packet. * - * This function should be called periodically with event == UIP_DRV_TIMER - * to perform period TCP processing. This function may also be called - * with UIP_DRV_POLL obtain queue TX data. + * This function will call the provided callback function for every active + * connection. Polling will continue until all connections have been polled + * or until the user-suplied function returns a non-zero value (which it + * should do only if it cannot accept further write data). * * When the callback function is called, there may be an outbound packet * waiting for service in the uIP packet buffer, and if so the d_len field - * is set to a value larger than zero. The device driver should be called to - * send out the packet. + * is set to a value larger than zero. The device driver should then send + * out the packet. * * Assumptions: * This function is called from the CAN device driver and may be called from @@ -89,58 +199,71 @@ * ****************************************************************************/ -int uip_poll(struct uip_driver_s *dev, uip_poll_callback_t callback, int event) +int uip_poll(struct uip_driver_s *dev, uip_poll_callback_t callback) { - struct uip_conn *conn; -#ifdef CONFIG_NET_UDP - struct uip_udp_conn *udp_conn; -#endif - irqstate_t flags; + int bstop; - /* Interrupts must be disabled while traversing the active connection list */ + /* Traverse all of the active TCP connections and perform the poll action */ - flags = irqsave(); + bstop = uip_polltcpconnections(dev, callback); + if (!bstop) + { + /* Traverse all of the allocated UDP connections and perform the poll action */ - /* Traverse all of the active TCP connections and perform the poll action */ + bstop = uip_polludpconnections(dev, callback); + } - conn = NULL; - while ((conn = uip_nexttcpconn(conn))) + return bstop; +} + +/**************************************************************************** + * Function: uip_timer + * + * Description: + * These function will traverse each active uIP connection structure and + * perform TCP timer operations (and UDP polling operations). The CAN + * driver MUST implement logic to periodically call uip_timer(). + * + * This function will call the provided callback function for every active + * connection. Polling will continue until all connections have been polled + * or until the user-suplied function returns a non-zero value (which it + * should do only if it cannot accept further write data). + * + * When the callback function is called, there may be an outbound packet + * waiting for service in the uIP packet buffer, and if so the d_len field + * is set to a value larger than zero. The device driver should then send + * out the packet. + * + * Assumptions: + * This function is called from the CAN device driver and may be called from + * the timer interrupt/watchdog handle level. + * + ****************************************************************************/ + +int uip_timer(struct uip_driver_s *dev, uip_poll_callback_t callback, int hsec) +{ + int bstop; + + /* Increment the timer used by the IP reassembly logic */ + +#if UIP_REASSEMBLY + if (uip_reasstmr != 0 && uip_reasstmr < UIP_REASS_MAXAGE) { - uip_conn = conn; - if (event == UIP_DRV_POLL) - { - uip_tcppoll(dev, conn); - } - else - { - uip_tcptimer(dev, conn); - } - - if (callback(dev)) - { - irqrestore(flags); - return 1; - } + uip_reasstmr += hsec; } - uip_conn = NULL; +#endif /* UIP_REASSEMBLY */ -#ifdef CONFIG_NET_UDP - /* Traverse all of the allocated UDP connections and perform a poll action */ + /* Traverse all of the active TCP connections and perform the timer action */ - udp_conn = NULL; - while ((udp_conn = uip_nextudpconn(udp_conn))) + bstop = uip_polltcptimer(dev, callback, hsec); + if (!bstop) { - uip_udppoll(dev, udp_conn); - if (callback(dev)) - { - irqrestore(flags); - return 1; - } + /* Traverse all of the allocated UDP connections and perform the poll action */ + + bstop = uip_polludpconnections(dev, callback); } -#endif /* CONFIG_NET_UDP */ - irqrestore(flags); - return 0; + return bstop; } #endif /* CONFIG_NET */ diff --git a/nuttx/net/uip/uip-tcppoll.c b/nuttx/net/uip/uip-tcppoll.c index 625b91931..f2deac0fa 100644 --- a/nuttx/net/uip/uip-tcppoll.c +++ b/nuttx/net/uip/uip-tcppoll.c @@ -106,6 +106,9 @@ void uip_tcppoll(struct uip_driver_s *dev, struct uip_conn *conn) dev->d_snddata = &dev->d_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN]; dev->d_appdata = &dev->d_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN]; + dev->d_len = 0; + dev->d_sndlen = 0; + /* Perfom the callback */ uip_flags = UIP_POLL; diff --git a/nuttx/net/uip/uip-tcptimer.c b/nuttx/net/uip/uip-tcptimer.c index 5b248f358..66210e246 100644 --- a/nuttx/net/uip/uip-tcptimer.c +++ b/nuttx/net/uip/uip-tcptimer.c @@ -81,8 +81,9 @@ * Handle a TCP timer expiration for the provided TCP connection * * Parameters: - * dev - The device driver structure to use in the send operation - * conn - The TCP "connection" to poll for TX data + * dev - The device driver structure to use in the send operation + * conn - The TCP "connection" to poll for TX data + * hsed - The polling interval in halves of a second * * Return: * None @@ -92,27 +93,18 @@ * ****************************************************************************/ -void uip_tcptimer(struct uip_driver_s *dev, struct uip_conn *conn) +void uip_tcptimer(struct uip_driver_s *dev, struct uip_conn *conn, int hsec) { dev->d_snddata = &dev->d_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN]; dev->d_appdata = &dev->d_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN]; - /* Increment the timer used by the reassembly logic */ - -#if UIP_REASSEMBLY - if (uip_reasstmr != 0) - { - uip_reasstmr++; - } -#endif /* UIP_REASSEMBLY */ - /* Increase the TCP sequence number */ uip_tcpnextsequence(); /* Reset the length variables. */ - dev->d_len = 0; + dev->d_len = 0; dev->d_sndlen = 0; /* Check if the connection is in a state in which we simply wait @@ -123,8 +115,10 @@ void uip_tcptimer(struct uip_driver_s *dev, struct uip_conn *conn) if (conn->tcpstateflags == UIP_TIME_WAIT || conn->tcpstateflags == UIP_FIN_WAIT_2) { - (conn->timer)++; - if (conn->timer == UIP_TIME_WAIT_TIMEOUT) + /* Increment the connection timer */ + + (conn->timer) += hsec; + if (conn->timer >= UIP_TIME_WAIT_TIMEOUT) { conn->tcpstateflags = UIP_CLOSED; vdbg("TCP state: UIP_CLOSED\n"); @@ -132,15 +126,29 @@ void uip_tcptimer(struct uip_driver_s *dev, struct uip_conn *conn) } else if (conn->tcpstateflags != UIP_CLOSED) { - /* If the connection has outstanding data, we increase the - * connection's timer and see if it has reached the RTO value - * in which case we retransmit. + /* If the connection has outstanding data, we increase the connection's + * timer and see if it has reached the RTO value in which case we + * retransmit. */ if (uip_outstanding(conn)) { - if (conn->timer-- == 0) + /* The connection has outstanding data */ + + if (conn->timer > hsec) + { + /* Will not yet decrement to zero */ + + conn->timer -= hsec; + } + else { + /* Will decrement to zero */ + + conn->timer = 0; + + /* Should we close the connection? */ + if (conn->nrtx == UIP_MAXRTX || ((conn->tcpstateflags == UIP_SYN_SENT || conn->tcpstateflags == UIP_SYN_RCVD) && @@ -166,7 +174,7 @@ void uip_tcptimer(struct uip_driver_s *dev, struct uip_conn *conn) /* Exponential backoff. */ conn->timer = UIP_RTO << (conn->nrtx > 4 ? 4: conn->nrtx); - ++(conn->nrtx); + (conn->nrtx)++; /* Ok, so we need to retransmit. We do this differently * depending on which state we are in. In ESTABLISHED, we @@ -216,6 +224,9 @@ void uip_tcptimer(struct uip_driver_s *dev, struct uip_conn *conn) } } } + + /* The connection does not have outstanding data */ + else if ((conn->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED) { /* If there was no need for a retransmission, we poll the diff --git a/nuttx/net/uip/uip-udppoll.c b/nuttx/net/uip/uip-udppoll.c index 209d4e2ae..aa5a205bc 100644 --- a/nuttx/net/uip/uip-udppoll.c +++ b/nuttx/net/uip/uip-udppoll.c @@ -105,6 +105,7 @@ void uip_udppoll(struct uip_driver_s *dev, struct uip_udp_conn *conn) dev->d_appdata = &dev->d_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN]; dev->d_snddata = &dev->d_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN]; + dev->d_len = 0; dev->d_sndlen = 0; |