On 9/21/07, Philip Levis <[EMAIL PROTECTED]> wrote:
> On Sep 21, 2007, at 2:06 AM, Chan kenniel wrote:
>
> > Dear all,
> >
> > We are about to make a nesc program testing application. The
> > application will insert some functions into the source code so that
> > the running environment can be recorded. Something like:
> > source:
> > While (i)
> > {
> > ...
> > i++;
> > }
> > inserted:
> > while(i)
> > {
> > record(i) //inserted code
> > ...
> > i++
> > }
> > The problem comes that current record() is written by c. And when I
> > try to compile the inserted code, and error of implicit declaration
> > occurred. I am wondering if there is any way I can make my function
> > recognized by the compiler, just like those familiar functions such
> > as memcpy or printf, which can be recognized by nesc compiler?
> >
>
> Just like in C, make an include file. The trickier part is linking
> the function in.
Actually there's nothing particularly tricky needed. You link in
separately-compiled C code just the same as you would in a regular C
project, e.g., if your C function is in mylib.o and your nesC app is
myapp.nc, then you would do:
ncc -o myapp myapp.nc mylib.o [+ other options]
The only tricky problem is doing this with the "magic" TinyOS make
system. A quick look suggests you should be able to add
LDFLAGS=mylib.o
to your Makefile. Or use a handbuilt Makefile, rather than TinyOS's
make system...
So to summarise, an example:
mylib.h:
void mystrangefn(int somearg);
mylib.c:
void mystrangefn(int somearg)
{
... do something exciting ...
}
in the nesC component using this:
somecomponent.nc:
#include "mylib.h"
module somecomponent { ... }
implementation {
... in some code somewhere:
mystrangefn(23 * x);
...
}
and in your Makefile:
LDFLAGS=mylib.o
CFLAGS=-I<path to where mylib.h is found>
<rest as usual>
You'll also need to compile mylib.c to mylib.o (you should be able
tomake that happen in the Makefile too).
David Gay
PS: The complexity Phil was discussing is related to implementing a C
function within a nesC module.
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help