Beispiel #1
0
int
main(void)
{
#if WITH_SD
  int r;
#endif /* WITH_SD */

  msp430_cpu_init();	
  watchdog_stop();

  /* Platform-specific initialization. */
  msb_ports_init();
  adc_init();

  clock_init();
  rtimer_init();

  sht11_init();
  leds_init();
  leds_on(LEDS_ALL);

  irq_init();
  process_init();

  /* serial interface */
  rs232_set_input(serial_line_input_byte);
  rs232_init();
  serial_line_init();

  uart_lock(UART_MODE_RS232);
  uart_unlock(UART_MODE_RS232);
#if WITH_UIP
  slip_arch_init(BAUD2UBR(115200));
#endif


#if WITH_SD
  r = sd_initialize();
  if(r < 0) {
    printf("Failed to initialize the SD driver: %s\n", sd_error_string(r));
  } else {
    sd_offset_t capacity;
    printf("The SD driver was successfully initialized\n");
    capacity = sd_get_capacity();
    if(capacity < 0) {
      printf("Failed to get the SD card capacity: %s\n", sd_error_string(r));
    } else {
      printf("SD card capacity: %u MB\n",
	(unsigned)(capacity / (1024UL * 1024)));
    }
  }
#endif

  /* System services */
  process_start(&etimer_process, NULL);
  ctimer_init();

  node_id_restore();

  init_net();

  energest_init();
 
#if PROFILE_CONF_ON
  profile_init();
#endif /* PROFILE_CONF_ON */
 
  leds_off(LEDS_ALL);

  printf(CONTIKI_VERSION_STRING " started. Node id %u, using %s.\n", 
         node_id, rime_mac->name);

  autostart_start(autostart_processes);

  /*
   * This is the scheduler loop.
   */
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  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. */
    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);

      if (uart_edge) {
	_BIC_SR(LPM1_bits + GIE);
      } else {
	_BIS_SR(LPM1_bits + GIE);
      }

      /*
       * 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);
#if PROFILE_CONF_ON
      profile_clear_timestamps();
#endif /* PROFILE_CONF_ON */
    }
  }

  return 0;
}
Beispiel #2
0
/*---------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
  /*
   * Initalize hardware.
   */
  msp430_cpu_init();
  clock_init();
  leds_init();
  leds_on(LEDS_RED);

  clock_wait(100);

  uart0_init(BAUD2UBR(UART0_BAUD_RATE)); /* Must come before first printf */
#if NETSTACK_CONF_WITH_IPV4
  slip_arch_init(BAUD2UBR(UART0_BAUD_RATE));
#endif /* NETSTACK_CONF_WITH_IPV4 */

  xmem_init();

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

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

  /* If no MAC address was burned, we use the node id or the Z1 product ID */
  if(!(node_mac[0] | node_mac[1] | node_mac[2] | node_mac[3] |
       node_mac[4] | node_mac[5] | node_mac[6] | node_mac[7])) {

#ifdef SERIALNUM
    if(!node_id) {
      PRINTF("Node id is not set, using Z1 product ID\n");
      node_id = SERIALNUM;
    }
#endif
    node_mac[0] = 0xc1;  /* Hardcoded for Z1 */
    node_mac[1] = 0x0c;  /* Hardcoded for Revision C */
    node_mac[2] = 0x00;  /* Hardcoded to arbitrary even number so that
                            the 802.15.4 MAC address is compatible with
                            an Ethernet MAC address - byte 0 (byte 2 in
                            the DS ID) */
    node_mac[3] = 0x00;  /* Hardcoded */
    node_mac[4] = 0x00;  /* Hardcoded */
    node_mac[5] = 0x00;  /* Hardcoded */
    node_mac[6] = node_id >> 8;
    node_mac[7] = node_id & 0xff;
  }

  /* Overwrite node MAC if desired at compile time */
#ifdef MACID
#warning "***** CHANGING DEFAULT MAC *****"
  node_mac[0] = 0xc1;  /* Hardcoded for Z1 */
  node_mac[1] = 0x0c;  /* Hardcoded for Revision C */
  node_mac[2] = 0x00;  /* Hardcoded to arbitrary even number so that
                          the 802.15.4 MAC address is compatible with
                          an Ethernet MAC address - byte 0 (byte 2 in
                          the DS ID) */
  node_mac[3] = 0x00;  /* Hardcoded */
  node_mac[4] = 0x00;  /* Hardcoded */
  node_mac[5] = 0x00;  /* Hardcoded */
  node_mac[6] = MACID >> 8;
  node_mac[7] = MACID & 0xff;
#endif

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

  /*
   * Initialize Contiki and our processes.
   */
  random_init(node_mac[6] + node_mac[7]);
  process_init();
  process_start(&etimer_process, NULL);

  ctimer_init();

  init_platform();

  set_rime_addr();

  cc2420_init();
  SENSORS_ACTIVATE(adxl345);

  {
    uint8_t longaddr[8];
    uint16_t shortaddr;

    shortaddr = (linkaddr_node_addr.u8[0] << 8) +
      linkaddr_node_addr.u8[1];
    memset(longaddr, 0, sizeof(longaddr));
    linkaddr_copy((linkaddr_t *)&longaddr, &linkaddr_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);
  }

  leds_off(LEDS_ALL);

#ifdef SERIALNUM
  PRINTF("Ref ID: %u\n", SERIALNUM);
#endif
  PRINTF(CONTIKI_VERSION_STRING " started. ");

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

#if NETSTACK_CONF_WITH_IPV6
  memcpy(&uip_lladdr.addr, node_mac, 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, CC2420_CONF_CHANNEL); */

  /* Setup X-MAC for 802.15.4 */
  queuebuf_init();

	netstack_init();
//  NETSTACK_RDC.init();
//  NETSTACK_MAC.init();
//  NETSTACK_LLSEC.init();
//  NETSTACK_NETWORK.init();

  printf("%s %s %s, channel check rate %lu Hz, radio channel %u\n",
         NETSTACK_LLSEC.name, NETSTACK_MAC.name, NETSTACK_RDC.name,
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1 :
                         NETSTACK_RDC.channel_check_interval()),
         CC2420_CONF_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, UIP_DS6_DEFAULT_PREFIX, 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 /* NETSTACK_CONF_WITH_IPV6 */

	netstack_init();
  //NETSTACK_RDC.init();
  //NETSTACK_MAC.init();
  //NETSTACK_LLSEC.init();
  //NETSTACK_NETWORK.init();

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

#if !NETSTACK_CONF_WITH_IPV4 && !NETSTACK_CONF_WITH_IPV6
  uart0_set_input(serial_line_input_byte);
  serial_line_init();
#endif

  leds_off(LEDS_GREEN);

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

#if NETSTACK_CONF_WITH_IPV4
  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,
               linkaddr_node_addr.u8[0], linkaddr_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 /* NETSTACK_CONF_WITH_IPV4 */

  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;
    do {
      /* Reset watchdog. */
      watchdog_periodic();
      r = process_run();
    } while(r > 0);

    /*
     * Idle processing.
     */
    int s = splhigh();    /* Disable interrupts. */
    /* uart0_active is for avoiding LPM3 when still sending or receiving */
    if(process_nevents() != 0 || uart0_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_SWITCH(ENERGEST_TYPE_CPU, 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_SWITCH(ENERGEST_TYPE_LPM, ENERGEST_TYPE_CPU);
    }
  }

  return 0;
}
Beispiel #3
0
int main(void)
{
    WDTCTL = WDTPW+WDTHOLD;

    set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();
    set_aclk_div(1);

    LEDS_INIT();
    LEDS_OFF();


    ds2411_init();
    nodeaddr = (((uint16_t)ds2411_id.serial1)<<8) + (ds2411_id.serial0);

    uart0_init(UART0_CONFIG_1MHZ_115200);
    uart0_register_callback(char_rx);
    eint();

    printf("[APP];BOOTING;%.4x\n",nodeaddr);


    //check if this node is the sink
    if (nodeaddr == sink_nodes)
    {
        type = SINK;
        level = DEFAULT_LEVEL;
    }
    else
    {
        //retrieve father
        for (idx=0; idx<NUMBER_NODES; idx++)
        {
            if (list_nodes[idx] == nodeaddr)
            {
                if(father_nodes1[idx] != 0x0000)
                {
                    parent_id = father_nodes1[idx];
                    level = 12;
                    break;
                }
            }
        }
    }
    
    //hack for mobile
    /*if(nodeaddr == 0x1f5d)
    {
        parent_id = 0x0000;
        mac_set_mobile(1);
        level = 12;
    }*/

    mac_init(10);
    mac_set_rx_cb(packet_received);
    mac_set_error_cb(packet_error);
    mac_set_sent_cb(packet_sent);

    timerB_set_alarm_from_now(TIMERB_ALARM_CCR6, 32768, 32768);
    timerB_register_cb(TIMERB_ALARM_CCR6, inc_clock);

    while (1)
    {
        LPM1;

        if (state == SM_TX)
        {
            if (level != UNDEF_LEVEL && type != SINK)
            {
                seq_max = NUM_SEQ_MAX;
                delay = rand();
                delay &= 0xCFFF;
                delay += 12000; //(369ms < delay < 1991ms)
                timerB_set_alarm_from_now(TIMERB_ALARM_CCR5, delay, 0);
                timerB_register_cb(TIMERB_ALARM_CCR5, next_send);
            }
            else
            {
                printf("[APP];NOROUTE\n");
            }

            state = SM_IDLE;
        }
        else if (state == SM_LOOP_TX)
        {
            if (level != UNDEF_LEVEL)
            {
                sprintf(sourceaddr,"%.4x",nodeaddr);
                data_txframe[0] = DATA;
                data_txframe[1] = level-1;
                data_txframe[2] = sourceaddr[0];
                data_txframe[3] = sourceaddr[1];
                data_txframe[4] = sourceaddr[2];
                data_txframe[5] = sourceaddr[3];
                data_txframe[6] = seq;	//sequence
                data_txframe[7] = 1;    //hops
                txlength = 8;

                stat_add(STAT_APP_TX);
                printf("[APP];NODE_TX;%.4x;%.4x;%u;%u-%u\n", nodeaddr, parent_id, seq, global_clock, timerB_time()/32);

                seq++;

                mac_send(data_txframe, txlength, parent_id);

                if (DEBUG_LEDS == 1)
                {
                    LED_GREEN_ON();
                }

                if (seq < seq_max)
                {
                    timerB_set_alarm_from_now(TIMERB_ALARM_CCR5, SEND_DATA_PERIOD, 0);
                    timerB_register_cb(TIMERB_ALARM_CCR5, next_send);
                }
            }
            state = SM_IDLE;
        }
     
    }

    return 0;
}
Beispiel #4
0
/**
 * The main function.
 */
int main( void )
{
	/* Stop the watchdog timer. */
	WDTCTL = WDTPW + WDTHOLD;
	
	/* Setup MCLK 8MHz and SMCLK 1MHz */
	set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();
	
	/* Enable Interrupts */
	eint();
	
	uart0_init(UART0_CONFIG_1MHZ_115200);
	uart0_register_callback(char_cb);
	printf("CC1100 RXTX test program\r\n");
	
	LEDS_INIT();
	LEDS_OFF();
	
	cc1100_init();
	
	cc1100_cfg_append_status(CC1100_APPEND_STATUS_ENABLE);
	cc1100_cfg_crc_autoflush(CC1100_CRC_AUTOFLUSH_DISABLE);
	cc1100_cfg_white_data(CC1100_DATA_WHITENING_ENABLE);
	cc1100_cfg_crc_en(CC1100_CRC_CALCULATION_ENABLE);
	cc1100_cfg_freq_if(0x0C);
	cc1100_cfg_fs_autocal(CC1100_AUTOCAL_NEVER);
	
	cc1100_cfg_mod_format(CC1100_MODULATION_MSK);
	
	cc1100_cfg_sync_mode(CC1100_SYNCMODE_30_32);
	
	cc1100_cfg_manchester_en(CC1100_MANCHESTER_DISABLE);
	
	printf("CC1100 initialized\r\nType 's' to send a message\r\n");
	
	while(1)
	{
		// Enter RX
		LED_RED_ON();
		cc1100_cmd_idle();
		cc1100_cmd_flush_rx();
		cc1100_cmd_calibrate();
		cc1100_cmd_rx();
		
		cc1100_cfg_gdo0(CC1100_GDOx_SYNC_WORD);
		cc1100_gdo0_int_set_falling_edge();
		cc1100_gdo0_int_clear();
		cc1100_gdo0_int_enable();
		cc1100_gdo0_register_callback(rx_ok);
		
		// Low Power Mode
		LPM0;
		
		// Check for send flag
		if (send == 1) {
			send = 0;
			LED_RED_OFF();
			cc1100_cmd_idle();
			cc1100_cmd_flush_tx();
			cc1100_cmd_calibrate();
			cc1100_gdo0_int_disable();
			
			frameseq ++;
			
			length = sprintf((char *)frame, "Hello World #%i", frameseq);
			
			printf("Sent : %s \r\n", frame);
			
			cc1100_fifo_put(&length, 1);
			cc1100_fifo_put(frame, length);
			
			cc1100_cmd_tx();
			
			// Wait for SYNC word sent
			while (cc1100_gdo0_read() == 0);
			
			// Wait for end of packet
			while (cc1100_gdo0_read() != 0);
		}
		
		// Check for receive flag
		if (receive == 1) {
			receive = 0;
			uint8_t i;

			// verify CRC result
			if ( !(cc1100_status_crc_lqi() & 0x80) ) {
				continue;
			}

			cc1100_fifo_get(&length, 1);
			
			if (length > 60) {
				continue;
			}
			
			cc1100_fifo_get(frame, length+2);

			uint16_t rssi = (uint16_t)frame[length];
			int16_t rssi_d;

			if (rssi >= 128)
				rssi_d = (rssi-256)-140;
			else
				rssi_d = rssi-140;

			printf("Frame received with RSSI=%d.%d dBm: ", rssi_d, 5*(rssi_d&0x1));
			for (i=0; i<length; i++) {
				printf("%c",frame[i]);
			}
			printf("\r\n");

			LED_GREEN_TOGGLE();
		}
	}
	
	return 0;
}
Beispiel #5
0
PROCESS_THREAD(scanning, ev, data)
{
 PROCESS_BEGIN();
 
 // Initial operations
 leds_off(LEDS_ALL);
 watchdog_stop(); 
 
 // Avoiding wrong RSSI readings
 unsigned temp;
 CC2420_READ_REG(CC2420_AGCTST1, temp);
 CC2420_WRITE_REG(CC2420_AGCTST1, (temp + (1 << 8) + (1 << 13))); 
 
 // Selecting the channel	
 SPI_SETCHANNEL_SUPERFAST(357+((CHANNEL-11)*5));
 
 // Avoiding the initial wrong readings by discarding the wrong readings
 CC2420_SPI_ENABLE();
 unsigned long k=0;
 for (k=0; k<=15; k++) {MY_FASTSPI_GETRSSI(temp);}
 CC2420_SPI_DISABLE(); 
 
 static struct etimer et;
 while(1){
	 	 
	 #if VERBOSE
	 printf("#START (dBm: occurrencies)\n");
	 #endif
	 
	 // Resetting everything
	 for(k=0;k<BUFFER_SIZE;k++){	
		buffer0[k] = 0;
	 }
	 
	 dint();				// Disable interrupts
	 boost_cpu(); 			// Temporarily boost CPU speed
	 CC2420_SPI_ENABLE(); 	// Enable SPI
	
	 // Actual scanning 
	 static signed char rssi;
	 for(k=0; k<MAX_VALUE; k++){		
		MY_FASTSPI_GETRSSI(rssi);	
		buffer0[rssi+55]++;
	 }	
 
	 CC2420_SPI_DISABLE();	// Disable SPI
	 restore_cpu();			// Restore CPU speed
	 eint(); 				// Re-enable interrupts
 
	 // Printing the stored values in compressed form 
	 unsigned long sum_cca = 0;
	 unsigned long max = 0, max_value = 0;
	 for(temp=0; temp<BUFFER_SIZE; temp++) {	
		sum_cca += (temp * buffer0[temp]);
		if(buffer0[temp] > max){
			max = buffer0[temp];
			max_value = temp;
		}		
	 }
	 
	 // Printing the results of the CCA
	 float f_cca = (((float) sum_cca*1.0000) / MAX_VALUE)-100.0000;		
	 #if VERBOSE
		printf("Average noise: %ld.%04u\nStatistic Mode noise: %ld\n", (long) f_cca, (unsigned)((f_cca-floor(f_cca))*10000), max_value-100);
	 #else
		printf("%ld.%04u\n", (long) f_cca, (unsigned)((f_cca-floor(f_cca))*10000));
	 #endif
	 
	 #if VERBOSE
		printf("#END\n");
	 #endif
	 
	 // Waiting for timer
	 etimer_set(&et, PERIOD_TIME);
	 PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));	
 
 }
 
 PROCESS_WAIT_EVENT();
 
 PROCESS_END();
}
/**
 * Application main entry point
 *
 * Initialize device drivers, start applications and handle
 * cooperative scheduling. If no task is requiring CPU time, the
 * controller enters low power mode.
 */
int
main(void)
{
  msp430_cpu_init();
  watchdog_stop();

  /* Platform-specific initialization. */
  msb_ports_init();
  adc_reset();

  clock_init();
  rtimer_init();

// use XT2 as main clock, set clock divder for SMCLK to 1
// MLCK:   8 MHz
// SMCLK:  8 MHz
// ACLK:  32.768 kHz
  BCSCTL1 = RSEL2 | RSEL1 | RSEL0;
  BCSCTL2 = SELM1 | SELS;

  leds_init();
  leds_on(LEDS_ALL);

  bluetooth_disable();
  mma7361_init();

  process_init();

  /* System timers */
  process_start(&etimer_process, NULL);
  ctimer_init();

  leds_off(LEDS_ALL);

  ds2411_init();

  /* Overwrite unique id, this was taken from the original Shimmer software */
  /* University of California Berkeley's OUI */
  ds2411_id[0] = 0x00;
  ds2411_id[1] = 0x12;
  ds2411_id[2] = 0x6d;

  /* Following two octets must be 'LO' -- "local" in order to use UCB's OUI */
  ds2411_id[3] = 'L';
  ds2411_id[4] = 'O';

  autostart_start(autostart_processes);

  /*
   * This is the scheduler loop.
   */
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  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. */
    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);

      watchdog_stop();

      /*
       * If a Bluetooth transmission is running, go only to LPM0.
       * LPM1 and higher interrupt running UART communications.
       */
      if (bluetooth_active()) {
        _BIS_SR(GIE | LPM0_bits);
      } else {
        _BIS_SR(GIE | LPM1_bits);
      }

      watchdog_start();

      /*
       * 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);
#if PROFILE_CONF_ON
      profile_clear_timestamps();
#endif /* PROFILE_CONF_ON */
    }
  }

  return 0;
}
Beispiel #7
0
/**
 * The main function.
 */
int main( void )
{
    // Stop the watchdog timer.
    WDTCTL = WDTPW + WDTHOLD;

    // Setup MCLK 8MHz and SMCLK 1MHz
    set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();
    set_aclk_div(8); // ACKL is at 4096Hz

    // Initialize the LEDs
    LEDS_INIT();
    LEDS_OFF();

    // Initialize the temperature sensor
    ds1722_init();
    ds1722_set_res(12);
    ds1722_sample_cont();

    // Initialier the Luminosity sensor
    tsl2550_init();
    tsl2550_powerup();
    tsl2550_set_standard();
    tsl2550_read_adc0();

    // Initialize the UART0
    uart0_init(UART0_CONFIG_1MHZ_115200); // We want 115kbaud,
                                          // and SMCLK is running at 1MHz
    uart0_register_callback(char_rx);   // Set the UART callback function
                                        // it will be called every time a
                                        // character is received.

    // Print first message
    printf("Senslab TP Ex2: UART\n");

    // Enable Interrupts
    eint();

    // Print information
    printf("Type command\n");
    printf("\tt:\ttemperature measure\n");
    printf("\tl:\tluminosity measure\n");

    // Declare 2 variables for storing the different values
    int16_t value_0, value_1;
    while (1) {
        printf("cmd > ");
        cmd = 0;

        while (cmd==0) {
            LPM1; // Low Power Mode 1: SMCLK remains active for UART
        }

        switch (cmd) {
        case 't':
            value_0 = ds1722_read_MSB();
            value_1 = ds1722_read_LSB();
            value_1 >>= 5;
            value_1 *= 125;
            printf("Temperature measure: %i.%i\n", value_0, value_1);
            break;
        case 'l':
            tsl2550_init();
            value_0 = tsl2550_read_adc0();
            value_1 = tsl2550_read_adc1();
            uart0_init(UART0_CONFIG_1MHZ_115200);
            uart0_register_callback(char_rx);
            printf("Luminosity measure: %i:%i\n", value_0, value_1);
            break;
        default:
            break;
        }
    }

    return 0;
}
Beispiel #8
0
/* Main function */
int main(void)
{
	sc_time_t my_timer;

	P5OUT = CAN_CS;
	dint();
	WDTCTL = WDTCTL_INIT;               //Init watchdog timer
	init_ports();
	init_clock();
	sc_init_timer();
	UART_Init();
	scandal_init(); 
	eint();
  
	/* Set the tyremaster to use  4800 baud */
	UART_baud_rate(2400, CLOCK_SPEED);
	
	my_timer = sc_get_timer();

	while(1) {
		handle_scandal();
		
		if(UART_is_received()) {
			uint8_t preamble, tyre_id, air_temp, batt_voltage, chksum, chksum_data, tyre_pressure_0, tyre_pressure_1;
			uint16_t tyre_pressure;

			preamble = UART_ReceiveByte();

			if(preamble == 0xAA) {
				
				tyre_id = UART_ReceiveByte(); 			// the tyre
				tyre_pressure_0 = UART_ReceiveByte();		// pressure low byte
				tyre_pressure_1 = UART_ReceiveByte();		// pressure hi byte
				air_temp = UART_ReceiveByte();			// air temp
				batt_voltage = UART_ReceiveByte();		// batt voltage
				chksum = UART_ReceiveByte();			// chksum
			
				chksum_data = tyre_id + air_temp + tyre_pressure_0 + tyre_pressure_1 + batt_voltage;

				if(chksum == chksum_data) { 
					tyre_pressure = (tyre_pressure_1 << 8) | tyre_pressure_0;
					
					toggle_red_led();
					scandal_send_channel(TELEM_LOW, tyre_id + TYREMASTER_PRESSURE,
							((uint32_t)tyre_pressure)*2970);
					scandal_send_channel(TELEM_LOW, tyre_id + TYREMASTER_AIR_TEMP,
							((uint32_t)(air_temp-50))*1000);
					scandal_send_channel(TELEM_LOW, tyre_id + TYREMASTER_BATT_VOLTAGE,
							((double)batt_voltage)*18.4+1730);
				} else {
					scandal_send_channel(TELEM_LOW, tyre_id + 4,
						(int)chksum);
					scandal_send_channel(TELEM_LOW, tyre_id + 5,
						(int)chksum_data);
				}
			}
		}

		if(sc_get_timer() >= my_timer + 1000) {
			my_timer = sc_get_timer();
			toggle_yellow_led();
		}

	}

}
/**
 * \brief Main routine for the cc2538dk platform
 */
int
main(void)
{
  nvic_init();
  sys_ctrl_init();
  clock_init();
  dint();
  /*Init Watchdog*/
  watchdog_init();//Need to check the watchdog on 123gxl

  rtimer_init();
  lpm_init();  
  gpio_init();
  ioc_init();

  leds_init();
  fade(LEDS_YELLOW);
  button_sensor_init();

  /*
   * Character I/O Initialisation.
   * When the UART receives a character it will call serial_line_input_byte to
   * notify the core. The same applies for the USB driver.
   *
   * If slip-arch is also linked in afterwards (e.g. if we are a border router)
   * it will overwrite one of the two peripheral input callbacks. Characters
   * received over the relevant peripheral will be handled by
   * slip_input_byte instead
   */
#if UART_CONF_ENABLE
  uart_init(0);
  uart_init(1);
  uart_set_input(SERIAL_LINE_CONF_UART, serial_line_input_byte);
#endif

#if USB_SERIAL_CONF_ENABLE
  usb_serial_init();
  usb_serial_set_input(serial_line_input_byte);
#endif

  serial_line_init();

  /*Enable EA*/
  eint();
  INTERRUPTS_ENABLE();
  fade(LEDS_GREEN);
  PRINTF("=================================\r\n");
  PUTS(CONTIKI_VERSION_STRING);
  PRINTF("======================\r\n");  
  PRINTF("\r\n");
  PUTS(BOARD_STRING);
  PRINTF("\r\n");

#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(&sensors_process, NULL);
  button_sensor_init();

  process_start(&etimer_process, NULL);

  ctimer_init();

  set_rime_addr();
  printf("finish addr seting\r\n");

  /* Initialise the H/W RNG engine. */
  random_init(0);

  udma_init();

  if(node_id > 0) {
    printf("Node id %u.\r\n", node_id);
  } else {
    printf("Node id not set.\r\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("CC2538 IEEE802154 PANID %d\r\n", IEEE802154_PANID);  
  cc2538_rf_set_addr(IEEE802154_PANID);

  printf("%s/%s %lu %u\r\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\r\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\r\n",
           ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
  }

#else /* WITH_UIP6 */

  netstack_init();
  PRINTF("CC2538 IEEE802154 PANID %d\r\n", IEEE802154_PANID);  
  cc2538_rf_set_addr(IEEE802154_PANID);
  
  printf("%s %lu %u\r\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\r\n");
#else /* NETSTACK_AES_H */
  printf("Warning: AES encryption is disabled\r\n");
#endif /* NETSTACK_AES_H */

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

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  simple_rpl_init();
  /*Watch dog configuration*/
  watchdog_periodic();
  watchdog_start();

  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...\r\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 */

  fade(LEDS_ORANGE);

  /*
   * This is the scheduler loop.
   */
  while(1) {
    uint8_t r;
    do {
      /* Reset watchdog and handle polls and events */
      // printf("reset watchdog\r\n");
      watchdog_periodic();

      r = process_run();
    } while(r > 0);

    /* We have serviced all pending events. Enter a Low-Power mode. */
    lpm_enter();
  }
}
Beispiel #10
0
/**
 * The main function.
 */
int main( void )
{
    /* Stop the watchdog timer */
    WDTCTL = WDTPW + WDTHOLD;

    /* Setup the MSP430 micro-controller clock frequency: MCLK, SMCLK and ACLK */

    /* Set MCLK at 8MHz and SMCLK at 1MHz */
    set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();

	/* Set ACKL at 4096Hz (32 768Hz / 8) */
    set_aclk_div(8);

    /* Initialize the LEDs */
    LEDS_INIT();
    LEDS_OFF();

    /* Initialize the temperature sensor */
    ds1722_init();
    ds1722_set_res(12);
    ds1722_sample_cont();

    /* Initialize the Luminosity sensor */
    tsl2550_init();
    tsl2550_powerup();
    tsl2550_set_standard();
    tsl2550_read_adc0();

    /* Initialize the UART0 */

	/* We want 115kbaud, and SMCLK is running at 1MHz */
    uart0_init(UART0_CONFIG_1MHZ_115200);

	/* Set the UART callback function it will be called every time a character is received. */
    uart0_register_callback(char_rx);

    /* Print first message */
    printf("\n\nSenslab Simple Demo program\n");

    /* Enable Interrupts */
    eint();

    /* Print information */
    printf("Type command\n");
    printf("\tt:\ttemperature measure\n");
    printf("\tl:\tluminosity measure\n");

    /* Initialize the timer for the LEDs */
    timerA_init();

	/*  TimerA clock is at 512Hz (4096Hz / 8) */
    timerA_start_ACLK_div(TIMERA_DIV_8);

    /* Configure the first timerA period to 1s (periodic) */
    timerA_set_alarm_from_now(TIMERA_ALARM_CCR0, 512, 512);

	/* Set the first timerA callback */
    timerA_register_cb(TIMERA_ALARM_CCR0, alarm);

    // Declare 2 variables for storing the different values
    int16_t value_0=0, value_1=1;
    while (1) {
        printf("cmd > ");
        cmd = 0;

        while (cmd==0) {
            LPM0; // Low Power Mode 1: SMCLK remains active for UART
        }

        switch (cmd) {
        case 't':
            value_0 = ds1722_read_MSB();
            value_1 = ds1722_read_LSB();
            value_1 >>= 5;
            value_1 *= 125;
            printf("Temperature measure: %i.%i\n", value_0, value_1);
            break;
        case 'l':
            tsl2550_init();
            value_0 = tsl2550_read_adc0();
            value_1 = tsl2550_read_adc1();
            uart0_init(UART0_CONFIG_1MHZ_115200);
            uart0_register_callback(char_rx);
            printf("Luminosity measure: %i:%i\n", value_0, value_1);
            break;
        default:
            break;
        }
    }

    return 0;
}
Beispiel #11
0
/**
 * The main function.
 */
int main( void )
{

    /* Stop the watchdog timer. */
    WDTCTL = WDTPW + WDTHOLD;

    /* Setup MCLK 8MHz and SMCLK 1MHz */
    set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();

    /* Enable Interrupts */
    eint();

    LEDS_INIT();
    LEDS_ON();

    uart0_init(UART0_CONFIG_1MHZ_115200);
    printf("CC2420 TX test program with address recognition and acknowledge frames\r\n");

    cc2420_init();
    cc2420_io_sfd_register_cb(sfd_cb);
    cc2420_io_sfd_int_set_falling();
    cc2420_io_sfd_int_clear();
    cc2420_io_sfd_int_enable();
    cc2420_set_txpower(CC2420_2_45GHz_TX_0dBm);

    uint8_t fcf[2] = {0x21, 0x88};  /* -> 00100001 10001000 -> reverse of bits for each byte -> 10000100 00010001 -> ack bit = 1 (6th bit), Frame type = 001 (don't forget to read from right to left) */
    uint8_t seq_numb = 0x01;
    uint8_t dest_pan_id[2] = {0x22, 0x00};
    uint8_t dest_addr[2] = {0x11, 0x11};

    uint8_t src_pan_id[2] = {0x22, 0x01};
    uint8_t src_addr[2] = {0x11, 0x12};

    while ( (cc2420_get_status() & 0x40) == 0 ); // waiting for xosc being stable

    cc2420_set_panid(src_pan_id); // save pan id in ram
    cc2420_set_shortadr(src_addr); // save short address in ram

    printf("CC2420 initialized\r\n");

    LEDS_OFF();

    while (1)
    {
        cc2420_cmd_idle();
        cc2420_cmd_flushtx();

        txlength = sprintf((char *)txframe, "Hello World #%i", seq_numb);

        printf("Sent : %s of length %d\r\n", txframe,txlength);

        txlength += 13;

        cc2420_fifo_put(&txlength, 1);
        cc2420_fifo_put(fcf, 2);
        cc2420_fifo_put(&seq_numb, 1);
        cc2420_fifo_put(dest_pan_id, 2);
        cc2420_fifo_put(dest_addr, 2);
        cc2420_fifo_put(src_pan_id, 2);
        cc2420_fifo_put(src_addr, 2);
        cc2420_fifo_put(txframe, txlength-13);

	LED_BLUE_TOGGLE();

        cc2420_cmd_tx();

        micro_delay(0xFFFF);
	while (cc2420_io_sfd_read());

	printf("Waiting for acknowledge frame...\n");

	if (rx_ack())
	{
            seq_numb ++;
	}
	else
	{
	    printf("No Acknowledge frame received for frame number #%i - Retrying...\r\n\n", seq_numb);
	    LED_RED_TOGGLE();
	}
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
    }


    return 0;
}
Beispiel #12
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;
}
Beispiel #13
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;
}
Beispiel #14
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 NETSTACK_CONF_WITH_IPV4
  slip_arch_init(BAUD2UBR(115200));
#endif /* NETSTACK_CONF_WITH_IPV4 */

  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 = (linkaddr_node_addr.u8[0] << 8) +
      linkaddr_node_addr.u8[1];
    memset(longaddr, 0, sizeof(longaddr));
    linkaddr_copy((linkaddr_t *)&longaddr, &linkaddr_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);
  }

  leds_off(LEDS_ALL);

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

#if NETSTACK_CONF_WITH_IPV6
  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()),
         CC2420_CONF_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, UIP_DS6_DEFAULT_PREFIX, 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 /* NETSTACK_CONF_WITH_IPV6 */

  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()),
         CC2420_CONF_CHANNEL);
#endif /* NETSTACK_CONF_WITH_IPV6 */

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

#if TIMESYNCH_CONF_ENABLED
  timesynch_init();
  timesynch_set_authority_level(linkaddr_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_SWITCH(ENERGEST_TYPE_CPU, 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_SWITCH(ENERGEST_TYPE_LPM, ENERGEST_TYPE_CPU);
    }
  }
}
Beispiel #15
0
/**
 * The main function.
 */
int main( void )
{
    uint8_t i;
    uint8_t length;

    /* Stop the watchdog timer. */
    WDTCTL = WDTPW + WDTHOLD;

    /* Setup MCLK 8MHz and SMCLK 1MHz */
    set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();

    /* Enable Interrupts */
    eint();

    LEDS_INIT();
    LEDS_ON();

    uart0_init(UART0_CONFIG_1MHZ_115200);
    printf("CC2420 RX test program with address recognition and acknowledge frames\r\n");

    cc2420_init();
    cc2420_io_sfd_register_cb(sfd_cb);
    cc2420_io_sfd_int_set_falling();
    cc2420_io_sfd_int_clear();
    cc2420_io_sfd_int_enable();

    uint8_t src_pan_id[2] = {0x22,0x00};
    uint8_t src_addr[2] = {0x11,0x11};

    while ( (cc2420_get_status() & 0x40) == 0 ); // waiting for xosc being stable

    cc2420_set_panid(src_pan_id); // save pan id in ram
    cc2420_set_shortadr(src_addr); // save short address in ram

    printf("CC2420 initialized\r\n");

    LEDS_OFF();

    while(1)
    {
        cc2420_cmd_idle();
        cc2420_cmd_flushrx();
        cc2420_cmd_rx();

        while (flag == 0) ;
        micro_delay(0xFFFF);
        flag = 0;
	LED_GREEN_TOGGLE();
        cc2420_fifo_get(&length, 1);
        if ( length < 128 )
        {
            cc2420_fifo_get(rxframe, length);
            // check CRC
            if ( (rxframe[length-1] & 0x80) != 0 )
            {
                printf("Frame received with rssi=%ddBm:\r\n", ((signed int)((signed char)(rxframe[length-2])))-45);
                LED_BLUE_TOGGLE();
		// ignore 11 first bytes (fcf,seq,addr) and the 2 last ones (crc)
                for (i=11; i<length-2; i++)
                {
                    printf("%c",rxframe[i]);
                }
                printf("\r\n\n");
            }
	    else {
		printf("CRC non OK, erreur de transmission?\n");
                printf("\r\n");
                LED_RED_TOGGLE();
	    }
        }
    }

    return 0;
}
Beispiel #16
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);
    }
  }
}
Beispiel #17
0
interrupt (TIMERB1_VECTOR) timerb1_int(void)
{
   dint();   
   
   uint8_t intVec = TBIV;
					
   if( intVec & TBIV_CCR2 )
   {
		TBCCR2 += SAMPLE_1MS;
		
	
		if(SoftTimerInterrupt(SoftTimer2[SC_AutoMenuUpdate]))
		{
         /* Update the Threshold and Retrigger bar */
         MenuSetInput(ActiveMenu, KP_UPDATE);
         MenuUpdate(ActiveMenu, RESET_MENU);
         //ThresholdBar();
         SoftTimerReset(SoftTimer2[SC_AutoMenuUpdate]);     
      }
         
		if(SoftTimerInterrupt(SoftTimer2[SC_VUDecay]))
		{
			SoftTimerReset(SoftTimer2[SC_VUDecay]); 
			/* Decay the VU Meters here */
			if( ActiveProcess == PLAY_MODE )
			{
   	   	VULevelDecay(ALL_METERS);
			}
		}
		
		if( SoftTimerInterrupt(SoftTimer2[SC_LCD_BL_Period]) )
		{
			SoftTimerReset( SoftTimer2[SC_LCD_BL_Period] );
			SoftTimerStop( SoftTimer2[SC_LCD_BL_Period] );
			UI_LCD_BL_Off();
			
			/* If no SoftTimer2's are enabled, then turn off the Timer2 module */
			if( !SoftTimer_IsTimer2Active() )
			{
            /* Stop the Auxuliary Timer */
            TBCCTL2 &= ~(CCIE);
         }
			
		}
         
		if(SoftTimerInterrupt(SoftTimer2[SC_VUMeterUpdate]))
		{
			SoftTimerReset(SoftTimer2[SC_VUMeterUpdate]); 
		
         /* Do the VU Meter*/
         uint16_t i;
         uint8_t  VURows = GetVURows();
			   			           
         for( i = 0 ; i < ANALOGUE_INPUTS; i++ )
         {
				if( GetChannelStatus(i) )
				{
					if( VUValues[i] > GetChannelThresh(i) )
					{
						uint16_t conditionedSignal = (VUValues[i] - GetChannelThresh(i));
						
						conditionedSignal = GainFunction(i, conditionedSignal);
						
		            /* Normalise with x rows */
		            VUSetLevel(i, VUNormaliseMIDI(conditionedSignal, VURows), VURows);            
					}
	         }
			}
         VUMeterPrint(SEQUENTIAL_METERS | 0x0F, VURows);
         ResetVUValues();
      }         
      
      /* Digital & Metronome VU Meter  */
		if(SoftTimerInterrupt(SoftTimer2[SC_DigitalVUUpdate]))
		{
			SoftTimerReset(SoftTimer2[SC_DigitalVUUpdate]); 
		
         /* Do the VU Meter*/
         uint16_t i;
         uint8_t  VURows = GetVURows();
			   			           
         for( i = 0 ; i < DIGITAL_INPUTS+METRONOME_INPUTS; i++ )
         {
            uint8_t ActualChannel = i + ANALOGUE_INPUTS;
            
				if( GetChannelStatus(ActualChannel) )
				{	
					if( VUValues[i] )
					{
						VUSetLevel(i, VUNormaliseMIDI(GetDigitalVelocity(i), VURows), VURows); 
					}
				}
			}
         VUMeterPrint(SEQUENTIAL_METERS | 0x0F, VURows);
         ResetVUValues();
      }          
      
		/* About Strings Update routine */   
      if( SoftTimerInterrupt(SoftTimer2[SC_AboutUpdate]) )
		{
			uint8_t nameIndex = 0;
			nameIndex = ThanksIndex(GET);
			if( ++nameIndex == SIZEOFTHANKS )
			{
				nameIndex = ThanksIndex(MAIN_SCREEN);	
			}
			ThanksIndex(nameIndex);
			aboutScroll(nameIndex);
			SoftTimerReset(SoftTimer2[SC_AboutUpdate]);
		}   
	}
	
	eint();
}
Beispiel #18
0
/**
* Run the application code (display messages from the radio and send responses)
*/
int main(void) 
{
	char pFlagData[32];

	/* Porting code -- Don't need to do this
	WDTCTL = WDTPW | WDTHOLD;	// Disable watchdog timer

	P1OUT  = 0x00;                     // Port data output
	P2OUT  = 0x00;
 
	P1DIR  = 0x00;                     // Port direction register
	P2DIR  = 0xff;
 
	P1IES  = 0x00;                     // Port interrupt enable (0=dis 1=enabled)
	P2IES  = 0x00;
	P1IE   = 0x0F;                     // Port interrupt Edge Select (0=pos 1=neg)
	P2IE   = 0x00;
	*/

	// Setup no buffering for XINETD service
        setvbuf( stdout, NULL, _IONBF, 0 );

	FILE *pFlagFile = fopen( FLAG_FILE_NAME, "r" );

	if ( !pFlagFile )
	{
		printf( "Failed to read flag data!\n" );
		exit(1);
	}

	memset( pFlagData, 0, 32 );	
	fgets( pFlagData, 32, pFlagFile );

	fclose( pFlagFile );
       
	// Setup sig alarm handler
        signal( SIGALRM, sig_alarm_handler );
        alarm( MAX_IDLE_SECS );
	
	sram_init();
	cli_init_uart();
	radio_init_uart();
	//init_gui();
	
	// PORT: OLD: g_myTeamID = TEAM_ID_ADDR; 
	g_myTeamID = 0; // PPP now 



	puts( "This is an infamous challenge from DEF CON CTF Finals in 2014, in which a custom hardware badge was made by the LegitBS team, I've ported it to work here, enjoy.\n" );	
	puts( "The buttons are mapped to the arrow keys.\n" );
	puts( ".........................................\n" );

	puts( "Application Core v1.0" );
	puts( "openMSP430 core by Oliver Girard" );
	puts( "p.s. I modded the core to make data executable -sirgoon" );

	// Enable interrupts
	eint();

	// Run process loop

	/*
	while ( 1 )
	{
		LPM0;
		cli_run();
		radio_uart_run();
	}
	*/
	interrupt_handler();
}
Beispiel #19
0
/* Main function */
int main(void) {
  sc_time_t     my_timer;  
  int32_t value; 

  dint();

#if USE_WATCHDOG
    init_watchdog(); 
#else
    WDTCTL = WDTCTL_INIT;               //Init watchdog timer
#endif
    
  init_ports();
  init_clock();
  sc_init_timer();

  scandal_init(); 

  config_read(); 

  {volatile int i; 
    for(i=0; i<100; i++)
      ;
  }

  /* Below here, we assume we have a config */ 

  /* Send out the error that we've reset -- it's not fatal obviously, 
     but we want to know when it happens, and it really is an error, 
     since something that's solar powered should be fairly constantly 
     powered */ 
  scandal_do_user_err(UNSWMPPTNG_ERROR_WATCHDOG_RESET); 
    
    /* Make sure our variables are set up properly */ 
    tracker_status = 0;     
    
  /* Initialise FPGA (or, our case, CPLD) stuff */ 
  fpga_init(); 

  /* Starts the ADC and control loop interrupt */
  control_init(); 

  /* Initialise the PV tracking mechanism */ 
  pv_track_init(); 

  eint();

  my_timer = sc_get_timer(); 

  while (1) {
    sc_time_t timeval; 

    timeval = sc_get_timer();

    handle_scandal(); 
    
    /* pv_track sends data when it feels like it */ 
    pv_track_send_data(); 

    /* Periodically send out the values recorded by the ADC */ 
    if(timeval >= my_timer + TELEMETRY_UPDATE_PERIOD){
        my_timer = timeval;
        toggle_yellow_led();
#if USE_WATCHDOG
	kick_watchdog(); 
#endif
        
        mpptng_do_errors(); 

        pv_track_send_telemetry(); 
        /* We send the Input current and voltage from 
            within the pvtrack module */ 

        /*  scandal_send_scaled_channel(TELEM_LOW, UNSWMPPTNG_IN_VOLTAGE, 
                        sample_adc(MEAS_VIN1));
            scandal_send_scaled_channel(TELEM_LOW, UNSWMPPTNG_IN_CURRENT, 
                        sample_adc(MEAS_IIN1));*/ 

        scandal_send_scaled_channel(TELEM_LOW, UNSWMPPTNG_OUT_VOLTAGE, 
                    sample_adc(MEAS_VOUT));
        scandal_send_scaled_channel(TELEM_LOW, UNSWMPPTNG_HEATSINK_TEMP, 
                    sample_adc(MEAS_THEATSINK));
        scandal_send_scaled_channel(TELEM_LOW, UNSWMPPTNG_15V, 
                    sample_adc(MEAS_15V));
        scandal_send_channel(TELEM_LOW, UNSWMPPTNG_STATUS, 
                    tracker_status); 

        /* Pre-scale for the temperature */ 
        {
            int32_t degC = sample_adc(MEAS_TAMBIENT); 
            degC = (((degC - 1615)*704*1000)/4095);
            scandal_send_scaled_channel(TELEM_LOW, UNSWMPPTNG_AMBIENT_TEMP, 
                                        degC);
        }

#if DEBUG >= 1
        scandal_send_channel(TELEM_LOW, 134, output);	
        scandal_send_channel(TELEM_LOW, 136, fpga_nFS()); 
#endif
    } 

    /*  If we're not tracking, 
        check to see that our start-up criteria are satisfied, and then
        initialise the control loops and restart tracking */ 
    if((tracker_status & STATUS_TRACKING) == 0){
        /* Check the input voltage */
        value = sample_adc(MEAS_VIN1); 
        scandal_get_scaled_value(UNSWMPPTNG_IN_VOLTAGE, &value);
        if(value < config.min_vin)
            continue; 

        /* Check the output voltage */
        value = sample_adc(MEAS_VOUT);
        scandal_get_scaled_value(UNSWMPPTNG_OUT_VOLTAGE, &value); 
        if(value > config.max_vout)
            continue; 

        tracker_status |= STATUS_TRACKING; 

        /* Initialise the tracking algorithm */ 
        //      pv_track_init(); 

        /* Reset the FPGA */ 	 
        fs_reset(); 

        /* Initialise the control loop */ 
        control_start(); 

        /* Enable the FPGA */ 
        fpga_enable(FPGA_ON); 
    }
  }
}
Beispiel #20
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();
  leds_init();
  leds_on(LEDS_RED);


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

  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!
   */

  
#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 */

  /* 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

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

  ctimer_init();

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

  init_platform();

  set_rime_addr();
  
  cc2420_init();
  {
    uint8_t longaddr[8];
    uint16_t shortaddr;
    
    shortaddr = (linkaddr_node_addr.u8[0] << 8) +
      linkaddr_node_addr.u8[1];
    memset(longaddr, 0, sizeof(longaddr));
    linkaddr_copy((linkaddr_t *)&longaddr, &linkaddr_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);
  }

  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 SLIP_RADIO
  memcpy(&uip_lladdr.addr, ds2411_id, sizeof(uip_lladdr.addr));
  queuebuf_init();
  NETSTACK_RDC.init();
  NETSTACK_MAC.init();
  NETSTACK_NETWORK.init();

  printf("%s %s, channel check rate %lu Hz, radio channel %u, CCA threshold %i\n",
         NETSTACK_MAC.name, NETSTACK_RDC.name,
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
                         NETSTACK_RDC.channel_check_interval()),
         CC2420_CONF_CHANNEL,
         CC2420_CONF_CCA_THRESH);
#else
#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, CC2420_CONF_CCA_THRESH); */

  /* 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, CCA threshold %i\n",
         NETSTACK_MAC.name, NETSTACK_RDC.name,
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
                         NETSTACK_RDC.channel_check_interval()),
         CC2420_CONF_CHANNEL,
         CC2420_CONF_CCA_THRESH);

  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_DS6_NO_STATIC_ADDRESS
  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]);
  }
#endif /* !UIP_DS6_NO_STATIC_ADDRESS */

#else /* WITH_UIP6 */

  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()),
         CC2420_CONF_CCA_THRESH);
#endif /* WITH_UIP6 */
#endif /* SLIP_RADIO */

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

  leds_off(LEDS_GREEN);

#if TIMESYNCH_CONF_ENABLED
  timesynch_init();
  timesynch_set_authority_level((linkaddr_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,
	       linkaddr_node_addr.u8[0],linkaddr_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 !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 */
  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;
    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;

#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;
}
Beispiel #21
0
PROCESS_THREAD(scanning, ev, data)
{
    PROCESS_BEGIN();

// Initial operations
    leds_off(LEDS_ALL);
    watchdog_stop();

// Avoiding wrong RSSI readings
    unsigned temp;
    CC2420_READ_REG(CC2420_AGCTST1, temp);
    CC2420_WRITE_REG(CC2420_AGCTST1, (temp + (1 << 8) + (1 << 13)));

// Selecting the channel
    SPI_SETCHANNEL_SUPERFAST(357+((CHANNEL-11)*5));

// Avoiding the initial wrong readings by discarding the wrong readings
    CC2420_SPI_ENABLE();
    int k=0;
    for (k=0; k<=15; k++) {
        MY_FASTSPI_GETRSSI(temp);
    }
    CC2420_SPI_DISABLE();

    static struct etimer et;
    while(1) {

        // Resetting everything
        for(k=0; k<(BUFFER_SIZE/2); k++) {
            buffer1[k] = 0;
            buffer0[k] = 0;
        }

        printf("#START [dBm: occurrencies]\n");

        dint();				// Disable interrupts
        boost_cpu(); 			// Temporarily boost CPU speed
        CC2420_SPI_ENABLE(); 	// Enable SPI

        // Actual scanning
        static signed char rssi;
        int current = 0;
        int previous = 0;
        int cnt = 1;
        for(k=0; k<(BUFFER_SIZE/2);) {
            // Sample the RSSI fast
            MY_FASTSPI_GETRSSI(rssi);
            current = rssi + 55;
            if((current == previous)&&(cnt<255)) {
                cnt++;
            }
            else {
                buffer0[k] = previous;
                buffer1[k++] = cnt;
                cnt = 1;
                previous = current;
            }
        }

        CC2420_SPI_DISABLE();	// Disable SPI
        restore_cpu();			// Restore CPU speed
        eint(); 				// Re-enable interrupts

        // Printing the stored values in compressed form
        for(temp=0; temp<(BUFFER_SIZE/2); temp++) {
            printf("%d: %d\n",buffer0[temp] - 100, buffer1[temp]);
            clock_delay(30000);
        }

        printf("#END\n");

        // Waiting for timer
        etimer_set(&et, PERIOD_TIME);
        PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

    }

    PROCESS_WAIT_EVENT();

    PROCESS_END();
}