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 /*
Yann 0:f30e2135b0db 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
Yann 0:f30e2135b0db 4
Yann 0:f30e2135b0db 5 Permission is hereby granted, free of charge, to any person obtaining a copy
Yann 0:f30e2135b0db 6 of this software and associated documentation files (the "Software"), to deal
Yann 0:f30e2135b0db 7 in the Software without restriction, including without limitation the rights
Yann 0:f30e2135b0db 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Yann 0:f30e2135b0db 9 copies of the Software, and to permit persons to whom the Software is
Yann 0:f30e2135b0db 10 furnished to do so, subject to the following conditions:
Yann 0:f30e2135b0db 11
Yann 0:f30e2135b0db 12 The above copyright notice and this permission notice shall be included in
Yann 0:f30e2135b0db 13 all copies or substantial portions of the Software.
Yann 0:f30e2135b0db 14
Yann 0:f30e2135b0db 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Yann 0:f30e2135b0db 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Yann 0:f30e2135b0db 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Yann 0:f30e2135b0db 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Yann 0:f30e2135b0db 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Yann 0:f30e2135b0db 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Yann 0:f30e2135b0db 21 THE SOFTWARE.
Yann 0:f30e2135b0db 22 */
Yann 0:f30e2135b0db 23
Yann 0:f30e2135b0db 24 /** \file
Yann 0:f30e2135b0db 25 Ethernet network interface header file
Yann 0:f30e2135b0db 26 */
Yann 0:f30e2135b0db 27
Yann 0:f30e2135b0db 28 #ifndef ETHERNETNETIF_H
Yann 0:f30e2135b0db 29 #define ETHERNETNETIF_H
Yann 0:f30e2135b0db 30
Yann 0:f30e2135b0db 31 struct netif;
Yann 0:f30e2135b0db 32
Yann 0:f30e2135b0db 33 #include "mbed.h"
Yann 0:f30e2135b0db 34
Yann 0:f30e2135b0db 35 #include "if/lwip/LwipNetIf.h"
Yann 0:f30e2135b0db 36
Yann 0:f30e2135b0db 37 ///Ethernet network interface return codes
Yann 0:f30e2135b0db 38 enum EthernetErr
Yann 0:f30e2135b0db 39 {
Yann 0:f30e2135b0db 40 __ETH_MIN = -0xFFFF,
Yann 0:f30e2135b0db 41 ETH_TIMEOUT, ///<Timeout during setup
Yann 0:f30e2135b0db 42 ETH_OK = 0 ///<Success
Yann 0:f30e2135b0db 43 };
Yann 0:f30e2135b0db 44
Yann 0:f30e2135b0db 45 ///Ethernet network interface
Yann 0:f30e2135b0db 46 /**
Yann 0:f30e2135b0db 47 This class provides Ethernet connectivity to the stack
Yann 0:f30e2135b0db 48 */
Yann 0:f30e2135b0db 49 class EthernetNetIf : public LwipNetIf
Yann 0:f30e2135b0db 50 {
Yann 0:f30e2135b0db 51 public:
Yann 0:f30e2135b0db 52 ///Instantiates the Interface and register it against the stack, DHCP will be used
Yann 0:f30e2135b0db 53 /**
Yann 0:f30e2135b0db 54 * An optional hostname can be specified which will be passed to the DHCP server.
Yann 0:f30e2135b0db 55 * Examples without and with hostname specified:
Yann 0:f30e2135b0db 56 *
Yann 0:f30e2135b0db 57 * @code
Yann 0:f30e2135b0db 58 * EthernetNetIf eth();
Yann 0:f30e2135b0db 59 * @endcode
Yann 0:f30e2135b0db 60 * @code
Yann 0:f30e2135b0db 61 * EthernetNetIf eth("mbedSE");
Yann 0:f30e2135b0db 62 * @endcode
Yann 0:f30e2135b0db 63 */
Yann 0:f30e2135b0db 64 EthernetNetIf(const char* hostname = NULL); //W/ DHCP
Yann 0:f30e2135b0db 65
Yann 0:f30e2135b0db 66 ///Instantiates the Interface and register it against the stack, DHCP will not be used
Yann 0:f30e2135b0db 67 /**
Yann 0:f30e2135b0db 68 IpAddr is a container class that can be constructed with either 4 bytes or no parameters for a null IP address.
Yann 0:f30e2135b0db 69 */
Yann 0:f30e2135b0db 70 EthernetNetIf(IpAddr ip, IpAddr netmask, IpAddr gateway, IpAddr dns); //W/o DHCP
Yann 0:f30e2135b0db 71 virtual ~EthernetNetIf();
Yann 0:f30e2135b0db 72
Yann 0:f30e2135b0db 73 ///Brings the interface up
Yann 0:f30e2135b0db 74 /**
Yann 0:f30e2135b0db 75 Uses DHCP if necessary
Yann 0:f30e2135b0db 76 @param timeout_ms : You can set the timeout parameter in milliseconds, if not it defaults to 15s
Yann 0:f30e2135b0db 77 @return : ETH_OK on success or ETH_TIMEOUT on timeout
Yann 0:f30e2135b0db 78 */
Yann 0:f30e2135b0db 79 EthernetErr setup(int timeout_ms = 15000);
Yann 0:f30e2135b0db 80
Yann 0:f30e2135b0db 81 virtual void poll();
Yann 0:f30e2135b0db 82
Yann 0:f30e2135b0db 83 private:
Yann 0:f30e2135b0db 84 Timer m_ethArpTimer;
Yann 0:f30e2135b0db 85 Timer m_dhcpCoarseTimer;
Yann 0:f30e2135b0db 86 Timer m_dhcpFineTimer;
Yann 0:f30e2135b0db 87 Timer m_igmpTimer;
Yann 0:f30e2135b0db 88
Yann 0:f30e2135b0db 89 bool m_useDhcp;
Yann 0:f30e2135b0db 90
Yann 0:f30e2135b0db 91 netif* m_pNetIf;
Yann 0:f30e2135b0db 92
Yann 0:f30e2135b0db 93 IpAddr m_netmask;
Yann 0:f30e2135b0db 94 IpAddr m_gateway;
Yann 0:f30e2135b0db 95
Yann 0:f30e2135b0db 96 const char* m_hostname;
Yann 0:f30e2135b0db 97
Yann 0:f30e2135b0db 98 };
Yann 0:f30e2135b0db 99
Yann 0:f30e2135b0db 100 #endif
Yann 0:f30e2135b0db 101