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.
Fork of WIZnet_Library by
WIZnetInterface/WIZnetInterface.h@8:cb8808b47e69, 2015-05-31 (annotated)
- Committer:
- Bongjun
- Date:
- Sun May 31 10:25:40 2015 +0000
- Revision:
- 8:cb8808b47e69
- Parent:
- 1:8138a268fbd2
fix some codes of reading Sn_RX_RSR, Sn_TX_FSR in W5100.cpp, W5200.cpp; added is_fin_received() in W5100, W5200 files
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jbkim | 0:b72d22e10709 | 1 | /* Copyright (C) 2012 mbed.org, MIT License |
jbkim | 0:b72d22e10709 | 2 | * |
jbkim | 0:b72d22e10709 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
jbkim | 0:b72d22e10709 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
jbkim | 0:b72d22e10709 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
jbkim | 0:b72d22e10709 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
jbkim | 0:b72d22e10709 | 7 | * furnished to do so, subject to the following conditions: |
jbkim | 0:b72d22e10709 | 8 | * |
jbkim | 0:b72d22e10709 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
jbkim | 0:b72d22e10709 | 10 | * substantial portions of the Software. |
jbkim | 0:b72d22e10709 | 11 | * |
jbkim | 0:b72d22e10709 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
jbkim | 0:b72d22e10709 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
jbkim | 0:b72d22e10709 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
jbkim | 0:b72d22e10709 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
jbkim | 0:b72d22e10709 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
jbkim | 0:b72d22e10709 | 17 | */ |
jbkim | 0:b72d22e10709 | 18 | |
jbkim | 0:b72d22e10709 | 19 | #pragma once |
jbkim | 0:b72d22e10709 | 20 | #include "wiznet.h" |
jbkim | 0:b72d22e10709 | 21 | |
jbkim | 0:b72d22e10709 | 22 | /** Interface using Wiznet chip to connect to an IP-based network |
jbkim | 0:b72d22e10709 | 23 | * |
jbkim | 0:b72d22e10709 | 24 | */ |
jbkim | 0:b72d22e10709 | 25 | class WIZnetInterface: public WIZnet_Chip { |
jbkim | 0:b72d22e10709 | 26 | public: |
jbkim | 0:b72d22e10709 | 27 | |
jbkim | 0:b72d22e10709 | 28 | /** |
jbkim | 0:b72d22e10709 | 29 | * Constructor |
jbkim | 0:b72d22e10709 | 30 | * |
jbkim | 0:b72d22e10709 | 31 | * \param mosi mbed pin to use for SPI |
jbkim | 0:b72d22e10709 | 32 | * \param miso mbed pin to use for SPI |
jbkim | 0:b72d22e10709 | 33 | * \param sclk mbed pin to use for SPI |
jbkim | 0:b72d22e10709 | 34 | * \param cs chip select of the WIZnet_Chip |
jbkim | 0:b72d22e10709 | 35 | * \param reset reset pin of the WIZnet_Chip |
jbkim | 0:b72d22e10709 | 36 | */ |
jbkim | 0:b72d22e10709 | 37 | WIZnetInterface(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset); |
jbkim | 0:b72d22e10709 | 38 | WIZnetInterface(SPI* spi, PinName cs, PinName reset); |
jbkim | 0:b72d22e10709 | 39 | |
jbkim | 0:b72d22e10709 | 40 | /** Initialize the interface with DHCP. |
jbkim | 0:b72d22e10709 | 41 | * Initialize the interface and configure it to use DHCP (no connection at this point). |
jbkim | 0:b72d22e10709 | 42 | * \return 0 on success, a negative number on failure |
jbkim | 0:b72d22e10709 | 43 | */ |
jbkim | 1:8138a268fbd2 | 44 | int init(uint8_t * mac); //With DHCP |
jbkim | 0:b72d22e10709 | 45 | |
jbkim | 0:b72d22e10709 | 46 | /** Initialize the interface with a static IP address. |
jbkim | 0:b72d22e10709 | 47 | * Initialize the interface and configure it with the following static configuration (no connection at this point). |
jbkim | 0:b72d22e10709 | 48 | * \param ip the IP address to use |
jbkim | 0:b72d22e10709 | 49 | * \param mask the IP address mask |
jbkim | 0:b72d22e10709 | 50 | * \param gateway the gateway to use |
jbkim | 0:b72d22e10709 | 51 | * \return 0 on success, a negative number on failure |
jbkim | 0:b72d22e10709 | 52 | */ |
jbkim | 1:8138a268fbd2 | 53 | int init(uint8_t * mac, const char* ip, const char* mask, const char* gateway); |
jbkim | 0:b72d22e10709 | 54 | |
jbkim | 0:b72d22e10709 | 55 | /** Connect |
jbkim | 0:b72d22e10709 | 56 | * Bring the interface up, start DHCP if needed. |
jbkim | 0:b72d22e10709 | 57 | * \return 0 on success, a negative number on failure |
jbkim | 0:b72d22e10709 | 58 | */ |
jbkim | 0:b72d22e10709 | 59 | int connect(); |
jbkim | 0:b72d22e10709 | 60 | |
jbkim | 0:b72d22e10709 | 61 | /** Disconnect |
jbkim | 0:b72d22e10709 | 62 | * Bring the interface down |
jbkim | 0:b72d22e10709 | 63 | * \return 0 on success, a negative number on failure |
jbkim | 0:b72d22e10709 | 64 | */ |
jbkim | 0:b72d22e10709 | 65 | int disconnect(); |
jbkim | 0:b72d22e10709 | 66 | |
jbkim | 0:b72d22e10709 | 67 | /** Get IP address & MAC address |
jbkim | 0:b72d22e10709 | 68 | * |
jbkim | 0:b72d22e10709 | 69 | * @ returns ip address |
jbkim | 0:b72d22e10709 | 70 | */ |
jbkim | 0:b72d22e10709 | 71 | char* getIPAddress(); |
jbkim | 0:b72d22e10709 | 72 | char* getNetworkMask(); |
jbkim | 0:b72d22e10709 | 73 | char* getGateway(); |
jbkim | 0:b72d22e10709 | 74 | char* getMACAddress(); |
jbkim | 0:b72d22e10709 | 75 | |
jbkim | 0:b72d22e10709 | 76 | int IPrenew(int timeout_ms = 15*1000); |
jbkim | 0:b72d22e10709 | 77 | |
jbkim | 0:b72d22e10709 | 78 | private: |
jbkim | 0:b72d22e10709 | 79 | char ip_string[20]; |
jbkim | 0:b72d22e10709 | 80 | char mask_string[20]; |
jbkim | 0:b72d22e10709 | 81 | char gw_string[20]; |
jbkim | 0:b72d22e10709 | 82 | char mac_string[20]; |
jbkim | 0:b72d22e10709 | 83 | bool ip_set; |
jbkim | 0:b72d22e10709 | 84 | }; |
jbkim | 0:b72d22e10709 | 85 | |
jbkim | 0:b72d22e10709 | 86 | #include "TCPSocketConnection.h" |
jbkim | 0:b72d22e10709 | 87 | #include "TCPSocketServer.h" |
jbkim | 0:b72d22e10709 | 88 | #include "UDPSocket.h" |