Embedded Freaks..

September 23, 2008

Using NesC without TinyOS

Filed under: WSN — Tags: , , — kunilkuda @ 5:45 pm

Being avid NesC user for a year makes me understand how powerful this language can be.

It’s not C++ (or some kind of new OO/Object Oriented language), but it has just enough OO features to support embedded system. C++ / J2ME is complety useless for 8-bits MCU with memory less than 1MByte. It’s not C, or another kind of portable assembly language, but it’s quite portable if you know how to design your interface. You can even replace the peripheral / IC drivers within 1 line of code.

My plan is to use NesC components without TinyOS. It will reduce a lot of code size. Hence, the whole program can be stored inside 2kBytes AVR, since the radio (CC2420) is replaced by transparent modem (Maxstream).

And here’s the thing that I found:

Minimum Program

#include <avr/io.h>

module MainC
  int main() __attribute__ ((C, spontaneous))
    DDRA  |=  (1 << PA0);
    PORTA &= ~(1 << PA0);

The code is simple code to pull low PA0 (yellow LED on Micaz-alike boards).

Compiling with Nesc

How do you compile this module ? Well, here’s how:

# nescc -gcc=avr-gcc -mmcu=atmega128 -Os MainC.nc -o main.elf

Let me explain it a bit. Nesc actually is not a real compiler. It will translate the NesC files (*.nc) into C, then call the C compiler to compile the C files.

The -gcc option tells NesC which C compiler that’s suppose to be used. The other options (-mmcu=atmega128 ,-Os, -o main.elf) will be passed to the compiler. The only thing that NesC needs is the component’s name: MainC.nc.

If you want to see its C file, you can use this:

# nescc -gcc=avr-gcc -mmcu=atmega128 -conly MainC.nc

Hex File, Listing, etc
Once you get the ELF file, the rest will be easy. You can take a look on AVR libc tutorial here to get the hex files, checking the size, generate listing, etc.

Next Step..

Generate you own Makefile, unless you are willing to type all day long.


  1. […] 2008. Filed under: WSN | Tags: nesc, WSN | are NesC is my term for NesC without TinyOS (refer to this post for my experiment with bare NesC). This post will continue the experiment, by interfacing the bare […]

    Pingback by Bare NesC: Wiring The Components « Embedded Freaks.. — September 24, 2008 @ 2:06 pm

  2. Thank you for this info! I have been thinking about using nesc on my atmega’s (stk500) without tinyos for a while now. This should get me started.

    Comment by R E — June 21, 2009 @ 4:44 am

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: