Diy_de2 dm9000a Nic debugging routine (4) -- Implementation of TCP/IP Based on nichestack protocol stack

Source: Internet
Author: User
I. Summary

The protocol stack used for TCP/IP implementation in the later version of The Altera software niosii (7.2 or later, which is used in this routine) is nichestack. There are two common routines, web_server and simple_socket_server.ArticleOnly describes the implementation process of simple_socket_server routine. Here, the driver of dm9000a is different from the Driver Based on LWIP in the previous blog.

 

Ii. Experimental Platform

Software Platform: Quartus II 9.0 + niosii 9.0

Hardware Platform: diy_de2

 

Iii. experiment content --> implement simple_socket_server 1. customized software cores with the help of the system.

The detailed steps for customizing soft cores are not described in detail. The above are customized soft cores.

Cpu_0:

Reset vector: cfi_flash_0,

Exception vector: sram_16bit_512k_0

Sys_timer_0 must be added for the uC/OS system.

Second tab: Data Master, where data cache is set to none

Assign the address, assign the interrupt number, and generate the address.

2. Hardware Circuit

Create a top-level file in the form of a schematic.

(1) Add the generated soft cores;

(2) Call the IP core of the Phase-Locked Loop;

(3) connecting and allocating pins;

(4) Compile and synthesize the configuration file.

Shows the final schematic.

Notes:

(1) Soft CoreProgramRun in the SDRAM. In order to speed up the soft core, the frequency of the SDRAM and the CPU are both set to 100 MB. The CPU clock clk_100 and SDRAM operation clock clk_50 are connected to the C0, 100 m of the PLL, and there is no phase offset. The clock pin sdram_clk of the sdram is connected to the C1, 100 m of the PLL, And the offset is-3ns.

(2) The clock pin of dm9000a is connected to 50 m and can be directly connected to the input end of the crystal oscillator.

(3) reset the pin to a high-level VCC.

(4) The reset pin flash_reset of cfi_flash can be connected to the high-level VCC.

3. Software

(1) Open the nio ii, create a project, and call the simple_socket_server Project template.

(2) Add the dm9000a DRIVER: dm9000a. h and dm9000a. C, and copy the above two files to the project folder created in the previous step.

(3) Open the network_utilities.c file and copy the appendixCodeOverwrite the original code. Here, the static IP method is used (the IP value will be described later) and assigned to the MAC value.

(4) Open the iniche_init.c file,

Add header file # include "dm9000a. H ",

Add the dm9000a interface statement dm9000a_instance (dm9000a_0, dm9000a_0 );

In the FunctionVoidSssinitialtask (Void* Task_data,

Add the initialization statement dm9000a_init (dm9000a_0, dm9000a_0) for dm9000a );

(5) Compile, download, and run the. Sof configuration file to FPGA. Run the ping command in DOS: Ping 192.168.2.1, as shown in. The ping command is normal.

Enter the Telnet command: Telnet 192.168.2.1, as shown in:

Enter 0-7 numbers on the PC keyboard, and the eight LEDs on diy_de2 will be highlighted or destroyed accordingly. At this point, it indicates that telnet is normal.

4. Interpretation of engineering documents

(1) alt_error_handler.h and alt_error_handler.c: handle file of the error type;

(2) dm9000a_regs.h, dm9000a. H, dm9000a. C: dm9000a driver;

(3) network_utilities.h and network_utilities.c: Set the IP address and MAC address;

(4) simple_socket_server.h and simple_socket_server.c: the main program of the project, including the task scheduling priority, default ipsettings, sockets, and various task scheduling;

(5) led. C: LED, seven-segment digital display program;

(6) iniche_init.c: main function of the program.

 

Iv. Analysis of experiment results

The running result of niosii is as follows:

After 2 minutes, the following result is displayed:

Experimental phenomenon: when the program starts running, it is first assigned to the static IP address. In this case, Ping can run, but Telnet cannot run. After 2 minutes (this default time can be adjusted when implementing the LWIP protocol stack, but it cannot be adjusted in the nichestack protocol stack, at least in the project file.). When the second result graph is displayed, Ping is normal and telnet is normal.

The analysis shows that although static IP addresses are assigned, the system still obtains the IP address through DHCP and gets the timeout. The default IP address is used. The default IP address is set in simple_socket_server.h. But the real Ping is normal, but telnet is normal but it is the static IP address assigned in advance.

 

Note: The method for canceling DHCP is the same as that in the previous blog.

 

5. Experiment description

1. IP value settings:

Because LAN communication is used, the first three IP addresses of PC and diy_de2 must be set to the same and the last IP address is different.

2. MAC value settings:

You can directly use the program settings, or store the MAC value in flash, and then read it after power-on. This example uses the previous method.

3. Port Settings:

Telnet requires listening on the port. When the listening port is the same as that set in diy_de2, communication can be normal. Method: When Telnet 192.168.2.1, there will be a dedicated port 23. Change the port number set in diy_de2 to 23 (in the simple_socket_server.h file ).# DefineSss_port 23 ).

4. About this routine in the aspect of niosii:

The reason why the lightweight TCP/IP stack option under the software components button is gray is not necessary. This is also confirmed by Youjing technology. If you use the lan91c111 Nic, the above-mentioned location options can be used normally. This means that the niosii software only recognizes the originally installed devices in the system.

 

 

 

Appendix:

Network_utilities.c File

 

# Include <alt_types.h> # Include <Ctype. h> # Include <Errno. h> # Include <Stdio. h> # Include <Sys/alt_flash.h> # Include  "  Includes. h  "  # Include  "  Io. h "  # Include  "  Simple_socket_server.h  "  # Include <Alt_iniche_dev.h> # Include  "  Ipport. h  "  # Include  "  Tcpport. h  "  # Include  " Network_utilities.h  "   # Define Ip4_addr (ipaddr, A, B, C, D) ipaddr = \ Htonl (alt_u32) ( & 0xff ) < 24 ) | (Alt_u32) (B & 0xff ) < 16 ) | \ (Alt_u32) (C & 0xff ) < 8 ) | (Alt_u32) (D & 0xff )))  /*  * Get_mac_addr ** read the MAC address in a board specific way *  */  Static Unsigned Char Macaddr [ 6 ] = { 0x00 , 0x07 , 0xed , 0xff , 0x06 , 0x00  }; Int Get_mac_addr (net, unsigned Char Mac_addr [ 6  ]) {  Int Rv =- 1  ;  /*  First 3 bytes are Altera's vendor ID  */    /*  Last 3 bytes are picked from serial number sticker  */  Mac_addr [  0 ] = Macaddr [ 0  ]; Mac_addr [  1 ] = Macaddr [ 1  ]; Mac_addr [  2 ] = Macaddr [ 2  ]; Mac_addr [  3 ] = Macaddr [ 3  ]; Mac_addr [  4 ] = Macaddr [ 4  ]; Mac_addr [  5 ] = Macaddr [ 5  ];  /*  Return the MAC address in the array  */  RV = 0  ;  Return  RV ;}  /* * Get_ip_addr () ** this routine is called by interniche to obtain an IP address for the * specified network adapter. like the MAC address, obtaining an IP address is * very system-dependant and therefore this function is exported for the * developer to control. ** in our system, we are either attempting DHCP auto-negotiation of IP address, * or we are setting our own static IP, gateway, and subnet mask addresses our * self. this routine is where that happens.  */  Int Get_ip_addr (alt_iniche_dev * P_dev, ip_addr * Ipaddr, ip_addr * Netmask, ip_addr *GW,  Int * Use_dhcp) {ip4_addr ( * Ipaddr, 192 , 168 , 2 , 1  ); Ip4_addr ( * GW, 192 , 168 , 2 , 1  ); Ip4_addr ( * Netmask, 255 , 255 , 255 , 0  ); # Ifdef dhcp_client * Use_dhcp = 1  ;  # Else /* Not dhcp_client */* use_dhcp = 0  ; Printf (  "  Static IP address is % d. % d \ n  "  , Ip4_addr1 ( * Ipaddr), ip4_addr2 ( * Ipaddr), ip4_addr3 ( * Ipaddr), ip4_addr4 ( * Ipaddr ));  # Endif /* Not dhcp_client */ /*  Non-standard API: return 1 for success  */      Return   1  ;} 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.