Example #1
0
/*---------------------------------------------------------------------------*/
void
collect_common_net_init(void)
{
#if CONTIKI_TARGET_Z1
  uart0_set_input(serial_line_input_byte);
#else
  uart1_set_input(serial_line_input_byte);
#endif
  serial_line_init();
}
static void
ieee_serial_init()
/* open up the serial line, ieee stack is getting initialized in ieee802.c
 * baudrate is set to 2MBaud to make sure we can fit the theoretical maximum
 * bandwidth of the ieee802.15.4 stack (666kbps ~= 84 kb/sec). */
{
    //uart0_init(2000000);
    //uart0_init(115200);
    uart0_init(57600);
    uart0_set_input(ieee_serial_input);
}
Example #3
0
/*---------------------------------------------------------------------------*/
void
collect_common_net_init(void)
{
#if CONTIKI_TARGET_Z1
  uart0_set_input(serial_line_input_byte);
#else
  uart1_set_input(serial_line_input_byte);
#endif
  serial_line_init();

  PRINTF("I am sink!\n");
  printf("Energy: %d\n", ENERGEST_CONF_ON);
}
Example #4
0
/*---------------------------------------------------------------------------*/
void
collect_common_net_init(void)
{
#if CONTIKI_TARGET_Z1
  uart0_set_input(serial_line_input_byte);
#else
  uart1_set_input(serial_line_input_byte);
#endif
  serial_line_init();

  PRINTF("I am sink!\n");
  //NETSTACK_RDC.off(0);
  //NETSTACK_RDC.init();
}
Example #5
0
PROCESS_THREAD(test_receive_process, ev, data)
{

	PROCESS_BEGIN();

	uart0_set_input(uart_rx_callback);

	while(1) 
	{
		PROCESS_YIELD(); 
	}

	PROCESS_END();
}
Example #6
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;
}
Example #7
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(serial_lprf_mac_process, ev, data)
{
  PROCESS_BEGIN();

  PUTSTRING("Serial LPRF MAC\n");

  rimeaddr_set_node_addr(&rimeaddr_node_addr);
#if (DEVICE_MODE == RF_TESTING_MASTER)
  PUTSTRING("RF Testing Master\n");

  NETSTACK_RADIO.init();
  NETSTACK_RDC.init();
  NETSTACK_MAC.init();
  etimer_set(&sendHelloEvent, CLOCK_SECOND * 6);

  while(1) {
    PROCESS_WAIT_EVENT();

    if(ev == PROCESS_EVENT_TIMER) {
      PUTSTRING("Send Hello World ");
      PUTDEC(count++);
      PUTSTRING("\n");
      packetbuf_clear();
      packetbuf_copyfrom("Hello World", sizeof("Hello World"));
      packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &rimeaddr_receiver);
      NETSTACK_RDC.send(NULL, NULL);
      leds_toggle(LEDS_GREEN);
      etimer_reset(&sendHelloEvent);
    }
  }
#elif (DEVICE_MODE == RF_TESTING_SLAVE)
  PUTSTRING("RF Testing Slave\n");

  NETSTACK_RADIO.init();
  NETSTACK_RDC.init();
  NETSTACK_MAC.init();
  while(1) {
    len = NETSTACK_RADIO.pending_packet();
    if(len) {
      packetbuf_clear();
      len = NETSTACK_RADIO.read(packetbuf_dataptr(), PACKETBUF_SIZE);
      if(len > 0) {
        packetbuf_set_datalen(len);
        NETSTACK_RDC.input();
      }
    }
  }
#else // SERIAL_LPRF_MAC
  uart0_set_input(serial_lprf_mac_serial_input);
	
	NETSTACK_RADIO.init();
	NETSTACK_RDC.init();
	NETSTACK_MAC.init();

	while(1) {
		if(state == SERIAL_REC_STATE_PACKET_COMPLETE)
		{
			switch(dataBuffer[0])
			{
				case 'S':
					PUTSTRING("Send packet\n");
					packetbuf_clear();
					packetbuf_copyfrom(&dataBuffer[9], pktLength - 8 - 1);
					packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, (rimeaddr_t*)&dataBuffer[1]);
					NETSTACK_RDC.send(NULL, NULL);
					leds_toggle(LEDS_GREEN);
					break;
				default:
					PUTSTRING("Wrong command received\n");
			}
			state = SERIAL_REC_STATE_WAIT_FOR_START;
		}
		
		len = NETSTACK_RADIO.pending_packet();
		if(len) {
			packetbuf_clear();
			len = NETSTACK_RADIO.read(packetbuf_dataptr(), PACKETBUF_SIZE);
			if(len > 0) {
				packetbuf_set_datalen(len);
				NETSTACK_RDC.input();
			}
		}
	}
#endif
  PROCESS_END();
}
Example #8
0
/**
 * Initalize the RS232 port and the SLIP driver.
 *
 */
void
slip_arch_init(unsigned long ubr)
{
  uart0_set_input(slip_input_byte);
}
/*---------------------------------------------------------------------------*/
int
main(void)
{
  clock_init();                                   // 初始化 睡眠定时器 必要
  soc_init();                                     // 还函数中启动了全局中断 可修改
  rtimer_init();                                  // rtimer为定时器1 必要

  /* Init LEDs here */
  leds_init();                                    // 初始化LED 可修改
  leds_off(LEDS_ALL);                             // 关闭所有LED 非必要
  fade(LEDS_GREEN);                               // 绿色闪烁一下 非必要

  /* initialize process manager. */
  process_init();                                 // 任务初始化 必要

  /* Init UART */
  uart0_init();                                   // 初始化串口0,先用于调试,可修改

#if DMA_ON
  dma_init();                                     // 非必要
#endif

#if SLIP_ARCH_CONF_ENABLE
  slip_arch_init(0);
#else
  uart0_set_input(serial_line_input_byte);
  serial_line_init();
#endif
  fade(LEDS_RED);                                 // 红色LED闪烁一下 非必要

  // 打印若干提示信息 非必要 可修改
  putstring("**************************************\r\n");
  putstring(CONTIKI_VERSION_STRING "\r\n");       // 打印若干信息
  putstring("Platform CC2530 NB\r\n");
  switch(CHIPID) {
  case 0xA5:
    putstring("CC2530");
    break;
  case 0xB5:
    putstring("CC2531");
    break;
  case 0x95:
    putstring("CC2533");
    break;
  case 0x8D:
    putstring("CC2540");
    break;
  }

  putstring("-F");
  switch(CHIPINFO0 & 0x70) {
  case 0x40:
    putstring("256,");
    break;
  case 0x30:
    putstring("128,");
    break;
  case 0x20:
    putstring("64,");
    break;
  case 0x10:
    putstring("32,");
    break;
  }
  puthex(CHIPINFO1 + 1);
  putstring("KB SRAM\r\n");

#if STARTUP_VERBOSE

  PUTSTRING("Net: ");                      // NETWORK名称
  PUTSTRING(NETSTACK_NETWORK.name);
  PUTCHAR('\r');PUTCHAR('\n');              
  PUTSTRING("MAC: ");                      // MAC名称
  PUTSTRING(NETSTACK_MAC.name);
  PUTCHAR('\r');PUTCHAR('\n');
  PUTSTRING("RDC: ");                      // RDC名称
  PUTSTRING(NETSTACK_RDC.name);
  PUTCHAR('\r');PUTCHAR('\n');
  PUTSTRING("**************************************\r\n");
#endif

  watchdog_init();                         // 初始化看门狗

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

  /* start services */
  process_start(&etimer_process, NULL);     // 启动etimer任务
  ctimer_init();                            // ctimer初始化 

  /* initialize the netstack */
  netstack_init();                          // NET协议栈初始化
  set_rime_addr();                          // 设置RIME地址,相当于设置IP地址

#if BUTTON_SENSOR_ON || ADC_SENSOR_ON
  process_start(&sensors_process, NULL);
  BUTTON_SENSOR_ACTIVATE();
  ADC_SENSOR_ACTIVATE();
#endif

#if UIP_CONF_IPV6                         // 非常重要,启动TCPIP查询任务
  memcpy(&uip_lladdr.addr, &rimeaddr_node_addr, sizeof(uip_lladdr.addr));
  queuebuf_init();
  process_start(&tcpip_process, NULL);
#endif /* UIP_CONF_IPV6 */

#if VIZTOOL_CONF_ON
  process_start(&viztool_process, NULL);
#endif

  energest_init();                        // 能量估计初始化,但是该功能未被打开
  ENERGEST_ON(ENERGEST_TYPE_CPU);         // 该功能未被打开

  autostart_start(autostart_processes);   // 启动被定义为自动启动的任务

  watchdog_start();                       // 看门狗初始化     

  fade(LEDS_YELLOW);                      // 黄色LED闪烁,完成所有初始化工作

  while(1) {
    do {
      /* Reset watchdog and handle polls and events */
      watchdog_periodic();                // 喂狗操作
      r = process_run();
    } while(r > 0);
#if SHORTCUTS_CONF_NETSTACK               // 循环查询无线输入数据包长度 tcpip_process
    len = NETSTACK_RADIO.pending_packet();
    if(len) {
      packetbuf_clear();
      len = NETSTACK_RADIO.read(packetbuf_dataptr(), PACKETBUF_SIZE);
      if(len > 0) {
        packetbuf_set_datalen(len);
        NETSTACK_RDC.input();
      }
    }
#endif

#if LPM_MODE                              // 该宏被定义为0,没有休眠功能,以下代码均无效
#if (LPM_MODE==LPM_MODE_PM2)
    SLEEP &= ~OSC_PD;            /* Make sure both HS OSCs are on */
    while(!(SLEEP & HFRC_STB));  /* Wait for RCOSC to be stable */
    CLKCON |= OSC;               /* Switch to the RCOSC */
    while(!(CLKCON & OSC));      /* Wait till it's happened */
    SLEEP |= OSC_PD;             /* Turn the other one off */
#endif /* LPM_MODE==LPM_MODE_PM2 */

    /*
     * Set MCU IDLE or Drop to PM1. Any interrupt will take us out of LPM
     * Sleep Timer will wake us up in no more than 7.8ms (max idle interval)
     */
    SLEEPCMD = (SLEEPCMD & 0xFC) | (LPM_MODE - 1);

#if (LPM_MODE==LPM_MODE_PM2)
    /*
     * Wait 3 NOPs. Either an interrupt occurred and SLEEP.MODE was cleared or
     * no interrupt occurred and we can safely power down
     */
    __asm
      nop
      nop
      nop
    __endasm;

    if(SLEEPCMD & SLEEP_MODE0) {
#endif /* LPM_MODE==LPM_MODE_PM2 */

      ENERGEST_OFF(ENERGEST_TYPE_CPU);
      ENERGEST_ON(ENERGEST_TYPE_LPM);

      /* We are only interested in IRQ energest while idle or in LPM */
      ENERGEST_IRQ_RESTORE(irq_energest);

      /* Go IDLE or Enter PM1 */
      PCON |= PCON_IDLE;

      /* First instruction upon exiting PM1 must be a NOP */
      __asm
        nop
      __endasm;

      /* Remember energest IRQ for next pass */
      ENERGEST_IRQ_SAVE(irq_energest);

      ENERGEST_ON(ENERGEST_TYPE_CPU);
      ENERGEST_OFF(ENERGEST_TYPE_LPM);

#if (LPM_MODE==LPM_MODE_PM2)
      SLEEPCMD &= ~SLEEP_OSC_PD;            /* Make sure both HS OSCs are on */
      while(!(SLEEPCMD & SLEEP_XOSC_STB));  /* Wait for XOSC to be stable */
      CLKCONCMD &= ~CLKCONCMD_OSC;              /* Switch to the XOSC */
      /*
       * On occasion the XOSC is reported stable when in reality it's not.
       * We need to wait for a safeguard of 64us or more before selecting it
       */
      clock_delay(10);
      while(CLKCONCMD & CLKCONCMD_OSC);         /* Wait till it's happened */
    }
#endif /* LPM_MODE==LPM_MODE_PM2 */
#endif /* LPM_MODE */
  }
}
Example #10
0
/**
 * \brief Main function for nRF52dk platform.
 * \note This function doesn't return.
 */
int
main(void)
{
  board_init();
  leds_init();

  clock_init();
  rtimer_init();

  watchdog_init();
  process_init();

  // Seed value is ignored since hardware RNG is used.
  random_init(0);

#ifdef UART0_ENABLED
  uart0_init();
#if SLIP_ARCH_CONF_ENABLE
  slip_arch_init(0);
#else
  uart0_set_input(serial_line_input_byte);
  serial_line_init();
#endif
#endif

  PRINTF("Starting " CONTIKI_VERSION_STRING "\n");

  process_start(&etimer_process, NULL);
  ctimer_init();

#if ENERGEST_CONF_ON
  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);
#endif

#ifdef SOFTDEVICE_PRESENT
  ble_stack_init();
  ble_advertising_init(DEVICE_NAME);

#if NETSTACK_CONF_WITH_IPV6
  netstack_init();
  linkaddr_t linkaddr;
  ble_get_mac(linkaddr.u8);
  /* Set link layer address */
  linkaddr_set_node_addr(&linkaddr);
  /* Set device link layer address in uip stack */
  memcpy(&uip_lladdr.addr, &linkaddr, sizeof(uip_lladdr.addr));
  process_start(&ble_iface_observer, NULL);
  process_start(&tcpip_process, NULL);
#endif /* NETSTACK_CONF_WITH_IPV6 */
#endif /* SOFTDEVICE_PRESENT */

  process_start(&sensors_process, NULL);
  autostart_start(autostart_processes);

  watchdog_start();

#ifdef SOFTDEVICE_PRESENT
  ble_advertising_start();
  PRINTF("Advertising name [%s]\n", DEVICE_NAME);
#endif

  while(1) {
    uint8_t r;
    do {
      r = process_run();
      watchdog_periodic();
    } while(r > 0);

    lpm_drop();
  }
}
/*---------------------------------------------------------------------------*/
int
main(void)
{
    /* Hardware initialization */
    clock_init();
    soc_init();
    rtimer_init();

    /* Init LEDs here */
    leds_init();
    leds_off(LEDS_ALL);
    fade(LEDS_GREEN);

    /* initialize process manager. */
    process_init();

    /* Init UART */
    uart0_init();

#if DMA_ON
    dma_init();
#endif

#if SLIP_ARCH_CONF_ENABLE
    slip_arch_init(0);
#else
    uart0_set_input(serial_line_input_byte);
    serial_line_init();
#endif
    fade(LEDS_RED);

    PUTSTRING("##########################################\n");
    putstring(CONTIKI_VERSION_STRING "\n");
    putstring("TI SmartRF05 EB\n");
    switch(CHIPID) {
    case 0xA5:
        putstring("cc2530");
        break;
    case 0xB5:
        putstring("cc2531");
        break;
    case 0x95:
        putstring("cc2533");
        break;
    case 0x8D:
        putstring("cc2540");
        break;
    }

    putstring("-F");
    switch(CHIPINFO0 & 0x70) {
    case 0x40:
        putstring("256, ");
        break;
    case 0x30:
        putstring("128, ");
        break;
    case 0x20:
        putstring("64, ");
        break;
    case 0x10:
        putstring("32, ");
        break;
    }
    puthex(CHIPINFO1 + 1);
    putstring("KB SRAM\n");

    PUTSTRING("\nSDCC Build:\n");
#if STARTUP_VERBOSE
#ifdef HAVE_SDCC_BANKING
    PUTSTRING("  With Banking.\n");
#endif /* HAVE_SDCC_BANKING */
#ifdef SDCC_MODEL_LARGE
    PUTSTRING("  --model-large\n");
#endif /* SDCC_MODEL_LARGE */
#ifdef SDCC_MODEL_HUGE
    PUTSTRING("  --model-huge\n");
#endif /* SDCC_MODEL_HUGE */
#ifdef SDCC_STACK_AUTO
    PUTSTRING("  --stack-auto\n");
#endif /* SDCC_STACK_AUTO */

    PUTCHAR('\n');

    PUTSTRING(" Net: ");
    PUTSTRING(NETSTACK_NETWORK.name);
    PUTCHAR('\n');
    PUTSTRING(" MAC: ");
    PUTSTRING(NETSTACK_MAC.name);
    PUTCHAR('\n');
    PUTSTRING(" RDC: ");
    PUTSTRING(NETSTACK_RDC.name);
    PUTCHAR('\n');

    PUTSTRING("##########################################\n");
#endif

    watchdog_init();

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

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

    /* initialize the netstack */
    netstack_init();
    set_rime_addr();

#if BUTTON_SENSOR_ON || ADC_SENSOR_ON
    process_start(&sensors_process, NULL);
    BUTTON_SENSOR_ACTIVATE();
    ADC_SENSOR_ACTIVATE();
#endif

#if UIP_CONF_IPV6
    memcpy(&uip_lladdr.addr, &rimeaddr_node_addr, sizeof(uip_lladdr.addr));
    queuebuf_init();
    process_start(&tcpip_process, NULL);
#endif /* UIP_CONF_IPV6 */

#if VIZTOOL_CONF_ON
    process_start(&viztool_process, NULL);
#endif

    energest_init();
    ENERGEST_ON(ENERGEST_TYPE_CPU);

    autostart_start(autostart_processes);

    watchdog_start();

    fade(LEDS_YELLOW);

    while(1) {
        do {
            /* Reset watchdog and handle polls and events */
            watchdog_periodic();

#if CLOCK_CONF_STACK_FRIENDLY
            if(sleep_flag) {
                if(etimer_pending() &&
                        (etimer_next_expiration_time() - clock_time() - 1) > MAX_TICKS) {
                    etimer_request_poll();
                }
                sleep_flag = 0;
            }
#endif
            r = process_run();
        } while(r > 0);
        len = NETSTACK_RADIO.pending_packet();
        if(len) {
            packetbuf_clear();
            len = NETSTACK_RADIO.read(packetbuf_dataptr(), PACKETBUF_SIZE);
            if(len > 0) {
                packetbuf_set_datalen(len);
                NETSTACK_RDC.input();
            }
        }

#if LPM_MODE
#if (LPM_MODE==LPM_MODE_PM2)
        SLEEP &= ~OSC_PD;            /* Make sure both HS OSCs are on */
        while(!(SLEEP & HFRC_STB));  /* Wait for RCOSC to be stable */
        CLKCON |= OSC;               /* Switch to the RCOSC */
        while(!(CLKCON & OSC));      /* Wait till it's happened */
        SLEEP |= OSC_PD;             /* Turn the other one off */
#endif /* LPM_MODE==LPM_MODE_PM2 */

        /*
         * Set MCU IDLE or Drop to PM1. Any interrupt will take us out of LPM
         * Sleep Timer will wake us up in no more than 7.8ms (max idle interval)
         */
        SLEEPCMD = (SLEEPCMD & 0xFC) | (LPM_MODE - 1);

#if (LPM_MODE==LPM_MODE_PM2)
        /*
         * Wait 3 NOPs. Either an interrupt occurred and SLEEP.MODE was cleared or
         * no interrupt occurred and we can safely power down
         */
        __asm
        nop
        nop
        nop
        __endasm;

        if(SLEEPCMD & SLEEP_MODE0) {
#endif /* LPM_MODE==LPM_MODE_PM2 */

            ENERGEST_OFF(ENERGEST_TYPE_CPU);
            ENERGEST_ON(ENERGEST_TYPE_LPM);

            /* We are only interested in IRQ energest while idle or in LPM */
            ENERGEST_IRQ_RESTORE(irq_energest);

            /* Go IDLE or Enter PM1 */
            PCON |= PCON_IDLE;

            /* First instruction upon exiting PM1 must be a NOP */
            __asm
            nop
            __endasm;

            /* Remember energest IRQ for next pass */
            ENERGEST_IRQ_SAVE(irq_energest);

            ENERGEST_ON(ENERGEST_TYPE_CPU);
            ENERGEST_OFF(ENERGEST_TYPE_LPM);

#if (LPM_MODE==LPM_MODE_PM2)
            SLEEPCMD &= ~SLEEP_OSC_PD;            /* Make sure both HS OSCs are on */
            while(!(SLEEPCMD & SLEEP_XOSC_STB));  /* Wait for XOSC to be stable */
            CLKCONCMD &= ~CLKCONCMD_OSC;              /* Switch to the XOSC */
            /*
             * On occasion the XOSC is reported stable when in reality it's not.
             * We need to wait for a safeguard of 64us or more before selecting it
             */
            clock_delay(10);
            while(CLKCONCMD & CLKCONCMD_OSC);         /* Wait till it's happened */
        }
#endif /* LPM_MODE==LPM_MODE_PM2 */
#endif /* LPM_MODE */
    }
}
Example #12
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(115200)); /* Must come before first printf */
#if WITH_UIP
  slip_arch_init(BAUD2UBR(115200));
#endif /* WITH_UIP */

  /* 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. */
  //Enric node_mac[2] &= 0xfe;
  node_mac[0] = 0x00;
  node_mac[1] = 0x12;
  node_mac[2] = 0x76;
  node_mac[3] = 0x01;
  node_mac[4] = 0x02;
  node_mac[5] = 0x03;
  node_mac[2] = 0x04;
  node_mac[7] = 0x05;

  
  xmem_init();

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

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


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

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

  process_start(&sensors_process, NULL);

  ctimer_init();

  set_rime_addr();

  cc2420_init();
  accm_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 ",
           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);

  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");
  }

  //Enric printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
	 //Enric node_mac[0], node_mac[1], node_mac[2], node_mac[3],
	 //Enric node_mac[4], node_mac[5], node_mac[6], node_mac[7]);

#if WITH_UIP6
  PRINTF("in WITH_UIP6\n"); //Enric
  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, 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 */

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

#if !WITH_UIP && !WITH_UIP6
  uart0_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 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 */

  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. */
    /* 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_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;
}
Example #13
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(void)
{
  /* Set stack overflow address for detecting overflow in runtime */
  vAHI_SetStackOverflow(TRUE, ((uint32_t *)&heap_location)[0]);

  /* Initialize random with a seed from the SoC random generator.
   * This must be done before selecting the high-precision external oscillator.
   */
  vAHI_StartRandomNumberGenerator(E_AHI_RND_SINGLE_SHOT, E_AHI_INTS_DISABLED);
  random_init(u16AHI_ReadRandomNumber());

  clock_init();
  rtimer_init();

#if JN516X_EXTERNAL_CRYSTAL_OSCILLATOR
  /* initialize the 32kHz crystal and wait for ready */
  xosc_init();
  /* need to reinitialize because the wait-for-ready process uses system timers */
  clock_init();
  rtimer_init();
#endif

  watchdog_init();
  leds_init();
  leds_on(LEDS_ALL);
  init_node_mac();

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  node_id_restore();

#if WITH_TINYOS_AUTO_IDS
  node_id = TOS_NODE_ID;
#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(node_mac, ieee, sizeof(uip_lladdr.addr));
    node_mac[7] = node_id & 0xff;
  }
#endif

  process_init();
  ctimer_init();
  uart0_init(UART_BAUD_RATE); /* Must come before first PRINTF */

#if NETSTACK_CONF_WITH_IPV4
  slip_arch_init(UART_BAUD_RATE);
#endif /* NETSTACK_CONF_WITH_IPV4 */

  /* check for reset source */
  if(bAHI_WatchdogResetEvent()) {
    PRINTF("Init: Watchdog timer has reset device!\r\n");
  }
  process_start(&etimer_process, NULL);
  set_linkaddr();
  netstack_init();

#if NETSTACK_CONF_WITH_IPV6
#if UIP_CONF_IPV6_RPL
  PRINTF(CONTIKI_VERSION_STRING " started with IPV6, RPL\n");
#else
  PRINTF(CONTIKI_VERSION_STRING " started with IPV6\n");
#endif
#elif NETSTACK_CONF_WITH_IPV4
  PRINTF(CONTIKI_VERSION_STRING " started with IPV4\n");
#else
  PRINTF(CONTIKI_VERSION_STRING " started\n");
#endif

  if(node_id > 0) {
    PRINTF("Node id is set to %u.\n", node_id);
  } else {
    PRINTF("Node id is not set.\n");
  }
#if NETSTACK_CONF_WITH_IPV6
  memcpy(&uip_lladdr.addr, node_mac, sizeof(uip_lladdr.addr));
  queuebuf_init();
#endif /* NETSTACK_CONF_WITH_IPV6 */

  PRINTF("%s %s %s\n", NETSTACK_LLSEC.name, NETSTACK_MAC.name, NETSTACK_RDC.name);

#if !NETSTACK_CONF_WITH_IPV4 && !NETSTACK_CONF_WITH_IPV6
  uart0_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] << 4) + 16);
#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 */

  watchdog_start();
  NETSTACK_LLSEC.init();

#if NETSTACK_CONF_WITH_IPV6
  start_uip6();
#endif /* NETSTACK_CONF_WITH_IPV6 */

  /* need this to reliably generate the first rtimer callback and callbacks in other 
     auto-start processes */
  (void)u32AHI_Init();

  start_autostart_processes();

  leds_off(LEDS_ALL);

  main_loop();

  return -1;
}
void
main(void)
{
  msp430_cpu_init();
  leds_init();
  leds_on(LEDS_ALL);
  clock_init();

  #if USE_SERIAL
  /* 
   * The Launchpad is limited to 9600 by the msp430--usb bridge; higher speeds can
   * be used with a separate uartserial->usb cable connected to the rxtx pins on
   * the header, but this Contiki port is kept at a maximum simplicity now, hence
   * 9600. If you do get one such cable, you can increase this to eg 115200.
   */
  uart0_init(BAUD2UBR(9600));
  #else
  /*
   * any printf's makes compiler complain of unresolved references to putchar;
   * this solves that. Must come before first printf.
   */
  #define printf(...)
  #endif  /* USE_SERIAL */

  rtimer_init();
  process_init();
  process_start(&etimer_process, NULL);
  ctimer_init();

  button_init();
  adc_init();

  #if _MCU_ == 2553
  #if HAS_EXT_OSC
  /* pwm only available on 2553 with external crystal as it has two hw timers */
  pwm_init(PWM_FREQ);
  #endif    /* HAS_EXT_OSC */
  #endif    /* _MCU_ == 2553 */

  #if USE_SERIAL
  uart0_set_input(serial_line_input_byte);
  serial_line_init();
  #endif  /* USE_SERIAL */


  #if USE_RADIO
  {
    rimeaddr_t addr;
    uint8_t i;
    /* Check that Magic number exists and node id first byte is not zero */
    if (NODEID_INFOMEM_LOCATION[0] != 0xBE || 
        NODEID_INFOMEM_LOCATION[1] != 0xEF ||
        NODEID_INFOMEM_LOCATION[2] == 0) {
      /* error - no address stored, just set to fail-address */
      addr.u8[0] = 0xde;    // 222
      addr.u8[1] = 0xad;    // 173
    } else {
      addr.u8[0] = NODEID_INFOMEM_LOCATION[2];
      addr.u8[1] = NODEID_INFOMEM_LOCATION[3];
    }
    rimeaddr_set_node_addr(&addr);
    printf("Rime started with address ");
    for(i = 0; i < sizeof(addr.u8) - 1; i++) {
      printf("%d.", addr.u8[i]);
    }
    printf("%d\n", addr.u8[i]);
  }

  netstack_init();
  #endif  /* USE_RADIO */

  watchdog_start();
  autostart_start(autostart_processes);
  leds_off(LEDS_ALL);
  printf(CONTIKI_VERSION_STRING " started.\n");

  //XXX sth messes with LEDs; find and fix
  leds_init();  // XXX remove when fixed.

  while(1) {
    /*
     * The Contiki main loop, greatly simplified and shortened compared with eg
     * msp430f1611 due to severe space constraints (mainly RAM).
     * As soon as we are not doing anything, we spend the time in LPM3.
     */
    int r;
    do {
      /* handle all events */
      watchdog_periodic();
      r = process_run();
    } while(r > 0);

    /* if not printing or pending events, sleep. */
    #if USE_SERIAL
      if(process_nevents() == 0 && !uart0_active()) {
    #else
      if(process_nevents() == 0) {
    #endif  /* USE_SERIAL */
      /* we are ready to go to sleep, LPM3 */
      if(dcoreq == 0) {
        LPM3;
      } else {
        LPM0;
      }
      asm("NOP;");

    }
  }
  return;
}