Book contents
- Frontmatter
- Contents
- List of Code examples
- Preface
- Acknowledgements
- Programming hints, condensed
- Part I TinyOS and nesC
- Part II Basic programming
- 3 Components and interfaces
- 4 Configurations and wiring
- 5 Execution model
- 6 Applications
- 7 Mote-PC communication
- Part III Advanced programming
- Part IV Appendix and references
- References
- Index
3 - Components and interfaces
Published online by Cambridge University Press: 05 August 2012
- Frontmatter
- Contents
- List of Code examples
- Preface
- Acknowledgements
- Programming hints, condensed
- Part I TinyOS and nesC
- Part II Basic programming
- 3 Components and interfaces
- 4 Configurations and wiring
- 5 Execution model
- 6 Applications
- 7 Mote-PC communication
- Part III Advanced programming
- Part IV Appendix and references
- References
- Index
Summary
This chapter describes components, the building blocks of nesC programs. Every component has a signature, which describes the functions it needs to call as well as the functions that others can call on it. A component declares its signature with interfaces, which are sets of functions for a complete service or abstraction. Modules are components that implement and call functions in C-like code. Configurations connect components into larger abstractions. This chapter focuses on modules, and covers configurations only well enough to modify and extend existing applications: Chapter 4 covers writing new configurations from scratch.
Component signatures
A nesC program is a collection of components. Every component is in its own source file, and there is a one-to-one mapping between component and source file names. For example, the file LedsC.nc contains the nesC code for the component LedsC, while the component PowerupC can be found in the file PowerupC.nc. Components in nesC reside in a global namespace: there is only one PowerupC definition, and so the nesC compiler loads only one file named PowerupC.nc.
There are two kinds of components: modules and configurations. Modules and configurations can be used interchangeably when combining components into larger services or abstractions. The two types of components differ in their implementation sections. Module implementation sections consist of nesC code that looks like C. Module code declares variables and functions, calls functions, and compiles to assembly code. Configuration implementation sections consist of nesC wiring code, which connects components together. Configurations are the major difference between nesC and C (and other C derivatives).
- Type
- Chapter
- Information
- TinyOS Programming , pp. 21 - 48Publisher: Cambridge University PressPrint publication year: 2009
- 3
- Cited by