mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 07:12:54 +08:00
Add SLIP test configuration
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3371 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
+26
-52
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* drivers/net/slip.c
|
||||
*
|
||||
* Copyright (C) 2010 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Reference: RFC 1055
|
||||
@@ -60,7 +60,6 @@
|
||||
#include <nuttx/net.h>
|
||||
|
||||
#include <net/uip/uip.h>
|
||||
#include <net/uip/uip-arp.h>
|
||||
#include <net/uip/uip-arch.h>
|
||||
|
||||
#if defined(CONFIG_NET) && defined(CONFIG_NET_SLIP)
|
||||
@@ -117,10 +116,6 @@
|
||||
# define SLIP_STAT(p,f)
|
||||
#endif
|
||||
|
||||
/* This is a helper pointer for accessing the contents of the Ethernet header */
|
||||
|
||||
#define BUF ((struct uip_eth_hdr *)priv->dev.d_buf)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
@@ -131,10 +126,7 @@
|
||||
struct slip_statistics_s
|
||||
{
|
||||
uint32_t transmitted; /* Number of packets transmitted */
|
||||
/* Number of packets received is the sum of: */
|
||||
uint32_t rxip; /* Number of IP packets received */
|
||||
uint32_t rxarp; /* + Number of ARP packets received */
|
||||
uint32_t rxproto; /* + Number of unsupported packets received */
|
||||
uint32_t received /* Number of packets received */
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -185,11 +177,11 @@ static inline void slip_putc(FAR struct slip_driver_s *priv, int ch);
|
||||
static int slip_transmit(FAR struct slip_driver_s *priv);
|
||||
static int slip_uiptxpoll(struct uip_driver_s *dev);
|
||||
|
||||
/* Interrupt handling */
|
||||
/* Packet receiver task */
|
||||
|
||||
static inline int slip_getc(FAR struct slip_driver_s *priv);
|
||||
static inline void slip_readpacket(FAR struct slip_driver_s *priv);
|
||||
static void slip_receive(FAR struct slip_driver_s *priv);
|
||||
static inline void slip_receive(FAR struct slip_driver_s *priv);
|
||||
static int slip_rxtask(int argc, char *argv[]);
|
||||
|
||||
/* Watchdog timer expirations */
|
||||
@@ -306,6 +298,7 @@ static int slip_transmit(FAR struct slip_driver_s *priv)
|
||||
|
||||
/* Increment statistics */
|
||||
|
||||
nvdbg("Sending packet size %d\n", priv->dev.d_len);
|
||||
SLIP_STAT(priv, transmitted);
|
||||
|
||||
/* Send an initial END character to flush out any data that may have
|
||||
@@ -423,7 +416,6 @@ static int slip_uiptxpoll(struct uip_driver_s *dev)
|
||||
|
||||
if (priv->dev.d_len > 0)
|
||||
{
|
||||
uip_arp_out(&priv->dev);
|
||||
slip_transmit(priv);
|
||||
}
|
||||
|
||||
@@ -479,6 +471,7 @@ static inline void slip_readpacket(FAR struct slip_driver_s *priv)
|
||||
* packet if we run out of room.
|
||||
*/
|
||||
|
||||
nvdbg("Receiving packet\n");
|
||||
for (;;)
|
||||
{
|
||||
/* Get the next character in the stream */
|
||||
@@ -494,6 +487,8 @@ static inline void slip_readpacket(FAR struct slip_driver_s *priv)
|
||||
*/
|
||||
|
||||
case SLIP_END:
|
||||
nvdbg("END\n");
|
||||
|
||||
/* a minor optimization: if there is no data in the packet, ignore
|
||||
* it. This is meant to avoid bothering IP with all the empty
|
||||
* packets generated by the duplicate END characters which are in
|
||||
@@ -502,6 +497,7 @@ static inline void slip_readpacket(FAR struct slip_driver_s *priv)
|
||||
|
||||
if (nbytes > 0)
|
||||
{
|
||||
nvdbg("Received packet size %d\n", nbytes);
|
||||
priv->dev.d_len = nbytes;
|
||||
return;
|
||||
}
|
||||
@@ -513,6 +509,7 @@ static inline void slip_readpacket(FAR struct slip_driver_s *priv)
|
||||
*/
|
||||
|
||||
case SLIP_ESC:
|
||||
nvdbg("ESC\n");
|
||||
ch = slip_getc(priv);
|
||||
|
||||
/* if "ch" is not one of these two, then we have a protocol
|
||||
@@ -523,8 +520,10 @@ static inline void slip_readpacket(FAR struct slip_driver_s *priv)
|
||||
switch (ch)
|
||||
{
|
||||
case SLIP_ESC_END:
|
||||
nvdbg("ESC-END\n");
|
||||
ch = SLIP_END;
|
||||
break;
|
||||
nvdbg("ESC-ESC\n");
|
||||
case SLIP_ESC_ESC:
|
||||
ch = SLIP_ESC;
|
||||
break;
|
||||
@@ -564,53 +563,28 @@ static inline void slip_readpacket(FAR struct slip_driver_s *priv)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void slip_receive(FAR struct slip_driver_s *priv)
|
||||
static inline void slip_receive(FAR struct slip_driver_s *priv)
|
||||
{
|
||||
/* Copy the data data from the hardware to priv->dev.d_buf until we put
|
||||
* together a whole packet.
|
||||
*/
|
||||
|
||||
slip_readpacket(priv);
|
||||
SLIP_STAT(priv, received);
|
||||
|
||||
/* We only accept IP packets of the configured type and ARP packets */
|
||||
/* All packets are assumed to be IP packets (we don't have a choice.. there
|
||||
* is no Ethernet header containing the EtherType)
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
if (BUF->type == HTONS(UIP_ETHTYPE_IP6))
|
||||
#else
|
||||
if (BUF->type == HTONS(UIP_ETHTYPE_IP))
|
||||
#endif
|
||||
uip_input(&priv->dev);
|
||||
|
||||
/* If the above function invocation resulted in data that should be
|
||||
* sent out on the network, the field d_len will set to a value > 0.
|
||||
*/
|
||||
|
||||
if (priv->dev.d_len > 0)
|
||||
{
|
||||
SLIP_STAT(priv, rxip);
|
||||
uip_arp_ipin(&priv->dev);
|
||||
uip_input(&priv->dev);
|
||||
|
||||
/* If the above function invocation resulted in data that should be
|
||||
* sent out on the network, the field d_len will set to a value > 0.
|
||||
*/
|
||||
|
||||
if (priv->dev.d_len > 0)
|
||||
{
|
||||
uip_arp_out(&priv->dev);
|
||||
slip_transmit(priv);
|
||||
}
|
||||
}
|
||||
else if (BUF->type == htons(UIP_ETHTYPE_ARP))
|
||||
{
|
||||
SLIP_STAT(priv, rxarp);
|
||||
uip_arp_arpin(&priv->dev);
|
||||
|
||||
/* If the above function invocation resulted in data that should be
|
||||
* sent out on the network, the field d_len will set to a value > 0.
|
||||
*/
|
||||
|
||||
if (priv->dev.d_len > 0)
|
||||
{
|
||||
slip_transmit(priv);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SLIP_STAT(priv, rxproto);
|
||||
slip_transmit(priv);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -912,7 +886,7 @@ int slip_initialize(int intf, const char *devname)
|
||||
|
||||
/* Get the interface structure associated with this interface number. */
|
||||
|
||||
DEBUGASSERT(inf < CONFIG_SLIP_NINTERFACES);
|
||||
DEBUGASSERT(intf < CONFIG_SLIP_NINTERFACES);
|
||||
priv = &g_slip[intf];
|
||||
|
||||
/* Initialize the driver structure */
|
||||
|
||||
Reference in New Issue
Block a user