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
LPC1768/lwip/netif/ppp/vj.h@0:e083abcfe7a8, 2011-06-22 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
cheungderek | 0:e083abcfe7a8 | 1 | /* |
cheungderek | 0:e083abcfe7a8 | 2 | * Definitions for tcp compression routines. |
cheungderek | 0:e083abcfe7a8 | 3 | * |
cheungderek | 0:e083abcfe7a8 | 4 | * $Id: vj.h,v 1.7 2010/02/22 17:52:09 goldsimon Exp $ |
cheungderek | 0:e083abcfe7a8 | 5 | * |
cheungderek | 0:e083abcfe7a8 | 6 | * Copyright (c) 1989 Regents of the University of California. |
cheungderek | 0:e083abcfe7a8 | 7 | * All rights reserved. |
cheungderek | 0:e083abcfe7a8 | 8 | * |
cheungderek | 0:e083abcfe7a8 | 9 | * Redistribution and use in source and binary forms are permitted |
cheungderek | 0:e083abcfe7a8 | 10 | * provided that the above copyright notice and this paragraph are |
cheungderek | 0:e083abcfe7a8 | 11 | * duplicated in all such forms and that any documentation, |
cheungderek | 0:e083abcfe7a8 | 12 | * advertising materials, and other materials related to such |
cheungderek | 0:e083abcfe7a8 | 13 | * distribution and use acknowledge that the software was developed |
cheungderek | 0:e083abcfe7a8 | 14 | * by the University of California, Berkeley. The name of the |
cheungderek | 0:e083abcfe7a8 | 15 | * University may not be used to endorse or promote products derived |
cheungderek | 0:e083abcfe7a8 | 16 | * from this software without specific prior written permission. |
cheungderek | 0:e083abcfe7a8 | 17 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
cheungderek | 0:e083abcfe7a8 | 18 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
cheungderek | 0:e083abcfe7a8 | 19 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
cheungderek | 0:e083abcfe7a8 | 20 | * |
cheungderek | 0:e083abcfe7a8 | 21 | * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989: |
cheungderek | 0:e083abcfe7a8 | 22 | * - Initial distribution. |
cheungderek | 0:e083abcfe7a8 | 23 | */ |
cheungderek | 0:e083abcfe7a8 | 24 | |
cheungderek | 0:e083abcfe7a8 | 25 | #ifndef VJ_H |
cheungderek | 0:e083abcfe7a8 | 26 | #define VJ_H |
cheungderek | 0:e083abcfe7a8 | 27 | |
cheungderek | 0:e083abcfe7a8 | 28 | #include "lwip/ip.h" |
cheungderek | 0:e083abcfe7a8 | 29 | #include "lwip/tcp_impl.h" |
cheungderek | 0:e083abcfe7a8 | 30 | |
cheungderek | 0:e083abcfe7a8 | 31 | #define MAX_SLOTS 16 /* must be > 2 and < 256 */ |
cheungderek | 0:e083abcfe7a8 | 32 | #define MAX_HDR 128 |
cheungderek | 0:e083abcfe7a8 | 33 | |
cheungderek | 0:e083abcfe7a8 | 34 | /* |
cheungderek | 0:e083abcfe7a8 | 35 | * Compressed packet format: |
cheungderek | 0:e083abcfe7a8 | 36 | * |
cheungderek | 0:e083abcfe7a8 | 37 | * The first octet contains the packet type (top 3 bits), TCP |
cheungderek | 0:e083abcfe7a8 | 38 | * 'push' bit, and flags that indicate which of the 4 TCP sequence |
cheungderek | 0:e083abcfe7a8 | 39 | * numbers have changed (bottom 5 bits). The next octet is a |
cheungderek | 0:e083abcfe7a8 | 40 | * conversation number that associates a saved IP/TCP header with |
cheungderek | 0:e083abcfe7a8 | 41 | * the compressed packet. The next two octets are the TCP checksum |
cheungderek | 0:e083abcfe7a8 | 42 | * from the original datagram. The next 0 to 15 octets are |
cheungderek | 0:e083abcfe7a8 | 43 | * sequence number changes, one change per bit set in the header |
cheungderek | 0:e083abcfe7a8 | 44 | * (there may be no changes and there are two special cases where |
cheungderek | 0:e083abcfe7a8 | 45 | * the receiver implicitly knows what changed -- see below). |
cheungderek | 0:e083abcfe7a8 | 46 | * |
cheungderek | 0:e083abcfe7a8 | 47 | * There are 5 numbers which can change (they are always inserted |
cheungderek | 0:e083abcfe7a8 | 48 | * in the following order): TCP urgent pointer, window, |
cheungderek | 0:e083abcfe7a8 | 49 | * acknowlegement, sequence number and IP ID. (The urgent pointer |
cheungderek | 0:e083abcfe7a8 | 50 | * is different from the others in that its value is sent, not the |
cheungderek | 0:e083abcfe7a8 | 51 | * change in value.) Since typical use of SLIP links is biased |
cheungderek | 0:e083abcfe7a8 | 52 | * toward small packets (see comments on MTU/MSS below), changes |
cheungderek | 0:e083abcfe7a8 | 53 | * use a variable length coding with one octet for numbers in the |
cheungderek | 0:e083abcfe7a8 | 54 | * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the |
cheungderek | 0:e083abcfe7a8 | 55 | * range 256 - 65535 or 0. (If the change in sequence number or |
cheungderek | 0:e083abcfe7a8 | 56 | * ack is more than 65535, an uncompressed packet is sent.) |
cheungderek | 0:e083abcfe7a8 | 57 | */ |
cheungderek | 0:e083abcfe7a8 | 58 | |
cheungderek | 0:e083abcfe7a8 | 59 | /* |
cheungderek | 0:e083abcfe7a8 | 60 | * Packet types (must not conflict with IP protocol version) |
cheungderek | 0:e083abcfe7a8 | 61 | * |
cheungderek | 0:e083abcfe7a8 | 62 | * The top nibble of the first octet is the packet type. There are |
cheungderek | 0:e083abcfe7a8 | 63 | * three possible types: IP (not proto TCP or tcp with one of the |
cheungderek | 0:e083abcfe7a8 | 64 | * control flags set); uncompressed TCP (a normal IP/TCP packet but |
cheungderek | 0:e083abcfe7a8 | 65 | * with the 8-bit protocol field replaced by an 8-bit connection id -- |
cheungderek | 0:e083abcfe7a8 | 66 | * this type of packet syncs the sender & receiver); and compressed |
cheungderek | 0:e083abcfe7a8 | 67 | * TCP (described above). |
cheungderek | 0:e083abcfe7a8 | 68 | * |
cheungderek | 0:e083abcfe7a8 | 69 | * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and |
cheungderek | 0:e083abcfe7a8 | 70 | * is logically part of the 4-bit "changes" field that follows. Top |
cheungderek | 0:e083abcfe7a8 | 71 | * three bits are actual packet type. For backward compatibility |
cheungderek | 0:e083abcfe7a8 | 72 | * and in the interest of conserving bits, numbers are chosen so the |
cheungderek | 0:e083abcfe7a8 | 73 | * IP protocol version number (4) which normally appears in this nibble |
cheungderek | 0:e083abcfe7a8 | 74 | * means "IP packet". |
cheungderek | 0:e083abcfe7a8 | 75 | */ |
cheungderek | 0:e083abcfe7a8 | 76 | |
cheungderek | 0:e083abcfe7a8 | 77 | /* packet types */ |
cheungderek | 0:e083abcfe7a8 | 78 | #define TYPE_IP 0x40 |
cheungderek | 0:e083abcfe7a8 | 79 | #define TYPE_UNCOMPRESSED_TCP 0x70 |
cheungderek | 0:e083abcfe7a8 | 80 | #define TYPE_COMPRESSED_TCP 0x80 |
cheungderek | 0:e083abcfe7a8 | 81 | #define TYPE_ERROR 0x00 |
cheungderek | 0:e083abcfe7a8 | 82 | |
cheungderek | 0:e083abcfe7a8 | 83 | /* Bits in first octet of compressed packet */ |
cheungderek | 0:e083abcfe7a8 | 84 | #define NEW_C 0x40 /* flag bits for what changed in a packet */ |
cheungderek | 0:e083abcfe7a8 | 85 | #define NEW_I 0x20 |
cheungderek | 0:e083abcfe7a8 | 86 | #define NEW_S 0x08 |
cheungderek | 0:e083abcfe7a8 | 87 | #define NEW_A 0x04 |
cheungderek | 0:e083abcfe7a8 | 88 | #define NEW_W 0x02 |
cheungderek | 0:e083abcfe7a8 | 89 | #define NEW_U 0x01 |
cheungderek | 0:e083abcfe7a8 | 90 | |
cheungderek | 0:e083abcfe7a8 | 91 | /* reserved, special-case values of above */ |
cheungderek | 0:e083abcfe7a8 | 92 | #define SPECIAL_I (NEW_S|NEW_W|NEW_U) /* echoed interactive traffic */ |
cheungderek | 0:e083abcfe7a8 | 93 | #define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U) /* unidirectional data */ |
cheungderek | 0:e083abcfe7a8 | 94 | #define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U) |
cheungderek | 0:e083abcfe7a8 | 95 | |
cheungderek | 0:e083abcfe7a8 | 96 | #define TCP_PUSH_BIT 0x10 |
cheungderek | 0:e083abcfe7a8 | 97 | |
cheungderek | 0:e083abcfe7a8 | 98 | |
cheungderek | 0:e083abcfe7a8 | 99 | /* |
cheungderek | 0:e083abcfe7a8 | 100 | * "state" data for each active tcp conversation on the wire. This is |
cheungderek | 0:e083abcfe7a8 | 101 | * basically a copy of the entire IP/TCP header from the last packet |
cheungderek | 0:e083abcfe7a8 | 102 | * we saw from the conversation together with a small identifier |
cheungderek | 0:e083abcfe7a8 | 103 | * the transmit & receive ends of the line use to locate saved header. |
cheungderek | 0:e083abcfe7a8 | 104 | */ |
cheungderek | 0:e083abcfe7a8 | 105 | struct cstate { |
cheungderek | 0:e083abcfe7a8 | 106 | struct cstate *cs_next; /* next most recently used state (xmit only) */ |
cheungderek | 0:e083abcfe7a8 | 107 | u_short cs_hlen; /* size of hdr (receive only) */ |
cheungderek | 0:e083abcfe7a8 | 108 | u_char cs_id; /* connection # associated with this state */ |
cheungderek | 0:e083abcfe7a8 | 109 | u_char cs_filler; |
cheungderek | 0:e083abcfe7a8 | 110 | union { |
cheungderek | 0:e083abcfe7a8 | 111 | char csu_hdr[MAX_HDR]; |
cheungderek | 0:e083abcfe7a8 | 112 | struct ip_hdr csu_ip; /* ip/tcp hdr from most recent packet */ |
cheungderek | 0:e083abcfe7a8 | 113 | } vjcs_u; |
cheungderek | 0:e083abcfe7a8 | 114 | }; |
cheungderek | 0:e083abcfe7a8 | 115 | #define cs_ip vjcs_u.csu_ip |
cheungderek | 0:e083abcfe7a8 | 116 | #define cs_hdr vjcs_u.csu_hdr |
cheungderek | 0:e083abcfe7a8 | 117 | |
cheungderek | 0:e083abcfe7a8 | 118 | |
cheungderek | 0:e083abcfe7a8 | 119 | struct vjstat { |
cheungderek | 0:e083abcfe7a8 | 120 | unsigned long vjs_packets; /* outbound packets */ |
cheungderek | 0:e083abcfe7a8 | 121 | unsigned long vjs_compressed; /* outbound compressed packets */ |
cheungderek | 0:e083abcfe7a8 | 122 | unsigned long vjs_searches; /* searches for connection state */ |
cheungderek | 0:e083abcfe7a8 | 123 | unsigned long vjs_misses; /* times couldn't find conn. state */ |
cheungderek | 0:e083abcfe7a8 | 124 | unsigned long vjs_uncompressedin; /* inbound uncompressed packets */ |
cheungderek | 0:e083abcfe7a8 | 125 | unsigned long vjs_compressedin; /* inbound compressed packets */ |
cheungderek | 0:e083abcfe7a8 | 126 | unsigned long vjs_errorin; /* inbound unknown type packets */ |
cheungderek | 0:e083abcfe7a8 | 127 | unsigned long vjs_tossed; /* inbound packets tossed because of error */ |
cheungderek | 0:e083abcfe7a8 | 128 | }; |
cheungderek | 0:e083abcfe7a8 | 129 | |
cheungderek | 0:e083abcfe7a8 | 130 | /* |
cheungderek | 0:e083abcfe7a8 | 131 | * all the state data for one serial line (we need one of these per line). |
cheungderek | 0:e083abcfe7a8 | 132 | */ |
cheungderek | 0:e083abcfe7a8 | 133 | struct vjcompress { |
cheungderek | 0:e083abcfe7a8 | 134 | struct cstate *last_cs; /* most recently used tstate */ |
cheungderek | 0:e083abcfe7a8 | 135 | u_char last_recv; /* last rcvd conn. id */ |
cheungderek | 0:e083abcfe7a8 | 136 | u_char last_xmit; /* last sent conn. id */ |
cheungderek | 0:e083abcfe7a8 | 137 | u_short flags; |
cheungderek | 0:e083abcfe7a8 | 138 | u_char maxSlotIndex; |
cheungderek | 0:e083abcfe7a8 | 139 | u_char compressSlot; /* Flag indicating OK to compress slot ID. */ |
cheungderek | 0:e083abcfe7a8 | 140 | #if LINK_STATS |
cheungderek | 0:e083abcfe7a8 | 141 | struct vjstat stats; |
cheungderek | 0:e083abcfe7a8 | 142 | #endif |
cheungderek | 0:e083abcfe7a8 | 143 | struct cstate tstate[MAX_SLOTS]; /* xmit connection states */ |
cheungderek | 0:e083abcfe7a8 | 144 | struct cstate rstate[MAX_SLOTS]; /* receive connection states */ |
cheungderek | 0:e083abcfe7a8 | 145 | }; |
cheungderek | 0:e083abcfe7a8 | 146 | |
cheungderek | 0:e083abcfe7a8 | 147 | /* flag values */ |
cheungderek | 0:e083abcfe7a8 | 148 | #define VJF_TOSS 1U /* tossing rcvd frames because of input err */ |
cheungderek | 0:e083abcfe7a8 | 149 | |
cheungderek | 0:e083abcfe7a8 | 150 | extern void vj_compress_init (struct vjcompress *comp); |
cheungderek | 0:e083abcfe7a8 | 151 | extern u_int vj_compress_tcp (struct vjcompress *comp, struct pbuf *pb); |
cheungderek | 0:e083abcfe7a8 | 152 | extern void vj_uncompress_err (struct vjcompress *comp); |
cheungderek | 0:e083abcfe7a8 | 153 | extern int vj_uncompress_uncomp(struct pbuf *nb, struct vjcompress *comp); |
cheungderek | 0:e083abcfe7a8 | 154 | extern int vj_uncompress_tcp (struct pbuf **nb, struct vjcompress *comp); |
cheungderek | 0:e083abcfe7a8 | 155 | |
cheungderek | 0:e083abcfe7a8 | 156 | #endif /* VJ_H */ |