Home  |  Buy on line  |  Contact us  |  Terms & Conditions  | 
  



New FOX Board G20



Buy on-line


FOX Board G20
FOX Board LX832
Easy Guardian
SMS FoxBox
Acme Systems srl




FOX Board LX832 is discontinued
To be informed about its availability and prices please CONTACT US
To know more about the new FOX Board G20 GO HERE

Using The Math Library with the Fox

This article describes how to compile an application that needs to use the mathematical library

Introduction

Inside the default image shipped by ACME Systems it is present the libm standard mathematical library so every application compiled for the Fox board requiring math functions like: sin() cos() tan() and the like needs only to add a proper line in the makefile to enable the math library.

We will also show you how to include your math enabled application in the fimage generated by the SDK enabling your flashed Fox to include automatically your application.

How to compile a math enabled application for the Fox board

Create a math application directory

So starting from the /home/fox/devboard-R2_01 directory initialize the environment (if not already done) with the command source init_env, switch to the apps directory and create the directory hellomath:
# cd /home/fox/devboard-R2_01
# source init_env
# cd apps
# mkdir hellomath
Copy into it the following files: Makefile hellomath.c

This is the content of the sample Makefile for math enabled applications:

AXIS_USABLE_LIBS = UCLIBC GLIBC
include $(AXIS_TOP_DIR)/tools/build/Rules.axis
PROGS     = hellomath
INSTDIR   = $(prefix)/mnt/flash/
INSTMODE  = 0755
INSTOWNER = root
INSTGROUP = root
OBJS = hellomath.o

all: $(PROGS)
LDFLAGS += -lm
$(PROGS): $(OBJS)
	$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@

install:	$(PROGS)
#	@echo Installing $(PROGS) in $(INSTDIR)
	$(INSTALL) -d $(INSTDIR)
	$(INSTALL) -m $(INSTMODE) -o $(INSTOWNER) -g $(INSTGROUP) $(PROGS) $(INSTDIR)
clean:
	rm -f $(PROGS) *.o core

As you can see from the reported Makefile there is a flag to set in order to enable the math library: LDFLAGS += -lm. Also in the options passed to the compiler you have to specify the flags and libs: $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ Finally it is stated here where the application has to appear on the target directory tree. We chose to put it into the read/write partition: /mnt/flash. Other choice could be to put it under the /bin directory that is read only so that it will not be possible to erase it without a reflash of the Fox board.

This Makefile is quite general. You can use it, and the instruction following, as a simple template to include your application (even if not requiring the math library) into the SDK target tree file so to be able to generate images for the Fox board with your application integrated into it. This will be shown in the second part of this article.

The content of the sample application just mentioned (hellomath.c) that uses a single cosine function is reported here:

#include "stdio.h"
#include "math.h"
#define PI 3.14159
int main () 
{
  double num;
  double arg= PI/4; // 45 degrees in radians
  num = cos(arg);
  printf("Hello math users: cos(PI/4)= %f\n", num);
  return 0;
}

Enabling the application source files to compile against the right library and environment

Now, starting in the apps/hellomath directory, execute the following command to enable the directory source files to be compiled against the right C library and environment:
# make cris-axis-linux-gnu
This creates, inside the directory hellomath, a hidden file: .target-makefrag that has instructions for the make process about which general library (in this case glibc) and the cris environment to consider during the compilation phase.

Note: to enable the compilation against uclibc the command would be:

# make cris-axis-linux-gnuuclibc

Compile your math application

From the hellomath directory now just invoke:
# make
In the same directory will appear the file hellomath ready to be transferred to the Fox board.

Transfer hellomath on the Fox Board and run it

To transfer the just compiled application hellomath onto the Fox Board you can use for example the scp command from your workstation:
# scp ./hellomath root@192.168.0.90:/mnt/flash/hellomath
The command will ask for the Fox password (pass) and will copy the hellomath file in the Fox /mnt/flash directory.

Now go to a Fox console (or telnet or ssh session) and invoke:

# cd /mnt/flash 
# ls -al
drwxr-xr-x    1 root     root            0 Jan  1 00:12 .
drwxr-xr-x    1 root     root           84 Jan 18  2006 ..
drwxr-xr-x    1 root     root            0 Jan  1 00:01 etc
-rwxr-xr-x    1 root     root        18386 Jan  1 00:12 hellomath
drwx------    1 root     root            0 Jan 18  2006 root
If the hellomath file doesn't present the permission x on the part: -rwxr-xr-x just make it executable with the command:
# chmod +x hellomath
Now you can call the hellomath program:
# ./hellomath
Hello math users: cos(PI/4)= 0.707107
#

Modify the general Makefile to make it aware of the new application: hellomath

If you want to generate a fimage containing your application (in this case hellomath) you have to inform the general make process over the presence of your application in the dev tree, so that it will be compiled and the executable file will be inserted under the specified target directory of the fimage generated. You have to edit the general Makefile, search for the SUBDIRS section and add under the last line of the SUBDIRS section of the general Makefile the following line:
# apps/hellomath
don't forget the "\" on the line above this one!:

So, open with an editor the general Makefile of the SDK that is inside the devboard-R2_01 directory: The resulting piece of Makefile after the modifications is reported here:

 ...
    packages/devices/scsi \
    packages/devices/ttyusb \
    apps/hellomath
 .PHONY: pre-install-recurse
 ...
After the Makefile addition quit the editor saving your modifications and run the general make:
# cd /home/fox/devboard-R2_01
# make
The image generated, once flashed onto the Fox board will contain also your application hellomath under the /mnt/flash directory.

When the FOX board restarts after the flashing login into the FOX board and type:

# cd /mnt/flash
# ls
etc        hellomath  root
# ./hellomath
Hello math users: cos(PI/4)= 0.707107
#