web analytics

C Compiler FAQ


Q: How do I install KTProject?

A: Just launch KTProject.exe

To install the KTproject, just double click on the KTproject icon and follow the instructions. Do not install the software in a folder that contain a space in its name (such as the Program Files folder), it may cause problems when using the soft-ware.

After installing the software, two icons should appear on your desktop: Kterminal and KTProject.

KTproject is a package software that allow you to edit, compile and navigate through your program files.

KTerminal is a java terminal software, extremely simple and easy to use.

Running KTProject allows you to create a project on the basis of a template file which already exists, it is also possible to create a new project on the basis of your specific files.

The project appears in the Source-Navigator window. As you can notice, the program automatically generated a makefile for the project, and the template program is now named after your project name.

The Cygnus software included in the KTproject have a good online documentation. To open the Editor, double click on one of the file displayed in the Navigator list.


Q: Where can I find examples?

A: For each hardware, we provide adequate sample code. You will find them under examples in the directory matching your hardware (Kameleon & REB: rebpack, Koala: koapack, Khepera: khepack, Khepera II: kh2pack, K6300: k63pack).

Look also in our users pages ( http://www.k-team.com ) : many of them propose freely their code.


Q: How do I compile?

A: Double click on the C file in the editor windows. Open the Build window in the Tools menu. Push the button start. The program should compile and download directly to the serial port indicated in the Makefile variable port, with the speed indicated in the Makefile variable speed. Q: Do I need to modify the Makefile?

If you are in a simple configuration, that is to say: a flat tree (binary, source in the same directory) and ONLY ONE C FILE, you can rely on the self generated makefile.

You don t have to modify it totally but there are some important things to notice about it.

1. You can open it by double-clicking on it, the Editor window.

2. You can change the serial connector name of your computer here and the baudrate for the communications between the board and the computer.


Q: There is a parse error on reading the Makefile.

A: Borland tools also includes a make utility. To ensure that you are running the right make.exe, you can type in the Build window, gmake instead of make. gmake stands for GNU Make.


Q: Assembler crash on a parse error

A: Variable starting by "cc" cause the assembler to crash.


Q: How do I write C code?

A: The C uses the newlib library. If you want to use the K-TEAM Operating System commands, you need to include:

#include

The C Application Interface for Kros is described in your BIOS manual. If you use printf, do not forget to write "" instead of "". In previous version of the compiler, you needed to use RESERVE_COM before printf and RELEASE_COM after. This is no longer needed with the current version.


Q: How do I write in Assembler?

A: You can write your code in Motorola Assembler (please consult GAS documentation). Here is an example extracted from those available with your package (sina directory):

{…}

.globl atan_lkup1,atan_lkup2

atan_lkup1:
movem.l d2/a2,-(a7)
move.l 12(a7),d2
move.l aTabAtan1,a2
tblu.l (a2),d2
move.l d2,d0
movem.l (a7)+,d2/a2
rts

{…}

where atan_lkup1 can be called from within C with the following convention:

long atan_lkup1 (unsigned int);

Another way to include C and assembler code is to use the following notation:

/* Fixed Point Multiplication in the Range [256,-256] on 32 bts (Signed 9.22) */
asm(".globl mul256");
asm("mul256:");
asm("movem.l d1-d2,-(a7)");
asm("move.l 12(a7),d0");
asm("move.l 16(a7),d1");
asm("muls.l d0,d2:d1");
asm("asl.l #8,d2");
asm("asl.l #1,d2");
asm("rol.l #8,d1");
asm("rol.l #1,d1");
asm("and.l #0x000001FF,d1");
asm("or.l d2,d1");
asm("move.l d1,d0");
asm("movem.l (a7)+,d1-d2");


Q: How do I compile into a Flash-able file or a ROM-able file?

A: If your filename is src/foobar.c , type in the build window :

make bin/project.s37 for a Flash-able file for Khepera II, Koala and Kameleon.
make bin/projectname.rom for ROM-able file for Khepera


Q: How do I avoid the deletion of the downloadable file (.s37) after compilation?

A: Add in your project Makefile the following line:

.PRECIOUS: %.s37


Q: My ROM files generated on Windows does not work.

A: Binary concatenation of bios.bin and your binary code does not work with Cygwin cat. The solution is to generate a binary version of your file by concatenating yourself files.


Q: How do I debug the program using the serial line?

A: You should use printf statements and take care that the printf operation is longer than any other standard operation.


Q: How do I send the program using the serial line?

A: You should use printf statements and take care that the printf operation is longer than any other standard operation.


Q: I want to compile by myself without implicit rules

A: If your filename is scr/foobar.c type:

make bin/foobar.s37


Q: How do I compile many C files?

A: If you have many C files, you should modify the canonical makefile.

First suppress all the existing rules (starting from "all: $(EXE)").

Second, for a program foobar.o based on foobar.c, foo.c, and bar.c, type:

all: foobar.S37

foobar.S37: foobar.c foo.o bar.o

foo.o: foo.c foo.h

bar.o: bar.c bar.o

Please take to always leave a blank line after each rule.


Q: I want to debug the assembler produced by the compiler: how can I read the resulting assembler code?

A: If you want only to read only your own code in assembler type:

make $(src_dir)/foobar.s

If you want to read the final code sent to the Khepera type:

make $(src_dir)/foobar.lst


Q: What is tim_install_task or bios_restart?

A: These functions are part of the K-TEAM Operating System. You need to read the K-TEAM documentation provided with your device (see also http://ftp.k-team.com ).


Q: I do not understand how the Makefile works, is there another way?

A: No, but Makefiles for KrOS are very easy to use. You can find information on makefiles in the GNU Makefile documentation online.


Q: No matter what I compile, I get "file path prefix.." message. Why?

A: The following message:

m68k-none-kos-gcc: file path prefix `/home/egcs/b-sparc-sun-solaris2-x-m68k-kos/lib/gcc-lib/m68k-none-kos/egcs-2.90.27/' never used means that you are not using the compiler builtin path, i.e. the one declared during the compilation of the compiler. THIS IS NOT HARMFUL.


Q: How do I build a cross-compiler?

A: If K-Team does not support your cross-compiler, you will have to install the cross-compiler on your machine yourself. You need to have the standard public domain GNU C compiler package and your machine must be supported by GNU. The GNU sub-packages that you need are binutils2.9.1.tar.gz (or later version) and gcc2.95.2.tar.gz (or later version).

If you do not have these GNU packages, you can obtain them on
http://sourceware.cygnus.com/gcc/ and http://sourceware.cygnus.com/binutils/

. If you do not have access to the Internet, please contact your distributor. To know if your machine is supported, read the INSTALL file of the GNU package.

To start, follow these instructions:

Create a directory in which you will install the cross-compiler. This directory needs roughly 200 MegaBytes. In this document we will refer to this directory as /path/to/kros. Every time that you see /path/to/kros, please replace it with the path of your directory.

Unpack the corresponding hardware package (khepack5.tgz for example) to /path/to/kros/. Uncompress binutilsXXX.tar.gz and gccXXX.tar.gz to this directory.

To compile the binary utilities (mainly the assembler and the linker):

Go to the binutilsXXX directory: cd /path/to/kros/binutilsXXX}.

./configure --target=m68k-none-elf --prefix=/path/to/kros

If the configure script can't determine your type of computer, give it the name as an argument, for instance:

./configure --target=m68k-none-elf --host=sparc-sun-sunos4.1.3 --prefix=/path/to/kros

The host option consists of a triplet including processor, company and OS, like sparc-sun-sunos4.1.3 (read point 3 and the section "Configurations Supported by GNU CC" in the file INSTALL in the directory gccXXX).

make install

To compile the cross-compiler:

Go to the gccXXX directory.

./configure --target=m68k-none-elf --prefix=/path/to/kros

Similarly, if the configure script can't determine your type of computer, give it the name as an argument, as described in the previous point.

'cp -r ../khepack5/include ../m68k-none-elf/include'
make LANGUAGES=''c c++'' all
make LANGUAGES=''c c++'' install

If everything works fine, you have now a working version of the cross-compiler. If you have problems during these compilations, please consult http://www.objsw.com/CrossGCC and http://sourceware.cygnus.com/ml/crossgcc/


Q: My old khepera package does not work with my gcc compiled version.

A: The old package used the AOUT binary format and KrOS uses the ELF format. Compatibility is not insured.


Q: Why C++ does not work?

A: C++ startup code is not working.


Q: How to fix "undefined reference" errors?

A: This problem is due to the GNU linker policy.

To get rid off the problem, you should modify the LOADLIBES variable in Makefile_Advanced. For that you need to use Makefile_Advanced (in your khepack examples directory) in place of Makefile: override the basic Makefile with the Makefile_Advanced. After that, you can play with the order of the libraries in

LOADLIBES:

$(SUPPLIB) -lgcc -lstdc++ -liostream -lio -lktdebug -lc -lkbus -lglue -lc

-lkernel -lm -lgcc

You can instead supply for instance:

$(SUPPLIB) -lgcc -lstdc++ -liostream -lio -lktdebug -lm -lc -lkbus -lglue -lc

-lkernel -lm -lgcc


Q: How can I measure internally or externally execution times?

A: You can measure time internally by using the tim_get_tic_count instruction. It returnss the value of a clock in millisecond.

You could measure externally by probing the line /CS on the K-Bus and add the following piece of code around your rountine (called here myroutine)to generate a pulse:

#define addrKBus ((volatile uint8)0x600000)

INTERRUPTION_OFF
for(;;)
{
register uint8 aByte;
addrKBus = aByte; /* Write Cycle on Kbus*/
addrKBus = (uint 8)0; /* Write Cycle on Kbus*/
myroutine(…);
aByte = *addrKBus; /* Read Cycle on Kbus*/
}