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 * fsm.h - Network Control Protocol Finite State Machine header file.
eqon 0:0ce833f21e63 3 *
eqon 0:0ce833f21e63 4 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
eqon 0:0ce833f21e63 5 * Copyright (c) 1997 Global Election Systems Inc.
eqon 0:0ce833f21e63 6 *
eqon 0:0ce833f21e63 7 * The authors hereby grant permission to use, copy, modify, distribute,
eqon 0:0ce833f21e63 8 * and license this software and its documentation for any purpose, provided
eqon 0:0ce833f21e63 9 * that existing copyright notices are retained in all copies and that this
eqon 0:0ce833f21e63 10 * notice and the following disclaimer are included verbatim in any
eqon 0:0ce833f21e63 11 * distributions. No written agreement, license, or royalty fee is required
eqon 0:0ce833f21e63 12 * for any of the authorized uses.
eqon 0:0ce833f21e63 13 *
eqon 0:0ce833f21e63 14 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
eqon 0:0ce833f21e63 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
eqon 0:0ce833f21e63 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
eqon 0:0ce833f21e63 17 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
eqon 0:0ce833f21e63 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
eqon 0:0ce833f21e63 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
eqon 0:0ce833f21e63 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
eqon 0:0ce833f21e63 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
eqon 0:0ce833f21e63 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
eqon 0:0ce833f21e63 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
eqon 0:0ce833f21e63 24 *
eqon 0:0ce833f21e63 25 ******************************************************************************
eqon 0:0ce833f21e63 26 * REVISION HISTORY
eqon 0:0ce833f21e63 27 *
eqon 0:0ce833f21e63 28 * 03-01-01 Marc Boucher <marc@mbsi.ca>
eqon 0:0ce833f21e63 29 * Ported to lwIP.
eqon 0:0ce833f21e63 30 * 97-11-05 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc.
eqon 0:0ce833f21e63 31 * Original based on BSD code.
eqon 0:0ce833f21e63 32 *****************************************************************************/
eqon 0:0ce833f21e63 33 /*
eqon 0:0ce833f21e63 34 * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions.
eqon 0:0ce833f21e63 35 *
eqon 0:0ce833f21e63 36 * Copyright (c) 1989 Carnegie Mellon University.
eqon 0:0ce833f21e63 37 * All rights reserved.
eqon 0:0ce833f21e63 38 *
eqon 0:0ce833f21e63 39 * Redistribution and use in source and binary forms are permitted
eqon 0:0ce833f21e63 40 * provided that the above copyright notice and this paragraph are
eqon 0:0ce833f21e63 41 * duplicated in all such forms and that any documentation,
eqon 0:0ce833f21e63 42 * advertising materials, and other materials related to such
eqon 0:0ce833f21e63 43 * distribution and use acknowledge that the software was developed
eqon 0:0ce833f21e63 44 * by Carnegie Mellon University. The name of the
eqon 0:0ce833f21e63 45 * University may not be used to endorse or promote products derived
eqon 0:0ce833f21e63 46 * from this software without specific prior written permission.
eqon 0:0ce833f21e63 47 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
eqon 0:0ce833f21e63 48 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
eqon 0:0ce833f21e63 49 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
eqon 0:0ce833f21e63 50 *
eqon 0:0ce833f21e63 51 * $Id: fsm.h,v 1.5 2009/12/31 17:08:08 goldsimon Exp $
eqon 0:0ce833f21e63 52 */
eqon 0:0ce833f21e63 53
eqon 0:0ce833f21e63 54 #ifndef FSM_H
eqon 0:0ce833f21e63 55 #define FSM_H
eqon 0:0ce833f21e63 56
eqon 0:0ce833f21e63 57 /*
eqon 0:0ce833f21e63 58 * LCP Packet header = Code, id, length.
eqon 0:0ce833f21e63 59 */
eqon 0:0ce833f21e63 60 #define HEADERLEN (sizeof (u_char) + sizeof (u_char) + sizeof (u_short))
eqon 0:0ce833f21e63 61
eqon 0:0ce833f21e63 62
eqon 0:0ce833f21e63 63 /*
eqon 0:0ce833f21e63 64 * CP (LCP, IPCP, etc.) codes.
eqon 0:0ce833f21e63 65 */
eqon 0:0ce833f21e63 66 #define CONFREQ 1 /* Configuration Request */
eqon 0:0ce833f21e63 67 #define CONFACK 2 /* Configuration Ack */
eqon 0:0ce833f21e63 68 #define CONFNAK 3 /* Configuration Nak */
eqon 0:0ce833f21e63 69 #define CONFREJ 4 /* Configuration Reject */
eqon 0:0ce833f21e63 70 #define TERMREQ 5 /* Termination Request */
eqon 0:0ce833f21e63 71 #define TERMACK 6 /* Termination Ack */
eqon 0:0ce833f21e63 72 #define CODEREJ 7 /* Code Reject */
eqon 0:0ce833f21e63 73
eqon 0:0ce833f21e63 74
eqon 0:0ce833f21e63 75 /*
eqon 0:0ce833f21e63 76 * Each FSM is described by an fsm structure and fsm callbacks.
eqon 0:0ce833f21e63 77 */
eqon 0:0ce833f21e63 78 typedef struct fsm {
eqon 0:0ce833f21e63 79 int unit; /* Interface unit number */
eqon 0:0ce833f21e63 80 u_short protocol; /* Data Link Layer Protocol field value */
eqon 0:0ce833f21e63 81 int state; /* State */
eqon 0:0ce833f21e63 82 int flags; /* Contains option bits */
eqon 0:0ce833f21e63 83 u_char id; /* Current id */
eqon 0:0ce833f21e63 84 u_char reqid; /* Current request id */
eqon 0:0ce833f21e63 85 u_char seen_ack; /* Have received valid Ack/Nak/Rej to Req */
eqon 0:0ce833f21e63 86 int timeouttime; /* Timeout time in milliseconds */
eqon 0:0ce833f21e63 87 int maxconfreqtransmits; /* Maximum Configure-Request transmissions */
eqon 0:0ce833f21e63 88 int retransmits; /* Number of retransmissions left */
eqon 0:0ce833f21e63 89 int maxtermtransmits; /* Maximum Terminate-Request transmissions */
eqon 0:0ce833f21e63 90 int nakloops; /* Number of nak loops since last ack */
eqon 0:0ce833f21e63 91 int maxnakloops; /* Maximum number of nak loops tolerated */
eqon 0:0ce833f21e63 92 struct fsm_callbacks* callbacks; /* Callback routines */
eqon 0:0ce833f21e63 93 char* term_reason; /* Reason for closing protocol */
eqon 0:0ce833f21e63 94 int term_reason_len; /* Length of term_reason */
eqon 0:0ce833f21e63 95 } fsm;
eqon 0:0ce833f21e63 96
eqon 0:0ce833f21e63 97
eqon 0:0ce833f21e63 98 typedef struct fsm_callbacks {
eqon 0:0ce833f21e63 99 void (*resetci)(fsm*); /* Reset our Configuration Information */
eqon 0:0ce833f21e63 100 int (*cilen)(fsm*); /* Length of our Configuration Information */
eqon 0:0ce833f21e63 101 void (*addci)(fsm*, u_char*, int*); /* Add our Configuration Information */
eqon 0:0ce833f21e63 102 int (*ackci)(fsm*, u_char*, int); /* ACK our Configuration Information */
eqon 0:0ce833f21e63 103 int (*nakci)(fsm*, u_char*, int); /* NAK our Configuration Information */
eqon 0:0ce833f21e63 104 int (*rejci)(fsm*, u_char*, int); /* Reject our Configuration Information */
eqon 0:0ce833f21e63 105 int (*reqci)(fsm*, u_char*, int*, int); /* Request peer's Configuration Information */
eqon 0:0ce833f21e63 106 void (*up)(fsm*); /* Called when fsm reaches LS_OPENED state */
eqon 0:0ce833f21e63 107 void (*down)(fsm*); /* Called when fsm leaves LS_OPENED state */
eqon 0:0ce833f21e63 108 void (*starting)(fsm*); /* Called when we want the lower layer */
eqon 0:0ce833f21e63 109 void (*finished)(fsm*); /* Called when we don't want the lower layer */
eqon 0:0ce833f21e63 110 void (*protreject)(int); /* Called when Protocol-Reject received */
eqon 0:0ce833f21e63 111 void (*retransmit)(fsm*); /* Retransmission is necessary */
eqon 0:0ce833f21e63 112 int (*extcode)(fsm*, int, u_char, u_char*, int); /* Called when unknown code received */
eqon 0:0ce833f21e63 113 char *proto_name; /* String name for protocol (for messages) */
eqon 0:0ce833f21e63 114 } fsm_callbacks;
eqon 0:0ce833f21e63 115
eqon 0:0ce833f21e63 116
eqon 0:0ce833f21e63 117 /*
eqon 0:0ce833f21e63 118 * Link states.
eqon 0:0ce833f21e63 119 */
eqon 0:0ce833f21e63 120 #define LS_INITIAL 0 /* Down, hasn't been opened */
eqon 0:0ce833f21e63 121 #define LS_STARTING 1 /* Down, been opened */
eqon 0:0ce833f21e63 122 #define LS_CLOSED 2 /* Up, hasn't been opened */
eqon 0:0ce833f21e63 123 #define LS_STOPPED 3 /* Open, waiting for down event */
eqon 0:0ce833f21e63 124 #define LS_CLOSING 4 /* Terminating the connection, not open */
eqon 0:0ce833f21e63 125 #define LS_STOPPING 5 /* Terminating, but open */
eqon 0:0ce833f21e63 126 #define LS_REQSENT 6 /* We've sent a Config Request */
eqon 0:0ce833f21e63 127 #define LS_ACKRCVD 7 /* We've received a Config Ack */
eqon 0:0ce833f21e63 128 #define LS_ACKSENT 8 /* We've sent a Config Ack */
eqon 0:0ce833f21e63 129 #define LS_OPENED 9 /* Connection available */
eqon 0:0ce833f21e63 130
eqon 0:0ce833f21e63 131 /*
eqon 0:0ce833f21e63 132 * Flags - indicate options controlling FSM operation
eqon 0:0ce833f21e63 133 */
eqon 0:0ce833f21e63 134 #define OPT_PASSIVE 1 /* Don't die if we don't get a response */
eqon 0:0ce833f21e63 135 #define OPT_RESTART 2 /* Treat 2nd OPEN as DOWN, UP */
eqon 0:0ce833f21e63 136 #define OPT_SILENT 4 /* Wait for peer to speak first */
eqon 0:0ce833f21e63 137
eqon 0:0ce833f21e63 138
eqon 0:0ce833f21e63 139 /*
eqon 0:0ce833f21e63 140 * Prototypes
eqon 0:0ce833f21e63 141 */
eqon 0:0ce833f21e63 142 void fsm_init (fsm*);
eqon 0:0ce833f21e63 143 void fsm_lowerup (fsm*);
eqon 0:0ce833f21e63 144 void fsm_lowerdown (fsm*);
eqon 0:0ce833f21e63 145 void fsm_open (fsm*);
eqon 0:0ce833f21e63 146 void fsm_close (fsm*, char*);
eqon 0:0ce833f21e63 147 void fsm_input (fsm*, u_char*, int);
eqon 0:0ce833f21e63 148 void fsm_protreject (fsm*);
eqon 0:0ce833f21e63 149 void fsm_sdata (fsm*, u_char, u_char, u_char*, int);
eqon 0:0ce833f21e63 150
eqon 0:0ce833f21e63 151
eqon 0:0ce833f21e63 152 /*
eqon 0:0ce833f21e63 153 * Variables
eqon 0:0ce833f21e63 154 */
eqon 0:0ce833f21e63 155 extern int peer_mru[]; /* currently negotiated peer MRU (per unit) */
eqon 0:0ce833f21e63 156
eqon 0:0ce833f21e63 157 #endif /* FSM_H */