Read NTP time from Ethernet and drive six 7-segment LEDs using a MAX7221 to show time, date, month, week, year etc....

Dependencies:   NTPClient_NetServices mbed

Committer:
cheungderek
Date:
Wed Jun 22 01:31:47 2011 +0000
Revision:
0:e083abcfe7a8
First release.
Just some testing but working code to read NTP time and drive 6 LEDs to display time, date, month, year etc...

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cheungderek 0:e083abcfe7a8 1 /*****************************************************************************
cheungderek 0:e083abcfe7a8 2 * lcp.h - Network Link Control Protocol header file.
cheungderek 0:e083abcfe7a8 3 *
cheungderek 0:e083abcfe7a8 4 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
cheungderek 0:e083abcfe7a8 5 * portions Copyright (c) 1997 Global Election Systems Inc.
cheungderek 0:e083abcfe7a8 6 *
cheungderek 0:e083abcfe7a8 7 * The authors hereby grant permission to use, copy, modify, distribute,
cheungderek 0:e083abcfe7a8 8 * and license this software and its documentation for any purpose, provided
cheungderek 0:e083abcfe7a8 9 * that existing copyright notices are retained in all copies and that this
cheungderek 0:e083abcfe7a8 10 * notice and the following disclaimer are included verbatim in any
cheungderek 0:e083abcfe7a8 11 * distributions. No written agreement, license, or royalty fee is required
cheungderek 0:e083abcfe7a8 12 * for any of the authorized uses.
cheungderek 0:e083abcfe7a8 13 *
cheungderek 0:e083abcfe7a8 14 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
cheungderek 0:e083abcfe7a8 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
cheungderek 0:e083abcfe7a8 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
cheungderek 0:e083abcfe7a8 17 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
cheungderek 0:e083abcfe7a8 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
cheungderek 0:e083abcfe7a8 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
cheungderek 0:e083abcfe7a8 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
cheungderek 0:e083abcfe7a8 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
cheungderek 0:e083abcfe7a8 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
cheungderek 0:e083abcfe7a8 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cheungderek 0:e083abcfe7a8 24 *
cheungderek 0:e083abcfe7a8 25 ******************************************************************************
cheungderek 0:e083abcfe7a8 26 * REVISION HISTORY
cheungderek 0:e083abcfe7a8 27 *
cheungderek 0:e083abcfe7a8 28 * 03-01-01 Marc Boucher <marc@mbsi.ca>
cheungderek 0:e083abcfe7a8 29 * Ported to lwIP.
cheungderek 0:e083abcfe7a8 30 * 97-11-05 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc.
cheungderek 0:e083abcfe7a8 31 * Original derived from BSD codes.
cheungderek 0:e083abcfe7a8 32 *****************************************************************************/
cheungderek 0:e083abcfe7a8 33 /*
cheungderek 0:e083abcfe7a8 34 * lcp.h - Link Control Protocol definitions.
cheungderek 0:e083abcfe7a8 35 *
cheungderek 0:e083abcfe7a8 36 * Copyright (c) 1989 Carnegie Mellon University.
cheungderek 0:e083abcfe7a8 37 * All rights reserved.
cheungderek 0:e083abcfe7a8 38 *
cheungderek 0:e083abcfe7a8 39 * Redistribution and use in source and binary forms are permitted
cheungderek 0:e083abcfe7a8 40 * provided that the above copyright notice and this paragraph are
cheungderek 0:e083abcfe7a8 41 * duplicated in all such forms and that any documentation,
cheungderek 0:e083abcfe7a8 42 * advertising materials, and other materials related to such
cheungderek 0:e083abcfe7a8 43 * distribution and use acknowledge that the software was developed
cheungderek 0:e083abcfe7a8 44 * by Carnegie Mellon University. The name of the
cheungderek 0:e083abcfe7a8 45 * University may not be used to endorse or promote products derived
cheungderek 0:e083abcfe7a8 46 * from this software without specific prior written permission.
cheungderek 0:e083abcfe7a8 47 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
cheungderek 0:e083abcfe7a8 48 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
cheungderek 0:e083abcfe7a8 49 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
cheungderek 0:e083abcfe7a8 50 *
cheungderek 0:e083abcfe7a8 51 * $Id: lcp.h,v 1.4 2010/01/18 20:49:43 goldsimon Exp $
cheungderek 0:e083abcfe7a8 52 */
cheungderek 0:e083abcfe7a8 53
cheungderek 0:e083abcfe7a8 54 #ifndef LCP_H
cheungderek 0:e083abcfe7a8 55 #define LCP_H
cheungderek 0:e083abcfe7a8 56 /*
cheungderek 0:e083abcfe7a8 57 * Options.
cheungderek 0:e083abcfe7a8 58 */
cheungderek 0:e083abcfe7a8 59 #define CI_MRU 1 /* Maximum Receive Unit */
cheungderek 0:e083abcfe7a8 60 #define CI_ASYNCMAP 2 /* Async Control Character Map */
cheungderek 0:e083abcfe7a8 61 #define CI_AUTHTYPE 3 /* Authentication Type */
cheungderek 0:e083abcfe7a8 62 #define CI_QUALITY 4 /* Quality Protocol */
cheungderek 0:e083abcfe7a8 63 #define CI_MAGICNUMBER 5 /* Magic Number */
cheungderek 0:e083abcfe7a8 64 #define CI_PCOMPRESSION 7 /* Protocol Field Compression */
cheungderek 0:e083abcfe7a8 65 #define CI_ACCOMPRESSION 8 /* Address/Control Field Compression */
cheungderek 0:e083abcfe7a8 66 #define CI_CALLBACK 13 /* callback */
cheungderek 0:e083abcfe7a8 67 #define CI_MRRU 17 /* max reconstructed receive unit; multilink */
cheungderek 0:e083abcfe7a8 68 #define CI_SSNHF 18 /* short sequence numbers for multilink */
cheungderek 0:e083abcfe7a8 69 #define CI_EPDISC 19 /* endpoint discriminator */
cheungderek 0:e083abcfe7a8 70
cheungderek 0:e083abcfe7a8 71 /*
cheungderek 0:e083abcfe7a8 72 * LCP-specific packet types (code numbers).
cheungderek 0:e083abcfe7a8 73 */
cheungderek 0:e083abcfe7a8 74 #define PROTREJ 8 /* Protocol Reject */
cheungderek 0:e083abcfe7a8 75 #define ECHOREQ 9 /* Echo Request */
cheungderek 0:e083abcfe7a8 76 #define ECHOREP 10 /* Echo Reply */
cheungderek 0:e083abcfe7a8 77 #define DISCREQ 11 /* Discard Request */
cheungderek 0:e083abcfe7a8 78 #define CBCP_OPT 6 /* Use callback control protocol */
cheungderek 0:e083abcfe7a8 79
cheungderek 0:e083abcfe7a8 80 /*
cheungderek 0:e083abcfe7a8 81 * The state of options is described by an lcp_options structure.
cheungderek 0:e083abcfe7a8 82 */
cheungderek 0:e083abcfe7a8 83 typedef struct lcp_options {
cheungderek 0:e083abcfe7a8 84 u_int passive : 1; /* Don't die if we don't get a response */
cheungderek 0:e083abcfe7a8 85 u_int silent : 1; /* Wait for the other end to start first */
cheungderek 0:e083abcfe7a8 86 u_int restart : 1; /* Restart vs. exit after close */
cheungderek 0:e083abcfe7a8 87 u_int neg_mru : 1; /* Negotiate the MRU? */
cheungderek 0:e083abcfe7a8 88 u_int neg_asyncmap : 1; /* Negotiate the async map? */
cheungderek 0:e083abcfe7a8 89 u_int neg_upap : 1; /* Ask for UPAP authentication? */
cheungderek 0:e083abcfe7a8 90 u_int neg_chap : 1; /* Ask for CHAP authentication? */
cheungderek 0:e083abcfe7a8 91 u_int neg_magicnumber : 1; /* Ask for magic number? */
cheungderek 0:e083abcfe7a8 92 u_int neg_pcompression : 1; /* HDLC Protocol Field Compression? */
cheungderek 0:e083abcfe7a8 93 u_int neg_accompression : 1; /* HDLC Address/Control Field Compression? */
cheungderek 0:e083abcfe7a8 94 u_int neg_lqr : 1; /* Negotiate use of Link Quality Reports */
cheungderek 0:e083abcfe7a8 95 u_int neg_cbcp : 1; /* Negotiate use of CBCP */
cheungderek 0:e083abcfe7a8 96 #ifdef PPP_MULTILINK
cheungderek 0:e083abcfe7a8 97 u_int neg_mrru : 1; /* Negotiate multilink MRRU */
cheungderek 0:e083abcfe7a8 98 u_int neg_ssnhf : 1; /* Negotiate short sequence numbers */
cheungderek 0:e083abcfe7a8 99 u_int neg_endpoint : 1; /* Negotiate endpoint discriminator */
cheungderek 0:e083abcfe7a8 100 #endif
cheungderek 0:e083abcfe7a8 101 u_short mru; /* Value of MRU */
cheungderek 0:e083abcfe7a8 102 #ifdef PPP_MULTILINK
cheungderek 0:e083abcfe7a8 103 u_short mrru; /* Value of MRRU, and multilink enable */
cheungderek 0:e083abcfe7a8 104 #endif
cheungderek 0:e083abcfe7a8 105 u_char chap_mdtype; /* which MD type (hashing algorithm) */
cheungderek 0:e083abcfe7a8 106 u32_t asyncmap; /* Value of async map */
cheungderek 0:e083abcfe7a8 107 u32_t magicnumber;
cheungderek 0:e083abcfe7a8 108 int numloops; /* Number of loops during magic number neg. */
cheungderek 0:e083abcfe7a8 109 u32_t lqr_period; /* Reporting period for LQR 1/100ths second */
cheungderek 0:e083abcfe7a8 110 #ifdef PPP_MULTILINK
cheungderek 0:e083abcfe7a8 111 struct epdisc endpoint; /* endpoint discriminator */
cheungderek 0:e083abcfe7a8 112 #endif
cheungderek 0:e083abcfe7a8 113 } lcp_options;
cheungderek 0:e083abcfe7a8 114
cheungderek 0:e083abcfe7a8 115 /*
cheungderek 0:e083abcfe7a8 116 * Values for phase from BSD pppd.h based on RFC 1661.
cheungderek 0:e083abcfe7a8 117 */
cheungderek 0:e083abcfe7a8 118 typedef enum {
cheungderek 0:e083abcfe7a8 119 PHASE_DEAD = 0,
cheungderek 0:e083abcfe7a8 120 PHASE_INITIALIZE,
cheungderek 0:e083abcfe7a8 121 PHASE_ESTABLISH,
cheungderek 0:e083abcfe7a8 122 PHASE_AUTHENTICATE,
cheungderek 0:e083abcfe7a8 123 PHASE_CALLBACK,
cheungderek 0:e083abcfe7a8 124 PHASE_NETWORK,
cheungderek 0:e083abcfe7a8 125 PHASE_TERMINATE
cheungderek 0:e083abcfe7a8 126 } LinkPhase;
cheungderek 0:e083abcfe7a8 127
cheungderek 0:e083abcfe7a8 128
cheungderek 0:e083abcfe7a8 129
cheungderek 0:e083abcfe7a8 130 extern LinkPhase lcp_phase[NUM_PPP]; /* Phase of link session (RFC 1661) */
cheungderek 0:e083abcfe7a8 131 extern lcp_options lcp_wantoptions[];
cheungderek 0:e083abcfe7a8 132 extern lcp_options lcp_gotoptions[];
cheungderek 0:e083abcfe7a8 133 extern lcp_options lcp_allowoptions[];
cheungderek 0:e083abcfe7a8 134 extern lcp_options lcp_hisoptions[];
cheungderek 0:e083abcfe7a8 135 extern ext_accm xmit_accm[];
cheungderek 0:e083abcfe7a8 136
cheungderek 0:e083abcfe7a8 137
cheungderek 0:e083abcfe7a8 138 void lcp_init (int);
cheungderek 0:e083abcfe7a8 139 void lcp_open (int);
cheungderek 0:e083abcfe7a8 140 void lcp_close (int, char *);
cheungderek 0:e083abcfe7a8 141 void lcp_lowerup (int);
cheungderek 0:e083abcfe7a8 142 void lcp_lowerdown(int);
cheungderek 0:e083abcfe7a8 143 void lcp_sprotrej (int, u_char *, int); /* send protocol reject */
cheungderek 0:e083abcfe7a8 144
cheungderek 0:e083abcfe7a8 145 extern struct protent lcp_protent;
cheungderek 0:e083abcfe7a8 146
cheungderek 0:e083abcfe7a8 147 /* Default number of times we receive our magic number from the peer
cheungderek 0:e083abcfe7a8 148 before deciding the link is looped-back. */
cheungderek 0:e083abcfe7a8 149 #define DEFLOOPBACKFAIL 10
cheungderek 0:e083abcfe7a8 150
cheungderek 0:e083abcfe7a8 151 #endif /* LCP_H */