nc2moml

TinyOS is an event-driven operating system designed for sensor network nodes that have very limited resources (e.g., 8K bytes of program memory, 512 bytes of RAM). TinyOS, is used, for example, on the Berkeley MICA motes, which are small wireless sensor nodes. nesC is an extension to the C programming language designed to embody the structuring concepts and execution model of TinyOS.

nc2moml is used to convert nesC files (.nc) into MoML (.moml) files. This will create the Ptolemy II libraries of components that are used to assemble models. TinyOS provides a rich library of nesC components. If you install TinyOS 1.x in $PTII/vendors/ptinyos/tinyos-1.x , then the Ptolemy II configure script will find it and automatically make the TinyOS libraries available.

Installation instructions

Note: As of 10/05, Windows users will not be able to run TinyOS models inside Ptolemy. The reason is that reloading the TinyOS shared objects into the running Ptolemy interface fails because the TinyOS shared objects use pthreads and under Windows, Java is using Windows native threads. We are working on a solution. In the interim, Windows users can convert .nc files to .moml files and create models, but running the model fails.

However, Windows and users on other platforms can generate code for the pc or other targets. See the help instructions in $PTII/ptolemy/configs/viptos/help.htm.

These installation instructions assume that you already have Ptolemy II installed, and that if you are running on Windows, you already have Cygwin installed. These instructions also assume that you do not already have the nesC compiler nor TinyOS installed. If you wish to use pre-existing installations, please set up the environment variables described in the steps below to point to proper directories.

If you already have AVR tools, TinyOS and nesC installed, try:
cd $PTII
mkdir -p vendors/ptinyos
cd $PTII/vendors/ptinyos
ln -s location_of_your_tiny-1.x_tree tinyos-1.x
ln -s location_of_your_nesc_tree nesc
	
Be sure to update to the latest nesC cvs version, then proceed to Set up the necessary environment variables below. You may skip installing TinyOS and nesc and proceed to unzipping the opts files and running nc2moml.

How to install nc2moml by downloading/building nesC from CVS

The nesC compiler can be downloaded and compiled from source, which requires an impressive suite of tools. These instructions ask you to first verify that you have the necessary programs installed, then to install the AVR tools, followed by TinyOS, then nesC.

  1. Under Linux or Cygwin, you must have the following programs installed on your system:
    • autoconf 2.50 or later
    • bison
    • emacs
    • emacs-el
    • gperf
    • perl
    • rpm

    For help with how to install these in Cygwin, see the Ptolemy II Cygwin Instructions. Note that most installations will not have gperf on them, at least, so you will likely need to install at least that.

  2. You must install the following AVR tools:
    • avarice
    • avr-binutils
    • avr-gcc
    • avr-insight
    • avr-libc

    Note: If the files below do not work for you, you can try using the latest files (although these have not been tested with Viptos yet): http://www.tinyos.net/dist-1.2.0/tools.

    Choose and follow the appropriate directions for your operating system:

    (The directions above were modified from the original TinyOS installation directions).
  3. Make a directory into which to store the source code, for example:
        mkdir -p $PTII/vendors/ptinyos
            
    Note that $PTII should not have spaces in it.
  4. We have put into the TinyOS makefiles a rule that you can run to create all the TinyOS libraries in one step. To use this, as of this writing, you need to get TinyOS from the CVS repository rather than getting the packaged install version. To do this, type:

    cd $PTII/vendors/ptinyos
    cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/tinyos login
    Hit Enter when prompted for a password
    cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/tinyos co tinyos-1.x
            

    Note to tinyos developers: why is this download so large? Perhaps there should be a core cvs module and then a contrib module? This will create a directory tinyos-1.x. For more information, see http://sourceforge.net/cvs/?group_id=28656.

  5. Set up the necessary environment variables. TOSROOT sets the location of the TinyOS source tree. TOSDIR sets the subdirectory in the TinyOS source tree. PTINYOS_MOMLROOT sets the MoML output directory.
    • Under bash, type:
      export TOSROOT=$PTII/vendors/ptinyos/tinyos-1.x
      export TOSDIR=$TOSROOT/tos
      export PTINYOS_MOMLROOT=$PTII/vendors/ptinyos/moml
                  
    • Under csh or tcsh:
      setenv TOSROOT $PTII/vendors/ptinyos/tinyos-1.x
      setenv TOSDIR $TOSROOT/tos
      setenv PTINYOS_MOMLROOT $PTII/vendors/ptinyos/moml
                  
    • Under Windows with Cygwin, you can permanently set environment variables from the System control panel. (For details, see Set the value of the PTII environment variable).

      Go to Start Menu -> Settings -> Control Panels -> System -> Advanced -> Environment Variables.
      Set TOSROOT to %PTII%/vendors/ptinyos/tinyos-1.x
      Set TOSDIR to %PTII%/vendors/ptinyos/tinyos-1.x/tos
      Set PTINYOS_MOMLROOT to %PTII%/vendors/ptinyos/moml

  6. Get the nesC CVS Tree, see http://sourceforge.net/cvs/?group_id=56288
    cd $PTII/vendors/ptinyos
    cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/nescc login
    Hit Enter when prompted for a password
    cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/nescc co nesc
            
  7. Boostrap nesC
    cd $PTII/vendors/ptinyos/nesc
    ./Bootstrap
            
  8. Run configure for nesc
    ./configure
            
    By default, this configuration will cause nesC to be installed in /usr/local. We assume that /usr/local/bin is in your path. If you wish to install in a different directory, run ./configure --prefix=<MYDIR> instead and add the bin directory to your path.

    FIXME: Necessary? If you are using Cygwin, and configure has trouble finding TOSROOT or TOSDIR, try expanding your $PTII environment variable to /cygdrive/c/ptII or something similar. Also try expanding the TOSROOT and TOSDIR environment variables if you still have problems.

  9. Install nesc
    make
    make install
            

    FIXME: necessary? If you are using Cygwin and make cannot find avr-gcc, then avr-gcc is probably not in your path. Locate avr-gcc and add the directory to your path. If you cannot find avr-gcc, then the AVR rpm's were not installed correctly, and you will need to try to reinstall them.

  10. Configure and install the TinyOS nesC tools
    cd $TOSROOT/tools/src/ncc
    ./Bootstrap
    ./configure
            
    By default, this configuration will cause the tools to be installed in /usr/local. We assume that /usr/local/bin is in your path. If you wish to install in a different directory, run ./configure --prefix=<MYDIR> instead and add the bin directory to your path.
    make
    make install
    
    	
    make failed for me:
    Making all in libcompat
    make[3]: Entering directory `/cygdrive/c/cxh/ptII/vendors/ptinyos/nesc/src/libcompat'
    if gcc -DHAVE_CONFIG_H -I. -I. -I.. -DNMEMDEBUG -DNDEBUG -O9    -g -Wall -MT regions.o -MD -MP -MF ".deps/regions.Tpo" -c -o regions.o regions.c; \
    then mv -f ".deps/regions.Tpo" ".deps/regions.Po"; else rm -f ".deps/regions.Tpo"; exit 1; fi
    In file included from /usr/local/include/sys/types.h:331,
                     from /usr/local/include/sys/unistd.h:9,
                     from /usr/local/include/unistd.h:4,
                     from stats.c:3,
                     from regions.c:40:
    /usr/include/cygwin/types.h:152: error: conflicting types for 'key_t'
    /usr/local/include/sys/types.h:137: error: previous declaration of 'key_t' was here
    /usr/include/cygwin/types.h:179: error: parse error before "u_int16_t"
    /usr/include/cygwin/types.h:187: error: parse error before "u_int64_t"
    /usr/include/cygwin/types.h:202: error: conflicting types for 'mode_t'
    /usr/local/include/sys/types.h:142: error: previous declaration of 'mode_t' was here
    In file included from /usr/local/include/fcntl.h:1,
                     from stats.c:4,
                     from regions.c:40:
    /usr/local/include/sys/fcntl.h:139: error: redefinition of `struct flock'
    make[3]: *** [regions.o] Error 1
    
    The solution was to uninstall one of the rpms.
    cd Location of avr rpms
    rpm -e arm-thumb-elf-gcc-3.2-1
    cd $PTII/vendors/ptinyos/nesc
    make
    make install
    cd Location of avr rpms
    rpm -force --ignoreos --nodeps -ivh *.rpm
    

    Note that you need to have pdflatex and bibtex installed, or else edit nesc/Makefile and comment remove doc from the SUBDIRS line.

  11. Compile tinyos
    cd $PTII/vendors/ptinyos/tinyos-1.x
    make
    make install
          

    tinyos-1.x/tools/src/uisp/src/Serial.C failed to compile

    Serial.C: In member function `void TSerial::OpenPort()':
    Serial.C:243: warning: right-hand operand of comma has no effect
    Serial.C:244: warning: right-hand operand of comma has no effect
    make[4]: *** [Serial.o] Error 1
          
    The solution is to edit tinyos-1.x/tools/src/uisp/src/Makefile and remove the -Werror and rerun make from the top.
  12. Run the script that will unzip the file that contains additional compiler flags. It will place "opts" files into various directories in your tinyos-1.x tree. The script assumes that you have placed your tinyos-1.x tree as indicated in the instructions above.
    cd $PTII/ptolemy/domains/ptinyos/util
    ./unzip-opts.sh
            

    If the executable permissions are not set correctly, run:

    chmod a+x unzip-opts.sh
            
    then try the step above again.
  13. Run the script to generate the .moml files from the .nc files.
    cd $PTII/ptolemy/domains/ptinyos/util/nc2moml
    ./nc2moml
            
    If the executable permissions are not set correctly, run:
    chmod a+x nc2moml*
            
    then try the step above again. The nc2moml command will take 10-30 minutes to complete.

    Note: The nc2moml tool requires that you build the tools in $PTII/bin. Do the following and rerun the script above if they are missing:

    cd $PTII/bin
    make
            
  14. See if it worked:
    1. You should see some valid MoML code in:
      $PTII/vendors/ptinyos/moml

      The directory structure should reflect that of the TinyOS directory structure.
      1. Try running Viptos:
        $PTII/bin/vergil -viptos
      2. Create a new PtinyOS Graph Editor from the File | New menu.
      3. Click in the left hand pane under Actors to see the newly generated directory structure.