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++
12603 Discussions

eCOS, Cyclone I/II, and Sockets

Altera_Forum
Honored Contributor II
1,607 Views

Hello All, 

 

I am a rank newbie to both the NIOS II, and eCOS; and I was hoping that I could get some advice/pointers on how to get an IP over RF (PHY) Modem/Router working on the NIOS II with eCOS. Essentially here are the basics of the project itself: 

 

(1) Have a PC transmit a video stream to another PC via TCP/IP over RF PHY (using the NIOS II board as a modem/router) 

 

(2) This will be done through an Ethernet interface connecting each PC to an RF MODEM HW 

 

(3) My target HW platform will consist of a CYCLONE II FPGA, with the NIOS II and a SMSC LAN91C111 Ethernet interface chip (I am now prototyping on CYCLONE I/NIOS II SDK Eval Board) 

 

Essentially my SW responsibilities are as follows: 

 

(1) Get the IP Packets from PC 

(2) Flatten the IP Packets and send them to the RF Modem’s input buffering 

(3) Get Data Buffer from the RF HW 

(4) Have the ability to change the Tx/Rx Channels of the RF HW via a telnet interface to the NIOS II (w/separate IP address for the board) 

(5) Do the same on the reverse link 

 

Questions: 

 

(1) Would eCOS be appropriate for this application? 

(2) Since I don’t know that much about eCOS how can I get it configured with my NIOS II HW and IDE 

(3) How can I get my SW to run automatically at bootup through eCOS? 

(4) Where can I find example SW demonstrating IP Sockets, IP Routing, and writing to an external memory?  

 

 

Any help would be greatly appreciated. Thanks!
0 Kudos
10 Replies
Altera_Forum
Honored Contributor II
570 Views

 

--- Quote Start ---  

originally posted by vava+oct 28 2005, 10:21 am--><div class='quotetop'>quote (vava @ oct 28 2005, 10:21 am)</div> 

--- quote start ---  

(1) would ecos be appropriate for this application?[/b] 

--- quote end ---  

 

it could do it. i&#39;m not sure exactly how much work it would be, since i&#39;ve never tried to mess with the routing layer of ip; i just do things from the application level. 

 

one caveat: your bandwidth will be limited by your cpu speed. expect 300-400 kbytes/sec. for 50 mhz. 

 

 

--- quote start ---  

originally posted by vava@oct 28 2005, 10:21 am 

(2) since i don’t know that much about ecos how can i get it configured with my nios ii hw and ide 

--- quote end ---  

 

start with the tutorial that comes with the ecos download. that should give you a good idea what it&#39;s going to take. 

 

 

--- quote start ---  

originally posted by vava@oct 28 2005, 10:21 am 

(3) how can i get my sw to run automatically at bootup through ecos? 

--- quote end ---  

 

unlike other os&#39;s like windows and linux, ecos isn&#39;t executable all by itself. when you build ecos, you&#39;ll get a library. you need to provide a cyg_user_start function, along with the rest of your code, and link your code with the ecos library to form the final executable, which you program to flash and execute just like a program with no os. 

 

<!--quotebegin-vava@Oct 28 2005, 10:21 AM 

(4) where can i find example sw demonstrating ip sockets, ip routing, and writing to an external memory? 

--- Quote End ---  

 

Writing to external memory is simple. main memory operates like any other memory; you can malloc() it, or create globals and use them. If you have other memories that aren&#39;t part of the main heap, you can get their base addresses from <cyg/hal/system.h> in your generated library. 

 

As far as sockets goes, eCos&#39; "net" template sets up with the FreeBSD stack, so you just use sockets the same way BSD does. The classic text is unix network programming: networking apis: sockets and xti, by W. Richard Stevens, ISBN 0-13-490012-X. 

 

By the way, it wouldn&#39;t be that hard to do a web interface with eCos. I use the simple HTTP server that comes with it to generate a set of web pages for system diagnostics and configuration.
0 Kudos
Altera_Forum
Honored Contributor II
570 Views

Hi vava, 

 

> (1) Get the IP Packets from PC 

> (2) Flatten the IP Packets and send them to the RF Modem’s input buffering 

<snip> 

> (5) Do the same on the reverse link 

 

Sounds like PPP -- you might want to take a look at the eCos PPP implementation. 

It might save you some time at the RF interface. 

 

> (1) Would eCOS be appropriate for this application? 

 

Sure ... it sounds like a good fit. 

 

> (4) Where can I find example SW demonstrating IP Sockets, IP Routing,  

 

If you can bolt-up underneath PPP, you may not have to worry about sockets ;-) 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
570 Views

 

--- Quote Start ---  

originally posted by smcnutt@Oct 28 2005, 01:29 PM 

if you can bolt-up underneath ppp, you may not have to worry about sockets ;-) 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=10665) 

--- quote end ---  

 

--- Quote End ---  

 

True, except for this... 

 

 

--- Quote Start ---  

originally posted by vava@Oct 28 2005, 10:21 AM 

(4) have the ability to change the tx/rx channels of the rf hw via a telnet interface to the nios ii (w/separate ip address for the board) 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=10661) 

--- quote end ---  

 

--- Quote End ---  

 

That telnet interface is going to have to use a socket. However, it shouldn&#39;t be particularly hard; there are several examples in the book I mentioned.
0 Kudos
Altera_Forum
Honored Contributor II
570 Views

Hi Mike, vava 

 

> That telnet interface is going to have to use a socket.  

 

Agreed. A bare-bones server waiting on a UDP port is about as simple as you can get 

... and all you really need. 

 

If you want to get fancy, I like Mike&#39;s web interface idea ... or you could use the SNMP 

agent with a really simple mib. 

 

I&#39;d forget about telnet ... unless you already have some telnet server code ... or you&#39;re 

a glutton for punishment ;-) Remember, eCos doesn&#39;t have a shell. 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
570 Views

Hello Again, 

 

I would just like to thank both of you for all your help with the eCOS on NIOS II (Cyclone II), it definitely cleared up some of the confusion I was having with regards to the system level implementation of eCOS. So thanks to your help, now I can get started :-). I do still have some more (specific) lingering questions:  

 

(1) Where can I obtain the PPP library for eCOS, I didn’t find it when I installed the OS bundle on my WinXP machine? How can it be built into my eCOS library (using nios2configtool)? 

 

(2) I was thinking that I would use separate threads for each of the tasks 

 

Tx Link (Downlink) 

(I) One thread for PPP to RF Communication 

(II) One thread for the telnet socket 

 

Rx Link (Uplink) 

(I) One thread for RF to PPP Communication 

(II) One thread for the telnet socket 

 

Is there any limitation on how many threads I can have? 

 

(3) I also understand from the documentation that heap memory can not be allocated in eCOS, and that all buffers must be statically allocated; is this true? 

 

I also have some off-topic questions on uCLinux: 

 

(1) Given the extremely short amount of time to complete this project (~ 4 weeks from today), would it be better to use eCOS or uCLinux? 

 

(2) From what I’ve gleaned from the uCLinux forum, it looks as though this OS is more full-featured, with the ability to develop standalone applications, which run from within a Linux command shell. Is this a fair assessment? How does eCOS differ from uCLinux? 

 

(3) Is there a port uCLinux for the NIOS II Cyclone I/II FPGA’s? 

 

Again I would really appreciate any help you could offer.
0 Kudos
Altera_Forum
Honored Contributor II
570 Views

Hi vava, 

 

> Where can I obtain the PPP library for eCOS, I didn’t find it 

 

C:\altera\kits\nios2\components\ecos\ecos-current\packages\net\ppp\current\src 

 

> How can it be built into my eCOS library  

 

Enable CYGPKG_PPP ... look for PPP support in Build->Packages 

 

> would it be better to use eCOS or uCLinux? 

 

That depends. If you already have eCos up-and-running ... you might not want 

to switch horses with only 4 weeks left. Although, having a shell (and telnetd) are 

certainly handy ;-) 

 

> Is there a port uCLinux for the NIOS II Cyclone I/II FPGA’s? 

 

Yes ... but the port is for Nios-II ... if Nios-II can be implemented on the device, 

you can use uClinux. 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
570 Views

 

--- Quote Start ---  

originally posted by smcnutt@Oct 28 2005, 04:31 PM 

if you want to get fancy, i like mike&#39;s web interface idea 

--- Quote End ---  

 

Thing is, it&#39;s not even that fancy. In your eCos configuration, go to the "Basic Networking Framework" section, "HTTP Daemon" subsection, and check "Autostart HTTPD" and "Simple Web System Monitor". With that, and assuming you rebuild and program your board, you should be able to type in "http://boardname/monitor" to your web browser and get a web page out of it. It&#39;s a pretty thorough "does the net work" test, for free. 

 

Then to add your own, you just need to write some code like: 

 

#include <cyg/httpd/httpd.h> cyg_bool WWWHome(FILE* client, char* path, char* formdata, void*) {         html_begin(client); // print web page to client with lines like: fprintf(client, "<foo>%s</foo>\n", fooStr);     html_end(client);     return true; } CYG_HTTPD_TABLE_ENTRY(wwwHome, "/", WWWHome, 0); 

And bam, your board has a home page. This makes debugging easier because you can just dump things to a web page and see how your system is doing at run time. 

 

Once you build your ecos library, in your library&#39;s install directory (NOT the altera/kits/nios2/components/ecos/... directory), look in include/cyg/httpd/httpd.h. There&#39;s a lot of macros and stuff in there to help you make the page. 

 

"Get" mode forms are also supported, so you can use this interface to change things, too. Be advised that these forms let you have a few small parameters, since it puts the form values into the URL, so it won&#39;t let you upload files. 

 

 

--- Quote Start ---  

originally posted by vava@Oct 28 2005, 04:41 PM 

(1) where can i obtain the ppp library for ecos, i didn’t find it when i installed the os bundle on my winxp machine?  how can it be built into my ecos library (using nios2configtool)? 

--- Quote End ---  

 

I&#39;ll assume you&#39;ve worked through the tutorial, at least up to where you get the simple web server/network support project built. If not, work through that, then the following will make more sense. 

 

When you run nios2configtool, you get your setup window. First, if you have a configuration file already, load it. If not, select the "net" template (refer to the tutorial if you forgot what this means). Once this is done, you go to the "Build" menu and select "Packages". Somewhere in the left list is "PPP Support" or somesuch; select it and move it into your project. Click OK and you should see the PPP settings in your project window. Configure, save, clean, and build library as normal. 

 

 

--- Quote Start ---  

originally posted by vava+oct 28 2005, 04:41 pm--><div class='quotetop'>quote (vava @ oct 28 2005, 04:41 pm)</div> 

--- quote start ---  

(2) i was thinking that i would use separate threads for each of the tasks[/b] 

--- quote end ---  

 

that&#39;s pretty standard; it should work. 

 

 

--- quote start ---  

originally posted by vava@oct 28 2005, 04:41 pm 

is there any limitation on how many threads i can have? 

--- quote end ---  

 

memory, and scheduler resources. i think there&#39;s a setting in the ecos kernel section for it. do you need more than 30? 

 

<!--quotebegin-vava@Oct 28 2005, 04:41 PM 

(3) i also understand from the documentation that heap memory can not be allocated in ecos, and that all buffers must be statically allocated; is this true? 

--- Quote End ---  

 

News to me. I&#39;ve been using malloc()/free() in C and new/delete in C++ for a while now. The "net" template turns on heap support, IIRC. 

 

 

--- Quote Start ---  

originally posted by vava+oct 28 2005, 04:41 pm--><div class='quotetop'>quote (vava @ oct 28 2005, 04:41 pm)</div> 

--- quote start ---  

(1) given the extremely short amount of time to complete this project (~ 4 weeks from today), would it be better to use ecos or uclinux?[/b] 

--- quote end ---  

 

honestly, given that schedule, whichever you choose, the other one is going to look like the better choice three weeks from now. with ecos, there&#39;s more work getting your makke file set up. with uclinux, you have to create a kernel, root filesystem, and application, fit all that in the flash somehow, and get it to boot right. either way, you&#39;re in for a good deal of work. 

 

 

--- quote start ---  

originally posted by vava@oct 28 2005, 04:41 pm 

(2) from what i’ve gleaned from the uclinux forum, it looks as though this os is more full-featured, with the ability to develop standalone applications, which run from within a linux command shell.  is this a fair assessment? 

--- quote end ---  

 

yes. don&#39;t forget the several-seconds startup time for linux. this is far more relevant to embedded systems than your average computer. 

 

 

--- quote start ---  

originally posted by vava@oct 28 2005, 04:41 pm 

how does ecos differ from uclinux? 

--- quote end ---  

 

no easy answer. linux is a timesharing operating system patterned after unix. ecos is a real-time operating system. both are posix compliant, and both are free software. 

 

<!--quotebegin-vava@Oct 28 2005, 04:41 PM 

(3) is there a port uclinux for the nios ii cyclone i/ii fpga’s? 

--- Quote End ---  

 

Check the uCLinux section on this board and download it from there.
0 Kudos
Altera_Forum
Honored Contributor II
570 Views

Thank you very much for the help.  

 

Though I&#39;ve been able to find the PPP library, I haven&#39;t found any sort of example code explaining how to get a session working via Ethernet on the PC. Where can I find an example, or some conceptual tips on how to get started with this? 

 

(1) So, once I get my PPP session initiated, and data is being exchanged between the PC and the Modem&#39;s Ethernet interface, do I just need to flatten the IP packet into the RF Modem input stream for Tx? And re-assemble the flattened packet on Rx? 

 

(2) Also is there any sort of code explaining how to control peripherals via I2C? 

 

Thanks again for all of your help!
0 Kudos
Altera_Forum
Honored Contributor II
570 Views

 

--- Quote Start ---  

originally posted by vava+oct 31 2005, 02:20 pm--><div class='quotetop'>quote (vava @ oct 31 2005, 02:20 pm)</div> 

--- quote start ---  

though i&#39;ve been able to find the ppp library, i haven&#39;t found any sort of example code explaining how to get a session working via ethernet on the pc.  where can i find an example, or some conceptual tips on how to get started with this?[/b] 

--- quote end ---  

 

scott mentioned the package&#39;s directory: 

 

c:\altera\kits\nios2\components\ecos\ecos-current\packages\net\ppp\current\src 

 

i&#39;d look through that at any .h files, or maybe even all the files, and see if they say anything. 

 

other than that, it&#39;s not easy finding docs on ecos stuff. one of the weaknesses of open source; most programmers aren&#39;t writers. 

 

 

--- quote start ---  

originally posted by vava@oct 31 2005, 02:20 pm 

(1) so, once i get my ppp session initiated, and data is being exchanged between the pc and the modem&#39;s ethernet interface, do i just need to flatten the ip packet into the rf modem input stream for tx?  and re-assemble the flattened packet on rx? 

--- quote end ---  

 

well, the whole point of this exercise was to have ppp do the flattening/unflattening to interface to the rf. then your system would just be a router with two network connections: one ethernet, and one ppp. 

 

<!--quotebegin-vava@Oct 31 2005, 02:20 PM 

(2) also is there any sort of code explaining how to control peripherals via i2c? 

--- Quote End ---  

 

That would be dependent on what IP you used for yor I2C controller; hopefully, there&#39;s example code in its documentation. If not, you can just write your own driver. It&#39;ll jsut take you a little while to figure out the I2C protocol. The I2C peripherals&#39; documentation should help here, too.
0 Kudos
Altera_Forum
Honored Contributor II
570 Views

Hello Again, 

 

Well, it looks as though the project has been pushed back by a few weeks (whew!), and the new project system architecture may not require PPP after all. Basically, after some discussion, instead of implementnting a Radio Link router, we&#39;ve scaled back the project to just be an ethernet-brige between two PC&#39;s streaming videos to one another. Below is the revised project block diagram 

 

[ PC ] <--> [ |ETH| <-|BUF|-> |RF| ] <--> [ |RF| <-|BUF|-> |ETH| ] <--> [ PC ]  

 

PC : Personal Computer 

RF : Radio Link 

BUF : DRAM Buffer (on board) 

ETH : Ethernet Link 

 

Essentially the NIOS II will now be responsible for doing the following: 

 

Tx Link 

(1) Grabbing each raw Ethernet packet from the controller 

(2) Reformat the data for RF Tx  

 

Rx Link 

(1) Reformat the data from RF Rx to Ethernet 

(2) Send out the raw Ethernet packets to the PC 

 

Essentially, I am now faced with the task of buffering the Ethernet packets coming from the SMSC LAN91C111 chip into an external DRAM, and now transferring this to the RF section&#39;s input FIFO. Just a few questions: 

 

(0) Would this approach work, or does PPP have to be used? 

(1) How can I grab the raw Ethernet frames/packets from the LAN chip in eCOS? 

(2) How can I implement a DMA buffer to buffer transfer in eCOS? 

 

 

Any help you can offer would be greatly appreciated. Thanks.
0 Kudos
Reply