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/include/netif/etharp.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 | * Copyright (c) 2001-2003 Swedish Institute of Computer Science. |
cheungderek | 0:e083abcfe7a8 | 3 | * Copyright (c) 2003-2004 Leon Woestenberg <leon.woestenberg@axon.tv> |
cheungderek | 0:e083abcfe7a8 | 4 | * Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands. |
cheungderek | 0:e083abcfe7a8 | 5 | * All rights reserved. |
cheungderek | 0:e083abcfe7a8 | 6 | * |
cheungderek | 0:e083abcfe7a8 | 7 | * Redistribution and use in source and binary forms, with or without modification, |
cheungderek | 0:e083abcfe7a8 | 8 | * are permitted provided that the following conditions are met: |
cheungderek | 0:e083abcfe7a8 | 9 | * |
cheungderek | 0:e083abcfe7a8 | 10 | * 1. Redistributions of source code must retain the above copyright notice, |
cheungderek | 0:e083abcfe7a8 | 11 | * this list of conditions and the following disclaimer. |
cheungderek | 0:e083abcfe7a8 | 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
cheungderek | 0:e083abcfe7a8 | 13 | * this list of conditions and the following disclaimer in the documentation |
cheungderek | 0:e083abcfe7a8 | 14 | * and/or other materials provided with the distribution. |
cheungderek | 0:e083abcfe7a8 | 15 | * 3. The name of the author may not be used to endorse or promote products |
cheungderek | 0:e083abcfe7a8 | 16 | * derived from this software without specific prior written permission. |
cheungderek | 0:e083abcfe7a8 | 17 | * |
cheungderek | 0:e083abcfe7a8 | 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
cheungderek | 0:e083abcfe7a8 | 19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
cheungderek | 0:e083abcfe7a8 | 20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
cheungderek | 0:e083abcfe7a8 | 21 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
cheungderek | 0:e083abcfe7a8 | 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
cheungderek | 0:e083abcfe7a8 | 23 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
cheungderek | 0:e083abcfe7a8 | 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
cheungderek | 0:e083abcfe7a8 | 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
cheungderek | 0:e083abcfe7a8 | 26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY |
cheungderek | 0:e083abcfe7a8 | 27 | * OF SUCH DAMAGE. |
cheungderek | 0:e083abcfe7a8 | 28 | * |
cheungderek | 0:e083abcfe7a8 | 29 | * This file is part of the lwIP TCP/IP stack. |
cheungderek | 0:e083abcfe7a8 | 30 | * |
cheungderek | 0:e083abcfe7a8 | 31 | * Author: Adam Dunkels <adam@sics.se> |
cheungderek | 0:e083abcfe7a8 | 32 | * |
cheungderek | 0:e083abcfe7a8 | 33 | */ |
cheungderek | 0:e083abcfe7a8 | 34 | |
cheungderek | 0:e083abcfe7a8 | 35 | #ifndef __NETIF_ETHARP_H__ |
cheungderek | 0:e083abcfe7a8 | 36 | #define __NETIF_ETHARP_H__ |
cheungderek | 0:e083abcfe7a8 | 37 | |
cheungderek | 0:e083abcfe7a8 | 38 | #include "lwip/opt.h" |
cheungderek | 0:e083abcfe7a8 | 39 | |
cheungderek | 0:e083abcfe7a8 | 40 | #if LWIP_ARP || LWIP_ETHERNET /* don't build if not configured for use in lwipopts.h */ |
cheungderek | 0:e083abcfe7a8 | 41 | |
cheungderek | 0:e083abcfe7a8 | 42 | #include "lwip/pbuf.h" |
cheungderek | 0:e083abcfe7a8 | 43 | #include "lwip/ip_addr.h" |
cheungderek | 0:e083abcfe7a8 | 44 | #include "lwip/netif.h" |
cheungderek | 0:e083abcfe7a8 | 45 | #include "lwip/ip.h" |
cheungderek | 0:e083abcfe7a8 | 46 | |
cheungderek | 0:e083abcfe7a8 | 47 | #ifdef __cplusplus |
cheungderek | 0:e083abcfe7a8 | 48 | extern "C" { |
cheungderek | 0:e083abcfe7a8 | 49 | #endif |
cheungderek | 0:e083abcfe7a8 | 50 | |
cheungderek | 0:e083abcfe7a8 | 51 | #ifndef ETHARP_HWADDR_LEN |
cheungderek | 0:e083abcfe7a8 | 52 | #define ETHARP_HWADDR_LEN 6 |
cheungderek | 0:e083abcfe7a8 | 53 | #endif |
cheungderek | 0:e083abcfe7a8 | 54 | |
cheungderek | 0:e083abcfe7a8 | 55 | #ifdef PACK_STRUCT_USE_INCLUDES |
cheungderek | 0:e083abcfe7a8 | 56 | # include "arch/bpstruct.h" |
cheungderek | 0:e083abcfe7a8 | 57 | #endif |
cheungderek | 0:e083abcfe7a8 | 58 | PACK_STRUCT_BEGIN |
cheungderek | 0:e083abcfe7a8 | 59 | struct eth_addr { |
cheungderek | 0:e083abcfe7a8 | 60 | PACK_STRUCT_FIELD(u8_t addr[ETHARP_HWADDR_LEN]); |
cheungderek | 0:e083abcfe7a8 | 61 | } PACK_STRUCT_STRUCT; |
cheungderek | 0:e083abcfe7a8 | 62 | PACK_STRUCT_END |
cheungderek | 0:e083abcfe7a8 | 63 | #ifdef PACK_STRUCT_USE_INCLUDES |
cheungderek | 0:e083abcfe7a8 | 64 | # include "arch/epstruct.h" |
cheungderek | 0:e083abcfe7a8 | 65 | #endif |
cheungderek | 0:e083abcfe7a8 | 66 | |
cheungderek | 0:e083abcfe7a8 | 67 | #ifdef PACK_STRUCT_USE_INCLUDES |
cheungderek | 0:e083abcfe7a8 | 68 | # include "arch/bpstruct.h" |
cheungderek | 0:e083abcfe7a8 | 69 | #endif |
cheungderek | 0:e083abcfe7a8 | 70 | PACK_STRUCT_BEGIN |
cheungderek | 0:e083abcfe7a8 | 71 | /* Ethernet header */ |
cheungderek | 0:e083abcfe7a8 | 72 | struct eth_hdr { |
cheungderek | 0:e083abcfe7a8 | 73 | #if ETH_PAD_SIZE |
cheungderek | 0:e083abcfe7a8 | 74 | PACK_STRUCT_FIELD(u8_t padding[ETH_PAD_SIZE]); |
cheungderek | 0:e083abcfe7a8 | 75 | #endif |
cheungderek | 0:e083abcfe7a8 | 76 | PACK_STRUCT_FIELD(struct eth_addr dest); |
cheungderek | 0:e083abcfe7a8 | 77 | PACK_STRUCT_FIELD(struct eth_addr src); |
cheungderek | 0:e083abcfe7a8 | 78 | PACK_STRUCT_FIELD(u16_t type); |
cheungderek | 0:e083abcfe7a8 | 79 | } PACK_STRUCT_STRUCT; |
cheungderek | 0:e083abcfe7a8 | 80 | PACK_STRUCT_END |
cheungderek | 0:e083abcfe7a8 | 81 | #ifdef PACK_STRUCT_USE_INCLUDES |
cheungderek | 0:e083abcfe7a8 | 82 | # include "arch/epstruct.h" |
cheungderek | 0:e083abcfe7a8 | 83 | #endif |
cheungderek | 0:e083abcfe7a8 | 84 | |
cheungderek | 0:e083abcfe7a8 | 85 | #define SIZEOF_ETH_HDR (14 + ETH_PAD_SIZE) |
cheungderek | 0:e083abcfe7a8 | 86 | |
cheungderek | 0:e083abcfe7a8 | 87 | #if ETHARP_SUPPORT_VLAN |
cheungderek | 0:e083abcfe7a8 | 88 | |
cheungderek | 0:e083abcfe7a8 | 89 | #ifdef PACK_STRUCT_USE_INCLUDES |
cheungderek | 0:e083abcfe7a8 | 90 | # include "arch/bpstruct.h" |
cheungderek | 0:e083abcfe7a8 | 91 | #endif |
cheungderek | 0:e083abcfe7a8 | 92 | PACK_STRUCT_BEGIN |
cheungderek | 0:e083abcfe7a8 | 93 | /* VLAN header inserted between ethernet header and payload |
cheungderek | 0:e083abcfe7a8 | 94 | * if 'type' in ethernet header is ETHTYPE_VLAN. |
cheungderek | 0:e083abcfe7a8 | 95 | * See IEEE802.Q */ |
cheungderek | 0:e083abcfe7a8 | 96 | struct eth_vlan_hdr { |
cheungderek | 0:e083abcfe7a8 | 97 | PACK_STRUCT_FIELD(u16_t tpid); |
cheungderek | 0:e083abcfe7a8 | 98 | PACK_STRUCT_FIELD(u16_t prio_vid); |
cheungderek | 0:e083abcfe7a8 | 99 | } PACK_STRUCT_STRUCT; |
cheungderek | 0:e083abcfe7a8 | 100 | PACK_STRUCT_END |
cheungderek | 0:e083abcfe7a8 | 101 | #ifdef PACK_STRUCT_USE_INCLUDES |
cheungderek | 0:e083abcfe7a8 | 102 | # include "arch/epstruct.h" |
cheungderek | 0:e083abcfe7a8 | 103 | #endif |
cheungderek | 0:e083abcfe7a8 | 104 | |
cheungderek | 0:e083abcfe7a8 | 105 | #define SIZEOF_VLAN_HDR 4 |
cheungderek | 0:e083abcfe7a8 | 106 | #define VLAN_ID(vlan_hdr) (htons((vlan_hdr)->prio_vid) & 0xFFF) |
cheungderek | 0:e083abcfe7a8 | 107 | |
cheungderek | 0:e083abcfe7a8 | 108 | #endif /* ETHARP_SUPPORT_VLAN */ |
cheungderek | 0:e083abcfe7a8 | 109 | |
cheungderek | 0:e083abcfe7a8 | 110 | #ifdef PACK_STRUCT_USE_INCLUDES |
cheungderek | 0:e083abcfe7a8 | 111 | # include "arch/bpstruct.h" |
cheungderek | 0:e083abcfe7a8 | 112 | #endif |
cheungderek | 0:e083abcfe7a8 | 113 | PACK_STRUCT_BEGIN |
cheungderek | 0:e083abcfe7a8 | 114 | /* the ARP message, see RFC 826 ("Packet format") */ |
cheungderek | 0:e083abcfe7a8 | 115 | struct etharp_hdr { |
cheungderek | 0:e083abcfe7a8 | 116 | PACK_STRUCT_FIELD(u16_t hwtype); |
cheungderek | 0:e083abcfe7a8 | 117 | PACK_STRUCT_FIELD(u16_t proto); |
cheungderek | 0:e083abcfe7a8 | 118 | PACK_STRUCT_FIELD(u8_t hwlen); |
cheungderek | 0:e083abcfe7a8 | 119 | PACK_STRUCT_FIELD(u8_t protolen); |
cheungderek | 0:e083abcfe7a8 | 120 | PACK_STRUCT_FIELD(u16_t opcode); |
cheungderek | 0:e083abcfe7a8 | 121 | PACK_STRUCT_FIELD(struct eth_addr shwaddr); |
cheungderek | 0:e083abcfe7a8 | 122 | PACK_STRUCT_FIELD(struct ip_addr2 sipaddr); |
cheungderek | 0:e083abcfe7a8 | 123 | PACK_STRUCT_FIELD(struct eth_addr dhwaddr); |
cheungderek | 0:e083abcfe7a8 | 124 | PACK_STRUCT_FIELD(struct ip_addr2 dipaddr); |
cheungderek | 0:e083abcfe7a8 | 125 | } PACK_STRUCT_STRUCT; |
cheungderek | 0:e083abcfe7a8 | 126 | PACK_STRUCT_END |
cheungderek | 0:e083abcfe7a8 | 127 | #ifdef PACK_STRUCT_USE_INCLUDES |
cheungderek | 0:e083abcfe7a8 | 128 | # include "arch/epstruct.h" |
cheungderek | 0:e083abcfe7a8 | 129 | #endif |
cheungderek | 0:e083abcfe7a8 | 130 | |
cheungderek | 0:e083abcfe7a8 | 131 | #define SIZEOF_ETHARP_HDR 28 |
cheungderek | 0:e083abcfe7a8 | 132 | #define SIZEOF_ETHARP_PACKET (SIZEOF_ETH_HDR + SIZEOF_ETHARP_HDR) |
cheungderek | 0:e083abcfe7a8 | 133 | |
cheungderek | 0:e083abcfe7a8 | 134 | /* 5 seconds period */ |
cheungderek | 0:e083abcfe7a8 | 135 | #define ARP_TMR_INTERVAL 5000 |
cheungderek | 0:e083abcfe7a8 | 136 | |
cheungderek | 0:e083abcfe7a8 | 137 | #define ETHTYPE_ARP 0x0806 |
cheungderek | 0:e083abcfe7a8 | 138 | #define ETHTYPE_IP 0x0800 |
cheungderek | 0:e083abcfe7a8 | 139 | #define ETHTYPE_VLAN 0x8100 |
cheungderek | 0:e083abcfe7a8 | 140 | #define ETHTYPE_PPPOEDISC 0x8863 /* PPP Over Ethernet Discovery Stage */ |
cheungderek | 0:e083abcfe7a8 | 141 | #define ETHTYPE_PPPOE 0x8864 /* PPP Over Ethernet Session Stage */ |
cheungderek | 0:e083abcfe7a8 | 142 | |
cheungderek | 0:e083abcfe7a8 | 143 | /* MEMCPY-like macro to copy to/from struct eth_addr's that are local variables |
cheungderek | 0:e083abcfe7a8 | 144 | * or known to be 32-bit aligned within the protocol header. */ |
cheungderek | 0:e083abcfe7a8 | 145 | #ifndef ETHADDR32_COPY |
cheungderek | 0:e083abcfe7a8 | 146 | #define ETHADDR32_COPY(src, dst) SMEMCPY(src, dst, ETHARP_HWADDR_LEN) |
cheungderek | 0:e083abcfe7a8 | 147 | #endif |
cheungderek | 0:e083abcfe7a8 | 148 | |
cheungderek | 0:e083abcfe7a8 | 149 | /* MEMCPY-like macro to copy to/from struct eth_addr's that are no local |
cheungderek | 0:e083abcfe7a8 | 150 | * variables and known to be 16-bit aligned within the protocol header. */ |
cheungderek | 0:e083abcfe7a8 | 151 | #ifndef ETHADDR16_COPY |
cheungderek | 0:e083abcfe7a8 | 152 | #define ETHADDR16_COPY(src, dst) SMEMCPY(src, dst, ETHARP_HWADDR_LEN) |
cheungderek | 0:e083abcfe7a8 | 153 | #endif |
cheungderek | 0:e083abcfe7a8 | 154 | |
cheungderek | 0:e083abcfe7a8 | 155 | #if LWIP_ARP /* don't build if not configured for use in lwipopts.h */ |
cheungderek | 0:e083abcfe7a8 | 156 | |
cheungderek | 0:e083abcfe7a8 | 157 | /* ARP message types (opcodes) */ |
cheungderek | 0:e083abcfe7a8 | 158 | #define ARP_REQUEST 1 |
cheungderek | 0:e083abcfe7a8 | 159 | #define ARP_REPLY 2 |
cheungderek | 0:e083abcfe7a8 | 160 | |
cheungderek | 0:e083abcfe7a8 | 161 | /* Define this to 1 and define LWIP_ARP_FILTER_NETIF_FN(pbuf, netif, type) |
cheungderek | 0:e083abcfe7a8 | 162 | * to a filter function that returns the correct netif when using multiple |
cheungderek | 0:e083abcfe7a8 | 163 | * netifs on one hardware interface where the netif's low-level receive |
cheungderek | 0:e083abcfe7a8 | 164 | * routine cannot decide for the correct netif (e.g. when mapping multiple |
cheungderek | 0:e083abcfe7a8 | 165 | * IP addresses to one hardware interface). |
cheungderek | 0:e083abcfe7a8 | 166 | */ |
cheungderek | 0:e083abcfe7a8 | 167 | #ifndef LWIP_ARP_FILTER_NETIF |
cheungderek | 0:e083abcfe7a8 | 168 | #define LWIP_ARP_FILTER_NETIF 0 |
cheungderek | 0:e083abcfe7a8 | 169 | #endif |
cheungderek | 0:e083abcfe7a8 | 170 | |
cheungderek | 0:e083abcfe7a8 | 171 | #if ARP_QUEUEING |
cheungderek | 0:e083abcfe7a8 | 172 | /* struct for queueing outgoing packets for unknown address |
cheungderek | 0:e083abcfe7a8 | 173 | * defined here to be accessed by memp.h |
cheungderek | 0:e083abcfe7a8 | 174 | */ |
cheungderek | 0:e083abcfe7a8 | 175 | struct etharp_q_entry { |
cheungderek | 0:e083abcfe7a8 | 176 | struct etharp_q_entry *next; |
cheungderek | 0:e083abcfe7a8 | 177 | struct pbuf *p; |
cheungderek | 0:e083abcfe7a8 | 178 | }; |
cheungderek | 0:e083abcfe7a8 | 179 | #endif /* ARP_QUEUEING */ |
cheungderek | 0:e083abcfe7a8 | 180 | |
cheungderek | 0:e083abcfe7a8 | 181 | #define etharp_init() /* Compatibility define, not init needed. */ |
cheungderek | 0:e083abcfe7a8 | 182 | void etharp_tmr(void); |
cheungderek | 0:e083abcfe7a8 | 183 | s8_t etharp_find_addr(struct netif *netif, ip_addr_t *ipaddr, |
cheungderek | 0:e083abcfe7a8 | 184 | struct eth_addr **eth_ret, ip_addr_t **ip_ret); |
cheungderek | 0:e083abcfe7a8 | 185 | err_t etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr); |
cheungderek | 0:e083abcfe7a8 | 186 | err_t etharp_query(struct netif *netif, ip_addr_t *ipaddr, struct pbuf *q); |
cheungderek | 0:e083abcfe7a8 | 187 | err_t etharp_request(struct netif *netif, ip_addr_t *ipaddr); |
cheungderek | 0:e083abcfe7a8 | 188 | /* For Ethernet network interfaces, we might want to send "gratuitous ARP"; |
cheungderek | 0:e083abcfe7a8 | 189 | * this is an ARP packet sent by a node in order to spontaneously cause other |
cheungderek | 0:e083abcfe7a8 | 190 | * nodes to update an entry in their ARP cache. |
cheungderek | 0:e083abcfe7a8 | 191 | * From RFC 3220 "IP Mobility Support for IPv4" section 4.6. */ |
cheungderek | 0:e083abcfe7a8 | 192 | #define etharp_gratuitous(netif) etharp_request((netif), &(netif)->ip_addr) |
cheungderek | 0:e083abcfe7a8 | 193 | |
cheungderek | 0:e083abcfe7a8 | 194 | #if ETHARP_SUPPORT_STATIC_ENTRIES |
cheungderek | 0:e083abcfe7a8 | 195 | err_t etharp_add_static_entry(ip_addr_t *ipaddr, struct eth_addr *ethaddr); |
cheungderek | 0:e083abcfe7a8 | 196 | err_t etharp_remove_static_entry(ip_addr_t *ipaddr); |
cheungderek | 0:e083abcfe7a8 | 197 | #endif /* ETHARP_SUPPORT_STATIC_ENTRIES */ |
cheungderek | 0:e083abcfe7a8 | 198 | |
cheungderek | 0:e083abcfe7a8 | 199 | #if LWIP_AUTOIP |
cheungderek | 0:e083abcfe7a8 | 200 | err_t etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr, |
cheungderek | 0:e083abcfe7a8 | 201 | const struct eth_addr *ethdst_addr, |
cheungderek | 0:e083abcfe7a8 | 202 | const struct eth_addr *hwsrc_addr, const ip_addr_t *ipsrc_addr, |
cheungderek | 0:e083abcfe7a8 | 203 | const struct eth_addr *hwdst_addr, const ip_addr_t *ipdst_addr, |
cheungderek | 0:e083abcfe7a8 | 204 | const u16_t opcode); |
cheungderek | 0:e083abcfe7a8 | 205 | #endif /* LWIP_AUTOIP */ |
cheungderek | 0:e083abcfe7a8 | 206 | |
cheungderek | 0:e083abcfe7a8 | 207 | #endif /* LWIP_ARP */ |
cheungderek | 0:e083abcfe7a8 | 208 | |
cheungderek | 0:e083abcfe7a8 | 209 | err_t ethernet_input(struct pbuf *p, struct netif *netif); |
cheungderek | 0:e083abcfe7a8 | 210 | |
cheungderek | 0:e083abcfe7a8 | 211 | #define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETHARP_HWADDR_LEN) == 0) |
cheungderek | 0:e083abcfe7a8 | 212 | |
cheungderek | 0:e083abcfe7a8 | 213 | extern const struct eth_addr ethbroadcast, ethzero; |
cheungderek | 0:e083abcfe7a8 | 214 | |
cheungderek | 0:e083abcfe7a8 | 215 | #ifdef __cplusplus |
cheungderek | 0:e083abcfe7a8 | 216 | } |
cheungderek | 0:e083abcfe7a8 | 217 | #endif |
cheungderek | 0:e083abcfe7a8 | 218 | |
cheungderek | 0:e083abcfe7a8 | 219 | #endif /* LWIP_ARP || LWIP_ETHERNET */ |
cheungderek | 0:e083abcfe7a8 | 220 | |
cheungderek | 0:e083abcfe7a8 | 221 | #endif /* __NETIF_ARP_H__ */ |