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