MOS Applications live in the src/apps/ directory inside your mantis source folder (mantis-1.0-beta or mantis-unstable). The very first step is to create a folder to hold your new application. We'll call our new application 'myblink'.
cd ~/mantis-unstable/src/apps/; mkdir myblink
At this point, we're ready to start coding. Create a file called 'myblink.c' in your myblink directory, and open it with your favorite editor.
touch myblink.c ; emacs myblink.c
myblink.c:
#include "msched.h" // include the mantis scheduler
#include "led.h" // include functions to access the LEDs.
void blink_thread(void)
{
while(1)
{
mos_led_toggle(0); // toggle the value of the 1st LED
mos_thread_sleep(1000); // sleep for one second
}
}
// this is the entry point of our application.
void start(void)
{
// create a new blink_thread with 128 bytes of stack space and normal priority.
mos_thread_new(blink_thread, 128, PRIORITY_NORMAL);
}
#include "mos.h" // always include the mos header
#include "msched.h" // include the mantis scheduler
#include "led.h" // include functions to access the LEDs.
void blink_thread(void)
{
while(1)
{
mos_led_toggle(0); // toggle the value of the 1st LED
mos_thread_sleep(1000); // sleep for one second
}
}
// this is the entry point of our application.
void start(void)
{
// create a new blink_thread with 128 bytes of stack space and normal priority.
mos_thread_new(blink_thread, 128, PRIORITY_NORMAL);
}
The next step is to create an optsconfig.h file which specifies which parts of MOS you can leave out (if you want to save code space).
optsconfig.h:
// build configuration options
// uncomment/comment to enable/disable support for a device,
// radio, or interface
#include "build_opts.h"
/* By default all devices and interfaces are defined in
src/lib/include/build_opts.h. You can check this file for
the list of possible build options.
To disable a build option, use #undef
Example:
#undef MICA2_ACCEL
#undef CC2420
#undef MAXSTREAM
will disable the accelerometer, the cc2420 radio, and the maxstream
radio drivers.
An exception is changing CC1000 from CSMA to another protocol, where
another must be defined. Ex:
#undef CC1000_CSMA
#define CC1000_TDMA
*/
#undef CC1000
#undef CC1000_CSMA
#undef CC2420
In this example, we only disable support for the CC1000 and CC2420 radios.
Once you've entered the code above, it's time to move on to compiling and installing the application.







