On Jan 31, 2008 6:17 AM, AIGroup [EMAIL PROTECTED] wrote:
OK! now it works, but only in simulation!!!
I tried to edit my makefile but without success!
add
BUILD_EXTRA_DEPS = Hello.o
to the Makefile (it's a magic variable listing things that should be
built before the main executable)
David Gay
How can I solve this problem?
Thank you!
2008/1/31, AIGroup [EMAIL PROTECTED]:
Hi David,
before all thank you for your help.
I tried to edit my files as you wrote, but I yet have problems.
I edited my nesc file as follows:
-
#include Timer.h
#include Hello.h //-- I included the header file here
module BlinkC
{
uses interface TimerTMilli as Timer0;
uses interface TimerTMilli as Timer1;
uses interface TimerTMilli as Timer2;
uses interface Leds;
uses interface Boot;
}
implementation
{
event void Boot.booted()
{
call Timer0.startPeriodic( 250 );
call Timer1.startPeriodic( 500 );
call Timer2.startPeriodic( 1000 );
}
event void Timer0.fired()
{
Hello(); //-This is the function call to Hello()
//dbg(BlinkC, Timer 0 fired @ %s.\n, sim_time_string());
//call Leds.led0Toggle();
}
The C files are these:
---
//Hello.h
#ifndef HELLO_H
#define HELLO_H
void Hello();
#endif
-
#include Hello.h
void Hello()
{
printf(\nHELLO!\n);
}
-
and my Makefile is the following:
COMPONENT=BlinkAppC
LDFLAGS = Hello.o
Hello.c: Hello.h
$(CC) -o Hello.o Hello.c
include $(MAKERULES)
---
where $(CC)... is tabbed
So, when I run make micaz sim this error occurs:
-
[EMAIL PROTECTED]:/opt/tinyos-2.x/apps/ImportC$ make micaz sim
mkdir -p build/micaz
placing object files in build/micaz
writing XML schema to app.xml
compiling BlinkAppC to object file sim.o
ncc -c -shared -fPIC -o build/micaz/sim.o -g -O0 -tossim
-fnesc-nido-tosnodes=1000 -fnesc-simulate
-fnesc-nido-motenumber=sim_node\(\) -finline-limit=10 -Wall -Wshadow
-Wnesc-all -target=micaz -fnesc-cfile=build/micaz/app.c -board=micasb
-DIDENT_PROGRAM_NAME=\BlinkAppC\ -DIDENT_USER_ID=\penguin\
-DIDENT_HOSTNAME=\penguin-laptop\ -DIDENT_USER_HASH=0xdef7cfbeL
-DIDENT_UNIX_TIME=0x47a18a21L -DIDENT_UID_HASH=0x77ab7dfaL
-Wno-nesc-data-race BlinkAppC.nc Hello.o -fnesc-dump=components
-fnesc-dump=variables -fnesc-dump=constants -fnesc-dump=typedefs
-fnesc-dump=interfacedefs -fnesc-dump=tags -fnesc-dumpfile=app.xml
gcc: Hello.o: No such file or directory
make: *** [sim-exe] Error 1
-
How can I solve the problem???
Thank you very much in advance for your precious help
Regards,
Roberto
2008/1/30, David Gay [EMAIL PROTECTED]:
#include works fine, but, as in C, it's just textual inclusion (it
really is nothing complicated ;-)). So it's all as if you just wrote:
module ...
implementation
{
#ifndef C_CODE
#define C_CODE
void Hello();
#endif
event void Boot.booted()
{
call Timer0.startPeriodic( 250 );
}
event void Timer0.fired()
{
Hello(); //Hello() is a function which is inside my C code
}
}
which therefore just declares Hello() as an internal function inside
BlinkC.
In nesC, C functions must be declared before the module/implementation
(or interface) part of a file. So what you wanted to do was:
/* nesC code*/
#include c_code.h
module ...
implementation
{
event void Boot.booted()
{
call Timer0.startPeriodic( 250 );
}
event void Timer0.fired()
{
Hello(); //Hello() is a function which is inside my C code
}
}
On Jan 30, 2008 6:37 AM, AIGroup [EMAIL PROTECTED] wrote:
I believed...
include directive works well. I have problem to edit the Makefile in
order
to compile also the C file.
Yes, you then also of course need to compile and link with your C
code. Several ways to do that... The easiest in this case at least is
probably to add
LDFLAGS = c_code.c
to your Makefile, which should cause ncc to compile and link c_code.c
with your nesC app. A slightly more traditional Makefile approach
would have you add
LDFLAGS = c_code.o
c_code.c: c_code.h
$(CC) -o c_code.o your favourite flags c_code.c
to your Makefile... (don't cut paste the text above, the character
before $(CC) needs to be a tab to keep make happy, in this email it's
some spaces...)
David Gay
2008/1/30, AIGroup [EMAIL PROTECTED]:
Hi all.
I would like to include some routines in my nesC code as follows
(considering the BlinkApp for example):
/* nesC code*/
implementation
{
#include c_code.h
event void Boot.booted()
{
call Timer0.startPeriodic( 250 );
}