MansOS LEDs

From DiLab
Jump to: navigation, search

Key include files:

mos/hil/leds.h
mos/platforms/<name>/ledslist.h

MansOS provides API for Light-Emitting Diode (LED) setting and status checking (whether a LED is ON or OFF). LEDs are connected directly to GPIO pins, and each platform must define pin numbers for available LEDs on the hardware platform.

LEDs can be addressed in two different forms: by color or by led number. LEDs are always accessible by number, starting from 0 up to LED_COUNT - 1, where LED_COUNT is a constant specifying LED count on the particular platform. LED addressing by color is optional, platform-dependent. On some platforms, such as TelosB, different colors are available, for example, red, green and blue LED. On some platforms all the LEDs can be of the same color.

Up to 8 LEDs are supported.

Usage and configuration

LED support is turned ON by default. It can be disabled by adding the following line to the application config file:

USE_LEDS = n

Dependencies

There are no dependencies for using LEDs.

Function reference

All platform-independent LED functions are described in mos/hil/leds.h . Implementation can be found under mos/hal/platforms/<platform-name>/

The following functions are available for any individual led. The "redLed" prefix is used as an example, and can be substituted by any other LED name or alias valid for the chosen platform, such as greenLed or led3.

redLedInit();        // Initialize the LED
redLedGet();         // Get the state of the LED
redLedSet( val );    // Set the state of the LED to "val"
redLedOn();          // Turn the LED on
redLedOff();         // Turn the LED off
redLedToggle();      // Toggle the LED
redLedMask();        // Get the mask value for the LED


The following functions are for a group of leds, addressed by using a mask, a bitfield.

// Init All leds (kernel uses this)
void ledsInit(void);               

// Set LEDs from a bitmask
void ledsSet(uint_t led_bitmask);

// Which LEDs are on? Returns a bitmask
uint_t ledsGet(void);

// Turn LEDs on using a bitmask
#define ledsOn(led_bitmask) ...

// Turn LEDs off using a bitmask
#define ledsOff(led_bitmask) ...

// Toggle LEDs using a bitmask
#define ledsToggle(led_bitmask) ...

// LEDs Constants
leds_count_t   LEDS_COUNT;     // Number of available LEDs
leds_all_t     LEDS_ALL_MASK;   // Mask for all LEDs

Examples

Blink

Blink the platform's default LED once every second.

// Example from apps/demo/Blink

while (1) {
    // change the red (default) LED status
    ledToggle();
 
    // wait for 1000 milliseconds
     mdelay(1000);
}

Counter representation on LEDs

Represent an incrementing counter on the LEDs. If less than 8 LEDs are supported by the platform, the youngest bits are shown.

// Example from apps/demo/CounterToLeds

uint8_t counter;
counter = 1;
while (1) {
    ledsSet(counter++);
    msleep(1000); // sleep one second
}