eCos real time operating system


2012-03-29Publicerad av Sven-Åke Andersson

Introduction


eCos (embedded configurable operating system) is a free and open source real-time operating system intended for embedded systems and applications which need only one process with multiple threads. It is designed to be customizable to precise application requirements of run-time performance and hardware needs. It is implemented in C/C++ and has compatibility layers and APIs for POSIX and µITRON.

Can we use eCos in our system? Let's find out. We will start by studying the eCos home page.


 

Information about eCos


Here are some links:
 



eCos on OpenRISC


OpenRISC is not mentioned on the eCos home page but I know about one company which has made a great effort in updating the eCos port for OpenRISC and that is Ant Micro. Here is what they say on their home page:

"We updated the port to eCos 3.0, fixed what was broken and run it on the OpenRISC development board when it became available to verify that it is functional. The port can now be grabbed from the OpenCores website, and Ant Micro is its official maintainer, with Piotr Skrzypek as the responsible person".
 

Getting eCos


eCos is hosted on OpenCores SVN. Use this command to download the complete package:

svn co http://opencores.org/ocsvn/openrisc/openrisc/trunk/rtos/ecos-3.0

 
 


Here are the installed files.
 


 


Installing eCos


eCos uses two tools to build and configure the system: configtool and ecosconfig. ecosconfig is a handy command line program that allows to select the desired eCos target and packages. configtool is a windowed application that provides a clear and intuitive environment to adjust all of the possible configuration options.


 eCos configuration tools
 

The eCos configuration tools are maintained by eCosCentric and can be downloaded from their web page. The pre-built binary of configtool can be downloaded using the following command:

wget http://www.ecoscentric.com/snapshots/configtool-100305.bz2





Unpack and copy to /usr/local/bin directory.


bunzip2 configtool-100305.bz2
chmod 755 configtool-100305
sudo cp configtool-100305 /usr/local/bin/.
sudo ln -s /usr/local/bin/configtool-100305 /usr/local/bin/configtool

Building ecosconfig


ecosconfig needs to be built from scratch. In order to build ecosconfig, go to the ecos-3.0 directory downloaded from SVN. Execute the following command:

./host/configure

The execution stops after a few seconds showing this error messsage.




 

Fixing the tcl/tk installation


We will start by adding the following packages:

sudo apt-get install tcl8.4-dev
sudo apt-get install tk8.4-dev






The configure script looks for the tclConfig.sh and tkConfig.sh files in the directory /usr/local/lib.  Let's copy the files to this directory and rerun the script.

sudo cp /usr/lib64/tcl8.4/tclConfig.sh /usr/local/lib/.

sudo cp /usr/lib64/tk8.4/tkConfig.sh /usr/local/lib/.





This time the configuration script finishes without errors. We are ready to build the ecosconfig tool.

make
sudo make install


Both ecosconfig and configtool require environmental variable ECOS_REPOSITORY. The variable must point to the packages directory, inside ecos-3.0 tree. We will add this line in our .bashrc file:

export ECOS_REPOSITORY=/opt/home/svan/OpenRISC/ecos/ecos-3.0/packages
 

Configuring eCos for OpenRISC


Create a directory to build the eCos library. First start with the default template:

ecosconfig new orpsoc

The default configuration fits the ORPSoC port for ordb2 reference platform. It assumes that hardware multiplication and division are implemented. Floating point variables are handled by software. System clock runs at 50 MHz. If we are using MinSoC, or ORPSoC with different configuation, we need to alter the settings:

configtool ecos.ecc
 



Let's take a look at the current setup.
 









We will not make any changes for the Atlys board so we can just save the ecc file. It is always a good idea to check for possible conflicts by running:

ecosconfig check

 


Building eCos with tests


ecosconfig tree
make
make tests

 

Writing programs with eCos


It is now possible to write programs linked with eCos. The most simple hello world program (hello.c) would look like this:

#include <stdio.h>
int main(void) {
 printf("Hello, eCos world!\n");
return 0;
 }



To compile the program, use gcc with the following flags:


or32-elf-gcc \
-g \
-O2 \
-nostdlib \
-install/include \
-Linstall/lib \
-Tinstall/lib/target.ld \
examples/hello.c -o hello.elf

 

Connecting a serial terminal


We are ready to load and run the Hello World program but before we do  we have to connect a serial terminal to see the output from the program. For more information about connecting a serial terminal see this chapter in the blog. We use gtkterm with the following setup.
 

 

Running eCos on the Atlys board


The most convenient way is to run the program using GDB debugger. First, start or_debug_proxy:

./or_debug_proxy -r 50001
 



In another terminal start the GDB debugger.

or32-elf-gdb hello.elf

 



 

Connect to the target and load and run the program.

target remote :50001
load
c


 



 

Output on the serial terminal.
 

 

More examples


The Hello World program is not the most interesting program to run in a real time operating system. There are some more programs found in the examples directory.
 



 

Here is a printout from the twothreads program.