Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12620 Discussions

Multiple Ethernet application under MicroC/OS-II

Altera_Forum
Honored Contributor II
2,261 Views

Hi, there  

 

I am a new one for the MicroC/OS II system. Now I am working on the multiple Ethernet application based on the NicheStack and MicroC/OS II. Can anyone provide some reference design about how to manage multiple Ethernet ports? I do appreciate it.
0 Kudos
15 Replies
Altera_Forum
Honored Contributor II
649 Views

I use two ports with tse and sgdma. 

I use one of them with tcp/ip (Nichestack) and the other with raw ethernet frames. I don't know if this is your case but I suppose it is even easier if you need to use both in the same way. 

I assume you have already built your sopc. Then all you need to do is: 

- call twice (or multiple times) alt_tse_system_add_sys() in the beginning of your application, to initialize all your devices 

- provide the required callback functions for assigning mac and ip addresses, get_board_mac_addr() and get_ip_addr()  

Then, the actual use of the ethernet interface, as I said above, depends on what you need them for. 

 

Cris
0 Kudos
Altera_Forum
Honored Contributor II
649 Views

Hi, Cris: 

 

Thanks for your reply. I am trying to build a simple telnet application demo with two Ethernet ports first. Then I will develop a more complex system to realize multiple UDP/IP transmissions.  

 

What confused me is that at the sopc builder, I connected four DMA controllers (For one Ethernet port, it has one DMA for transmission and the other for receiving. Two Ethernet ports are needed, therefore I have four DMA controllers) at the same DDR memory module. It turns out the top level verilog file can not pass the synthesis. Here is the Error: 

Net"DE3_Referenceup_SOPC:DE3_Referenceup_SOPC_Instance|mem_dqs_to_and_from_the_altmemddr[2]", which fans out to "DE3_Referenceup_SOPC:DE3_Referenceup_SOPC_Instance|altmemddr:the_altmemddr|mem_dqs[2]", cannot be assigned more than one value 

 

So I am just wandering if it is necessary to allocate a separate DDR memory module for each pair of DMA controllers. 

 

The other problem is about socket programming. I have no experience about that before. Am I supposed to allocate one IP address and one port number for each Ethernet port? Each Ethernet port need to be managed by one individual socket?
0 Kudos
Altera_Forum
Honored Contributor II
649 Views

You don't need a separate DDR: all dma share the same memory. My system is the same as yours: 2 tse, 4 dma a single dram; the only difference being I'm using sdram controller, not ddr. 

I can't tell you what that error is due to. Try check in sopc builder: 

- connections between dma and ddr 

- interrupts, arbitration,base addresses  

- ddr module configuration 

Then in Quartus, if you use top level schematic, check if any connection is missing or if a couple of them has been wrongly connected together. 

 

About socket programming. 

One ip address for each Ethernet port (you must define the get_ip_addr() function which will be called by interniche upon initialization)  

One socket for each tcp/udp connection you need. 

The tcp/ip stack will take care to move data to and from the correct physical Ethernet port.
0 Kudos
Altera_Forum
Honored Contributor II
649 Views

The sopc builder problem has been solved.  

 

Unfortunately, I am still got stuck by the initialization steps of Ethernet MAC and IP address. I knew that I should use get_ip_addr and get_board_mac_addr twice to get the correct parameters for each Ethernet port. However, I can not find where these two functions have been used in the simple socket server example. Are they used by the alt_iniche_init()?
0 Kudos
Altera_Forum
Honored Contributor II
649 Views

More precisely, I think I should ask are those two Ethernet interfaces should be initialized simultaneously during the calling of alt_iniche_init() and net_main(), or one Ethernet port can acquire the IP and MAC after the initialization.

0 Kudos
Altera_Forum
Honored Contributor II
649 Views

I can't understand exactly what is your problem. 

Maybe you are missing a point: you don't have to call get_ip_addr and get_board_mac_addr functions; you'd rather have to define them into your project.  

iniche will call them during alt_iniche init or net_main (now I can't remember which) in order to know from you which ip and mac you want to assign to every network interface you have. 

 

If instead your problem is to reassign ip and mac AFTER initialization, this is possible, although I think it is not recommended. You need to change some fields in the device data structure (so, making nothing less than a re-initialization of the device). 

You can place a breakpoint into the above init functions and step with debugger in order to find where ip and mac data are stored. 

 

Cris
0 Kudos
Altera_Forum
Honored Contributor II
649 Views

Hi, Cris 

 

My problem is I can not figure out the way that iniche assign the IP address and MAC address to the Ethernet port. I went through the targnios.c, which define the alt_iniche_init function, and net_main.c. I did not find that the alt_iniche_init and net_main call the get_ip_addr and get_board_mac_addr directly. That's why I am so confused. 

 

I am not quite sure about your "define" means. Do you mean like that:# define GETIP get_ip_addr(), Then put GETIP twice in the alt_iniche or net_main to get the IP address for two Ethernet ports? Or you mean rewrite these two functions for support multiple Ethernet ports?
0 Kudos
Altera_Forum
Honored Contributor II
649 Views

With "define" I didn't mean# define, but I meant you must provide in your code the two functions. These will be called by iniche upon initialization. 

Here are two simple templates: 

 

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, 101, 100); IP4_ADDR(*gw, 192, 168, 101, 1); IP4_ADDR(*netmask, 255, 255, 255, 0); # ifdef DHCP_CLIENT *use_dhcp = 1;# else /* not DHCP_CLIENT */ *use_dhcp = 0; printf("TCP/IP port\n"); printf("Static IP Address is %d.%d.%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; }  

 

int get_mac_addr(NET net, unsigned char mac_addr) { mac_addr = MAC_BYTE1; mac_addr = MAC_BYTE2; mac_addr = MAC_BYTE3; mac_addr = MAC_BYTE4; mac_addr = MAC_BYTE5; mac_addr = MAC_BYTE6; printf("Default Ethernet MAC address is %02x:%02x:%02x:%02x:%02x:%02x\n", mac_addr, mac_addr, mac_addr, mac_addr, mac_addr, mac_addr); }  

 

get_ip_address() is called by iniche_devices_init(), which is in file alt_iniche_dev.c 

get_mac_address() is called by your MAC initialization function; if you use TSE is prep_tse_mac() in ins_tse_mac.c file 

 

Regards 

Cris
0 Kudos
Altera_Forum
Honored Contributor II
649 Views

TO_BE_DONE

0 Kudos
Altera_Forum
Honored Contributor II
649 Views

Hi Cris72, 

I am debugging my simple socket server project and I have found that my Target MAC address: 00:00:00_00:00:00 (00:00:00:00:00:00) 

 

I have modified the get_mac_addr() in network_utilities.c 

 

int get_mac_addr(NET net, unsigned char mac_addr[6]) 

 

mac_addr[0]=0x00; 

mac_addr[1]=0x07; 

mac_addr[2]=0xED; 

mac_addr[3]=0x0E; 

mac_addr[4]=0xD3; 

mac_addr[5]=0xA2; 

 

return 0; 

 

In my design I am using TSE and as you said get_mac_address() should be called by prep_tse_mac() in ins_tse_mac.c file. 

 

I can't find ins_tse_mac.c 

Where can I find that? 

Thank you very much in advance  

 

 

--- Quote Start ---  

With "define" I didn't mean# define, but I meant you must provide in your code the two functions. These will be called by iniche upon initialization. 

Here are two simple templates: 

 

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, 101, 100); IP4_ADDR(*gw, 192, 168, 101, 1); IP4_ADDR(*netmask, 255, 255, 255, 0); # ifdef DHCP_CLIENT *use_dhcp = 1;# else /* not DHCP_CLIENT */ *use_dhcp = 0; printf("TCP/IP port\n"); printf("Static IP Address is %d.%d.%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; } int get_mac_addr(NET net, unsigned char mac_addr) { mac_addr = MAC_BYTE1; mac_addr = MAC_BYTE2; mac_addr = MAC_BYTE3; mac_addr = MAC_BYTE4; mac_addr = MAC_BYTE5; mac_addr = MAC_BYTE6; printf("Default Ethernet MAC address is %02x:%02x:%02x:%02x:%02x:%02x\n", mac_addr, mac_addr, mac_addr, mac_addr, mac_addr, mac_addr); } get_ip_address() is called by iniche_devices_init(), which is in file alt_iniche_dev.c 

get_mac_address() is called by your MAC initialization function; if you use TSE is prep_tse_mac() in ins_tse_mac.c file 

 

Regards 

Cris 

--- Quote End ---  

0 Kudos
Altera_Forum
Honored Contributor II
649 Views

Hello Cris and Red_alert, 

 

I am also trying to achieve what you already have: to build a simple system with two Ethernet ports... 

 

I build the system and program it on the Altera DE4 board. For the software, I use the Simple Socket Server template in Nios II (involving NicheStack and MicroC/OS II). When I check the alt_sys_init() function, ALTERA_AVALON_SGDMA_INIT is called four times (for the four SGDMAs) and TRIPLE_SPEED_ETHERNET_INIT twice (for two TSEs). It seems that the template automatically generates the calls to these function calls, using the SOPCINFO file. 

 

When I run the code, I get the error -22. The problem occurs in the 2nd TRIPLE_SPEED_ETHERNET_INIT() call, where "the pointer to the alt_tse_system_info structure from the global array" "could not be found". The error is explained to be "ran out of other queue-able resource" in ipport.h sourcecode.  

 

Do you know if this is a pure System problem? Does it mean that I need to increase the memory size in my system? Or, could it be a software error, since I did not make any changes to the template. As far as I understand, the template can initialize all the ethernet ports (up to 4 ports), without any change. 

 

Thank you very much, 

Kind regards, 

Turhan
0 Kudos
Altera_Forum
Honored Contributor II
649 Views

Sorry for the double post =( 

Here is the error I see in the NIOS II Console: 

 

InterNiche Portable TCP/IP, v3.1 Copyright 1996-2008 by InterNiche Technologies. All rights reserved. prep_tse_mac 0 Your Ethernet MAC address is 00:07:ed:ff:ed:15 prepped 2 interfaces, initializing... Error opening TX SGDMA init error -22 on net mctest init called IP address of : 0.0.0.0 dtrap - needs breakpoint dtrap - needs breakpoint Error sending DHCP packet on iface 1. ip_exit: calling func 0x509af00 netclose: closing iface Altera TSE MAC ethernet ip_exit: calling func 0x50a2da4
0 Kudos
Altera_Forum
Honored Contributor II
649 Views

Dear All, 

I am also trying to make a Nios II Ethernet application with two Ethernet interface. 

Please tell me what all components shall I include in Qsys and how to set the network parameters for two Ethernet interfaces. 

I wish to assign network settings statically (I will be not using DHCP for setting network parameters). 

Waiting for reply.............
0 Kudos
Altera_Forum
Honored Contributor II
649 Views

I believe this old thread already explains most of the stuff. Please specify what you need or what you didn't understand.

0 Kudos
Reply