Example #1
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_rfchannel_process, ev, data)
{
  struct {
    uint16_t len;
    uint16_t channel;
  } msg;
  const char *newptr;
  PROCESS_BEGIN();

  msg.channel = shell_strtolong(data, &newptr);
  
  /* If no channel was given on the command line, we print out the
     current channel. */
  if(newptr == data) {
    msg.channel = cc2420_get_channel();
  } else {
    cc2420_set_channel(msg.channel);
  }

  msg.len = 1;

  shell_output(&rfchannel_command, &msg, sizeof(msg), "", 0);

  PROCESS_END();
}
// Initialize RDC layer
static void init(void)
{
  //get node id
  node_id_restore();

  //set slot number
  sf_tdma_set_slot_num(node_id);


  //reset rime & radio address
  sf_tdma_set_mac_addr();

  //reset packet number
  seq_num = 0;

  //check the if the number of time slot is large enough
  uint32_t min_segment_len = TS_period*total_slot_num + BS_period;
  if (min_segment_len > segment_period)
  {
    printf("min_segment_len > segment_period\n");
    assert(1);
  }


  printf("Init RDC layer,packet size\n");

#ifdef SF_MOTE_TYPE_SENSOR
  incorrect_rx_counter = 0;
#endif

  cc2420_set_channel(RF_CHANNEL_CONST);
  cc2420_set_txpower(CC2420_TXPOWER_MAX);

  on();
}
Example #3
0
int
cmd_handler_cc2420(const uint8_t *data, int len)
{
  if(data[0] == '!') {
    if(data[1] == 'C' && len == 3) {
      printf("cc2420_cmd: setting channel: %d\n", data[2]);
      cc2420_set_channel(data[2]);
      return 1;
    } else if(data[1] == 'M' && len == 10) {
        printf("cc2420_cmd: Got MAC\n");
        memcpy(uip_lladdr.addr, data+2, sizeof(uip_lladdr.addr));
        linkaddr_set_node_addr((linkaddr_t *) uip_lladdr.addr);
        uint16_t shortaddr = (linkaddr_node_addr.u8[0] << 8) +
          linkaddr_node_addr.u8[1];
        cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, linkaddr_node_addr.u8);
        return 1;
      }
  } else if(data[0] == '?') {
    if(data[1] == 'C' && len == 2) {
      uint8_t buf[4];
      printf("cc2420_cmd: getting channel: %d\n", data[2]);
      buf[0] = '!';
      buf[1] = 'C';
      buf[2] = cc2420_get_channel();
      cmd_send(buf, 3);
      return 1;
    }
  }
  return 0;
}
Example #4
0
PROCESS_THREAD(interferer_example, ev, data)
{
 PROCESS_EXITHANDLER()  
 PROCESS_BEGIN();

 // Initial configurations on CC2420: channel and tx power
 watchdog_stop();
 cc2420_set_txpower(CC2420_TXPOWER_MAX);
 cc2420_set_channel(INTERFERED_CHANNEL);
 printf("HandyMote: interfering continuously with random power\n");
 
 // Interfering continuously with random power
 CC2420_SPI_ENABLE();
 set_jammer(CARRIER_TYPE);
 int randelay, randpower;
 while(1){
	 randpower = random_value(MIN_POWER,MAX_POWER);
	 randelay = random_value(MIN_TIME,MAX_TIME);	 
	 power_jammer(randpower);
	 clock_delay(randelay);
 }
 CC2420_SPI_DISABLE();

 PROCESS_WAIT_EVENT();  
 PROCESS_END();
}
Example #5
0
void start(void) {
	mos_node_id_set(1);
	
	is_base = false;
	
	// Initialize net layer
	net_init();
		   
	
	
	// Start the CTP backends 
	ctp_proto_init();
	
	// Wait a while till the routing is possibly established      
	mos_mdelay(10);
	
	net_ioctl(CTP_PROTO_ID, CTP_SET_TESTBED);
	
	com_ioctl_IFACE_RADIO (CC2420_TX_POWER, 2); //set the tx power from 0 (min) to 31 (max)  
	cc2420_set_channel(26);
	
	printf("Running net layer and CTP backend... \n");
	
	// transportInit(true);
}
Example #6
0
/**
 * @brief init
 */
static void init(){

    /*int k = 0, k1 = random_int(100);

    for(k = 0; k < 100; k++){
        random_rand();
    }*/

    ///initialize setting must be called before neighbors init bcz
    initialize_settings();
    
    ///initialize list of neighbors
    neighs_init();

    //on();
    
    PT_INIT(&pt);
    
    /** start the node discovery process NOTE: ONLY USED FOR COOJA SIMULATIONS*/
    process_start(&autotrigger_process, NULL);

    process_start(&output_process, NULL);

    ///START UP PROTOCOL...INDRIYA ONLY.....
    ///@todo..comment this code afterwards..
    //cc2420_set_channel(i3e154_channels[random_int(num_channels)]);
    cc2420_set_channel(i3e154_channels[0]);
}
Example #7
0
static int
do_rssi(void)
{
  static int sample;
  int channel;
  
  NETSTACK_MAC.off(0);

  cc2420_on();
  for(channel = 11; channel <= 26; ++channel) {
    cc2420_set_channel(channel);
    rssi_samples[sample].channel[channel - 11] = cc2420_rssi() + 53;
  }
  
  NETSTACK_MAC.on();
  
  sample = (sample + 1) % NUM_SAMPLES;

  {
    int channel, tot;
    tot = 0;
    for(channel = 0; channel < 16; ++channel) {
      int max = -256;
      int i;
      for(i = 0; i < NUM_SAMPLES; ++i) {
	max = MAX(max, rssi_samples[i].channel[channel]);
      }
      tot += max / 20;
    }
    return tot;
  }
}
Example #8
0
/*---------------------------------------------------------------------------*/
int
cc2420_init(void)
{
  uint16_t reg;
  {
    int s = splhigh();
    cc2420_arch_init();		/* Initalize ports and SPI. */
    DISABLE_FIFOP_INT();
    FIFOP_INT_INIT();
    splx(s);
  }

  /* Turn on voltage regulator and reset. */
  SET_VREG_ACTIVE();
  //clock_delay(250); OK
  SET_RESET_ACTIVE();
  clock_delay(127);
  SET_RESET_INACTIVE();
  //clock_delay(125); OK


  /* Turn on the crystal oscillator. */
  strobe(CC2420_SXOSCON);

  /* Turn on/off automatic packet acknowledgment and address decoding. */
  reg = getreg(CC2420_MDMCTRL0);

  reg |= 0x40; /* XXX CCA mode 1 */
  
#if CC2420_CONF_AUTOACK
  reg |= AUTOACK | ADR_DECODE;
#else
  reg &= ~(AUTOACK | ADR_DECODE);
#endif /* CC2420_CONF_AUTOACK */
  setreg(CC2420_MDMCTRL0, reg);

  /* Change default values as recomended in the data sheet, */
  /* correlation threshold = 20, RX bandpass filter = 1.3uA. */
  setreg(CC2420_MDMCTRL1, CORR_THR(20));
  reg = getreg(CC2420_RXCTRL1);
  reg |= RXBPF_LOCUR;
  setreg(CC2420_RXCTRL1, reg);

  /* Set the FIFOP threshold to maximum. */
  setreg(CC2420_IOCFG0, FIFOP_THR(127));

  /* Turn off "Security enable" (page 32). */
  reg = getreg(CC2420_SECCTRL0);
  reg &= ~RXFIFO_PROTECTION;
  setreg(CC2420_SECCTRL0, reg);

  cc2420_set_pan_addr(0xffff, 0x0000, NULL);
  cc2420_set_channel(26);

  process_start(&cc2420_process, NULL);
  return 1;
}
Example #9
0
/*---------------------------------------------------------------------------*/
static void
do_sending(void)
{
  int i;

  cc2420_set_channel(11);
  cc2420_set_txpower(1);

  for(i = 0;i < send_amount; i++) {
    packetbuf_copyfrom(send_string, send_length);

    mac->on();
    abc_send(&abc);
    mac->off(0);
  }
  cc2420_set_txpower(31);
  cc2420_set_channel(RF_CHANNEL);
}
Example #10
0
/*---------------------------------------------------------------*/
static void scan_channel(void)
{
	uint i = 0;
	int rx_power = 0;
	for(i = 11; i <= 26; i++)
	{
		cc2420_set_channel(i);
		rx_power = cc2420_rssi()-45;
		printf("Channel %u: %d dBm\n",i,rx_power);
	}
	printf("\n");
	ctimer_reset(&ct);
}
PROCESS_THREAD(interferer_example, ev, data)
{
 PROCESS_EXITHANDLER()  
 PROCESS_BEGIN();
 
 static struct etimer et;
 //powertrace_start(CLOCK_SECOND * 2);

 // Initial configurations on CC2420: channel and tx power
 watchdog_stop();
 cc2420_set_txpower(power);
 cc2420_set_channel(26);
 //printf("interfering with periodic interference\n"); 
 // Continuous Interference
 
 CC2420_SPI_ENABLE();
 
 //SPI_SET_UNMODULATED(0x1800,0x0100,0x0508,0x0004);
 SPI_SET_MODULATED(0x050C);
 
 //powertrace_start(CLOCK_SECOND*2);

 while(1){	
 
 for(power=3; power<32; power+=4){
 SPI_SET_TXPOWER((0xa0ff & 0xffe0) | (power & 0x1f));
 etimer_set(&et, CLOCK_SECOND/1000);
 PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
 //printf ("transmit power = %d\n",power);
 }
 
 for(power=27; power>3; power-=4){
 SPI_SET_TXPOWER((0xa0ff & 0xffe0) | (power & 0x1f));
 etimer_set(&et, CLOCK_SECOND/1000);
 PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
 //printf ("transmit power = %d\n",power);
 }
 
 for(power=3; power<32; power+=2){
 SPI_SET_TXPOWER((0xa0ff & 0xffe0) | (0 & 0x1f));
 etimer_set(&et, CLOCK_SECOND/1000);
 PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
 //printf ("transmit power = %d\n",power);
 }
 
} 
 CC2420_SPI_DISABLE();
 void powertrace_stop(void); 
 PROCESS_WAIT_EVENT();  
 PROCESS_END();
}
Example #12
0
void appRecv() {
	char recvdDataBuf[12];
	
	// avoid signal interference with default channel (26) and wi-fi 
	cc2420_set_channel(24);

	while (1) {
		memset(recvdDataBuf, 0, sizeof(recvdDataBuf));
		
		receiveData(TRANSPORT_LISTENING_PORT, recvdDataBuf, 
				sizeof(recvdDataBuf), 1);
		printf("In appRecv(), received data: %s \n", recvdDataBuf);
	}
}
Example #13
0
/**
 * @brief start_discovery_process
 */
static void start_discovery_process(){
    uint16_t Tup_bound = 0, random_slot = 1;

    random_slot = 1 +  random_rand()%period_length;

    Tup_bound = (period_length*period_length)/4;

    //random_slot = random_slot + random_rand()%Tup_bound ;

    /*if (rimeaddr_node_addr.u8[0] < 130){
        random_slot = random_slot + random_rand()%period_length;
    }else{
        random_slot = random_slot + Tup_bound + random_rand()%period_length;
    }*/


    /*if(rimeaddr_node_addr.u8[0] == 10 || rimeaddr_node_addr.u8[0] == 11){
      //uint8_t channel_group = 1+rimeaddr_node_addr.u8[0]%GROUP_MERGE_SIZE;
      uint8_t channel_group = 1;
      
      
      random_slot = 0;

      cc2420_set_channel(i3e154_channels[channel_group]);
    }*/

    //enable random offset wait flag..
    rand_offset_wait_flag = 1;
    node_slots_offset     = random_slot;
    slot_upperBound       = 10000 - node_slots_offset;

    //-------- HERE WE DIVIDE NODES INTO CHANNELS.........
    if(1 /*rimeaddr_node_addr.u8[0] == 10*/){
        //uint8_t channel_group = 1+rimeaddr_node_addr.u8[0]%GROUP_MERGE_SIZE;
        uint8_t channel_group = 0;

        cc2420_set_channel(i3e154_channels[channel_group]);
    }

    COOJA_DEBUG_PRINTF("======>>>>> ID:%2u, channel:%2u\n", rimeaddr_node_addr.u8[0], cc2420_get_channel());
    //--------END GROUP CHANNEL SETTING...

    rtimer_clock_t startTime = RTIMER_NOW() + 2;

    int ret = rtimer_set(&generic_timer, startTime, 1,
                         (void (*)(struct rtimer *, void *))power_cycle, NULL);
    if(ret){
        PRINTF("synchronization failed\n");
    }
}
Example #14
0
void cc2420_init(int tpid)
{
    uint16_t reg;
    transceiver_pid = tpid;

    cc2420_spi_init();
    hwtimer_wait(CC2420_WAIT_TIME);
    cc2420_reset();

    cc2420_strobe(CC2420_STROBE_XOSCON);               //enable crystal

    while((cc2420_strobe(NOBYTE) & 0x40) == 0);        //wait for crystal to be stable
    hwtimer_wait(CC2420_WAIT_TIME);

    reg = cc2420_read_reg(CC2420_REG_MDMCTRL0);
    reg |= CC2420_ADR_DECODE;                          //enable adr decode
    reg |= CC2420_AUTOACK;                             //enable auto ack
    reg |= CC2420_AUTOCRC;                             //enable auto crc
    reg &= ~(CC2420_RES_FRM_MODE);                     //disable reserved frames
    cc2420_write_reg(CC2420_REG_MDMCTRL0, reg);

    /* Change default values as recomended in the data sheet, */
    /* RX bandpass filter = 1.3uA. */
    reg = cc2420_read_reg(CC2420_REG_RXCTRL1);
    reg |= CC2420_RXBPF_LOCUR;
    cc2420_write_reg(CC2420_REG_RXCTRL1, reg);

    /* Set the FIFOP threshold to maximum. */
    cc2420_write_reg(CC2420_REG_IOCFG0, 127);

    /* Turn off "Security enable" (page 32). */
    reg = cc2420_read_reg(CC2420_REG_SECCTRL0);
    reg &= ~CC2420_RXFIFO_PROTECTION;
    cc2420_write_reg(CC2420_REG_SECCTRL0, reg);

    /* set output power to 0dbm */
    cc2420_write_reg(CC2420_REG_TXCTRL, 0xA0FF);

    cc2420_set_channel(CC2420_DEFAULT_CHANNR);
    cc2420_set_pan(0x1111);
    DEBUG("CC2420 initialized and set to channel %i and pan %i\n", radio_channel, radio_pan);
    cc2420_init_interrupts();
    cc2420_switch_to_rx();

}
Example #15
0
/*---------------------------------------------------------------------------*/
static void
free_packet(struct neighbor_queue *n, struct rdc_buf_list *p)
{
  if(p != NULL) {

//ADILA EDIT 09/02/14
//cc2420_set_channel(list_length(n->queued_packet_list) + 10);
//printf("%d BEFORE FREE Q %d\n", cc2420_get_channel(), list_length(n->queued_packet_list));
//-------------------

    /* Remove packet from list and deallocate */
    list_remove(n->queued_packet_list, p);

    queuebuf_free(p->buf);
    memb_free(&metadata_memb, p->ptr);
    memb_free(&packet_memb, p);

//ADILA EDIT 09/02/14
if((list_length(n->queued_packet_list)) == 0) {
cc2420_set_channel(26);
//printf("%d empty Q %d\n", cc2420_get_channel(), list_length(n->queued_packet_list));

}
//-------------------

    PRINTF("csma: free_queued_packet, queue length %d\n",
        list_length(n->queued_packet_list));
    if(list_head(n->queued_packet_list) != NULL) {
      /* There is a next packet. We reset current tx information */
      n->transmissions = 0;
      n->collisions = 0;
      n->deferrals = 0;
      /* Set a timer for next transmissions */
      ctimer_set(&n->transmit_timer, default_timebase(),
                 transmit_packet_list, n);
    } else {
      /* This was the last packet in the queue, we free the neighbor */
      ctimer_stop(&n->transmit_timer);
      list_remove(neighbor_list, n);
      memb_free(&neighbor_memb, n);
    }
  }
}
Example #16
0
static void
configure(void)
{
  uint16_t reg;
  BUSYWAIT_UNTIL(status() & (BV(CC2420_XOSC16M_STABLE)), RTIMER_SECOND / 100);

  /* Turn on/off automatic packet acknowledgment and address decoding. */
  reg = getreg(CC2420_MDMCTRL0);

#if CC2420_CONF_AUTOACK
  reg |= AUTOACK | ADR_DECODE;
#else
  reg &= ~(AUTOACK | ADR_DECODE);
#endif /* CC2420_CONF_AUTOACK */
  setreg(CC2420_MDMCTRL0, reg);

  /* Set transmission turnaround time to the lower setting (8 symbols
     = 0.128 ms) instead of the default (12 symbols = 0.192 ms). */
  /*  reg = getreg(CC2420_TXCTRL);
  reg &= ~(1 << 13);
  setreg(CC2420_TXCTRL, reg);*/

  /* Change default values as recomended in the data sheet, */
  /* correlation threshold = 20, RX bandpass filter = 1.3uA. */
  setreg(CC2420_MDMCTRL1, CORR_THR(20));
  reg = getreg(CC2420_RXCTRL1);
  reg |= RXBPF_LOCUR;
  setreg(CC2420_RXCTRL1, reg);

  /* Set the FIFOP threshold to maximum. */
  setreg(CC2420_IOCFG0, FIFOP_THR(127));

  /* Turn off "Security enable" (page 32). */
  reg = getreg(CC2420_SECCTRL0);
  reg &= ~RXFIFO_PROTECTION;
  setreg(CC2420_SECCTRL0, reg);

  cc2420_set_pan_addr(pan, addr, NULL);
  cc2420_set_channel(channel);

  flushrx();

}
Example #17
0
PROCESS_THREAD(sensys_tx, ev, data)
{
 PROCESS_EXITHANDLER()
 PROCESS_BEGIN();
 
 // Initial configurations  on CC2420 and resetting the timer
 leds_off(LEDS_ALL);
 cc2420_set_txpower(POWER);
 cc2420_set_channel(CHANNEL_SENDER);
 unicast_open(&uc, RIME_SENDER, &unicast_callbacks); 
 ctimer_stop(&timer1);
  
 // Ready to send...
 leds_on(LEDS_BLUE); 
 
 while(1) {
	PROCESS_WAIT_EVENT();		
 }        
 PROCESS_END();
}
Example #18
0
/*
 * @brief Sets the radio channel for any transceiver device
 *
 * @param t         The transceiver device
 * @param channel   The channel to be set
 *
 * @return The radio channel AFTER calling the set command, -1 on error
 */
static int32_t set_channel(transceiver_type_t t, void *channel)
{
    /* cppcheck: c is read depending on enabled modules */
    /* cppcheck-suppress unreadVariable */
    uint8_t c = *((uint8_t *)channel);

    switch (t) {
        case TRANSCEIVER_CC1100:
#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY))
            return cc110x_set_channel(c);
#elif MODULE_CC110X_LEGACY_CSMA
            return cc1100_set_channel(c);
#else
            return -1;
#endif
#ifdef MODULE_CC2420

        case TRANSCEIVER_CC2420:
            return cc2420_set_channel(c);
#endif
#ifdef MODULE_MC1322X

        case TRANSCEIVER_MC1322X:
            maca_set_channel(c);
            return c; ///< TODO: should be changed!implement get channel
#endif
#ifdef MODULE_NATIVENET

        case TRANSCEIVER_NATIVE:
            return nativenet_set_channel(c);
#endif
#ifdef MODULE_AT86RF231

        case TRANSCEIVER_AT86RF231:
            return at86rf231_set_channel(c);
#endif

        default:
            return -1;
    }
}
PROCESS_THREAD(markov_process, ev, data) {
    int new_state = b[0];
    int i,j;

    PROCESS_BEGIN();

    //etimer_set(&et, CLOCK_SECOND);
    //PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

    // Initial configurations  on CC2420
    cc2420_set_txpower(MAX_POWER);
    cc2420_set_channel(INTERFERED_CHANNEL);
    watchdog_stop();

    printf("RAND_MAX %d INTMAX %d\n", RANDOM_RAND_MAX, INT_MAX);
    random_init(19);


    /* XXX should use formula */
    W[0]= 31;
    W[1]= 62;
    W[2]= 124;
    W[3]= 248;
    W[4]= 496;
    W[5]= 992;
    W[6]= 1023;
    W[7]= 1023;

    for(i=0; i<NRSTATES; i++) {
        b[i] = bSTATE_MIN+i;
        B[i] = BSTATE_MIN+i;
        bctr[i] = 0;
        Bctr[i] = 0;
        ALFA[i] = 2.0/((float)W[i]);
        BETA[i] = 2.0/((float)(W[i]-1));
    }

    printf("a %d, b %d, c %d d %d BETA1 %d\n",
           100*((1-P)*ALFA[0]),
           100*((1-P)*(1-ALFA[0])),
           100*(P*ALFA[1]),
           100*(P*(1-ALFA[1])),
           100*BETA[1]);


    /* this is the first "dry" run where we compute the state for
       the real run */
    new_state = b[0];
    for(i=0; i<SAVESTATES; i++) {
        sstate [i] = 0;
        visits[i] = 0;
    }
    while (cs<SAVESTATES) {
        new_state = compute_state(new_state);
    }
    new_state = b[0];

    /* now we start the real run */
    cur_state = 0;
    cur_visits = 0;

    CC2420_SPI_ENABLE();

#if 0
    while (cs<) {
        ctr++;
        if (ctr % 100 == 0) {
            int ctr_sum = 0;
            printf("time %f\n", time);
            float b = 0;
            for(i=bSTATE_MIN; i<bSTATE_MIN+NRSTATES; i++) {
                printf("counter[%d]: %d\n", i, bctr[i]);
                ctr_sum += bctr[i];
                b += timeb[i];
            }
            for(i= 0; i<NRSTATES; i++) {
                printf("counter[%d]: %d\n", i, Bctr[i]);
                ctr_sum += Bctr[i];
            }
            b = b / time;
            printf("counter %d percent in b: %f\n", ctr_sum, b);
        }
        if (ctr > MAX) {
            int ctr_sum = 0;
            float b = 0;
            for(i=bSTATE_MIN; i<bSTATE_MIN+NRSTATES; i++) {
                printf("counter[%d]: %d\n", i, bctr[i]);
                ctr_sum += bctr[i];
            }
            for(i= 0; i<NRSTATES; i++) {
                printf("counter[%d]: %d\n", i, Bctr[i]);
                ctr_sum += Bctr[i];
            }
            printf("counter %d percent in b: %f\n", ctr_sum, b);
            printf("ctrs: b0 %d B0 %d b1 %d B1 %d b5 %d B5 %d\n",
                   bctr[0], Bctr[0], bctr[1], Bctr[1], bctr[5], Bctr[5]);
            exit(1);
        }
        update_state();
    }
#endif
    printf("after modelling\n");
    j=0;
    for(i=0; i<SAVESTATES; i++) {
        //printf("state %d visits% d\n", sstate[i], visits[i]);
        j += visits[i];
    }
    printf("sum visits %d\n", j);
    /* correct very first state */
    if (visits[0] == 0)
        visits[0] = 1;

    ctr = 0;
    printf("--------- real run -------------\n");
    update_state();

    CC2420_SPI_DISABLE();
    PROCESS_END();
}
Example #20
0
/*---------------------------------------------------------------------------*/
int
cc2420_init(void)
{
  uint16_t reg;
  {
    int s = splhigh();
    cc2420_arch_init();		/* Initalize ports and SPI. */
    CC2420_DISABLE_FIFOP_INT();
    CC2420_FIFOP_INT_INIT();
    splx(s);
  }

  /* Turn on voltage regulator and reset. */
  SET_VREG_ACTIVE();
  clock_delay(250);
  SET_RESET_ACTIVE();
  clock_delay(127);
  SET_RESET_INACTIVE();
  clock_delay(125);


  /* Turn on the crystal oscillator. */
  strobe(CC2420_SXOSCON);

  /* Turn on/off automatic packet acknowledgment and address decoding. */
  reg = getreg(CC2420_MDMCTRL0);

#if CC2420_CONF_AUTOACK
  reg |= AUTOACK | ADR_DECODE;
#else
  reg &= ~(AUTOACK | ADR_DECODE);
#endif /* CC2420_CONF_AUTOACK */
  setreg(CC2420_MDMCTRL0, reg);

  /* Set transmission turnaround time to the lower setting (8 symbols
     = 0.128 ms) instead of the default (12 symbols = 0.192 ms). */
  /*  reg = getreg(CC2420_TXCTRL);
  reg &= ~(1 << 13);
  setreg(CC2420_TXCTRL, reg);*/

  
  /* Change default values as recomended in the data sheet, */
  /* correlation threshold = 20, RX bandpass filter = 1.3uA. */
  setreg(CC2420_MDMCTRL1, CORR_THR(20));
  reg = getreg(CC2420_RXCTRL1);
  reg |= RXBPF_LOCUR;
  setreg(CC2420_RXCTRL1, reg);

  /* Set the FIFOP threshold to maximum. */
  setreg(CC2420_IOCFG0, FIFOP_THR(127));

  /* Turn off "Security enable" (page 32). */
  reg = getreg(CC2420_SECCTRL0);
  reg &= ~RXFIFO_PROTECTION;
  setreg(CC2420_SECCTRL0, reg);

  cc2420_set_pan_addr(0xffff, 0x0000, NULL);
  cc2420_set_channel(CC2420_CONF_CHANNEL);
  cc2420_set_cca_threshold(CC2420_CONF_CCA_THRESH);

  flushrx();

  process_start(&cc2420_process, NULL);
  return 1;
}
Example #21
0
void appSend () {
	static uint8_t smpl_cnt = 10;  //number of samples we take to average on each channel
	uint8_t  count = 0;            //temp counter for samples taken
	uint8_t  i;
	uint8_t  nchannels=1;
	uint8_t  channels[1] = {INTERNAL_VOLTAGE};  //use only internal voltage for now  

	uint16_t adc_raw[8];
	uint8_t  ledcount = 0;
	uint8_t  ix;

	char     sendData[12];
	char     testStr[] = "test";
	char     iStr[3];
	uint16_t pause_time = 1000;

	// Avoid signal interference with default channel (26) and wi-fi 
	cc2420_set_channel(24);

	// Set transmit power to low-power mode 
	com_ioctl(IFACE_RADIO, CC2420_LOW_POWER_MODE);

    printf("Opening connection on port %d... \n", TRANSPORT_LISTENING_PORT);
    connect(TRANSPORT_LISTENING_PORT, 0);
    printf("Opened connection on port %d \n", TRANSPORT_LISTENING_PORT);
	
	//mos_thread_sleep(2000);
	while (true) {
		//--- MEASURING BATTERY VOLTAGE ---// 
		
		//mos_led_display( (ledcount++)%8 );  //see explanation in test_adc.c
		adc_on();  //turn on the ADC/Vref
		mos_thread_sleep(20);  //time to wait for the internal reference to settle in theory 

		// Measure each channel, possibly with multiple samples
		for(ix=0; ix<nchannels; ix++) {
			//take 10 samples and average the result
			//split this value out as the final channel reading
			count = 0;  //clear the samples counter
		 	adc_raw[ix]=0;  // clear adc reading accum

            //For this channel, do as many samples as are 'requested'
		    while(count < smpl_cnt) {
		    	adc_raw[ix] += adc_get_conversion16( channels[ix] );
	            count++;  //increment the no. of readings counter
	        }   //end of samples loop for this channel
		} //end channels loop 

		// Average the data for the samples taken on each channel
		for( ix=0; ix<nchannels; ix++ ) {
	    	adc_raw[ix] /= smpl_cnt;
        }

        // Report the results 
	   	//printf("Raw voltage reading = %x\n", adc_raw[0]); 
	    
		adc_off();
	    //mos_thread_sleep(4000);

		
		//--- SENDING DATA ---// 
		
		memset(sendData, 0, sizeof(sendData));
		strcpy(sendData, testStr);
		itoa(i, iStr, 10);
		strcat(sendData, iStr);

		printf("Calling sendPacket() for: %s \n", sendData);
		sendPacket(TRANSPORT_LISTENING_PORT, sendData, sizeof(sendData), 0);

		i++;
		// Reset counter
	    if (i >= 60) {
	    	i = 0;
	    }
		
		// Get raw voltage reading 
		printf("***** Raw voltage reading = %x *****\n", adc_raw[0]); 
		
		// Adjust pause time (send rate) for each specific voltage 
		if (adc_raw[0] > 0x950) {
			pause_time = 1000; 
		} else if (adc_raw[0] > 0x925) {
			pause_time = 1500;
		} else if (adc_raw[0] > 0x900) {
			pause_time = 2000;
		}
		// and so on... 
		// need to find the optimal values ... 
		
		mos_thread_sleep(pause_time); //adaptive send rate 
		
		// Close connection to destination (last) node; port 0
		closeConn(0, 3);
	    printf("Closed connection on port %d \n", TRANSPORT_LISTENING_PORT);
	}
}
Example #22
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(example_abc_process, ev, data)
{
	
	static struct channel *c;
	static struct etimer et;

	PROCESS_BEGIN();
	char buffer[32];	
	
	//button_sensor.activate();
	SENSORS_ACTIVATE(button_sensor);
	
	
	printf("ready to rock\n");
	
	//ds2411_init();
	static int i;
	
	
	//cc2420_init();
	//cc2420_set_pan_addr(panId, 0 /*XXX*/, ds2411_id);
	//cc2420_set_channel(26);

	//abc_open(&abc, 128, &abc_call);
//  set_rime_addr();	
//  cc2420_init();
  //cc2420_set_pan_addr(panId, 0 , ds2411_id);
//  cc2420_set_channel(RF_CHANNEL);

  //cc2420_set_txpower(31);
  //nullmac_init(&cc2420_driver);
  //rime_init(&nullmac_driver);


	//cc2420_set_txpower(31);

	//cc2420_on();
	channel_init();

	packetbuf_clear();

	driver = nullmac_init(&cc2420_driver);	
        //rime_init(driver);
	//driver = sicslowmac_init(&cc2420_driver);
	
	cc2420_set_channel(26);
	channel_open(c, 34);		
	/*packetbuf_clear();*/
	
	driver->set_receive_function(recv);
	//packetbuf_clear();
	
	channel_set_attributes(34, attributes);
	//set_receive_function(driver);	

	driver->on();	
	leds_toggle(LEDS_RED);
	
	packetbuf_clear();
	etimer_set(&et, CLOCK_SECOND * 2 + random_rand() % (CLOCK_SECOND * 2));
	PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
	leds_toggle(LEDS_RED);
	PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event && data == &button_sensor);
	

	while(1)
	{
		if (i % 20 == 19)
		{
			PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event && data == &button_sensor);
		}
		else
		{

			printf("wait!");
			etimer_set(&et, CLOCK_SECOND * 0.5 +  random_rand() % (CLOCK_SECOND) * 0.25);
				
			PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
		}	
		sprintf(buffer, "ping %d\0",i);
		
		printf("Attempting to send %s\n", buffer);

		// send the message straight to the radio
		//cc2420_send ( buffer, (int)strlen(buffer) );
		packetbuf_clear();

		packetbuf_copyfrom(&buffer, (int)strlen(buffer));
                //driver->on();
		//cc2420_driver.send(&buffer, (int)strlen(buffer));
		//cc2420_send ( &buffer, (int)strlen(buffer) );
		
		driver->send();
		
		//rime_output();		
		//abc_send(&abc);
		//chameleon_output(c);
		//driver->off(1);		
		printf("Message sent\n");
		leds_toggle(LEDS_YELLOW);

		i = i + 1;
	}

	PROCESS_END();
}
Example #23
0
void radio_set_channel(int channel) {
    cc2420_set_channel(channel);
}
Example #24
0
int
main()
{
  disableIRQ();
  disableFIQ();
  *AT91C_AIC_IDCR = 0xffffffff;
  *AT91C_PMC_PCDR = 0xffffffff;
  *AT91C_PMC_PCER = (1 << AT91C_ID_PIOA);
  
  dbg_setup_uart();
  printf("Initialising\n");
  leds_arch_init();
  clock_init();
  process_init();
  process_start(&etimer_process, NULL);
  ctimer_init();

  robot_stepper_init();

  enableIRQ();

  cc2420_init();
  cc2420_set_pan_addr(0x2024, 0, &uip_hostaddr.u16[1]);
  cc2420_set_channel(RF_CHANNEL);
  rime_init(nullmac_init(&cc2420_driver));
  printf("CC2420 setup done\n");

  rimeaddr_set_node_addr(&node_addr);
  
    #if WITH_UIP
  {
    uip_ipaddr_t hostaddr, netmask;
    
    uip_init();

    uip_ipaddr(&hostaddr, 172,16,
               rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]);
    uip_ipaddr(&netmask, 255,255,0,0);
    uip_ipaddr_copy(&meshif.ipaddr, &hostaddr);
    printf("Host addr\n");
    uip_sethostaddr(&hostaddr);
    uip_setnetmask(&netmask);
    uip_over_mesh_set_net(&hostaddr, &netmask);
    /*    uip_fw_register(&slipif);*/
    /*uip_over_mesh_set_gateway_netif(&slipif);*/
    uip_fw_default(&meshif);
    printf("Mesh init\n");
    uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
    printf("uIP started with IP address %d.%d.%d.%d\n",
           uip_ipaddr_to_quad(&hostaddr));
  }
#endif /* WITH_UIP */


#if WITH_UIP
  process_start(&tcpip_process, NULL);
  process_start(&uip_fw_process, NULL); /* Start IP output */
#endif /* WITH_UIP */
  
  printf("Heap size: %ld bytes\n", &__heap_end__ - (char*)sbrk(0));
  printf("Started\n");

  autostart_start(autostart_processes);
  printf("Processes running\n");
  while(1) {
    do {
      /* Reset watchdog. */
      wdt_reset();
    } while(process_run() > 0);
    /* Idle! */
    /* Stop processor clock */
    *AT91C_PMC_SCDR |= AT91C_PMC_PCK;
  }
  return 0;
}
/*--------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
  /*
   * Initalize hardware.
   */
  msp430_cpu_init();
  clock_init();
  leds_init();

  leds_on(LEDS_RED);

  uart1_init(BAUD2UBR(115200)); /* Must come before first printf */
#if WITH_UIP
  slip_arch_init(BAUD2UBR(115200));
#endif /* WITH_UIP */

  leds_on(LEDS_GREEN);
  /* xmem_init(); */
  
  rtimer_init();

  lcd_init();

  PRINTF(CONTIKI_VERSION_STRING "\n");
  /*
   * Hardware initialization done!
   */
  
  leds_on(LEDS_RED);
  /* Restore node id if such has been stored in external mem */

  //  node_id_restore();
#ifdef NODEID
  node_id = NODEID;

#ifdef BURN_NODEID
  flash_setup();
  flash_clear(0x1800);
  flash_write(0x1800, node_id);
  flash_done();
#endif /* BURN_NODEID */
#endif /* NODE_ID */

  if(node_id == 0) {
    node_id = *((unsigned short *)0x1800);
  }
  memset(node_mac, 0, sizeof(node_mac));
  node_mac[6] = node_id >> 8;
  node_mac[7] = node_id & 0xff;

  /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */
#ifdef MAC_1
  {
    uint8_t ieee[] = { MAC_1, MAC_2, MAC_3, MAC_4, MAC_5, MAC_6, MAC_7, MAC_8 };
    memcpy(node_mac, ieee, sizeof(uip_lladdr.addr));
  }
#endif

   /*
   * Initialize Contiki and our processes.
   */
  process_init();
  process_start(&etimer_process, NULL);

  ctimer_init();

  set_rime_addr();

  cc2420_init();

  {
    uint8_t longaddr[8];
    uint16_t shortaddr;

    shortaddr = (rimeaddr_node_addr.u8[0] << 8) +
      rimeaddr_node_addr.u8[1];
    memset(longaddr, 0, sizeof(longaddr));
    rimeaddr_copy((rimeaddr_t *)&longaddr, &rimeaddr_node_addr);
    printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
           longaddr[0], longaddr[1], longaddr[2], longaddr[3],
           longaddr[4], longaddr[5], longaddr[6], longaddr[7]);

    cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
  }

  cc2420_set_channel(RF_CHANNEL);

  leds_off(LEDS_ALL);

  if(node_id > 0) {
    PRINTF("Node id %u.\n", node_id);
  } else {
    PRINTF("Node id not set.\n");
  }

#if WITH_UIP6
  memcpy(&uip_lladdr.addr, node_mac, sizeof(uip_lladdr.addr));
  /* Setup nullmac-like MAC for 802.15.4 */

  queuebuf_init();

  NETSTACK_RDC.init();
  NETSTACK_MAC.init();
  NETSTACK_NETWORK.init();

  printf("%s %lu %u\n",
         NETSTACK_RDC.name,
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
                         NETSTACK_RDC.channel_check_interval()),
         RF_CHANNEL);

  process_start(&tcpip_process, NULL);

  printf("IPv6 ");
  {
    uip_ds6_addr_t *lladdr;
    int i;
    lladdr = uip_ds6_get_link_local(-1);
    for(i = 0; i < 7; ++i) {
      printf("%02x%02x:", lladdr->ipaddr.u8[i * 2],
             lladdr->ipaddr.u8[i * 2 + 1]);
    }
    printf("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
  }

  if(!UIP_CONF_IPV6_RPL) {
    uip_ipaddr_t ipaddr;
    int i;
    uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
    uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
    uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);
    printf("Tentative global IPv6 address ");
    for(i = 0; i < 7; ++i) {
      printf("%02x%02x:",
             ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
    }
    printf("%02x%02x\n",
           ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
  }

#else /* WITH_UIP6 */

  NETSTACK_RDC.init();
  NETSTACK_MAC.init();
  NETSTACK_NETWORK.init();

  printf("%s %lu %u\n",
         NETSTACK_RDC.name,
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1:
                         NETSTACK_RDC.channel_check_interval()),
         RF_CHANNEL);
#endif /* WITH_UIP6 */

#if !WITH_UIP6
  uart1_set_input(serial_line_input_byte);
  serial_line_init();
#endif

#if TIMESYNCH_CONF_ENABLED
  timesynch_init();
  timesynch_set_authority_level(rimeaddr_node_addr.u8[0]);
#endif /* TIMESYNCH_CONF_ENABLED */


  /*  process_start(&sensors_process, NULL);
      SENSORS_ACTIVATE(button_sensor);*/

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  print_processes(autostart_processes);
  autostart_start(autostart_processes);

  duty_cycle_scroller_start(CLOCK_SECOND * 2);

  /*
   * This is the scheduler loop.
   */
  watchdog_start();
  watchdog_stop(); /* Stop the wdt... */
  while(1) {
    int r;
    do {
      /* Reset watchdog. */
      watchdog_periodic();
      r = process_run();
    } while(r > 0);

    /*
     * Idle processing.
     */
    int s = splhigh();          /* Disable interrupts. */
    /* uart1_active is for avoiding LPM3 when still sending or receiving */
    if(process_nevents() != 0 || uart1_active()) {
      splx(s);                  /* Re-enable interrupts. */
    } else {
      static unsigned long irq_energest = 0;

      /* Re-enable interrupts and go to sleep atomically. */
      ENERGEST_OFF(ENERGEST_TYPE_CPU);
      ENERGEST_ON(ENERGEST_TYPE_LPM);
      /* We only want to measure the processing done in IRQs when we
         are asleep, so we discard the processing time done when we
         were awake. */
      energest_type_set(ENERGEST_TYPE_IRQ, irq_energest);
      watchdog_stop();
      _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This
                                              statement will block
                                              until the CPU is
                                              woken up by an
                                              interrupt that sets
                                              the wake up flag. */

      /* We get the current processing time for interrupts that was
         done during the LPM and store it for next time around.  */
      dint();
      irq_energest = energest_type_time(ENERGEST_TYPE_IRQ);
      eint();
      watchdog_start();
      ENERGEST_OFF(ENERGEST_TYPE_LPM);
      ENERGEST_ON(ENERGEST_TYPE_CPU);
    }
  }
}
Example #26
0
/*--------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
  /*
   * Initalize hardware.
   */
  msp430_cpu_init();
  clock_init();
  leds_init();

  leds_on(LEDS_RED);

  uart1_init(BAUD2UBR(115200)); /* Must come before first printf */

  leds_on(LEDS_GREEN);
  /* xmem_init(); */
  
  rtimer_init();

  lcd_init();

  watchdog_init();
  
  PRINTF(CONTIKI_VERSION_STRING "\n");
  /*  PRINTF("Compiled at %s, %s\n", __TIME__, __DATE__);*/

  /*
   * Hardware initialization done!
   */
  
  leds_on(LEDS_RED);

  /* Restore node id if such has been stored in external mem */
#ifdef NODEID
  node_id = NODEID;

#ifdef BURN_NODEID
  node_id_burn(node_id);
  node_id_restore(); /* also configures node_mac[] */
#endif /* BURN_NODEID */
#else
  node_id_restore(); /* also configures node_mac[] */
#endif /* NODE_ID */

  /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */
#ifdef MAC_1
  {
    uint8_t ieee[] = { MAC_1, MAC_2, MAC_3, MAC_4, MAC_5, MAC_6, MAC_7, MAC_8 };
    memcpy(node_mac, ieee, sizeof(uip_lladdr.addr));
  }
#endif

   /*
   * Initialize Contiki and our processes.
   */
  process_init();
  process_start(&etimer_process, NULL);

  ctimer_init();

  set_rime_addr();

  random_init(node_id);

  NETSTACK_RADIO.init();
#if CC11xx_CC1101 || CC11xx_CC1120
  printf("Starting up cc11xx radio at channel %d\n", RF_CHANNEL);
  cc11xx_channel_set(RF_CHANNEL);
#endif /* CC11xx_CC1101 || CC11xx_CC1120 */
#if CONFIGURE_CC2420 || CONFIGURE_CC2520
  {
    uint8_t longaddr[8];
    uint16_t shortaddr;

    shortaddr = (rimeaddr_node_addr.u8[0] << 8) + rimeaddr_node_addr.u8[1];
    memset(longaddr, 0, sizeof(longaddr));
    rimeaddr_copy((rimeaddr_t *)&longaddr, &rimeaddr_node_addr);
    printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", longaddr[0],
           longaddr[1], longaddr[2], longaddr[3], longaddr[4], longaddr[5],
           longaddr[6], longaddr[7]);

#if CONFIGURE_CC2420
    cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
#endif /* CONFIGURE_CC2420 */
#if CONFIGURE_CC2520
    cc2520_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
#endif /* CONFIGURE_CC2520 */
  }
#if CONFIGURE_CC2420
  cc2420_set_channel(RF_CHANNEL);
#endif /* CONFIGURE_CC2420 */
#if CONFIGURE_CC2520
  cc2520_set_channel(RF_CHANNEL);
#endif /* CONFIGURE_CC2520 */
#endif /* CONFIGURE_CC2420 || CONFIGURE_CC2520 */

  NETSTACK_RADIO.on();

  leds_off(LEDS_ALL);

  if(node_id > 0) {
    PRINTF("Node id %u.\n", node_id);
  } else {
    PRINTF("Node id not set.\n");
  }

#if WITH_UIP6
  memcpy(&uip_lladdr.addr, node_mac, sizeof(uip_lladdr.addr));
  /* Setup nullmac-like MAC for 802.15.4 */

  queuebuf_init();

  netstack_init();

  printf("%s/%s %lu %u\n",
         NETSTACK_RDC.name,
         NETSTACK_MAC.name,
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
                         NETSTACK_RDC.channel_check_interval()),
         RF_CHANNEL);

  process_start(&tcpip_process, NULL);

  printf("IPv6 ");
  {
    uip_ds6_addr_t *lladdr;
    int i;
    lladdr = uip_ds6_get_link_local(-1);
    for(i = 0; i < 7; ++i) {
      printf("%02x%02x:", lladdr->ipaddr.u8[i * 2],
             lladdr->ipaddr.u8[i * 2 + 1]);
    }
    printf("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
  }

  if(1) {
    uip_ipaddr_t ipaddr;
    int i;
    uip_ip6addr(&ipaddr, 0xfc00, 0, 0, 0, 0, 0, 0, 0);
    uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
    uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);
    printf("Tentative global IPv6 address ");
    for(i = 0; i < 7; ++i) {
      printf("%02x%02x:",
             ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
    }
    printf("%02x%02x\n",
           ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
  }

#else /* WITH_UIP6 */

  netstack_init();

  printf("%s %lu %u\n",
         NETSTACK_RDC.name,
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1:
                         NETSTACK_RDC.channel_check_interval()),
         RF_CHANNEL);
#endif /* WITH_UIP6 */

#if !WITH_UIP6
  uart1_set_input(serial_line_input_byte);
  serial_line_init();
#endif

#ifdef NETSTACK_AES_H
#ifndef NETSTACK_AES_KEY
#error Please define NETSTACK_AES_KEY!
#endif /* NETSTACK_AES_KEY */
  {
    const uint8_t key[] = NETSTACK_AES_KEY;
    netstack_aes_set_key(key);
  }
  /*printf("AES encryption is enabled: '%s'\n", NETSTACK_AES_KEY);*/
  printf("AES encryption is enabled\n");
#else /* NETSTACK_AES_H */
  printf("Warning: AES encryption is disabled\n");
#endif /* NETSTACK_AES_H */

#if TIMESYNCH_CONF_ENABLED
  timesynch_init();
  timesynch_set_authority_level(rimeaddr_node_addr.u8[0]);
#endif /* TIMESYNCH_CONF_ENABLED */


#if CC11xx_CC1101 || CC11xx_CC1120
  printf("cc11xx radio at channel %d\n", RF_CHANNEL);
  cc11xx_channel_set(RF_CHANNEL);
#endif /* CC11xx_CC1101 || CC11xx_CC1120 */
#if CONFIGURE_CC2420
  {
    uint8_t longaddr[8];
    uint16_t shortaddr;

    shortaddr = (rimeaddr_node_addr.u8[0] << 8) +
      rimeaddr_node_addr.u8[1];
    memset(longaddr, 0, sizeof(longaddr));
    rimeaddr_copy((rimeaddr_t *)&longaddr, &rimeaddr_node_addr);
    printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
           longaddr[0], longaddr[1], longaddr[2], longaddr[3],
           longaddr[4], longaddr[5], longaddr[6], longaddr[7]);

    cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
  }
  cc2420_set_channel(RF_CHANNEL);
#endif /* CONFIGURE_CC2420 */
  NETSTACK_RADIO.on();

  /*  process_start(&sensors_process, NULL);
      SENSORS_ACTIVATE(button_sensor);*/

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  simple_rpl_init();

  watchdog_start();

  print_processes(autostart_processes);
  autostart_start(autostart_processes);

  duty_cycle_scroller_start(CLOCK_SECOND * 2);

#if IP64_CONF_UIP_FALLBACK_INTERFACE_SLIP && WITH_SLIP
  /* Start the SLIP */
  printf("Initiating SLIP: my IP is 172.16.0.2...\n");
  slip_arch_init(0);
  {
    uip_ip4addr_t ipv4addr, netmask;

    uip_ipaddr(&ipv4addr, 172, 16, 0, 2);
    uip_ipaddr(&netmask, 255, 255, 255, 0);
    ip64_set_ipv4_address(&ipv4addr, &netmask);
  }
  uart1_set_input(slip_input_byte);
#endif /* IP64_CONF_UIP_FALLBACK_INTERFACE_SLIP */

  /*
   * This is the scheduler loop.
   */
  while(1) {
    int r;
    do {
      /* Reset watchdog. */
      watchdog_periodic();
      r = process_run();
    } while(r > 0);

    /*
     * Idle processing.
     */
    int s = splhigh();          /* Disable interrupts. */
    /* uart1_active is for avoiding LPM3 when still sending or receiving */
    if(process_nevents() != 0 || uart1_active()) {
      splx(s);                  /* Re-enable interrupts. */
    } else {
      static unsigned long irq_energest = 0;

      /* Re-enable interrupts and go to sleep atomically. */
      ENERGEST_OFF(ENERGEST_TYPE_CPU);
      ENERGEST_ON(ENERGEST_TYPE_LPM);
      /* We only want to measure the processing done in IRQs when we
         are asleep, so we discard the processing time done when we
         were awake. */
      energest_type_set(ENERGEST_TYPE_IRQ, irq_energest);
      watchdog_stop();
      _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This
                                              statement will block
                                              until the CPU is
                                              woken up by an
                                              interrupt that sets
                                              the wake up flag. */

      /* We get the current processing time for interrupts that was
         done during the LPM and store it for next time around.  */
      dint();
      irq_energest = energest_type_time(ENERGEST_TYPE_IRQ);
      eint();
      watchdog_start();
      ENERGEST_OFF(ENERGEST_TYPE_LPM);
      ENERGEST_ON(ENERGEST_TYPE_CPU);
    }
  }
}
Example #27
0
/*---------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
  /*
   * Initalize hardware.
   */
  msp430_cpu_init();
  clock_init();
  leds_init();
  leds_on(LEDS_RED);

  uart1_init(BAUD2UBR(115200)); /* Must come before first printf */
#if WITH_UIP
  slip_arch_init(BAUD2UBR(115200));
#endif /* WITH_UIP */

  leds_on(LEDS_GREEN);
  ds2411_init();

  /* XXX hack: Fix it so that the 802.15.4 MAC address is compatible
     with an Ethernet MAC address - byte 0 (byte 2 in the DS ID)
     cannot be odd. */
  ds2411_id[2] &= 0xfe;
  
  leds_on(LEDS_BLUE);
  xmem_init();

  leds_off(LEDS_RED);
  rtimer_init();
  /*
   * Hardware initialization done!
   */

  
  /* Restore node id if such has been stored in external mem */
  node_id_restore();

  random_init(ds2411_id[0] + node_id);
  
  leds_off(LEDS_BLUE);
  /*
   * Initialize Contiki and our processes.
   */
  process_init();
  process_start(&etimer_process, NULL);
  process_start(&sensors_process, NULL);

  /*
   * Initialize light and humidity/temp sensors.
   */
  sensors_light_init();
  battery_sensor.activate();
  sht11_init();

  ctimer_init();

  cc2420_init();
  cc2420_set_pan_addr(IEEE802154_PANID, 0 /*XXX*/, ds2411_id);
  cc2420_set_channel(RF_CHANNEL);

  printf(CONTIKI_VERSION_STRING " started. ");
  if(node_id > 0) {
    printf("Node id is set to %u.\n", node_id);
  } else {
    printf("Node id is not set.\n");
  }
  set_rime_addr();
  printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
	 ds2411_id[0], ds2411_id[1], ds2411_id[2], ds2411_id[3],
	 ds2411_id[4], ds2411_id[5], ds2411_id[6], ds2411_id[7]);

#if WITH_UIP6
  memcpy(&uip_lladdr.addr, ds2411_id, sizeof(uip_lladdr.addr));
  sicslowpan_init(sicslowmac_init(&cc2420_driver));
  process_start(&tcpip_process, NULL);
  printf(" %s channel %u\n", sicslowmac_driver.name, RF_CHANNEL);
#if UIP_CONF_ROUTER
  rime_init(rime_udp_init(NULL));
  uip_router_register(&rimeroute);
#endif /* UIP_CONF_ROUTER */
#else /* WITH_UIP6 */
  rime_init(MAC_DRIVER.init(&cc2420_driver));
  printf(" %s channel %u\n", rime_mac->name, RF_CHANNEL);
#endif /* WITH_UIP6 */

#if !WITH_UIP && !WITH_UIP6
  uart1_set_input(serial_line_input_byte);
  serial_line_init();
#endif

#if PROFILE_CONF_ON
  profile_init();
#endif /* PROFILE_CONF_ON */

  leds_off(LEDS_GREEN);

#if WITH_FTSP
  ftsp_init();
#endif /* WITH_FTSP */

#if TIMESYNCH_CONF_ENABLED
  timesynch_init();
  timesynch_set_authority_level(rimeaddr_node_addr.u8[0]);
#endif /* TIMESYNCH_CONF_ENABLED */

#if WITH_UIP
  process_start(&tcpip_process, NULL);
  process_start(&uip_fw_process, NULL);	/* Start IP output */
  process_start(&slip_process, NULL);

  slip_set_input_callback(set_gateway);

  {
    uip_ipaddr_t hostaddr, netmask;

    uip_init();

    uip_ipaddr(&hostaddr, 172,16,
	       rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]);
    uip_ipaddr(&netmask, 255,255,0,0);
    uip_ipaddr_copy(&meshif.ipaddr, &hostaddr);

    uip_sethostaddr(&hostaddr);
    uip_setnetmask(&netmask);
    uip_over_mesh_set_net(&hostaddr, &netmask);
    /*    uip_fw_register(&slipif);*/
    uip_over_mesh_set_gateway_netif(&slipif);
    uip_fw_default(&meshif);
    uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
    printf("uIP started with IP address %d.%d.%d.%d\n",
	   uip_ipaddr_to_quad(&hostaddr));
  }
#endif /* WITH_UIP */

  button_sensor.activate();

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  print_processes(autostart_processes);
  autostart_start(autostart_processes);

  /*
   * This is the scheduler loop.
   */
#if DCOSYNCH_CONF_ENABLED
  timer_set(&mgt_timer, DCOSYNCH_PERIOD * CLOCK_SECOND);
#endif
  watchdog_start();
  /*  watchdog_stop();*/
  while(1) {
    int r;
#if PROFILE_CONF_ON
    profile_episode_start();
#endif /* PROFILE_CONF_ON */
    do {
      /* Reset watchdog. */
      watchdog_periodic();
      r = process_run();
    } while(r > 0);
#if PROFILE_CONF_ON
    profile_episode_end();
#endif /* PROFILE_CONF_ON */

    /*
     * Idle processing.
     */
    int s = splhigh();		/* Disable interrupts. */
    /* uart1_active is for avoiding LPM3 when still sending or receiving */
    if(process_nevents() != 0 || uart1_active()) {
      splx(s);			/* Re-enable interrupts. */
    } else {
      static unsigned long irq_energest = 0;

#if DCOSYNCH_CONF_ENABLED
      /* before going down to sleep possibly do some management */
      if (timer_expired(&mgt_timer)) {
	timer_reset(&mgt_timer);
	msp430_sync_dco();
      }
#endif

      /* Re-enable interrupts and go to sleep atomically. */
      ENERGEST_OFF(ENERGEST_TYPE_CPU);
      ENERGEST_ON(ENERGEST_TYPE_LPM);
      /* We only want to measure the processing done in IRQs when we
	 are asleep, so we discard the processing time done when we
	 were awake. */
      energest_type_set(ENERGEST_TYPE_IRQ, irq_energest);
      watchdog_stop();
      _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This
					      statement will block
					      until the CPU is
					      woken up by an
					      interrupt that sets
					      the wake up flag. */

      /* We get the current processing time for interrupts that was
	 done during the LPM and store it for next time around.  */
      dint();
      irq_energest = energest_type_time(ENERGEST_TYPE_IRQ);
      eint();
      watchdog_start();
      ENERGEST_OFF(ENERGEST_TYPE_LPM);
      ENERGEST_ON(ENERGEST_TYPE_CPU);
    }
  }

  return 0;
}
/*---------------------------------------------------------------------------*/
#if WITH_TINYOS_AUTO_IDS
uint16_t TOS_NODE_ID = 0x1234; /* non-zero */
uint16_t TOS_LOCAL_ADDRESS = 0x1234; /* non-zero */
#endif /* WITH_TINYOS_AUTO_IDS */
int
main(int argc, char **argv)
{
  /*
   * Initalize hardware.
   */
  msp430_cpu_init();
  clock_init();
#if USE_LEDS
  leds_init();
  leds_on(LEDS_RED);
#endif

#if USE_SERIAL
  uart1_init(BAUD2UBR(115200)); /* Must come before first PRINTF */
#endif

#if USE_LEDS
  leds_on(LEDS_GREEN);
#endif
#if USE_ADDRESSING
  ds2411_init();

  /* XXX hack: Fix it so that the 802.15.4 MAC address is compatible
     with an Ethernet MAC address - byte 0 (byte 2 in the DS ID)
     cannot be odd. */
  ds2411_id[2] &= 0xfe;
#endif

#if USE_LEDS
  leds_on(LEDS_BLUE);
#endif
#if USE_XMEM
  xmem_init();
#endif

#if USE_LEDS
  leds_off(LEDS_RED);
#endif
#if USE_RTIMER
  rtimer_init();
#endif
  /*
   * Hardware initialization done!
   */

#if USE_ADDRESSING
  
#if WITH_TINYOS_AUTO_IDS
  node_id = TOS_NODE_ID;
#else /* WITH_TINYOS_AUTO_IDS */
  /* Restore node id if such has been stored in external mem */
  node_id_restore();
#endif /* WITH_TINYOS_AUTO_IDS */

#endif // USE_ADDRESSING

  /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */
#ifdef IEEE_802154_MAC_ADDRESS
  {
    uint8_t ieee[] = IEEE_802154_MAC_ADDRESS;
    memcpy(ds2411_id, ieee, sizeof(uip_lladdr.addr));
    ds2411_id[7] = node_id & 0xff;
  }
#endif

#if USE_RANDOM
  random_init(ds2411_id[0] + node_id);
#endif  

#if USE_LEDS
  leds_off(LEDS_BLUE);
#endif
  /*
   * Initialize Contiki and our processes.
   */
  process_init();
  process_start(&etimer_process, NULL);

#if USE_ALARMS
  ctimer_init();
#endif

#if WITH_UIP
  slip_arch_init(BAUD2UBR(115200));
#endif /* WITH_UIP */

  init_platform();

#if USE_ADDRESSING
  set_rime_addr();
#endif

#if USE_RADIO  
  cc2420_init();
#if USE_ADDRESSING
  {
    uint8_t longaddr[8];
    uint16_t shortaddr;
    
    shortaddr = (rimeaddr_node_addr.u8[0] << 8) +
      rimeaddr_node_addr.u8[1];
    memset(longaddr, 0, sizeof(longaddr));
    rimeaddr_copy((rimeaddr_t *)&longaddr, &rimeaddr_node_addr);
    PRINTF("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
           longaddr[0], longaddr[1], longaddr[2], longaddr[3],
           longaddr[4], longaddr[5], longaddr[6], longaddr[7]);
    
    cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
  }
#endif // USE_ADDRESSING
  cc2420_set_channel(RF_CHANNEL);
#endif // USE_RADIO

  PRINTF(CONTIKI_VERSION_STRING " started. ");
  if(node_id > 0) {
    PRINTF("Node id is set to %u.\n", node_id);
  } else {
    PRINTF("Node id is not set.\n");
  }

  /*  PRINTF("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
	 ds2411_id[0], ds2411_id[1], ds2411_id[2], ds2411_id[3],
	 ds2411_id[4], ds2411_id[5], ds2411_id[6], ds2411_id[7]);*/

#if WITH_UIP6
  memcpy(&uip_lladdr.addr, ds2411_id, sizeof(uip_lladdr.addr));
  /* Setup nullmac-like MAC for 802.15.4 */
/*   sicslowpan_init(sicslowmac_init(&cc2420_driver)); */
/*   PRINTF(" %s channel %u\n", sicslowmac_driver.name, RF_CHANNEL); */

  /* Setup X-MAC for 802.15.4 */
  queuebuf_init();
  NETSTACK_RDC.init();
  NETSTACK_MAC.init();
  NETSTACK_NETWORK.init();

  PRINTF("%s %s, channel check rate %lu Hz, radio channel %u\n",
         NETSTACK_MAC.name, NETSTACK_RDC.name,
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
                         NETSTACK_RDC.channel_check_interval()),
         RF_CHANNEL);

  process_start(&tcpip_process, NULL);

  PRINTF("Tentative link-local IPv6 address ");
  {
    uip_ds6_addr_t *lladdr;
    int i;
    lladdr = uip_ds6_get_link_local(-1);
    for(i = 0; i < 7; ++i) {
      PRINTF("%02x%02x:", lladdr->ipaddr.u8[i * 2],
             lladdr->ipaddr.u8[i * 2 + 1]);
    }
    PRINTF("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
  }

  if(!UIP_CONF_IPV6_RPL) {
    uip_ipaddr_t ipaddr;
    int i;
    uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
    uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
    uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);
    PRINTF("Tentative global IPv6 address ");
    for(i = 0; i < 7; ++i) {
      PRINTF("%02x%02x:",
             ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
    }
    PRINTF("%02x%02x\n",
           ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
  }

#else /* WITH_UIP6 */

#if CONTIKI_MY_OPTIMIZATIONS
  // disable net completely, totally and fully
#else
  NETSTACK_RDC.init();
  NETSTACK_MAC.init();
  NETSTACK_NETWORK.init();

  PRINTF("%s %s, channel check rate %lu Hz, radio channel %u\n",
         NETSTACK_MAC.name, NETSTACK_RDC.name,
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1:
                         NETSTACK_RDC.channel_check_interval()),
         RF_CHANNEL);
#endif
#endif /* WITH_UIP6 */

#if USE_SERIAL
#if !WITH_UIP && !WITH_UIP6
  uart1_set_input(serial_line_input_byte);
  serial_line_init();
#endif
#endif

#if PROFILE_CONF_ON
  profile_init();
#endif /* PROFILE_CONF_ON */

#if USE_LEDS
  leds_off(LEDS_GREEN);
#endif

#if TIMESYNCH_CONF_ENABLED
  timesynch_init();
  timesynch_set_authority_level((rimeaddr_node_addr.u8[0] << 4) + 16);
#endif /* TIMESYNCH_CONF_ENABLED */

#if WITH_UIP
  process_start(&tcpip_process, NULL);
  process_start(&uip_fw_process, NULL);	/* Start IP output */
  process_start(&slip_process, NULL);

  slip_set_input_callback(set_gateway);

  {
    uip_ipaddr_t hostaddr, netmask;

    uip_init();

    uip_ipaddr(&hostaddr, 172,16,
	       rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]);
    uip_ipaddr(&netmask, 255,255,0,0);
    uip_ipaddr_copy(&meshif.ipaddr, &hostaddr);

    uip_sethostaddr(&hostaddr);
    uip_setnetmask(&netmask);
    uip_over_mesh_set_net(&hostaddr, &netmask);
    /*    uip_fw_register(&slipif);*/
    uip_over_mesh_set_gateway_netif(&slipif);
    uip_fw_default(&meshif);
    uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
    PRINTF("uIP started with IP address %d.%d.%d.%d\n",
	   uip_ipaddr_to_quad(&hostaddr));
  }
#endif /* WITH_UIP */

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  watchdog_start();

#if USE_SERIAL
#if !PROCESS_CONF_NO_PROCESS_NAMES
  print_processes(autostart_processes);
#else /* !PROCESS_CONF_NO_PROCESS_NAMES */
  putchar('\n'); /* include putchar() */
#endif /* !PROCESS_CONF_NO_PROCESS_NAMES */
#endif
  autostart_start(autostart_processes);

  /*
   * This is the scheduler loop.
   */
#if DCOSYNCH_CONF_ENABLED
  timer_set(&mgt_timer, DCOSYNCH_PERIOD * CLOCK_SECOND);
#endif

  /*  watchdog_stop();*/
  while(1) {
    int r;
#if PROFILE_CONF_ON
    profile_episode_start();
#endif /* PROFILE_CONF_ON */
    do {
      /* Reset watchdog. */
      watchdog_periodic();
      r = process_run();
    } while(r > 0);
#if PROFILE_CONF_ON
    profile_episode_end();
#endif /* PROFILE_CONF_ON */

    /*
     * Idle processing.
     */
    int s = splhigh();		/* Disable interrupts. */
    /* uart1_active is for avoiding LPM3 when still sending or receiving */
    if(process_nevents() != 0
#if USE_SERIAL
 || uart1_active()
#endif
) {
      splx(s);			/* Re-enable interrupts. */
    } else {
      static unsigned long irq_energest = 0;

#if DCOSYNCH_CONF_ENABLED
      /* before going down to sleep possibly do some management */
      if(timer_expired(&mgt_timer)) {
        watchdog_periodic();
	timer_reset(&mgt_timer);
	msp430_sync_dco();
#if CC2420_CONF_SFD_TIMESTAMPS
        cc2420_arch_sfd_init();
#endif /* CC2420_CONF_SFD_TIMESTAMPS */
      }
#endif
      
      /* Re-enable interrupts and go to sleep atomically. */
      ENERGEST_OFF(ENERGEST_TYPE_CPU);
      ENERGEST_ON(ENERGEST_TYPE_LPM);
      /* We only want to measure the processing done in IRQs when we
	 are asleep, so we discard the processing time done when we
	 were awake. */
      energest_type_set(ENERGEST_TYPE_IRQ, irq_energest);
      watchdog_stop();
      /* check if the DCO needs to be on - if so - only LPM 1 */
      if (msp430_dco_required) {
	_BIS_SR(GIE | CPUOFF); /* LPM1 sleep for DMA to work!. */
      } else {
	_BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This
						statement will block
						until the CPU is
						woken up by an
						interrupt that sets
						the wake up flag. */
      }
      /* We get the current processing time for interrupts that was
	 done during the LPM and store it for next time around.  */
      dint();
      irq_energest = energest_type_time(ENERGEST_TYPE_IRQ);
      eint();
      watchdog_start();
      ENERGEST_OFF(ENERGEST_TYPE_LPM);
      ENERGEST_ON(ENERGEST_TYPE_CPU);
    }
  }

  return 0;
}
Example #29
0
/*---------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
  /*
   * Initalize hardware.
   */
  msp430_cpu_init();
  clock_init();
  leds_init();
  leds_toggle(LEDS_RED | LEDS_GREEN | LEDS_BLUE);
  
#if WITH_UIP
  slip_arch_init(BAUD2UBR(115200)); /* Must come before first printf */
#else /* WITH_UIP */
  uart1_init(BAUD2UBR(115200)); /* Must come before first printf */
#endif /* WITH_UIP */
  
  printf("Starting %s "
	 "($Id: contiki-sky-main.c,v 1.9 2009/11/20 10:45:07 nifi Exp $)\n", __FILE__);
  ds2411_init();
  xmem_init();
  leds_toggle(LEDS_RED | LEDS_GREEN | LEDS_BLUE);

  rtimer_init();
  /*
   * Hardware initialization done!
   */

  /* Restore node id if such has been stored in external mem */
//  node_id_burn(3);
  node_id_restore();
  printf("node_id : %hu\n", node_id);

  printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
	 ds2411_id[0], ds2411_id[1], ds2411_id[2], ds2411_id[3],
	 ds2411_id[4], ds2411_id[5], ds2411_id[6], ds2411_id[7]);

#if WITH_UIP
  uip_init();
  uip_sethostaddr(&slipif.ipaddr);
  uip_setnetmask(&slipif.netmask);
  uip_fw_default(&slipif);	/* Point2point, no default router. */
#endif /* WITH_UIP */

  /*
   * Initialize Contiki and our processes.
   */
  process_init();
  process_start(&etimer_process, NULL);
  process_start(&sensors_process, NULL);

  /*
   * Initialize light and humidity/temp sensors.
   */
  SENSORS_ACTIVATE(light_sensor);
  SENSORS_ACTIVATE(sht11_sensor);

  ctimer_init();

  set_rime_addr();

  cc2420_init();
  cc2420_set_pan_addr(panId, 0 /*XXX*/, ds2411_id);
  cc2420_set_channel(RF_CHANNEL);

  cc2420_set_txpower(31);
  nullmac_init(&cc2420_driver);
  rime_init(&nullmac_driver);
//  xmac_init(&cc2420_driver);
//  rime_init(&xmac_driver);

  /*  rimeaddr_set_node_addr*/
#if WITH_UIP
  process_start(&tcpip_process, NULL);
  process_start(&uip_fw_process, NULL);	/* Start IP output */
  process_start(&slip_process, NULL);
#endif /* WITH_UIP */

  SENSORS_ACTIVATE(button_sensor);
  
  print_processes(autostart_processes);
  autostart_start(autostart_processes);

  energest_init();
  
  /*
   * This is the scheduler loop.
   */
  printf("process_run()...\n");
  ENERGEST_ON(ENERGEST_TYPE_CPU);
  while (1) {
    do {
      /* Reset watchdog. */
    } while(process_run() > 0);

    /*
     * Idle processing.
     */
    if(lpm_en) {
    int s = splhigh();		/* Disable interrupts. */
    if(process_nevents() != 0) {
      splx(s);			/* Re-enable interrupts. */
    } else {
    	
      static unsigned long irq_energest = 0;
      /* Re-enable interrupts and go to sleep atomically. */
      ENERGEST_OFF(ENERGEST_TYPE_CPU);
      ENERGEST_ON(ENERGEST_TYPE_LPM);
      /* We only want to measure the processing done in IRQs when we
	 are asleep, so we discard the processing time done when we
	 were awake. */
      energest_type_set(ENERGEST_TYPE_IRQ, irq_energest);
      _BIS_SR(GIE | SCG0 | /*SCG1 |*/ CPUOFF); /* LPM3 sleep. */
      /* We get the current processing time for interrupts that was
	 done during the LPM and store it for next time around.  */
      dint();
      irq_energest = energest_type_time(ENERGEST_TYPE_IRQ);
      eint();
      ENERGEST_OFF(ENERGEST_TYPE_LPM);
      ENERGEST_ON(ENERGEST_TYPE_CPU);
    }
    }
  }

  return 0;
}