This is WIZnet Ethernet Interface using Hardware TCP/IP chip, W5500, W5200 and W5100. One of them can be selected by enabling it in wiznet.h.

Dependents:   Embedded_web EmailButton EmailButton HTTPClient_Weather ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers WIZnetInterface.h Source File

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