WIZnetInterface
WIZnet Ethernet Interface using Hardware TCP/IP chip, W5500 and TCP/IP Offload Engine, W7500.
Users » embeddist » Code » WIZnetInterface
Users » embeddist » Code » WIZnetInterface
WIZnetInterface ?
- EthernetInterface in ARM mbed
mbed.org는 Handbook>>Ethernet에 ARM mbed platform들이 Internet에 Connecting하기 위한 Network Library인 EthernetInterface를 제공하고 있다. EthernetInterface는 TCP/IP Software stack으로 lwIP을 채택하고 있다. - WIZnet TCP/IP Offload Engine
아래의 그림과 같이 TOE는 TCP이하의 Network Layer가 Hardware적으로 설계되어 있어 Operating System과 Microcontroller의 Networking을 위한 리소스와 메모리를 최소화 해준다. 따라서, 리소스가 제한되는 Low-end IoT Device에서 TOE의 기능이 탑재한 MCU혹은 TOE를 채택한 System은 보다 Networking 이외의 기능들에 최적화 시킬 수 있다.
- 과연, ARM mbed에서 이러한 TOE를 적용한 Platform혹은 Components 있나?
있습니다. 있고요.
Platform으로는 W7500이 적용된 WIZwiki_W7500이 있습니다.
Component로는 W5500이 적용된 W5500 Ethernet Shield가 있습니다. 둘다 made in 대한민국!- Platforms: WIZwiki_W7500
- Components: W5500 Ethernet Shield
What is new?
- W7500과 W5500을 어떻게 선택하나
eth_arch.h을 추가하여 Web-IDE에서 platform을 선택하면 Target Platform에 따라 자동적으로 W7500혹은 W5500을 적용할 수 있다. W5500과 W7500이 통합된 Library이지만 둘 중 하나를 선택하기 위해 여분의 Configuration이 필요없다.#if defined(TARGET_WIZwiki_W7500) #include "W7500x_toe.h" #define __DEF_USED_IC101AG__ //For using IC+101AG@WIZwiki-W7500 #else #include "W5500.h" // W5500 Ethernet Shield //#define USE_WIZ550IO_MAC // WIZ550io; using the MAC address #endif
- PHY링크를 어떻게 설정하고 확인하나
Ethernet PHY는 아래의 그림과 같이 RJ45의 Link LED와 Active LED를 이용하여 육안으로 확인이 가능하다. Embedded system에서는 MCU의 GPIO에 Link와 Active Signal을 연결하거나 MDIO Interface를 확인 할 수 있다.
(http://www.avtech.com/Support/modules/KB/Image/Image/166_RA_LEDs/Ethernet_LEDs_NormalOperation_BothTypes.gif)
EthernetInterface에서 이러한 기능을 위해 link()와 set_link()를 제공하고 WIZnetInterface에서도 이 API를 제공하고 있다.- link()
PHY링크를 확인할 수 있는 함수 return값이 True이면 Link이고, Fail이면 Link-Fail이다* Check if an ethernet link is pressent or not. * * @returns true if successful */ bool link(int wait_time_ms= 3*1000);
- set_link()
PHY의 Duplex/SPEED를 설정할 수 있는 함수이다./* * Sets the speed and duplex parameters of an ethernet link. * * @returns true if successful */ void set_link(PHYMode phymode);
How to import
- import and update
Where is Clone repository
파일 버젼관린 시스템 Git과 같은 Mecurial를 ARM mbed에서 적용하고 있다.
아래의 명령어를 이용하여 WIZnetInterface를 Clone할 수 있으며 hg명령어를 이용하여 버젼관리를 할 수 있다.
hg clone https://embeddist@developer.mbed.org/users/embeddist/code/WIZnetInterface/
아래의 명령어를 이용하여 WIZnetInterface를 Clone할 수 있으며 hg명령어를 이용하여 버젼관리를 할 수 있다.
hg clone https://embeddist@developer.mbed.org/users/embeddist/code/WIZnetInterface/
또한, WIZnetInterface는 ARM mbed의 Team WIZnet에서 관리하고 있으므로 https://developer.mbed.org/teams/WIZnet/를 방문하여 다운 및 다수의 예제를 활용할 수 있다.
How to use
- make main.cpp
- WIZwiki_W7500
#define _DHCP_ EthernetInterface eth; /*1. Creat eth object from EthernetInteface class*/ main() { /*2. MAC address as arr in HEX-Type*/ uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x01, 0x02, 0x03}; /*3. Select DHCP or Fixed IP address*/ #ifdef _DHCP_ /*3.1 Set MAC address, Initialize the interface with DHCP*/ eth.init(mac_addr); #else /*3.2 Set MAC address and Set MAC, IP, Gatway address and Subnet Mask as String-Type*/ eth.init(mac_addr, "192.168.77.34", "255.255.255.0", "192.168.77.1"); #endif /*4. Check Ethernet Link-Done */ printf("Check Ethernet Link\r\n"); if(eth.link() == true) { printf("- Ethernet PHY Link-Done \r\n"); } else {printf("- Ethernet PHY Link- Fail\r\n");} /*5. Set IP addresses ,start DHCP if needed */ if( eth.connect() == ture ) { printf("Connected, IP: %s\n\r", eth.getIPAddress()); printf("MASK: %s\n\r", eth.getNetworkMask()); printf("GW: %s\n\r",eth.getGateway()); } else { printf("eth.connect fail\n\r"); } ... /* Your application Visit for examples - https://developer.mbed.org/teams/WIZnet/ */ }
- W5500 Ethernet Shield
#define _DHCP_ /* 0. Set SPI Interface with SPI API*/ SPI spi(D11, D12, D13); // mosi, miso, sclk /*1. Creat eth object from EthernetInteface class*/ EthernetInterface eth(&spi, D10, D9); // spi, cs, reset main() { /*2. MAC address as arr in HEX-Type*/ uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x01, 0x02, 0x03}; /*3. Select DHCP or Fixed IP address*/ #ifdef _DHCP_ /*3.1 Set MAC address, Initialize the interface with DHCP*/ eth.init(mac_addr); #else /*3.2 Set MAC address and Set MAC, IP, Gatway address and Subnet Mask as String-Type */ eth.init(mac_addr, "192.168.77.34", "255.255.255.0", "192.168.77.1"); #endif /*3. Check Ethernet Link-Done */ printf("Check Ethernet Link\r\n"); if(eth.link() == true) { printf("- Ethernet PHY Link-Done \r\n"); } else {printf("- Ethernet PHY Link- Fail\r\n");} /*4. Set IP addresses ,start DHCP if needed */ if( eth.connect() == ture ) { printf("Connected, IP: %s\n\r", eth.getIPAddress()); printf("MASK: %s\n\r", eth.getNetworkMask()); printf("GW: %s\n\r",eth.getGateway()); } else { printf("eth.connect fail\n\r"); } ... /* Your application Visit for examples - https://developer.mbed.org/teams/WIZnet/ */ }
WIZnetInterface APIs for mbed Ethenret Interface
Ethernet 기반의 Networking을 위해 *Ethenret Interface Library를 ARM mbed에서 제공하고 있으며, 이 Library는 크게 4가지 TCP/IP Protocol layer, Ethernet, EthernetInterface and Socket로 구성되있다.
Internet에 연결하기 위해 EthernetInterface의 각각의 Layer는 APIs들로 구성되어 있다. 각각의 API는 아래의 경로에서 확인할 수 있다.
- EthernetInterfaec : https://developer.mbed.org/handbook/Ethernet-Interface
- Socket : https://developer.mbed.org/handbook/Socket
- TCP/IP Protocols : https://developer.mbed.org/handbook/TCP-IP-protocols-and-APIs
- Ethernet : https://developer.mbed.org/handbook/Ethernet
WIZnetInterface Implementation base on mbed Ethernet Interface
- EthernetInterface- EthernetInterface Class
Type Func. Descriptions WIZnetInterface static int init () Initialize the interface with DHCP. O static int init (const char ip, const char mask, const char *gateway) Initialize the interface with a static IP address. O static int connect (unsigned int timeout_ms=15000) Connect Bring the interface up, start DHCP if needed. O static int disconnect () Disconnect Bring the interface down. no use static char* getMACAddress () Get the MAC address of your Ethernet interface. O static char* getIPAddress () Get the IP address of your Ethernet interface. O static char* getGateway () Get the Gateway address of your Ethernet interface. O static char* getNetworkMask () Get the Network mask of your Ethernet interface. O void EthernetInterface (PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset) Initialize SPI SPI pins to user for SPI interface and Reset pin for W5500 0 (for W5500) void EthernetInterface (SPI* spi, PinName cs, PinName reset) Initialize SPI SPI pins to user for SPI interface and Reset pin for W5500 O (for W5500) - Socket - TCPSocketServer Class
Type Func. Descriptions WIZnetInterface TCPSocketServer () Instantiate a TCP Server. O int bind (int port) Bind a socket to a specific port. O int listen (int backlog=1) Start listening for incoming connections. O int accept ( TCPSocketConnection &connection) Accept a new connection. O void set_blocking (bool blocking, unsigned int timeout=1500) Set blocking or non-blocking mode of the socket and a timeout on blocking socket operations. O int set_option (int level, int optname, const void *optval, socklen_t optlen) Set socket options. no use int get_option (int level, int optname, void optval, socklen_t optlen) Get socket options. no use int close (bool shutdown=true) Get socket options. O - Socket - TCPSocketConnection Class
Type Func. Descriptions WIZnetInterface TCPSocketConnection () TCP socket connection. O int connect (const char *host, const int port) Connects this TCP socket to the server. O bool is_connected (void) Check if the socket is connected. O int send (char *data, int length) Send data to the remote host. O int send_all (char *data, int length) Send all the data to the remote host. O int receive (char *data, int length) Receive data from the remote host. O int receive_all (char *data, int length) Receive all the data from the remote host. O void set_blocking (bool blocking, unsigned int timeout=1500) Set blocking or non-blocking mode of the socket and a timeout on blocking socket operations. O int set_option (int level, int optname, const void *optval, socklen_t optlen) Set socket options. no use int get_option (int level, int optname, void optval, socklen_t optlen) Get socket options. no use int close (bool shutdown=true) Close the socket. O void reset_address (void) Reset the address of this endpoint. O int set_address (const char *host, const int port) Set the address of this endpoint. O char* get_address (void) Get the IP address of this endpoint. O int get_port (void) Get the port of this endpoint. O - etnerhet_api - ethernet_api Class
Type Func. Descriptions WIZnetInterface Ethernet () Initialise the ethernet interface. no use virtual ~Ethernet () Powers the hardware down. no use int write (const char *data, int size) Writes into an outgoing ethernet packet. no use int send () Send an outgoing ethernet packet. no use int receive () Recevies an arrived ethernet packet. no use int read (const char *data, int size) Read from an recevied ethernet packet. no use void address (char *mac) Gives the ethernet address of the mbed. no use int link() Returns if an ethernet link is pressent or not. O void set_link(Mode mode) Sets the speed and duplex parameters of an ethernet link. O
댓글 없음:
댓글 쓰기