Difference between revisions of "The simplest TinyOS program"
m |
|||
(11 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
− | There is some value in knowing | + | There is some value in knowing 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 | ||
+ | <code bash> | ||
+ | $ gcc test.c | ||
+ | </code> | ||
+ | which produces the executable file <tt>a.out</tt>, 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 <tt>Simple</tt>. | ||
+ | |||
+ | 0. Create a new directory to put the files. We can name this directory ''Simple'': | ||
+ | |||
+ | <code bash> | ||
+ | $ mkdir Simple | ||
+ | $ cd Simple | ||
+ | </code> | ||
+ | |||
+ | 1. You need to create a ''Configuration'' file SimpleAppC.nc (following the suggested naming convention). | ||
+ | <code> | ||
+ | configuration SimpleAppC{ | ||
+ | } | ||
+ | implementation{ | ||
+ | components SimpleC, MainC; | ||
+ | |||
+ | SimpleC.Boot -> MainC.Boot; | ||
+ | } | ||
+ | </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. | ||
+ | |||
+ | 2. You need to create the ''Component'' file SimpleC.nc. This has definition (implementation) of the component SimpleC. | ||
<code> | <code> | ||
+ | module SimpleC{ | ||
+ | uses interface Boot; | ||
+ | } | ||
+ | |||
+ | implementation{ | ||
+ | event void Boot.booted() | ||
+ | { | ||
+ | //The entry point of the program | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
− | + | 3. Now you need to create a ''Makefile'' so that the compiler can compile it. Create the file called <tt>Makefile</tt> with the following two lines: | |
− | + | ||
− | + | <code> | |
+ | COMPONENT=SimpleAppC | ||
+ | include $(MAKERULES) | ||
</code> | </code> | ||
− | + | I.e., you put the name of the top level configuration in the ''COMPONENT'' field. | |
+ | |||
+ | |||
+ | Now you are ready to compile: | ||
+ | |||
<code bash> | <code bash> | ||
− | + | $ make micaz | |
</code> | </code> | ||
− | which | + | which should work successfully provided you have set up the environment properly. |
+ | |||
+ | Now you can start extending this skeleton code by adding more components. The first thing is to try adding the Leds component to glow a specific pattern of leds. After that you can add the Timer component and start to Blink them, as shown in the Blink example in the tutorial. | ||
+ | |||
+ | [[Category:TinyOS]] |
Latest revision as of 21:42, 9 November 2009
There is some value in knowing 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()
{
//The entry point of the program
}
}
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.
Now you can start extending this skeleton code by adding more components. The first thing is to try adding the Leds component to glow a specific pattern of leds. After that you can add the Timer component and start to Blink them, as shown in the Blink example in the tutorial.