Hello Xeno World

I thought I would go over quickly how to make a very simple Xenomai user space application.  This is just a simple hello world program that will help use create a make environment for Xenomai applications.  Our goal here is not to do anything interesting, we just want to setup a cross-compiling environment for out Zynq development platform.

Before we start you should have to complete my tutorial about building Xenomai 3 for Zynq.  We are going to need to use our stage directory from that tutorial.  This directory contains libraries and helper scripts.  We will need the xeno-config script to help build our applications.  The config script holds all of our information about what we are targeting.  If we run it alone we should see something similar to the photo below…..

Screenshot from 2017-08-07 23-21-04Using this script we should have all the information we need to create our first Xenomai program.  All the source is located on github here. First let’s look at the makefile.

Screenshot from 2017-08-07 23-33-39

I created a variables PATH_TO_STAGE which holds the path to where your xenomai 3 libraries and scripts are located.  Change this in the makefile to match with your local system.  We’ll need to set the DESTDIR variable to this path so the cross compile tools can find our libraries during the build stage.  I haven’t added a clean option to this makefile since it’s very simple.  Feel free to add a clean option if you’d like, we’ll add that in the future tutorials.  The xeno-config script will hold all the information that we need to make sure we are building for the correct platform with the correct compiler and linker flags.  The other thing to note here is I have chosen the native skin, if you want the posix skin, vx skin or any other the other ones you would just change –native to the option of your choice.  You can list the options by running xeno-config.

Now on to our very simple cpp file.

Screenshot from 2017-08-08 00-43-49.png

Again this is available on git hub at the link I posted above, but all we are doing here is using the native skin and printing a message to the screen.  The function rt_printf is form the native Xenomai API and behaves like normal printf from plan libc.

All we need to do now is call make and we should see some build output and then our new executable file.  We can copy this to our sdcard and then boot our board.  I copied it to my ubuntu user home directory.  We should be able to plug the Zybo into a network and scp the file over (something for another post) but for now I’ll just copy to the sdcard.

Once we have booted our board we have to add the path to where our libraries are to the file /etc/ld.so.conf.  Each file in this directory will contain a path where linux will search for libraries for our executables.  For our xenomai libs we’ll need to add the line “/usr/xenomai/lib”.  Since I have vi installed on my target I created the file with vi, use which ever method you’d like.  Once that is done we need to run:

sudo ldconfig -v

Now when we try to execute your Xenomai program we shouldn’t get any missing library failures.  So now we need to execute our hello program using sudo and we should see our print.

sudo ./hello_xeno_world

Now we should see our print statement, and have our first realtime program running.  The goal of this short post was to create a simple Xenomai application and getting the build environment set up.  Going forward we will be doing some more interesting things then just printing to the console.