Wednesday, August 10, 2016

Generate an improved interfering node in Contiki OS

Objective

The objective of this post is to make an improved version of the interfering node that i made in a previous tutorial:

http://contiki-iot.blogspot.com.co/2016/08/objective-to-create-interfering-node.html

The previous tutorial just generates an unmodulated carrier as noise, i would like to mention that i got the idea and part of the code from the paper [2]. Now, in this tutorial i improved this version of interfering node adding a model of interference called Bursty Interference described in the section 3.3 of paper [1]. The model just turns the unmodulated carrier on and off with different time periods (t1 and t2). For example, it turns the carrier on for 240ms (t1 = 240ms) and then it turns the carrier off for 510ms (t2 = 510ms); the times t1 and t2 follow a uniform distribution between 0 seconds and 1,5 seconds. I strongly recommend you to read the paper [1].

Code for the sky mote

Below i show you the code that implements the improved interfering node. I order to understand the code you must read section 3.3 of the paper [1], i try to add comments to the code and use the same variables that the paper did.

/*
 * Copyright (c) 2007, Swedish Institute of Computer Science.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the Institute nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * This file is part of the Contiki operating system.
 *
 */

/**
 * \file
 *       Improved example of an interfering node
 * \author
 *        Sergio Diaz
 */


/*INCLUDES*/
#include "contiki.h"
#include "/home/sink/Desktop/contiki-3.0/dev/cc2420/cc2420_const.h" // Include the CC2420 constants 
#include "/home/sink/Desktop/contiki-3.0/core/dev/spi.h" // Include basic SPI macros
#include "dev/leds.h" // Include Leds to debbug
#include "sys/rtimer.h" //Include the real time library

/*DEFINES*/
#define INTERFERENCE  0x01 // I set the less significant bit to indicate there is interference (0x01 = 00000000 00000001)
#define CONSTANT_MICROS 300 // 300 us was defined by the paper [1]
#define TIME_TICK 31 // The time of 1 tick is 30,51 us in rtimer for sky motes in Contiki v3.0. TIME_TICK = 1 / RTIMER_ARCH_SECOND = 1 / 32768 s


/*STRUCT DEFINITIONS*/
struct states{
 unsigned char carrier; // Defines the state of the carrier: Either INTERFERENCE = 0x01 or Not INTERFERENCE = ~0x01
};

struct states state; //Create the state of the carrier
static struct rtimer rtimer; // Create the rtimer variable

/*FUNCTION DEFINITIONS*/

/*---------------------------------------------------------------------------*/
/*
* Generate a random number between 0 and (MaxValue - 1)
*/
unsigned int random_number(unsigned int MaxValue){
       return  rand() % MaxValue;
}
/*---------------------------------------------------------------------------*/
/** 
 * Writes to a register.
 * Note: the SPI_WRITE(0) seems to be needed for getting the
 * write reg working on the Z1 / MSP430X platform
 */
static void
setreg(enum cc2420_register regname, uint16_t value)
{
  CC2420_SPI_ENABLE();
  SPI_WRITE_FAST(regname);
  SPI_WRITE_FAST((uint8_t) (value >> 8));
  SPI_WRITE_FAST((uint8_t) (value & 0xff));
  SPI_WAITFORTx_ENDED();
  SPI_WRITE(0);
  CC2420_SPI_DISABLE();
}

/* Sends a strobe */
static void
strobe(enum cc2420_register regname)
{
  CC2420_SPI_ENABLE();
  SPI_WRITE(regname);
  CC2420_SPI_DISABLE();
}

/*
* Function called by the rtimer to turn the carrier on and off.
*/
static void carrier_OnOff(struct rtimer* timer, void* ptr)
{

    unsigned int R; // Uniformly distributed over [1,100]
    unsigned int Qx;  // Uniformly distributed over [1,x], where x = 50
    unsigned int randNum; // Random number between [1-10]
    uint32_t time_next_period; // Next time period. The duration of the interference or not interference state.
    uint32_t num_ticks; // Number of ticks of the time_next_period

    // Calculate a random number between [1-10]
    randNum = 1 + abs( random_number(10) ) ;
    
    // Decide whether to produce interference or not with equal probability (0.5)
    if( randNum <= 5) // If the random number is less than 5 generate no interference 
    {
        // In this case there will be no interference
        state.carrier &= ~INTERFERENCE; // Set the carrier state to no interference (NOT INTERFERENCE)
    }else{
        // In this case there will be interference
        state.carrier |= INTERFERENCE; // Set the carrier state to interference
    }

    // Turn the unmodulated carrier on or off depending on the carrier state (state.carrier)
    if( state.carrier & INTERFERENCE) // should the node generate interference?
    {
       //The node must generate interference. Turn the carrier on.
       // Creates an unmodulated carrier by setting the appropiate registers in the CC2420
       setreg(CC2420_MANOR, 0x0100); 
       setreg(CC2420_TOPTST, 0x0004);
       setreg(CC2420_MDMCTRL1, 0x0508);
       setreg(CC2420_DACTST, 0x1800);
       strobe(CC2420_STXON);
       // Turn the leds for debug. LEDS_RED on means there is interference
       leds_on(LEDS_RED);
       leds_off(LEDS_GREEN);

    }else{
       //The node must not generate interference. Turn the carrier off.
       //Reset the changes and set back the CC2420 radio chip in normal mode.
       //Not generate unmodulated carrier
       setreg(CC2420_MANOR, 0x0000);
       setreg(CC2420_TOPTST, 0x0010);
       setreg(CC2420_MDMCTRL1, 0x0500);
       setreg(CC2420_DACTST, 0x0000);
       strobe(CC2420_STXON);
       // Turn the leds for debug. LEDS_GREEN on means there is no interference
       leds_on(LEDS_GREEN);
       leds_off(LEDS_RED);
    }
    // Calculate the time of the next period ( time_next_period = R*Q(x)*CONSTANT_MICROS ) 
       R  = 1 +  abs( random_number(100) )  ; // Generate random numbers between [1,100]
       Qx = 1 +  abs(random_number(50))   ; // Generate random numbers between [1,50]
       time_next_period = R * Qx ; // Compute the next time period according to the paper [1]
       time_next_period = time_next_period * CONSTANT_MICROS ;  // Compute the next time period according to the paper [1]


    // Set the rtimer to the time_next_period (num_ticks)
       num_ticks = time_next_period / TIME_TICK; // Compute the number of ticks that corresponds to time_next_period
       printf("Interference = %d ,R = %d, Qx = %d, time = %lu, ticks =  %lu \n", state.carrier & INTERFERENCE, R, Qx, time_next_period, num_ticks); // View the results in console
       rtimer_set(&rtimer, RTIMER_NOW() + num_ticks , 1, carrier_OnOff, NULL);// Set the rtimer again to the time_next_period (num_ticks)
}


/*---------------------------------------------------------------------------*/

PROCESS(turn_carrier_OnOff, "Turn Carrier On Off"); // Declares the process to turn the carrier on and off
AUTOSTART_PROCESSES( &turn_carrier_OnOff); // Load the process on boot

PROCESS_THREAD(turn_carrier_OnOff, ev, data) // Process to turn carrier on and off
{ 
   
  PROCESS_BEGIN(); // Says where the process starts

  rtimer_set(&rtimer, RTIMER_NOW() + RTIMER_ARCH_SECOND, 1, carrier_OnOff, NULL); //Initiates the rtimer 1 second after boot

  PROCESS_END();  //Says where the process ends
}

/*---------------------------------------------------------------------------*/


Video

I created an unmodulated carrier at channel 20 and to visualize the signal i am using the rssi-scanner provided by Contiki. The vertical node is the interfering one. When the interfering node's red led is on, then the carrier at channel 20 appears; and when the interfering node's green led is on, then the carrier at channel 20 disappears. The time of carrier on/off is a uniform distribution between 0 and 1,5 seconds.

References

[1] Boano, Carlo Alberto; Voigt, Thiemo; Tsiftes, Nicolas; Mottola, Luca; Römer, Kay; Zúñiga, Marco Antonio. Making Sensornet MAC Protocols Robust against Interference. Proceedings of the Wireless Sensor Networks: 7th European Conference - EWSN, Coimbra, Portugal, February 17-19, 2010, pp. 272-288.

[2] C. A. Boano, Z. He, Y. Li, T. Voigt, M. Zúñniga and A. Willig, "Controllable radio interference for experimental and testing purposes in Wireless Sensor Networks," 2009 IEEE 34th Conference on Local Computer Networks, Zurich, 2009, pp. 865-872.

Timers: etimer and rtimer - lowest resolution in us and ms

Objective

The objective of this tutorial is to understand which is the lowest resolution that etimer(ms) and rtimer(us) can provide. In order to do this tutorial i used sky motes, however, the same procedure applies to other architectures. I tested the code in Contiki v3.0 and lubuntu 16.04.

Some Background

The lowest resolution of the etimer is given by the CLOCK_SECOND constant, and for the rtimer is given by the RTIMER_ARCH_SECOND constant. The formula for obtaining the lowest etimer resolution is 1 / CLOCK_SECOND seconds, and for obtaining the lowest rtimer resolution is 1 / RTIMER_ARCH_SECOND seconds. Or in Adam Dunkels' words "The only constant is the RTIMER_ARCH_SECOND. I.e., if you have a hardware timer that runs at 32768Hz, the rtimer units is 1/32768 s and RTIMER_ARCH_SECOND is 32768" (See Reference [1] below).

Check the CLOCK_SECOND and the RTIMER_ARCH_SECOND value

So, in order to know the lowest etimer and rtimer resolution you need to know the value of the CLOCK_SECOND and RTIMER_ARCH_SECOND constants, respectively. Following this, to print that values in console you must run the following code in one node. The code creates the #define SHOW_DEFINE(x), which is used to print the values of the constants CLOCK_SECOND and RTIMER_ARCH_SECOND

/*
 * Copyright (c) 2007, Swedish Institute of Computer Science.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the Institute nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * This file is part of the Contiki operating system.
 *
 */

/**
 * \file
 *       Show CLOCK_SECOND and RTIMER_ARCH_SECOND values
 * \author
 *        Sergio Diaz
 */


/*INCLUDES*/
#include "contiki.h"

//Show #define values: To USE them put it in the process like this: // SHOW_DEFINE(CLOCK_SECOND); // SHOW_DEFINE(RTIMER_ARCH_SECOND);
#define STR(x) #x
#define SHOW_DEFINE(x) printf("%s=%s\n", #x, STR(x))


/*---------------------------------------------------------------------------*/

PROCESS(show_define_values, "Show define values"); // Declares the process to show the #define values
AUTOSTART_PROCESSES( &show_define_values); // Load the process on boot

PROCESS_THREAD(show_define_values, ev, data) // Start of the process to show the #define values
{ 
  static struct etimer et;
  PROCESS_BEGIN(); // Says where the process starts

  while(1)
  {
    //Printf value every 1 second
    etimer_set(&et, CLOCK_SECOND);

    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); //Wait for etimer (et) to expire

    SHOW_DEFINE(CLOCK_SECOND); // Show the value of the CLOCK_SECOND in console. To be aware of the etimer resolution
    SHOW_DEFINE(RTIMER_ARCH_SECOND); // Show the value of the RTIMER_ARCH_SECOND in console. To be aware of the rtimer resolution
    printf("\n"); //Printf a "\n"
  }

  PROCESS_END();  //Says where the process ends
}

/*---------------------------------------------------------------------------*/

When you run this code in a Sky mote and view the messages in the console, then you will see this:

CLOCK_SECOND=128UL
RTIMER_ARCH_SECOND=(4096U*8)

That means that the CLOCK_SECOND value is 128 Unsigned (U) Long (L), and that the RTIMER_ARCH_SECOND value is 4096 Unsigned (U) * 8, it means RTIMER_ARCH_SECOND value is 32768. So the lowest resolution for etimer is 1 / CLOCK_SECOND = 1 / 128 s = 7,8125 ms. Besides, the lowest resolution for rtimer is 1 / RTIMER_ARCH_SECOND = 1 / 4096U*8 = 1 / 32768 = 30,5175 us.

Example Setting etimer and rtimer

If you want to set the etimer and rtimer to the lowest resolution in the sky mote you can do the following.

etimer_set(&et, (CLOCK_SECOND / 128) ); //The etimer expires in 7,8125 ms
rtimer_set(&rtimer, RTIMER_NOW() + (RTIMER_ARCH_SECOND / 32768) , 1, carrier_OnOff, NULL);// The rtimer expires in 30,5175 us

You can not use a bigger number than 128 to divide the CLOCK_SECOND, and you can not use a bigger number than 32768 to divide the RTIMER_ARCH_SECOND; because you can not have a bigger resolution without changing the default behaviour of the sky node. If you want the timers to expire in 0,5 seconds you can do this:

etimer_set(&et, (CLOCK_SECOND / 2) ); //The etimer expires in 0,5 s
rtimer_set(&rtimer, RTIMER_NOW() + (RTIMER_ARCH_SECOND / 2) , 1, carrier_OnOff, NULL);// The rtimer expires in 0,5 s

References

[1] https://sourceforge.net/p/contiki/mailman/message/18577635/

Sunday, August 7, 2016

Generate an interfering node in Contiki OS

Objective

To create an interfering node using a sky CM5000 node that has a CC2420 radio. The interference will be created using an unmodulated carrier. I used the paper [1] to get the code and the idea. I strongly recommend you reading the paper [1] if you want to make a serious study of interference in WSN. I tested the code using Contiki v3.0 and lubuntu 16.04.

Step 1: To disable the MAC layer of the node

The first step in order to create an unmodulated carrier (interference) is to disable the MAC layer of Contiki. To that end, you must create a file named project-conf.h. I am going to create that file in the RIME directory because that is where i am working:

/home/YOURUSER/contiki-3.0/examples/rime/project-conf.h

Within project-conf.h you must disable the MAC by selecting the null mac driver and the null rdc driver. If you want more information about the Contiki communication stack please read the information provided by the following link:

http://anrg.usc.edu/contiki/index.php/MAC_protocols_in_ContikiOS

Then, your project-conf.h must look like this:

#define NETSTACK_CONF_MAC     nullmac_driver // Define the MAC driver to use
#define NETSTACK_CONF_RDC     nullrdc_driver // Define the RDC driver to use
In order that Contiki reads the information that your project-conf.h file contains, then you must insert the following line CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" in the Makefile, which is located in the rime directory (where we are working). Consequently, your Makefile must look like this:
CONTIKI = ../..
 
all: example-abc example-mesh example-collect example-trickle example-polite \
     example-rudolph1 example-rudolph2 example-rucb \
     example-runicast example-unicast example-neighbors
 
CONTIKI_WITH_RIME = 1
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
include $(CONTIKI)/Makefile.include
Now, you have disabled the MAC layer of your interfering node. If you load the Rime broadcast example in your node (example-broadcast.c), then you will see the nullmac and the nullrdc configured (see the code below). The following link explains in detail how to create the project-conf.h file, but this example changes the radio channel, not the MAC layer.

http://contiki-iot.blogspot.com.co/2016/07/project-configuration-example.html

Rime started with address 1.0                                                
MAC 01:00:00:00:00:00:00:00 Contiki 3.0 started. Node id is set to 1.        
nullsec nullmac nullrdc, channel check rate 8 Hz, radio channel 20           
Starting 'Broadcast example'

Step 2: To generate an unmodulated carrier

In order to generate an unmodulated carrier i used the idea and the code from the paper [1]. I show you the complete Contiki code:
/*
 * Copyright (c) 2007, Swedish Institute of Computer Science.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the Institute nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * This file is part of the Contiki operating system.
 *
 */

/**
 * \file
 *        Example of an interfering node
 * \author
 *        Sergio Diaz
 */

#include "contiki.h"

#include "/home/sink/Desktop/contiki-3.0/dev/cc2420/cc2420.h" // Include the CC2420 library
#include "/home/sink/Desktop/contiki-3.0/dev/cc2420/cc2420_const.h" // Include the CC2420 constants 
#include "/home/sink/Desktop/contiki-3.0/core/dev/spi.h" // Include basic SPI macros

/*---------------------------------------------------------------------------*/
PROCESS(unmodulated_carrier, "CC2420 Unmodulated Carrier"); // Declares the process unmodulated_carrier
AUTOSTART_PROCESSES(&unmodulated_carrier); // Load the process on boot

/*---------------------------------------------------------------------------*/
/** 
 * Writes to a register.
 * Note: the SPI_WRITE(0) seems to be needed for getting the
 * write reg working on the Z1 / MSP430X platform
 */
static void
setreg(enum cc2420_register regname, uint16_t value) // Set the register of the cc2420 radio
{
  CC2420_SPI_ENABLE();
  SPI_WRITE_FAST(regname);
  SPI_WRITE_FAST((uint8_t) (value >> 8));
  SPI_WRITE_FAST((uint8_t) (value & 0xff));
  SPI_WAITFORTx_ENDED();
  SPI_WRITE(0);
  CC2420_SPI_DISABLE();
}

/* Sends a strobe */
static void
strobe(enum cc2420_register regname)
{
  CC2420_SPI_ENABLE();
  SPI_WRITE(regname);
  CC2420_SPI_DISABLE();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(unmodulated_carrier, ev, data) // Defines the process unmodulated_carrier
{

  PROCESS_BEGIN();  // Says where the process starts

  // Creates an unmodulated carrier
  setreg(CC2420_MANOR, 0x0100);
  setreg(CC2420_TOPTST, 0x0004);
  setreg(CC2420_MDMCTRL1, 0x0508);
  setreg(CC2420_DACTST, 0x1800);
  strobe(CC2420_STXON); 

  PROCESS_END();  //Says where the process ends
}
/*---------------------------------------------------------------------------*/


I tested the interfering node in the following set up. I have three nodes: a sink, a temperature node and an interfering node. The temperature node sends its data to the sink via radio, then i observe in the sink that the messages arrive without problem. Then, i turn the interfering node on and i suddenly observe that no more packets arrive. If i turn the interfering node off then the packets arrive again with no problem. Consequently, the interfering node introduces noise in the communication between the sink and the temperature node. This noise (an unmodulated carrier) is so strong that no more packets arrive to the sink. If you want a more sophisticated interfering node i strongly recommend you to read the paper [2] and make my tutorial named Generate an improved interfering node in Contiki OS located in the following link.

http://contiki-iot.blogspot.com.co/2016/08/generate-improved-interfering-node-in.html

Reset the CC2420 to normal behaviour

When you are done using your interfering node, then you must reset the CC2420's register to normal behaviour. To that end, you must run the following code in your node:
/*
 * Copyright (c) 2007, Swedish Institute of Computer Science.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the Institute nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * This file is part of the Contiki operating system.
 *
 */

/**
 * \file
 *        Example of an interfering node
 * \author
 *        Sergio Diaz
 */

#include "contiki.h"

#include "/home/sink/Desktop/contiki-3.0/dev/cc2420/cc2420.h" // Include the CC2420 library
#include "/home/sink/Desktop/contiki-3.0/dev/cc2420/cc2420_const.h" // Include the CC2420 constants 
#include "/home/sink/Desktop/contiki-3.0/core/dev/spi.h" // Include basic SPI macros

/*---------------------------------------------------------------------------*/
PROCESS(reset_cc2420_registers, "CC2420 Reset Registers"); // Declares the process reset_cc2420_registers
AUTOSTART_PROCESSES(&reset_cc2420_registers); // Load the process on boot

/*---------------------------------------------------------------------------*/
/** 
 * Writes to a register.
 * Note: the SPI_WRITE(0) seems to be needed for getting the
 * write reg working on the Z1 / MSP430X platform
 */
static void
setreg(enum cc2420_register regname, uint16_t value) // Set the register of the cc2420 radio
{
  CC2420_SPI_ENABLE();
  SPI_WRITE_FAST(regname);
  SPI_WRITE_FAST((uint8_t) (value >> 8));
  SPI_WRITE_FAST((uint8_t) (value & 0xff));
  SPI_WAITFORTx_ENDED();
  SPI_WRITE(0);
  CC2420_SPI_DISABLE();
}

/* Sends a strobe */
static void
strobe(enum cc2420_register regname)
{
  CC2420_SPI_ENABLE();
  SPI_WRITE(regname);
  CC2420_SPI_DISABLE();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(reset_cc2420_registers, ev, data) // Defines the process reset_cc2420_registers
{

  PROCESS_BEGIN();  // Says where the process starts

  // Reset CC2420's register to normal behaviour
   setreg(CC2420_MANOR, 0x0000);
   setreg(CC2420_TOPTST, 0x0010);
   setreg(CC2420_MDMCTRL1, 0x0500);
   setreg(CC2420_DACTST, 0x0000);
   strobe(CC2420_STXON);

  PROCESS_END();  //Says where the process ends
}
/*---------------------------------------------------------------------------*/


Video

I created an unmodulated carrier at channel 20 and to visualize the signal i am using the rssi-scanner provided by Contiki. When i press the restart button of the sky mote the carrier at channel 20 disappears, then it appears when the program starts running again.

References

Notice that the author from papers [1] and [2] is the same guy (Carlo Alberto Boano ).

[1] C. A. Boano, Z. He, Y. Li, T. Voigt, M. Zúñniga and A. Willig, "Controllable radio interference for experimental and testing purposes in Wireless Sensor Networks," 2009 IEEE 34th Conference on Local Computer Networks, Zurich, 2009, pp. 865-872.

[2] Boano, Carlo Alberto; Voigt, Thiemo; Tsiftes, Nicolas; Mottola, Luca; Römer, Kay; Zúñiga, Marco Antonio. Making Sensornet MAC Protocols Robust against Interference. Proceedings of the Wireless Sensor Networks: 7th European Conference - EWSN, Coimbra, Portugal, February 17-19, 2010, pp. 272-288.