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 * pap.h - PPP Password Authentication 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-12-04 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 * upap.h - User/Password Authentication 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
cheungderek 0:e083abcfe7a8 52 #ifndef PAP_H
cheungderek 0:e083abcfe7a8 53 #define PAP_H
cheungderek 0:e083abcfe7a8 54
cheungderek 0:e083abcfe7a8 55 #if PAP_SUPPORT /* don't build if not configured for use in lwipopts.h */
cheungderek 0:e083abcfe7a8 56
cheungderek 0:e083abcfe7a8 57 /*
cheungderek 0:e083abcfe7a8 58 * Packet header = Code, id, length.
cheungderek 0:e083abcfe7a8 59 */
cheungderek 0:e083abcfe7a8 60 #define UPAP_HEADERLEN (sizeof (u_char) + sizeof (u_char) + sizeof (u_short))
cheungderek 0:e083abcfe7a8 61
cheungderek 0:e083abcfe7a8 62
cheungderek 0:e083abcfe7a8 63 /*
cheungderek 0:e083abcfe7a8 64 * UPAP codes.
cheungderek 0:e083abcfe7a8 65 */
cheungderek 0:e083abcfe7a8 66 #define UPAP_AUTHREQ 1 /* Authenticate-Request */
cheungderek 0:e083abcfe7a8 67 #define UPAP_AUTHACK 2 /* Authenticate-Ack */
cheungderek 0:e083abcfe7a8 68 #define UPAP_AUTHNAK 3 /* Authenticate-Nak */
cheungderek 0:e083abcfe7a8 69
cheungderek 0:e083abcfe7a8 70 /*
cheungderek 0:e083abcfe7a8 71 * Each interface is described by upap structure.
cheungderek 0:e083abcfe7a8 72 */
cheungderek 0:e083abcfe7a8 73 typedef struct upap_state {
cheungderek 0:e083abcfe7a8 74 int us_unit; /* Interface unit number */
cheungderek 0:e083abcfe7a8 75 const char *us_user; /* User */
cheungderek 0:e083abcfe7a8 76 int us_userlen; /* User length */
cheungderek 0:e083abcfe7a8 77 const char *us_passwd; /* Password */
cheungderek 0:e083abcfe7a8 78 int us_passwdlen; /* Password length */
cheungderek 0:e083abcfe7a8 79 int us_clientstate; /* Client state */
cheungderek 0:e083abcfe7a8 80 int us_serverstate; /* Server state */
cheungderek 0:e083abcfe7a8 81 u_char us_id; /* Current id */
cheungderek 0:e083abcfe7a8 82 int us_timeouttime; /* Timeout (seconds) for auth-req retrans. */
cheungderek 0:e083abcfe7a8 83 int us_transmits; /* Number of auth-reqs sent */
cheungderek 0:e083abcfe7a8 84 int us_maxtransmits; /* Maximum number of auth-reqs to send */
cheungderek 0:e083abcfe7a8 85 int us_reqtimeout; /* Time to wait for auth-req from peer */
cheungderek 0:e083abcfe7a8 86 } upap_state;
cheungderek 0:e083abcfe7a8 87
cheungderek 0:e083abcfe7a8 88 /*
cheungderek 0:e083abcfe7a8 89 * Client states.
cheungderek 0:e083abcfe7a8 90 */
cheungderek 0:e083abcfe7a8 91 #define UPAPCS_INITIAL 0 /* Connection down */
cheungderek 0:e083abcfe7a8 92 #define UPAPCS_CLOSED 1 /* Connection up, haven't requested auth */
cheungderek 0:e083abcfe7a8 93 #define UPAPCS_PENDING 2 /* Connection down, have requested auth */
cheungderek 0:e083abcfe7a8 94 #define UPAPCS_AUTHREQ 3 /* We've sent an Authenticate-Request */
cheungderek 0:e083abcfe7a8 95 #define UPAPCS_OPEN 4 /* We've received an Ack */
cheungderek 0:e083abcfe7a8 96 #define UPAPCS_BADAUTH 5 /* We've received a Nak */
cheungderek 0:e083abcfe7a8 97
cheungderek 0:e083abcfe7a8 98 /*
cheungderek 0:e083abcfe7a8 99 * Server states.
cheungderek 0:e083abcfe7a8 100 */
cheungderek 0:e083abcfe7a8 101 #define UPAPSS_INITIAL 0 /* Connection down */
cheungderek 0:e083abcfe7a8 102 #define UPAPSS_CLOSED 1 /* Connection up, haven't requested auth */
cheungderek 0:e083abcfe7a8 103 #define UPAPSS_PENDING 2 /* Connection down, have requested auth */
cheungderek 0:e083abcfe7a8 104 #define UPAPSS_LISTEN 3 /* Listening for an Authenticate */
cheungderek 0:e083abcfe7a8 105 #define UPAPSS_OPEN 4 /* We've sent an Ack */
cheungderek 0:e083abcfe7a8 106 #define UPAPSS_BADAUTH 5 /* We've sent a Nak */
cheungderek 0:e083abcfe7a8 107
cheungderek 0:e083abcfe7a8 108
cheungderek 0:e083abcfe7a8 109 extern upap_state upap[];
cheungderek 0:e083abcfe7a8 110
cheungderek 0:e083abcfe7a8 111 void upap_authwithpeer (int, char *, char *);
cheungderek 0:e083abcfe7a8 112 void upap_authpeer (int);
cheungderek 0:e083abcfe7a8 113
cheungderek 0:e083abcfe7a8 114 extern struct protent pap_protent;
cheungderek 0:e083abcfe7a8 115
cheungderek 0:e083abcfe7a8 116 #endif /* PAP_SUPPORT */
cheungderek 0:e083abcfe7a8 117
cheungderek 0:e083abcfe7a8 118 #endif /* PAP_H */