Difference between revisions of "Ethernet Module"

From OpenCircuits
Jump to navigation Jump to search
Line 1: Line 1:
==Introduction==
+
==Objectives==
*let a device have the following capabilities
+
The Internet provides an indispensable means to exchange information over long distances. Connection to the Internet is enabled by following the implementation of the Open Systems Interconnection Reference Model (OSI model). In simple words, internet applications require a TCP/IP stack to pack and unpack information into data packets for proper transmission and reception over the Internet. The TCP/IP stack is usually implemented by software and included in the Operating System. Applications can use the stack transparently through socket programming.
**can be controlled by a general browser in a desktop computer
 
**access a server by itself to providing data, such as: device model no., serial no., any application data, or send out email for any events.
 
*This project aims to develop an Ethernet Module, to be used in conjunction with a 8/16 bits embedded system such as the [http://opencircuits.com/DsPIC30F_5011_Development_Board dsPic33F development board].
 
*Architecture
 
**See [http://www.opencircuits.com/Multi-purpose_Embedded_System#TCP.2FIP_Stack here] for block diagram
 
*Connection Schemes
 
::[[Image:Connection_schemes.png ]]
 
::[[Image:connection_schemes_withdhcp.png]]
 
  
 +
Since a full-scale TCP/IP stack consumes a large amount of memory and processing power, a number of small footprint TCP/IP stacks have been devised for embedded systems, such as uIP and lwIP. Nevertheless, these TCP/IP stacks are usually not compatible to socket programming, and being implemented by software, still consumes a considerable amount of system resources. Therefore, hardware chips that implemented the TCP/IP stack (e.g. WIZNET W5300) emerged in recent years so as to offload the computation power from the host microcontroller unit (MCU).
  
 +
This project aims to devise a driver and Linux socket wrapper inside freertos_posix for a hardware implemented TCP/IP stack. It is to be used in conjunction with a 8/16 bits embedded system such as (but not restricted to) the [http://opencircuits.com/DsPIC30F_5011_Development_Board dsPic33F development board]. Based on the Linux socket API, common application protocols (DHCP/HTTP/DNS/SMTP/SNMP/TELNET) are devised to enable remote control and monitoring.
  
==Bug List==
+
===Benefits===
*DHCP
+
*provide a means to perform remote control and monitoring via Internet
**dhcp client fault from buffalo router
+
*offload TCP/IP stack to chip, freeing memory and processing power of MCU to perform other tasks (e.g. HTTPS)
**occasionally cannot access webserver with dhcp
+
*socket API implementation allows more extensible framework for future development and upgrades
 +
*enable remote control and monitoring via
 +
**web browser on desktop computer (better web page design and implementation)
 +
**SNMP agents, controlling and monitoring several instruments simultaneously
 +
**TELNET applications for command prompt control and monitoring
 +
**SMTP by sending out email when critical any events occurs
  
*DHCP
+
===Limitations===
**dhcp client fault from main router
+
*higher cost chips compare to software stack
**occasionally cannot access webserver with dhcp
+
*need to change hardware if features in stack are updated
**possible cause: module tries to get IP configuration when switching on and off too frequently. This causes the router to enter into an unknown state. Even using the static mode with the same IP cannot get Internet access properly. When wait for some time and switch on the module again, the router may have been "reset", and the connection is ok again.
 
  
  
==ToDo List==
+
==Architecture==
*32kB constant limitations
+
*See [http://www.opencircuits.com/Multi-purpose_Embedded_System#TCP.2FIP_Stack here] for block diagram
**see if webserver can be stored in flash in file system
 
*[{{SERVER}}/Ethernet_Module#SNMP_Agent SNMP]
 
**porting snmp to uip
 
**reference to lwip
 
**a API(or any method) to let other system to talk to our device OR by scpi, modbus
 
*SMTP
 
**some router cannot used SMTP module
 
**the router return its own IP as DNS resolver, and it does support only parsing direct IP function
 
**desktop applications (e.g. outlook, thunderbird, webmail) do not use DNS resolver (UDP application) to connect to the mail server, but use TCP/IP to do the job
 
*https by SSL
 
**on chip SSL(more faster) OR software SSL(need to upgrade CPU power to process the calculation)
 
**reference - http://www.networkworld.com/news/tech/2002/0729tech.html
 
  
  
==Hardware==
+
==[[Development Roadmap]]==
===Component List===
+
*Contains directions for development
 +
 
 +
 
 +
==Connection Schemes==
 +
[[Image:Connection_schemes.png ]]
 +
[[Image:connection_schemes_withdhcp.png]]
 +
 
 +
 
 +
==Software TCP/IP Stack Solution==
 +
===Circuit and PCB===
 +
*In [http://chungyan5.no-ip.org/vc/?root=ethernet gEDA format] and its gEDA [http://www.opencircuits.com/PCB_Footprints#gEDA_Symbols_and_footprints sym and footprints]
 
{|border="1" cellspacing="0" cellpadding="5"
 
{|border="1" cellspacing="0" cellpadding="5"
 
! Special Item !! Description !! Quantity
 
! Special Item !! Description !! Quantity
Line 64: Line 60:
 
|}
 
|}
  
===Circuit and PCB===
 
in [http://chungyan5.no-ip.org/vc/?root=ethernet gEDA format]
 
and its gEDA [http://www.opencircuits.com/PCB_Footprints#gEDA_Symbols_and_footprints sym and footprints]
 
  
  
==Software Driver==
+
===Software Implementation===
 +
===Driver===
 
*Download [http://chungyan5.no-ip.org/vc/trunk/demo_posix/dspic/drivers/?root=freertos_posix dm9000a.c]
 
*Download [http://chungyan5.no-ip.org/vc/trunk/demo_posix/dspic/drivers/?root=freertos_posix dm9000a.c]
 
*Download [http://chungyan5.no-ip.org/vc/trunk/demo_posix/dspic/drivers/include/?root=freertos_posix dm9000a.h]
 
*Download [http://chungyan5.no-ip.org/vc/trunk/demo_posix/dspic/drivers/include/?root=freertos_posix dm9000a.h]
Line 80: Line 74:
 
**'''void dmfe_interrupt(void)''': process the transmit interrupt from DM9000A
 
**'''void dmfe_interrupt(void)''': process the transmit interrupt from DM9000A
  
 +
===[[uIP]]===
 +
*Light-weight TCP/IP stack designed for 8-bit/16-bit embedded systems
  
==TCP/IP Stack==
 
*uIP and lwIP are light weight TCP/IP Stack designed for 8-bit/16-bit embedded systems.
 
 
----
 
 
===uIP===
 
*Developed by Adam Dunkels of the Networked Embedded Systems group at the Swedish Institute of Computer Science.
 
*[http://www.sics.se/~adam/uip/ uIP] is under the [http://www.sics.se/~adam/uip/index.php/License BSD-style license]
 
====CVS Repository====
 
{|border="1" cellspacing="0" cellpadding="5"
 
! Attribute !! Value
 
|-valign="top"
 
| Host || uip-stack.cvs.sourceforge.net
 
|-
 
| Repository Path || /cvsroot/uip-stack
 
|-
 
| Connection Type || pserver
 
|-
 
| User || anonymous
 
|-
 
|}
 
 
====Patches====
 
*Changes made to CVS Repository for porting to [http://chungyan5.no-ip.org/vc/?root=freertos_posix freertos_posix]
 
*uip-patch-1.0-01.diff (minimal)
 
**'''uip.c'''
 
***Comment out all DEBUG_PRINTF(...) in lines 1, 323, 910, 1015, 1070, 1863, 1868, 1869
 
*uip-patch-1.0-02.diff (for pic30-elf-gcc compiler v3.01 or above)
 
**'''uip.h'''
 
***Change line 1070 to<br>#      define HTONS(n) (u16_t)(((((u16_t) (n)) << 8)&0xff00) | ((((u16_t) (n)) >> 8)&0x00ff))
 
**'''psock.c'''
 
***Change line 188 to<br>s->sendptr = (u8_t*) buf;
 
***Change lines 276, 303 to<br>buf_setup(&psock->buf, (u8_t*)(psock->bufptr), psock->bufsize);
 
***Change line 334 to<br>buf_setup(&psock->buf, (u8_t*)buffer, buffersize);
 
 
====Porting====
 
*Include the following files to use the uIP stack
 
**timer.c
 
**uip.c
 
**uip_arp.c
 
**psock.c
 
*The following files have been created to port uIP 1.0 to dsPic33F development board using FreeRTOS
 
*[http://chungyan5.no-ip.org/vc/trunk/demo_posix/dspic/drivers/?root=freertos_posix clock-arch.c]: return the os tick counts since the system is turned on.
 
*[http://chungyan5.no-ip.org/vc/trunk/demo_posix/dspic/drivers/include/?root=freertos_posix clock-arch.h]: a constant specifying the number of os ticks in one second.
 
*uip-config.h: configuration for your application.
 
 
----
 
 
===lwIP===
 
*[http://savannah.nongnu.org/projects/lwip/ lwIP] is a small independent implementation of uIP.
 
*It is more powerful than uIP but requires more memory.
 
*lwIP is under the [http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5 Modified BSD License]
 
====CVS Repository====
 
{|border="1" cellspacing="0" cellpadding="5"
 
! Attribute !! Value
 
|-valign="top"
 
| Host || cvs.savannah.nongnu.org
 
|-
 
| Repository Path || /sources/lwip
 
|-
 
| Connection Type || pserver
 
|-
 
| User || anonymous
 
|-
 
|}
 
====Porting====
 
*To be added
 
 
 
==uIP Ethernet Application==
 
 
===DHCP Client===
 
*Enable UDP in "uip-config.h"
 
      #define UIP_CONF_UDP            1
 
*Make sure your uip buffer size is large enough (DHCP messages from some servers can be more than 500 bytes). In my setting, I use 1536 in "uip-config.h"
 
      #define UIP_CONF_BUFFER_SIZE    1536
 
*Include the dhcpc.h header file in "uip-config.h"
 
      #include "dhcpc.h"
 
*Change PT_WAIT_UNTIL(...) to PT_YIELD_UNTIL(...) in line 259 and 276 in "dhcpc.c" [This is a known bug in dhcpc.c]
 
*In your main loop, initialize your MAC address and DHCP if UIP_FIXEDADDR is 0 in "uip-opt.h", for example:
 
  int main(void)
 
  {
 
      uip_ipaddr_t ipaddr;
 
      struct timer periodic_timer, arp_timer;
 
      struct uip_eth_addr mac = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
 
     
 
      timer_set(&periodic_timer, CLOCK_SECOND / 2);
 
      timer_set(&arp_timer, CLOCK_SECOND * 10);
 
     
 
      tapdev_init();
 
      uip_init();
 
     
 
      uip_setethaddr(mac);
 
      dhcpc_init(&mac, 6);
 
     
 
      while(1){
 
        //normal codes goes here
 
      }
 
  }
 
*Implement dhcpc_configured(). This function will be called after DHCP client has obtained an IP address. Basically, you have to at least set your IP address, subnet mask and default gateway, for example,
 
  void dhcpc_configured(const struct dhcpc_state *s)
 
  {
 
    uip_sethostaddr(s->ipaddr);
 
    uip_setnetmask(s->netmask);
 
    uip_setdraddr(s->default_router);
 
   
 
    //you can print your ip addr to your console/lcd to see if you get a valid ip address
 
  }
 
*An example of using DHCP Client in the dsPic33F development board can be found [http://chungyan5.no-ip.org/vc/tags/1.09.05/demo_posix/common/app_http.c?root=freertos_posix&view=markup here].
 
 
===Web Server===
 
*Include the "webserver.h" header file in "uip-config.h"
 
      #include "webserver.h"
 
*Modify httpd-fs.h
 
**HTTPD_FS_STATISTICS set to 0
 
*Create a website using HTML tags with/without Javascript
 
*Modify httpd-fs.c
 
**changed #include "httpd-fsdata.c" to #include <httpd-fsdata.c>
 
*Generate httpd-fsdata.c for your website by executing '''perl makefsdata''' under your web root directory.
 
====add-on====
 
*The Web Server included in uIP 1.0 has been designed to load/reload the entire page (either html/shtml files) in response to a HTTP GET command, e.g.
 
  GET /index.html HTTP/1.1
 
  GET /abc.shtml HTTP/1.1
 
*As a result, if the webpage is required to refresh the dynamic data periodically, the surfing experience will be degraded by the large transfer of datastream.
 
*In consideration of the above issue, a solution is proposed here, so that the webserver can handle this kind of cgi HTTP-request
 
  GET /abc.shtml?val=500.0&button=Set HTTP/1.1
 
*Modify httpd.c
 
**added #include "httpd-hget.h" in line 63
 
**added httpd_hget(s->filename) in line 224
 
*Create httpd-hget.h
 
**added to generate dynamic pages, e.g. /abc.shtml?button=Refresh
 
  #ifndef __HTTPD_HGET_H__
 
  #define __HTTPD_HGET_H__
 
      extern void httpd_hget(char *name);
 
  #endif
 
*Create httpd-hget.c
 
**an example is shown [http://chungyan5.no-ip.org/vc/tags/1.09.05/demo_posix/dspic/dspic33/rackmount/04_uip/uip/httpd-hget.c?root=freertos_posix&view=markup here]
 
 
 
==SNMP Agent==
 
*Simple Network Management Protocol (SNMP) is a standard protocol to access variables to remote device via the Internet. Reference in [http://en.wikipedia.org/wiki/Simple_Network_Management_Protocol wikipedia.org]
 
*It belongs to the Application Layer, as in HTTP.
 
*If a device is SNMP compatible, any SNMP compatible host system can monitor and control that device.
 
 
===Components in a SNMP System===
 
*Network Management Station (NMS)
 
**This is a client, initiating SNMP communication.
 
**This can be a PC with an NMS software (e.g. [http://nino.sourceforge.net/nino/index.html NINO]), polling data from the SNMP agents periodically.
 
*SNMP Agents
 
**These are servers, responding to one or multiple NMS requests.
 
*Management Information Base (MIB)
 
**A special collection of variables managed by the SNMP agents.
 
**MIB has a tree-like structure.
 
**An Object Identifier (OID) is given for each node.
 
**Data are stored at the end-nodes.
 
**Private variables may be constructed under the "enterprise" sub-tree.
 
**The OID for "enterprise" can be obtained from [http://www.iana.org/cgi-bin/enterprise.pl Internet Assigned Number Authority (IANA)].
 
  
===Abstract Syntax Notation===
+
===[[lwIP]]===
*Each MIB variable contains several attributes, such as data type, access type and object identifier.
+
*Light-weight TCP/IP stack designed for 8-bit/16-bit embedded systems
*Abstract Syntax Notation version 1 (ASN.1) is a language to define these attributes in SNMP.
+
*consume more resource than uIP
  
  
==Reference==
+
==Hardware TCP/IP Stack Solution==
===DM9000A===
+
*to be added
*[http://www.davicom.com.tw/eng/products/dm9000a.htm DM9000A Description]
 
*[http://www.davicom.com.tw/big5/download/Data%20Sheet/DM9000A-DS-F01-101906.pdf DM9000A Datasheet]
 
*[http://www.davicom.com.tw/big5/download/AC/dm9000a/DM9000A%20circuit_EMI_052306.pdf Application Circuit]
 
*[http://www.davicom.com.tw/big5/download/LayoutGuide/DM9000A_9010-LG-V11_031706.pdf Layout Guidelines]
 
*[http://www.davicom.com.tw/big5/download/ApplicationNote/DM9000A%20Application%20Notes%20Ver%201_20_101906.pdf Application Note]
 
*[http://www.davicom.com.tw/eng/download/Driver/driver_9000.htm DM9000A Official Drivers]
 
===dsPic33F Development Board===
 
*[http://opencircuits.com/DsPIC30F_5011_Development_Board dsPic33F Development Board]
 
===uIP===
 
*[http://www.sics.se/~adam/uip/index.php/Main_Page uIP Description]
 
*[http://www.sics.se/~adam/uip/index.php/Documentation uIP Documentation]
 
*[http://www.sics.se/~adam/uip/index.php/Download Download]
 
*[http://sourceforge.net/cvs/?group_id=186227 CVS Repository]
 
===lwIP===
 
*[http://savannah.nongnu.org/projects/lwip/ lwIP Description]
 
*[http://www.nongnu.org/lwip/ Documentation]
 
===HTML===
 
*[http://www.w3schools.com/default.asp W3 Schools]: Learning how to write HTML and JavaScript
 
*[http://www.nvu.com/index.php Nvu]: Open source HTML Editor
 
===SNMP===
 
*[http://www.snmplink.org SNMP Link]: Information on SNMP Agents
 
*[http://pen.iana.org/pen/PenApplication.page IANA]: Applying a Private Enterprise Number
 

Revision as of 19:59, 16 February 2009

Objectives

The Internet provides an indispensable means to exchange information over long distances. Connection to the Internet is enabled by following the implementation of the Open Systems Interconnection Reference Model (OSI model). In simple words, internet applications require a TCP/IP stack to pack and unpack information into data packets for proper transmission and reception over the Internet. The TCP/IP stack is usually implemented by software and included in the Operating System. Applications can use the stack transparently through socket programming.

Since a full-scale TCP/IP stack consumes a large amount of memory and processing power, a number of small footprint TCP/IP stacks have been devised for embedded systems, such as uIP and lwIP. Nevertheless, these TCP/IP stacks are usually not compatible to socket programming, and being implemented by software, still consumes a considerable amount of system resources. Therefore, hardware chips that implemented the TCP/IP stack (e.g. WIZNET W5300) emerged in recent years so as to offload the computation power from the host microcontroller unit (MCU).

This project aims to devise a driver and Linux socket wrapper inside freertos_posix for a hardware implemented TCP/IP stack. It is to be used in conjunction with a 8/16 bits embedded system such as (but not restricted to) the dsPic33F development board. Based on the Linux socket API, common application protocols (DHCP/HTTP/DNS/SMTP/SNMP/TELNET) are devised to enable remote control and monitoring.

Benefits

  • provide a means to perform remote control and monitoring via Internet
  • offload TCP/IP stack to chip, freeing memory and processing power of MCU to perform other tasks (e.g. HTTPS)
  • socket API implementation allows more extensible framework for future development and upgrades
  • enable remote control and monitoring via
    • web browser on desktop computer (better web page design and implementation)
    • SNMP agents, controlling and monitoring several instruments simultaneously
    • TELNET applications for command prompt control and monitoring
    • SMTP by sending out email when critical any events occurs

Limitations

  • higher cost chips compare to software stack
  • need to change hardware if features in stack are updated


Architecture

  • See here for block diagram


Development Roadmap

  • Contains directions for development


Connection Schemes

Connection schemes.png Connection schemes withdhcp.png


Software TCP/IP Stack Solution

Circuit and PCB

Special Item Description Quantity
DM9000AEP Ethernet Controller from Davicom 1
HR911102A RJ45 Connector with Integrated Magnetics for 10/100 Base-TX 1
93LC46B-I/SN 1K Serial EEPROM 1 (Optional)
25MHz Crystal Crystal 1
22pF For Crystal Use 2
220uF For RXVDD25/TXVDD25 1
49.9ohm For RX+/RX-/TX+/TX- 4
6.8kohm For BGRES/BGGND 1
510ohm For LEDs 2


Software Implementation

Driver

  • Download dm9000a.c
  • Download dm9000a.h
  • Base on FreeRTOS and dsPIC33 platform
  • Using POSIX-like API:
    • int dmfe_open(int flags): initialize the Ethernet controller for 10MHz Half-Duplex
    • int dmfe_close(): turn off the PHY layer
    • int dmfe_read(void): copy a packet to the default buffer
    • int dmfe_write(unsigned char device, unsigned char *buf, int count): copy count bytes of the data from buf and transmit
    • void dmfe_interrupt(void): process the transmit interrupt from DM9000A

uIP

  • Light-weight TCP/IP stack designed for 8-bit/16-bit embedded systems


lwIP

  • Light-weight TCP/IP stack designed for 8-bit/16-bit embedded systems
  • consume more resource than uIP


Hardware TCP/IP Stack Solution

  • to be added