fork WIZnetInterface

Dependents:   Weather_Forecast_Helloworld_WIZwiki-W750 Weather_Forecast_Helloworld_WIZwiki-W750 Weather_Forecast_Helloworld_WIZwiki-W750_test DHCPAddressAssignment ... more

Fork of WIZnetInterface by WIZnet

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)
00028     /**
00029     * Constructor
00030     *
00031     * \param mosi mbed pin to use for SPI
00032     * \param miso mbed pin to use for SPI
00033     * \param sclk mbed pin to use for SPI
00034     * \param cs chip select of the WIZnet_Chip
00035     * \param reset reset pin of the WIZnet_Chip
00036     */
00037     EthernetInterface(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset);
00038     EthernetInterface(SPI* spi, PinName cs, PinName reset);
00039 #endif
00040 
00041   /** Initialize the interface with DHCP.
00042   * Initialize the interface and configure it to use DHCP (no connection at this point).
00043   * \return 0 on success, a negative number on failure
00044   */
00045   int init();              //With DHCP
00046   int init(uint8_t * mac); //With DHCP
00047 
00048   /** Initialize the interface with a static IP address.
00049   * Initialize the interface and configure it with the following static configuration (no connection at this point).
00050   * \param ip the IP address to use
00051   * \param mask the IP address mask
00052   * \param gateway the gateway to use
00053   * \return 0 on success, a negative number on failure
00054   */
00055   int init(uint8_t * mac, const char* ip, const char* mask, const char* gateway);
00056 
00057   /** Connect
00058   * Bring the interface up, start DHCP if needed.
00059   * \return 0 on success, a negative number on failure
00060   */
00061   int connect();
00062   
00063   /** Disconnect
00064   * Bring the interface down
00065   * \return 0 on success, a negative number on failure
00066   */
00067   int disconnect();
00068   
00069   /** Get IP address & MAC address
00070   *
00071   * @ returns ip address
00072   */
00073   char* getIPAddress();
00074   char* getNetworkMask();
00075   char* getGateway();
00076   char* getMACAddress();
00077 
00078   int IPrenew(int timeout_ms = 15*1000);
00079     
00080 private:
00081     char ip_string[20];
00082     char mask_string[20];
00083     char gw_string[20];
00084     char mac_string[20];
00085     bool ip_set;
00086 };
00087 
00088 #include "TCPSocketConnection.h"
00089 #include "TCPSocketServer.h"
00090 #include "UDPSocket.h"