-
Notifications
You must be signed in to change notification settings - Fork 4
Apps::Blink
Let us write a simple application in MansOS that blinks an LED once a second. We call the application Blink, and it is also available at the MansOS/apps/demo/Blink There will be three files that need to be created:
- Makefile - that sets the rules for building the application
- config - to enable or disable support for certain features in the code, such as radio or LEDs.
- main.c - the main source code
Each of these files is described in detail below.
Makefile configures the rules for building the whole project. It can be quite simple here and refer to the main Makefile of the MansOS system like this:
# Sources are all project source files, excluding MansOS files
SOURCES = main.c
# Module is the name of the main module built by this Makefile
APPMOD = Blink
# --------------------------------------------------------------------
# Set the key variables
PROJDIR = $(CURDIR)
ifndef MOSROOT
MOSROOT = $(PROJDIR)/../../..
endif
# Include the main makefile
include ${MOSROOT}/mos/make/MakefileThe config file is a text file, where every supported feature can be turned on or off by adding 'y' or 'n' to the feature name. For the Blink application it is sufficient to enable the LEDs feature, like this:
USE_LEDS=y
The main.c source code file has the appMain() function that is the starting (entry) point of the application. First we include the standard MansOS header file stdmansos.h.
Then we write the appMain() function, that can have initialization code, not used here, and the main infinite loop realized as while(1). The loop contains two things: it toggles the statuss of the default LED of the hardware platform from on to off or from off to on, and delays the execution for 1 second, or 1000 milliseconds in other words.
#include "stdmansos.h"
void appMain(void)
{
while (1) {
// change the default LED status
ledToggle();
// wait for 1000 milliseconds
mdelay(1000);
}
}Simple, experimental applications often are not using the watchdog timer. In fact, it needs to be disabled, or it will restart the system after a while, or it needs to be reset periodically. By default MansOS kernel disables the watchdog timer using a watchdogStop() call, so it is taken care of.
Once you work on the serious and robust applications, you may want to use the watchdog timer to prevent unintended hangups of the system. Then you can use the watchdog timer functions as declared in MansOS/mos/include/watchdog.h