Difference between revisions of "NesC (network embedded systems C)"

From Bauman National Library
This page was last modified on 21 May 2016, at 23:29.
 
Line 118: Line 118:
 
# [http://nescc.sourceforge.net// nesc]
 
# [http://nescc.sourceforge.net// nesc]
 
# [http://nescc.sourceforge.net/papers/nesc-ref.pdf nesc ref]
 
# [http://nescc.sourceforge.net/papers/nesc-ref.pdf nesc ref]
# [http://ru.bmstu.wiki/NesC_(network_embedded_systems_C) bmstu.wiki]
 
  
 
[[ru:NesC (network embedded systems C)]]
 
[[ru:NesC (network embedded systems C)]]

Latest revision as of 23:29, 21 May 2016

NesC
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: Blink.gif

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;
  }
}

External links

  1. nesc
  2. nesc ref