This short program illustrates how to use the DS130x_I2C library. My objective is to share the same RTC with Microchip 18F MCU.

Dependencies:   mbed DebugLibrary

Committer:
Yann
Date:
Wed Feb 09 13:57:49 2011 +0000
Revision:
0:f30e2135b0db
V0.0.0.1

Who changed what in which revision?

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