Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

Getting Board Information for Webserver on uClinux

Hi,

I am trying to get parameters from the board like the CPU Clock, i.e. to print this information on a website.

So I included the 'nios2.h' in my c file to print out the value of "na_cpu_clock_freq". But the problem is that the header 'nios2.h' includes '<asm/pio_struct.h>' which can't be found. Even if set the full path to 'pio_struct.h' it does not work, because the 'nios2.h' is always generated new.

Is there another way to get the actual CPU Clock?

Thanks

Urmel

9 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I seem to remember that when I used haserl to create html pages for the device, I used

    cat /proc/cpuinfo

    to show the system clock.

    See the pages in the wiki I created on "haserl" for more information.

    -Michael
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks for the fast answer.

    That's exactly what I am searching for.

    This leads me to another question how to use the apps started in the console to work with my cgi script in c-code. But this is probably explained in the wiki article about 'haserl' which you mentioned.

    Urmel
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Yep. This is exactly what haserl does.

    You don't write a CGI in C code, but you design a web page in some standard HTML designer and either when designing or after designing you insert some haserl tags. To make the web page a haserl cgi-script you insert

    # ! /bin/haserl

    or something like this as the fist line, so that haserl is started, when the web server starts the file as a cgi "program".

    When the haserl script is executed, the tags are replaced by the result of bash (or some other command line interpreter), that haserl calls with the parameters given on the tag.

    If you really need special purpose C code in some places, you can write a command line tool in C and have it called by the command line interpreter that is called by haserl (that is called by the web server).

    -Michael
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hello mschnell,

    I thought it was better to write the cgi in C. It take much more time to developp but the code is optimized by the gcc whereas haserl is interpreted.

    Is it the good way of thinking ?

    -Clement
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Of course haserl generated web pages can be rather slow. In a no-MMU environment with the command line interpreter and many standard command line tools in busybox, the busybox executable is loaded many times from Flash into RAM. This reduces the speed a lot, especially if (like with NIOS noMMU) busybox is statically linked and thus huge. I did not test this, but I suppose in an MMU environment with dynamic linking and/or "execute in place (XIP)" provided, haserl scrips will do fairly fast.

    I myself would not create html code directly in C, as this is very unflexible. So if doing C, I would read a html file with tags, and use C code to replace the tags with the C code in realltime.

    But in fact this is exactly what haserl does.

    A more advanced way and more "standard" to do dynamic html pages is using LUA instead of the normal command line interpreter. I don't know much about LUA, but I do know that LUA is supported by haserl as well).

    Of course the most "standard" way of doing all this is running PHP scripts. I myself did not consider this, as I would need to add the PHP syntax to my old and already quite full brain.

    -Michael
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi Michael,

    thank you for the detailed explanation of haserl.

    I think haserl is the right thing for my tasks.

    The first task is:

    I want to display network informations such as the actual ip address and mac address of the board as well as some parameters like the used kernel version and things like that.

    The second task:

    Control the board through the website like let the leds blink. I have this already done with a different stack (interniche's nichestack) under the nios-ide. But under uClinux I don't see how to change the bits of the leds because I can't use macros like "IOWR16_DIRECT". But this is another topic. If I understand you right I could start an applicaton or program through the haserl script.

    But I still have a question on haserl. I used your haserl script on the alterawiki and tried to run the file 'config.has' in the cgi-bin directory on my board with boa. I didn't change the file except replacing the line

    #! /bin/haserl --shell=/bin/msh
    to
    #! haserl --shell=/bin/hush
    because i can't find haserl under the /bin directory and I use 'hush' instead of 'msh'.

    I always get the 502 Bad Gateway Error. When I start the 'config.has' on the command line I can't execute it. Only by writing
    haserl config.has
    the script starts but without recognizing the html code. I always get "Bad command or file name" error. Execution of terminal programs as i.e.
    cat/proc/version
    in the script work fine.

    Urmel
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    AFAIK, you are right: hush now is the recommended command line interpreter rather than msh. AFAIK, some speed problems are solved with hush, as it has more internal commands than msh.

    AFAIK you are supposed to give the complete path to the interpreter after the# ! so you should fine out where the haserl binary is located.

    For a test you can just start the config.has file from the commnad line and it should output the raw html code with resolved haserl tags.

    You might be able to redirect this in a file and use a browser to look at it.

    -Michael
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi Michael,

    thank you so much!

    The hint with the path to haserl was the solution. Under my uClinux distribution with the kernel 2.6.30 (nios2-linux-20090730.tar) haserl was located in '/usr/bin'

    Urmel