Difference between revisions of "The simplest TinyOS program"
Line 1: | Line 1: | ||
There is some value in knowing the the simplest code that can be compiled without errors. The C equivalent is | There is some value in knowing the the simplest code that can be compiled without errors. The C equivalent is | ||
− | int main () { | + | int main () { |
return 0; | return 0; | ||
− | } | + | } |
Line 9: | Line 9: | ||
<code bash> | <code bash> | ||
− | $ gcc test.c | + | $ gcc test.c |
</code> | </code> | ||
Line 19: | Line 19: | ||
<code bash> | <code bash> | ||
− | $ mkdir Simple | + | $ mkdir Simple |
− | $ cd Simple | + | $ cd Simple |
</code> | </code> | ||
1. You need to create a ''Configuration'' file SimpleAppC.nc (following the suggested naming convention). | 1. You need to create a ''Configuration'' file SimpleAppC.nc (following the suggested naming convention). | ||
<code> | <code> | ||
− | configuration SimpleAppC{ | + | configuration SimpleAppC{ |
− | } | + | } |
− | implementation{ | + | implementation{ |
− | + | components SimpleC, MainC; | |
SimpleC.Boot -> MainC.Boot; | SimpleC.Boot -> MainC.Boot; | ||
− | } | + | } |
</code> | </code> | ||
There are two components in this program: your component called SimpleC and the ''Main'' component <tt>MainC</tt>. The MainC component provides the Boot.booted signal which essentially is the entry point of the application. | There are two components in this program: your component called SimpleC and the ''Main'' component <tt>MainC</tt>. The MainC component provides the Boot.booted signal which essentially is the entry point of the application. | ||
Line 38: | Line 38: | ||
<code> | <code> | ||
− | module SimpleC{ | + | module SimpleC{ |
uses interface Boot; | uses interface Boot; | ||
− | } | + | } |
− | implementation{ | + | implementation{ |
event void Boot.booted() | event void Boot.booted() | ||
{ | { | ||
} | } | ||
− | } | + | } |
</code> | </code> | ||
Line 52: | Line 52: | ||
<code> | <code> | ||
− | COMPONENT=SimpleAppC | + | COMPONENT=SimpleAppC |
− | include $(MAKERULES) | + | include $(MAKERULES) |
</code> | </code> | ||
Line 62: | Line 62: | ||
<code bash> | <code bash> | ||
− | $ make micaz | + | $ make micaz |
</code> | </code> | ||
which should work successfully provided you have set up the environment properly. | which should work successfully provided you have set up the environment properly. |
Revision as of 22:18, 9 September 2008
There is some value in knowing the the simplest code that can be compiled without errors. The C equivalent is
int main () { return 0; }
which is written in a file, say, simple.c and compiled with the command
$ gcc test.c
which produces the executable file a.out, which of course does nothing!
In TinyOS, to get the same thing, you need to create three files. Suppose the program we create is called Simple.
0. Create a new directory to put the files. We can name this directory Simple:
$ mkdir Simple
$ cd Simple
1. You need to create a Configuration file SimpleAppC.nc (following the suggested naming convention).
configuration SimpleAppC{
}
implementation{
components SimpleC, MainC;
SimpleC.Boot -> MainC.Boot;
}
There are two components in this program: your component called SimpleC and the Main component MainC. The MainC component provides the Boot.booted signal which essentially is the entry point of the application.
2. You need to create the Component file SimpleC.nc. This has definition (implementation) of the component SimpleC.
module SimpleC{
uses interface Boot;
}
implementation{
event void Boot.booted()
{
}
}
3. Now you need to create a Makefile so that the compiler can compile it. Create the file called Makefile with the following two lines:
COMPONENT=SimpleAppC
include $(MAKERULES)
I.e., you put the name of the top level configuration in the COMPONENT field.
Now you are ready to compile:
$ make micaz
which should work successfully provided you have set up the environment properly.