code that uses Watchdog to reset Mbed every 30seconds. After 30-60mins, the ethernet interface fails to setup() after WatchDog reset.

Dependencies:   mbed

Committer:
eqon
Date:
Thu Jun 07 05:44:29 2012 +0000
Revision:
0:0ce833f21e63

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
eqon 0:0ce833f21e63 1 /*
eqon 0:0ce833f21e63 2 * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
eqon 0:0ce833f21e63 3 * Copyright (c) 2003-2004 Leon Woestenberg <leon.woestenberg@axon.tv>
eqon 0:0ce833f21e63 4 * Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands.
eqon 0:0ce833f21e63 5 * All rights reserved.
eqon 0:0ce833f21e63 6 *
eqon 0:0ce833f21e63 7 * Redistribution and use in source and binary forms, with or without modification,
eqon 0:0ce833f21e63 8 * are permitted provided that the following conditions are met:
eqon 0:0ce833f21e63 9 *
eqon 0:0ce833f21e63 10 * 1. Redistributions of source code must retain the above copyright notice,
eqon 0:0ce833f21e63 11 * this list of conditions and the following disclaimer.
eqon 0:0ce833f21e63 12 * 2. Redistributions in binary form must reproduce the above copyright notice,
eqon 0:0ce833f21e63 13 * this list of conditions and the following disclaimer in the documentation
eqon 0:0ce833f21e63 14 * and/or other materials provided with the distribution.
eqon 0:0ce833f21e63 15 * 3. The name of the author may not be used to endorse or promote products
eqon 0:0ce833f21e63 16 * derived from this software without specific prior written permission.
eqon 0:0ce833f21e63 17 *
eqon 0:0ce833f21e63 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
eqon 0:0ce833f21e63 19 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
eqon 0:0ce833f21e63 20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
eqon 0:0ce833f21e63 21 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
eqon 0:0ce833f21e63 22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
eqon 0:0ce833f21e63 23 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
eqon 0:0ce833f21e63 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
eqon 0:0ce833f21e63 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
eqon 0:0ce833f21e63 26 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
eqon 0:0ce833f21e63 27 * OF SUCH DAMAGE.
eqon 0:0ce833f21e63 28 *
eqon 0:0ce833f21e63 29 * This file is part of the lwIP TCP/IP stack.
eqon 0:0ce833f21e63 30 *
eqon 0:0ce833f21e63 31 * Author: Adam Dunkels <adam@sics.se>
eqon 0:0ce833f21e63 32 *
eqon 0:0ce833f21e63 33 */
eqon 0:0ce833f21e63 34
eqon 0:0ce833f21e63 35 #ifndef __NETIF_ETHARP_H__
eqon 0:0ce833f21e63 36 #define __NETIF_ETHARP_H__
eqon 0:0ce833f21e63 37
eqon 0:0ce833f21e63 38 #include "lwip/opt.h"
eqon 0:0ce833f21e63 39
eqon 0:0ce833f21e63 40 #if LWIP_ARP || LWIP_ETHERNET /* don't build if not configured for use in lwipopts.h */
eqon 0:0ce833f21e63 41
eqon 0:0ce833f21e63 42 #include "lwip/pbuf.h"
eqon 0:0ce833f21e63 43 #include "lwip/ip_addr.h"
eqon 0:0ce833f21e63 44 #include "lwip/netif.h"
eqon 0:0ce833f21e63 45 #include "lwip/ip.h"
eqon 0:0ce833f21e63 46
eqon 0:0ce833f21e63 47 #ifdef __cplusplus
eqon 0:0ce833f21e63 48 extern "C" {
eqon 0:0ce833f21e63 49 #endif
eqon 0:0ce833f21e63 50
eqon 0:0ce833f21e63 51 #ifndef ETHARP_HWADDR_LEN
eqon 0:0ce833f21e63 52 #define ETHARP_HWADDR_LEN 6
eqon 0:0ce833f21e63 53 #endif
eqon 0:0ce833f21e63 54
eqon 0:0ce833f21e63 55 #ifdef PACK_STRUCT_USE_INCLUDES
eqon 0:0ce833f21e63 56 # include "arch/bpstruct.h"
eqon 0:0ce833f21e63 57 #endif
eqon 0:0ce833f21e63 58 PACK_STRUCT_BEGIN
eqon 0:0ce833f21e63 59 struct eth_addr {
eqon 0:0ce833f21e63 60 PACK_STRUCT_FIELD(u8_t addr[ETHARP_HWADDR_LEN]);
eqon 0:0ce833f21e63 61 } PACK_STRUCT_STRUCT;
eqon 0:0ce833f21e63 62 PACK_STRUCT_END
eqon 0:0ce833f21e63 63 #ifdef PACK_STRUCT_USE_INCLUDES
eqon 0:0ce833f21e63 64 # include "arch/epstruct.h"
eqon 0:0ce833f21e63 65 #endif
eqon 0:0ce833f21e63 66
eqon 0:0ce833f21e63 67 #ifdef PACK_STRUCT_USE_INCLUDES
eqon 0:0ce833f21e63 68 # include "arch/bpstruct.h"
eqon 0:0ce833f21e63 69 #endif
eqon 0:0ce833f21e63 70 PACK_STRUCT_BEGIN
eqon 0:0ce833f21e63 71 /* Ethernet header */
eqon 0:0ce833f21e63 72 struct eth_hdr {
eqon 0:0ce833f21e63 73 #if ETH_PAD_SIZE
eqon 0:0ce833f21e63 74 PACK_STRUCT_FIELD(u8_t padding[ETH_PAD_SIZE]);
eqon 0:0ce833f21e63 75 #endif
eqon 0:0ce833f21e63 76 PACK_STRUCT_FIELD(struct eth_addr dest);
eqon 0:0ce833f21e63 77 PACK_STRUCT_FIELD(struct eth_addr src);
eqon 0:0ce833f21e63 78 PACK_STRUCT_FIELD(u16_t type);
eqon 0:0ce833f21e63 79 } PACK_STRUCT_STRUCT;
eqon 0:0ce833f21e63 80 PACK_STRUCT_END
eqon 0:0ce833f21e63 81 #ifdef PACK_STRUCT_USE_INCLUDES
eqon 0:0ce833f21e63 82 # include "arch/epstruct.h"
eqon 0:0ce833f21e63 83 #endif
eqon 0:0ce833f21e63 84
eqon 0:0ce833f21e63 85 #define SIZEOF_ETH_HDR (14 + ETH_PAD_SIZE)
eqon 0:0ce833f21e63 86
eqon 0:0ce833f21e63 87 #if ETHARP_SUPPORT_VLAN
eqon 0:0ce833f21e63 88
eqon 0:0ce833f21e63 89 #ifdef PACK_STRUCT_USE_INCLUDES
eqon 0:0ce833f21e63 90 # include "arch/bpstruct.h"
eqon 0:0ce833f21e63 91 #endif
eqon 0:0ce833f21e63 92 PACK_STRUCT_BEGIN
eqon 0:0ce833f21e63 93 /* VLAN header inserted between ethernet header and payload
eqon 0:0ce833f21e63 94 * if 'type' in ethernet header is ETHTYPE_VLAN.
eqon 0:0ce833f21e63 95 * See IEEE802.Q */
eqon 0:0ce833f21e63 96 struct eth_vlan_hdr {
eqon 0:0ce833f21e63 97 PACK_STRUCT_FIELD(u16_t tpid);
eqon 0:0ce833f21e63 98 PACK_STRUCT_FIELD(u16_t prio_vid);
eqon 0:0ce833f21e63 99 } PACK_STRUCT_STRUCT;
eqon 0:0ce833f21e63 100 PACK_STRUCT_END
eqon 0:0ce833f21e63 101 #ifdef PACK_STRUCT_USE_INCLUDES
eqon 0:0ce833f21e63 102 # include "arch/epstruct.h"
eqon 0:0ce833f21e63 103 #endif
eqon 0:0ce833f21e63 104
eqon 0:0ce833f21e63 105 #define SIZEOF_VLAN_HDR 4
eqon 0:0ce833f21e63 106 #define VLAN_ID(vlan_hdr) (htons((vlan_hdr)->prio_vid) & 0xFFF)
eqon 0:0ce833f21e63 107
eqon 0:0ce833f21e63 108 #endif /* ETHARP_SUPPORT_VLAN */
eqon 0:0ce833f21e63 109
eqon 0:0ce833f21e63 110 #ifdef PACK_STRUCT_USE_INCLUDES
eqon 0:0ce833f21e63 111 # include "arch/bpstruct.h"
eqon 0:0ce833f21e63 112 #endif
eqon 0:0ce833f21e63 113 PACK_STRUCT_BEGIN
eqon 0:0ce833f21e63 114 /* the ARP message, see RFC 826 ("Packet format") */
eqon 0:0ce833f21e63 115 struct etharp_hdr {
eqon 0:0ce833f21e63 116 PACK_STRUCT_FIELD(u16_t hwtype);
eqon 0:0ce833f21e63 117 PACK_STRUCT_FIELD(u16_t proto);
eqon 0:0ce833f21e63 118 PACK_STRUCT_FIELD(u8_t hwlen);
eqon 0:0ce833f21e63 119 PACK_STRUCT_FIELD(u8_t protolen);
eqon 0:0ce833f21e63 120 PACK_STRUCT_FIELD(u16_t opcode);
eqon 0:0ce833f21e63 121 PACK_STRUCT_FIELD(struct eth_addr shwaddr);
eqon 0:0ce833f21e63 122 PACK_STRUCT_FIELD(struct ip_addr2 sipaddr);
eqon 0:0ce833f21e63 123 PACK_STRUCT_FIELD(struct eth_addr dhwaddr);
eqon 0:0ce833f21e63 124 PACK_STRUCT_FIELD(struct ip_addr2 dipaddr);
eqon 0:0ce833f21e63 125 } PACK_STRUCT_STRUCT;
eqon 0:0ce833f21e63 126 PACK_STRUCT_END
eqon 0:0ce833f21e63 127 #ifdef PACK_STRUCT_USE_INCLUDES
eqon 0:0ce833f21e63 128 # include "arch/epstruct.h"
eqon 0:0ce833f21e63 129 #endif
eqon 0:0ce833f21e63 130
eqon 0:0ce833f21e63 131 #define SIZEOF_ETHARP_HDR 28
eqon 0:0ce833f21e63 132 #define SIZEOF_ETHARP_PACKET (SIZEOF_ETH_HDR + SIZEOF_ETHARP_HDR)
eqon 0:0ce833f21e63 133
eqon 0:0ce833f21e63 134 /* 5 seconds period */
eqon 0:0ce833f21e63 135 #define ARP_TMR_INTERVAL 5000
eqon 0:0ce833f21e63 136
eqon 0:0ce833f21e63 137 #define ETHTYPE_ARP 0x0806
eqon 0:0ce833f21e63 138 #define ETHTYPE_IP 0x0800
eqon 0:0ce833f21e63 139 #define ETHTYPE_VLAN 0x8100
eqon 0:0ce833f21e63 140 #define ETHTYPE_PPPOEDISC 0x8863 /* PPP Over Ethernet Discovery Stage */
eqon 0:0ce833f21e63 141 #define ETHTYPE_PPPOE 0x8864 /* PPP Over Ethernet Session Stage */
eqon 0:0ce833f21e63 142
eqon 0:0ce833f21e63 143 /* MEMCPY-like macro to copy to/from struct eth_addr's that are local variables
eqon 0:0ce833f21e63 144 * or known to be 32-bit aligned within the protocol header. */
eqon 0:0ce833f21e63 145 #ifndef ETHADDR32_COPY
eqon 0:0ce833f21e63 146 #define ETHADDR32_COPY(src, dst) SMEMCPY(src, dst, ETHARP_HWADDR_LEN)
eqon 0:0ce833f21e63 147 #endif
eqon 0:0ce833f21e63 148
eqon 0:0ce833f21e63 149 /* MEMCPY-like macro to copy to/from struct eth_addr's that are no local
eqon 0:0ce833f21e63 150 * variables and known to be 16-bit aligned within the protocol header. */
eqon 0:0ce833f21e63 151 #ifndef ETHADDR16_COPY
eqon 0:0ce833f21e63 152 #define ETHADDR16_COPY(src, dst) SMEMCPY(src, dst, ETHARP_HWADDR_LEN)
eqon 0:0ce833f21e63 153 #endif
eqon 0:0ce833f21e63 154
eqon 0:0ce833f21e63 155 #if LWIP_ARP /* don't build if not configured for use in lwipopts.h */
eqon 0:0ce833f21e63 156
eqon 0:0ce833f21e63 157 /* ARP message types (opcodes) */
eqon 0:0ce833f21e63 158 #define ARP_REQUEST 1
eqon 0:0ce833f21e63 159 #define ARP_REPLY 2
eqon 0:0ce833f21e63 160
eqon 0:0ce833f21e63 161 /* Define this to 1 and define LWIP_ARP_FILTER_NETIF_FN(pbuf, netif, type)
eqon 0:0ce833f21e63 162 * to a filter function that returns the correct netif when using multiple
eqon 0:0ce833f21e63 163 * netifs on one hardware interface where the netif's low-level receive
eqon 0:0ce833f21e63 164 * routine cannot decide for the correct netif (e.g. when mapping multiple
eqon 0:0ce833f21e63 165 * IP addresses to one hardware interface).
eqon 0:0ce833f21e63 166 */
eqon 0:0ce833f21e63 167 #ifndef LWIP_ARP_FILTER_NETIF
eqon 0:0ce833f21e63 168 #define LWIP_ARP_FILTER_NETIF 0
eqon 0:0ce833f21e63 169 #endif
eqon 0:0ce833f21e63 170
eqon 0:0ce833f21e63 171 #if ARP_QUEUEING
eqon 0:0ce833f21e63 172 /* struct for queueing outgoing packets for unknown address
eqon 0:0ce833f21e63 173 * defined here to be accessed by memp.h
eqon 0:0ce833f21e63 174 */
eqon 0:0ce833f21e63 175 struct etharp_q_entry {
eqon 0:0ce833f21e63 176 struct etharp_q_entry *next;
eqon 0:0ce833f21e63 177 struct pbuf *p;
eqon 0:0ce833f21e63 178 };
eqon 0:0ce833f21e63 179 #endif /* ARP_QUEUEING */
eqon 0:0ce833f21e63 180
eqon 0:0ce833f21e63 181 #define etharp_init() /* Compatibility define, not init needed. */
eqon 0:0ce833f21e63 182 void etharp_tmr(void);
eqon 0:0ce833f21e63 183 s8_t etharp_find_addr(struct netif *netif, ip_addr_t *ipaddr,
eqon 0:0ce833f21e63 184 struct eth_addr **eth_ret, ip_addr_t **ip_ret);
eqon 0:0ce833f21e63 185 err_t etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr);
eqon 0:0ce833f21e63 186 err_t etharp_query(struct netif *netif, ip_addr_t *ipaddr, struct pbuf *q);
eqon 0:0ce833f21e63 187 err_t etharp_request(struct netif *netif, ip_addr_t *ipaddr);
eqon 0:0ce833f21e63 188 /* For Ethernet network interfaces, we might want to send "gratuitous ARP";
eqon 0:0ce833f21e63 189 * this is an ARP packet sent by a node in order to spontaneously cause other
eqon 0:0ce833f21e63 190 * nodes to update an entry in their ARP cache.
eqon 0:0ce833f21e63 191 * From RFC 3220 "IP Mobility Support for IPv4" section 4.6. */
eqon 0:0ce833f21e63 192 #define etharp_gratuitous(netif) etharp_request((netif), &(netif)->ip_addr)
eqon 0:0ce833f21e63 193
eqon 0:0ce833f21e63 194 #if ETHARP_SUPPORT_STATIC_ENTRIES
eqon 0:0ce833f21e63 195 err_t etharp_add_static_entry(ip_addr_t *ipaddr, struct eth_addr *ethaddr);
eqon 0:0ce833f21e63 196 err_t etharp_remove_static_entry(ip_addr_t *ipaddr);
eqon 0:0ce833f21e63 197 #endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
eqon 0:0ce833f21e63 198
eqon 0:0ce833f21e63 199 #if LWIP_AUTOIP
eqon 0:0ce833f21e63 200 err_t etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr,
eqon 0:0ce833f21e63 201 const struct eth_addr *ethdst_addr,
eqon 0:0ce833f21e63 202 const struct eth_addr *hwsrc_addr, const ip_addr_t *ipsrc_addr,
eqon 0:0ce833f21e63 203 const struct eth_addr *hwdst_addr, const ip_addr_t *ipdst_addr,
eqon 0:0ce833f21e63 204 const u16_t opcode);
eqon 0:0ce833f21e63 205 #endif /* LWIP_AUTOIP */
eqon 0:0ce833f21e63 206
eqon 0:0ce833f21e63 207 #endif /* LWIP_ARP */
eqon 0:0ce833f21e63 208
eqon 0:0ce833f21e63 209 err_t ethernet_input(struct pbuf *p, struct netif *netif);
eqon 0:0ce833f21e63 210
eqon 0:0ce833f21e63 211 #define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETHARP_HWADDR_LEN) == 0)
eqon 0:0ce833f21e63 212
eqon 0:0ce833f21e63 213 extern const struct eth_addr ethbroadcast, ethzero;
eqon 0:0ce833f21e63 214
eqon 0:0ce833f21e63 215 #ifdef __cplusplus
eqon 0:0ce833f21e63 216 }
eqon 0:0ce833f21e63 217 #endif
eqon 0:0ce833f21e63 218
eqon 0:0ce833f21e63 219 #endif /* LWIP_ARP || LWIP_ETHERNET */
eqon 0:0ce833f21e63 220
eqon 0:0ce833f21e63 221 #endif /* __NETIF_ARP_H__ */