LineLedControl

Dependencies:   LPD8806 mbed

Fork of LPD8806_Test by Jelmer Tiete

Committer:
sfjmt
Date:
Mon Aug 19 12:14:37 2013 +0000
Revision:
3:b0a1b4b24d3c
LPD8806 control

Who changed what in which revision?

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