This is Library using WIZnet Hardware TCP/IP chip, W5500 and WIZnet TCP/IP Offload Engine, W7500.

Dependents:   HTTP_SDcard_file_server_WIZwiki-W7500 SSD1306_smart_watch TCPEchoServer-WIZwiki-W7500 httpServer-WIZwiki-W7500 ... more

Fork of WIZnetInterface by Soohwan Kim

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EthernetInterface.h Source File

EthernetInterface.h

00001 /* Copyright (C) 2012 mbed.org, MIT License
00002  *
00003  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00004  * and associated documentation files (the "Software"), to deal in the Software without restriction,
00005  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
00006  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
00007  * furnished to do so, subject to the following conditions:
00008  *
00009  * The above copyright notice and this permission notice shall be included in all copies or
00010  * substantial portions of the Software.
00011  *
00012  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00013  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00014  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00015  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00016  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00017  */
00018 
00019 #pragma once
00020 #include "eth_arch.h"
00021  /** Interface using Wiznet chip to connect to an IP-based network
00022  *
00023  */
00024 class EthernetInterface: public WIZnet_Chip {
00025 public:
00026 
00027 #if (not defined TARGET_WIZwiki_W7500) && (not defined TARGET_WIZwiki_W7500P) && (not defined TARGET_WIZwiki_W7500ECO)
00028 
00029     /**
00030     * Constructor
00031     *
00032     * \param mosi mbed pin to use for SPI
00033     * \param miso mbed pin to use for SPI
00034     * \param sclk mbed pin to use for SPI
00035     * \param cs chip select of the WIZnet_Chip
00036     * \param reset reset pin of the WIZnet_Chip
00037     */
00038     EthernetInterface(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset);
00039     EthernetInterface(SPI* spi, PinName cs, PinName reset);
00040 #endif
00041 
00042   /** Initialize the interface with DHCP.
00043   * Initialize the interface and configure it to use DHCP (no connection at this point).
00044   * \return 0 on success, a negative number on failure
00045   */
00046   int init();              //With DHCP
00047   int init(uint8_t * mac); //With DHCP
00048 
00049   /** Initialize the interface with a static IP address.
00050   * Initialize the interface and configure it with the following static configuration (no connection at this point).
00051   * \param ip the IP address to use
00052   * \param mask the IP address mask
00053   * \param gateway the gateway to use
00054   * \return 0 on success, a negative number on failure
00055   */
00056   int init(uint8_t * mac, const char* ip, const char* mask, const char* gateway);
00057 
00058   /** Connect
00059   * Bring the interface up, start DHCP if needed.
00060   * \return 0 on success, a negative number on failure
00061   */
00062   int connect();
00063   
00064   /** Disconnect
00065   * Bring the interface down
00066   * \return 0 on success, a negative number on failure
00067   */
00068   int disconnect();
00069   
00070   /** Get IP address & MAC address
00071   *
00072   * @ returns ip address
00073   */
00074   char* getIPAddress();
00075   char* getNetworkMask();
00076   char* getGateway();
00077   char* getMACAddress();
00078 
00079   int IPrenew(int timeout_ms = 15*1000);
00080     
00081 private:
00082     char ip_string[20];
00083     char mask_string[20];
00084     char gw_string[20];
00085     char mac_string[20];
00086     bool ip_set;
00087 };
00088 
00089 #include "TCPSocketConnection.h"
00090 #include "TCPSocketServer.h"
00091 #include "UDPSocket.h"