Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of WIZnetInterface by
EthernetInterface.h@3:f8c6efc8bf83, 2015-06-15 (annotated)
- Committer:
- embeddist
- Date:
- Mon Jun 15 12:55:19 2015 +0000
- Revision:
- 3:f8c6efc8bf83
- Parent:
- 0:6f28332c466f
- Child:
- 7:da6fcec0f3fe
on debugging: fixed some bugs
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Soohwan Kim |
0:6f28332c466f | 1 | /* Copyright (C) 2012 mbed.org, MIT License |
Soohwan Kim |
0:6f28332c466f | 2 | * |
Soohwan Kim |
0:6f28332c466f | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
Soohwan Kim |
0:6f28332c466f | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
Soohwan Kim |
0:6f28332c466f | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
Soohwan Kim |
0:6f28332c466f | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
Soohwan Kim |
0:6f28332c466f | 7 | * furnished to do so, subject to the following conditions: |
Soohwan Kim |
0:6f28332c466f | 8 | * |
Soohwan Kim |
0:6f28332c466f | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
Soohwan Kim |
0:6f28332c466f | 10 | * substantial portions of the Software. |
Soohwan Kim |
0:6f28332c466f | 11 | * |
Soohwan Kim |
0:6f28332c466f | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
Soohwan Kim |
0:6f28332c466f | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
Soohwan Kim |
0:6f28332c466f | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
Soohwan Kim |
0:6f28332c466f | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Soohwan Kim |
0:6f28332c466f | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Soohwan Kim |
0:6f28332c466f | 17 | */ |
Soohwan Kim |
0:6f28332c466f | 18 | |
Soohwan Kim |
0:6f28332c466f | 19 | #pragma once |
Soohwan Kim |
0:6f28332c466f | 20 | #include "eth_arch.h" |
Soohwan Kim |
0:6f28332c466f | 21 | /** Interface using Wiznet chip to connect to an IP-based network |
Soohwan Kim |
0:6f28332c466f | 22 | * |
Soohwan Kim |
0:6f28332c466f | 23 | */ |
Soohwan Kim |
0:6f28332c466f | 24 | class EthernetInterface: public WIZnet_Chip { |
Soohwan Kim |
0:6f28332c466f | 25 | public: |
Soohwan Kim |
0:6f28332c466f | 26 | |
embeddist | 3:f8c6efc8bf83 | 27 | EthernetInterface(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset); |
embeddist | 3:f8c6efc8bf83 | 28 | EthernetInterface(SPI* spi, PinName cs, PinName reset); |
Soohwan Kim |
0:6f28332c466f | 29 | |
Soohwan Kim |
0:6f28332c466f | 30 | /** Initialize the interface with DHCP. |
Soohwan Kim |
0:6f28332c466f | 31 | * Initialize the interface and configure it to use DHCP (no connection at this point). |
Soohwan Kim |
0:6f28332c466f | 32 | * \return 0 on success, a negative number on failure |
Soohwan Kim |
0:6f28332c466f | 33 | */ |
Soohwan Kim |
0:6f28332c466f | 34 | int init(uint8_t * mac); //With DHCP |
Soohwan Kim |
0:6f28332c466f | 35 | |
Soohwan Kim |
0:6f28332c466f | 36 | /** Initialize the interface with a static IP address. |
Soohwan Kim |
0:6f28332c466f | 37 | * Initialize the interface and configure it with the following static configuration (no connection at this point). |
Soohwan Kim |
0:6f28332c466f | 38 | * \param ip the IP address to use |
Soohwan Kim |
0:6f28332c466f | 39 | * \param mask the IP address mask |
Soohwan Kim |
0:6f28332c466f | 40 | * \param gateway the gateway to use |
Soohwan Kim |
0:6f28332c466f | 41 | * \return 0 on success, a negative number on failure |
Soohwan Kim |
0:6f28332c466f | 42 | */ |
Soohwan Kim |
0:6f28332c466f | 43 | int init(uint8_t * mac, const char* ip, const char* mask, const char* gateway); |
Soohwan Kim |
0:6f28332c466f | 44 | |
Soohwan Kim |
0:6f28332c466f | 45 | /** Connect |
Soohwan Kim |
0:6f28332c466f | 46 | * Bring the interface up, start DHCP if needed. |
Soohwan Kim |
0:6f28332c466f | 47 | * \return 0 on success, a negative number on failure |
Soohwan Kim |
0:6f28332c466f | 48 | */ |
Soohwan Kim |
0:6f28332c466f | 49 | int connect(); |
Soohwan Kim |
0:6f28332c466f | 50 | |
Soohwan Kim |
0:6f28332c466f | 51 | /** Disconnect |
Soohwan Kim |
0:6f28332c466f | 52 | * Bring the interface down |
Soohwan Kim |
0:6f28332c466f | 53 | * \return 0 on success, a negative number on failure |
Soohwan Kim |
0:6f28332c466f | 54 | */ |
Soohwan Kim |
0:6f28332c466f | 55 | int disconnect(); |
Soohwan Kim |
0:6f28332c466f | 56 | |
Soohwan Kim |
0:6f28332c466f | 57 | /** Get IP address & MAC address |
Soohwan Kim |
0:6f28332c466f | 58 | * |
Soohwan Kim |
0:6f28332c466f | 59 | * @ returns ip address |
Soohwan Kim |
0:6f28332c466f | 60 | */ |
Soohwan Kim |
0:6f28332c466f | 61 | char* getIPAddress(); |
Soohwan Kim |
0:6f28332c466f | 62 | char* getNetworkMask(); |
Soohwan Kim |
0:6f28332c466f | 63 | char* getGateway(); |
Soohwan Kim |
0:6f28332c466f | 64 | char* getMACAddress(); |
Soohwan Kim |
0:6f28332c466f | 65 | |
Soohwan Kim |
0:6f28332c466f | 66 | int IPrenew(int timeout_ms = 15*1000); |
Soohwan Kim |
0:6f28332c466f | 67 | |
Soohwan Kim |
0:6f28332c466f | 68 | private: |
Soohwan Kim |
0:6f28332c466f | 69 | char ip_string[20]; |
Soohwan Kim |
0:6f28332c466f | 70 | char mask_string[20]; |
Soohwan Kim |
0:6f28332c466f | 71 | char gw_string[20]; |
Soohwan Kim |
0:6f28332c466f | 72 | char mac_string[20]; |
Soohwan Kim |
0:6f28332c466f | 73 | bool ip_set; |
Soohwan Kim |
0:6f28332c466f | 74 | }; |
Soohwan Kim |
0:6f28332c466f | 75 | |
Soohwan Kim |
0:6f28332c466f | 76 | #include "TCPSocketConnection.h" |
Soohwan Kim |
0:6f28332c466f | 77 | #include "TCPSocketServer.h" |
Soohwan Kim |
0:6f28332c466f | 78 | #include "UDPSocket.h" |