NesC (network embedded systems C)
This page was last modified on 21 May 2016, at 23:29.
Paradigm | imperative |
---|---|
Stable release | 1.1.3 / 14 December 2004 |
License | New BSD |
Website | NesC |
Influenced by | |
C |
NesC ( network embedded systems C - C network for embedded systems language) - component event-oriented programming language used to create applications for TinyOS platform. NesC - an extension of the C language that adds additional features to the TinyOS - environment built for embedded devices that are used in wireless sensor networks.
Modules
Modules implement a component specification with C code:
module-implementation:
implementation { translation-unit }
where translation-unit
is a list of C declarations and definitions.
The top-level declarations of the module’s translation-unit
belong to the module’s component-implementation scope. These declarations have indefinite extent and can be: any standard C declaration or definition, a task declaration or definition, a commands or event implementation.
Configurations
Configurations implement a component specification by connecting, or wiring, together a collection of other components:
configuration-implementation:
implementation { component-listopt connection-list }
The component-list
lists the components that are used to build this configuration, the connection-list
specifies how these components are wired to each other and to the configuration’s specification.
In the rest of this section, we call specification elements from the configuration’s specification external
, and specification elements from one of the configuration’s components internal
.
Example application
The following shows the structure (components and connections) Blink simple application that blinks a LED once per second:
The sourcecode for Blink is in two parts, the wiring in Blink and the actual application logic (C code) in BlinkM. Blink:
/*
* Copyright (c) 2000-2002 The Regents of the University of California.
* and Copyright (c) 2002 Intel Corporation
* All rights reserved.
*/
configuration Blink {
}
implementation {
components Main, BlinkM, ClockC, LedsC;
Main.StdControl -> BlinkM.StdControl;
BlinkM.Clock -> ClockC;
BlinkM.Leds -> LedsC;
}
BlinkM:
/*
* Copyright (c) 2000-2002 The Regents of the University of California.
* and Copyright (c) 2002 Intel Corporation
* All rights reserved.
*
* Implementation for Blink application. Toggle the red LED when the
* clock fires.
*/
module BlinkM {
provides interface StdControl;
uses interface Clock;
uses interface Leds;
}
implementation {
bool state; /* the state of the red LED (on or off) */
/* Initialize the component.
* @return Always returns SUCCESS */
command result_t StdControl.init() {
state = FALSE;
call Leds.init();
return SUCCESS;
}
/* Start things up. This just sets the rate for the clock component.
* @return Always returns SUCCESS */
command result_t StdControl.start() {
return call Clock.setRate(TOS_I1PS, TOS_S1PS);
}
/* Halt execution of the application.
* This just disables the clock component.
* @return Always returns SUCCESS */
command result_t StdControl.stop() {
return call Clock.setRate(TOS_I0PS, TOS_S0PS);
}
/* Toggle the red LED in response to the Clock.fire event.
* @return Always returns SUCCESS */
event result_t Clock.fire() {
state = !state;
if (state) {
call Leds.redOn();
} else {
call Leds.redOff();
}
return SUCCESS;
}
}
Присоединяйся к команде
ISSN:
Следуй за Полисом
Оставайся в курсе последних событий
License
Except as otherwise noted, the content of this page is licensed under the Creative Commons Creative Commons «Attribution-NonCommercial-NoDerivatives» 4.0 License, and code samples are licensed under the Apache 2.0 License. See Terms of Use for details.