2015년 6월 18일 목요일

WIZnetInterface for ARMmbed

WIZnetInterface for ARMmbed

This is WIZnet Ethernet Interface using Hardware TCP/IP chip, W5500 and TCP/IP Offload Engine, W7500.
Users » embeddist » Code » WIZnetInterface
-> WIZnetInterface Lib will be released on Team WIZnet

What is this?

This is an Ethernet Interface library port-based on EthernetInterface. This is where the driver using TCP/IP offload(W5500/W7500), which is a market-proven hardwired TCP/IP stack, is implemented. Therefore, this library does not need lwip-eth.library.

  • The Socket folder contains files that implement the SocketAPI and Protocols as like DHCP and DNS.
  • The arch folder contains files that implement the driver for W5500 and W7500x_TOE.
  • The EthernetInterface.c/.h implement the functions from SocketAPI/EthernetInterface.h
  • The eth_arch.h implement to select TCP/IP TOE depending on platform.

What is new?

  • eth_arch.h
    The eth_arch.h file is added to select arch depending to Target platform, we used define of TARGET_platform.

    #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
    
  • link()
    The link function is added to check Ethernet link (PHY) up or not.

      * Check if an ethernet link is pressent or not.
      *
      * @returns true if successful
      */
      bool link(int wait_time_ms= 3*1000);
    
  • link_set()
    The set_link function is added to check Ethernet link (PHY) up or not.

     /*
      * Sets the speed and duplex parameters of an ethernet link.
      *
      * @returns true if successful
      */
      void set_link(PHYMode phymode);
    
  • Included DHCP and DNS lib
    DHCP and DNS lib moved in Socket folder.
    Included DHCP&DNS

How to import

  • import and update
    • Right Click and click ‘From Import Wizard’ to import WIZnetInterface Library
      import library
    • In import Wizard, input ‘WIZnetInterfae” in search box and click ‘Search’ button. Click ‘WIZnetInterface’ in search result window and click ‘Import’ button.
      Search WIZnetInterface
    • Set ‘Import name’ and ‘Target path’, check ‘update’
      import and update WIZnetInterface

Where is Clone repository

hg clone https://embeddist@developer.mbed.org/users/embeddist/code/WIZnetInterface/

How to use

  • make main.cpp

    • WIZwiki_W7500

      #define _DHCP_
      EthernetInterface eth;  /*1. Creat eth object from EthernetInteface class*/
      
      main()
      {
        uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x01, 0x02, 0x03};  
      
        /*2. Set MAC, IP, Gatway address and Subnet Mask*/
      #ifdef _DHCP_
        /*2.1 Set  MAC address, Initialize the interface with DHCP*/
        eth.init(mac_addr); 
      #else   
        /*2.2 Set  MAC address and Set MAC, IP, Gatway address and Subnet Mask with string type */
        eth.init(mac_addr, "192.168.77.34", "255.255.255.0", "192.168.77.1"); //Use fixed IP address 
      #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  */
        eth.connect();
        printf("Connected, IP: %s\n\r", eth.getIPAddress());
        printf("MASK: %s\n\r", eth.getNetworkMask());
        printf("GW: %s\n\r",eth.getGateway());
        ...
      
        /* 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()
      {
        uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x1D, 0x62, 0x11}; 
        /*2. Set MAC, IP, Gatway address and Subnet Mask*/
      #ifdef _DHCP_
        /*2.1 Set  MAC address, Initialize the interface with DHCP*/
        eth.init(mac_addr); 
      #else
        /*2.2 Set  MAC address and Set MAC, IP, Gatway address and Subnet Mask with string type */
        eth.init(mac_addr, "192.168.77.34", "255.255.255.0", "192.168.77.1"); //Use fixed IP address 
      #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  */
        eth.connect();
        printf("Connected, IP: %s\n\r", eth.getIPAddress());
        printf("MASK: %s\n\r", eth.getNetworkMask());
        printf("GW: %s\n\r",eth.getGateway());
        ...
      
        /* Your application 
           Visit for examples - https://developer.mbed.org/teams/WIZnet/
        */
      
      }
      

WIZnetInterface Implementations for mbed Ethenret Interface

For networking based on Ethernet network, Ethenret Interface library is provided and is composed TCP/IP Protocol layer, Ethernet, EthernetInterface and Socket. In other words, the EthernetInterface library includes the networking stack necessary for connect betwwen mbed platform and Internet.

Each layer in EthernetInterface provides APIs to connect to the internet.

WIZnetInterface Implementation base on mbed Ethernet Interface

  • EthernetInterface- EthernetInterface Class

    Type Func. Descriptions WIZnetInterface Support
    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. X
    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 Support
    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. X
    int get_option (int level, int optname, void optval, socklen_t optlen) Get socket options. X
    int close (bool shutdown=true) Get socket options. O
  • Socket - TCPSocketConnection Class

    Type Func. Descriptions WIZnetInterface Support
    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. X
    int get_option (int level, int optname, void optval, socklen_t optlen) Get socket options. X
    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 Support
    Ethernet () Initialise the ethernet interface. X
    virtual ~Ethernet () Powers the hardware down. X
    int write (const char *data, int size) Writes into an outgoing ethernet packet. X
    int send () Send an outgoing ethernet packet. X
    int receive () Recevies an arrived ethernet packet. X
    int read (const char *data, int size) Read from an recevied ethernet packet. X
    void address (char *mac) Gives the ethernet address of the mbed. X
    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

Revision History

  • Initial Release : 19 June. 2015

댓글 없음:

댓글 쓰기