コード例 #1
0
int
main()
{
  configure_mcu_clocks();
  uart_init(115200);
  printf("Platform init complete, starting contiki init\n");

  clock_init();
  rtimer_init();
  leds_init();
  process_init();
#if WITH_SERIAL_LINE_INPUT
  uart_set_input(serial_line_input_byte);
  serial_line_init();
#endif
  process_start(&etimer_process, NULL);
  ctimer_init();
  autostart_start(autostart_processes);
  while(1) {
    do {
	// meant to do some sleeping here, if we want to save power...
	//
    } while(process_run() > 0);
  }
  return 0;
}
コード例 #2
0
ule6lo_status_t ule6loGI_init(const ule6lo_IPEI_t *IPEIAddr) {
	process_init();
	process_start(&etimer_process, NULL);
	ctimer_init();
	rtimer_init();
	set_rime_addr();
	//queuebuf_init();
	netstack_init();


	printf("Size of uip_ipeiaddr.addr = %i\n", (int)(sizeof(uip_ipeiaddr.addr)));
	if( IPEIAddr != NULL){
	    printf("Size of uip_ipeiaddr.addr = %i\n", (int)(sizeof(uip_ipeiaddr.addr)));
	    uip_ipeiaddr.addr[0] = 0x00;
	    memcpy(&uip_ipeiaddr.addr[1], IPEIAddr, sizeof(ule6lo_IPEI_t));
	}
#if ! FILTERED_BORDER_ROUTER
	process_start(&tcpip_process, NULL);
#endif

	autostart_start(autostart_processes);

	stack_status = STATUS_SUCCESS;
	return stack_status;
}
コード例 #3
0
ファイル: contiki-main.c プロジェクト: Babody/contiki
int
main(void)
{
  cpu_init();
  /* Initialize UART connected to Galileo Gen2 FTDI header */
  quarkX1000_uart_init(QUARK_X1000_UART_1);
  clock_init();
  rtimer_init();

  printf("Starting Contiki\n");

  ENABLE_IRQ();

  process_init();
  procinit_init();
  ctimer_init();
  autostart_start(autostart_processes);

  eth_init();

  while(1) {
    process_run();
  }

  return 0;
}
コード例 #4
0
ファイル: contiki-main.c プロジェクト: dak664/contiki-2.x
/*---------------------------------------------------------------------------*/
int
main(void)
{
  printf("Starting Contiki\n");
  process_init();
  ctimer_init();

  netstack_init();
  
  procinit_init();

  serial_line_init();
  
  autostart_start(autostart_processes);

  
  /* Make standard output unbuffered. */
  setvbuf(stdout, (char *)NULL, _IONBF, 0);
  
  while(1) {
    fd_set fds;
    int n;
    struct timeval tv;
    
    clock_time_t next_event;
	
    n = process_run();
    next_event = etimer_next_expiration_time()-clock_time();

#if DEBUG_SLEEP
    if(n > 0) {
      printf("%d events pending\n",n);
    } else {
      printf("next event: T-%.03f\n",(double)next_event/(double)CLOCK_SECOND);
    }
#endif

	if(next_event>CLOCK_SECOND*2)
		next_event = CLOCK_SECOND*2;
    tv.tv_sec = n?0:next_event/CLOCK_SECOND;
    tv.tv_usec = n?0:next_event%1000*1000;

    FD_ZERO(&fds);
    FD_SET(STDIN_FILENO, &fds);
    select(1, &fds, NULL, NULL, &tv);

    if(FD_ISSET(STDIN_FILENO, &fds)) {
      char c;
      if(read(STDIN_FILENO, &c, 1) > 0) {
	serial_line_input_byte(c);
      }
    }
    
    etimer_request_poll();
  }
  
  return 0;
}
コード例 #5
0
ファイル: contiki-main.c プロジェクト: jensnielsen/contiki
/*---------------------------------------------------------------------------*/
int main(void)
{

  /*
   * Initialise hardware.
   */
  //halInit();
    clock_init();

  //uart1_init(115200);

    // Led initialisation
    leds_init();
    leds_on(LEDS_RED);

    /* configure ethernet (GPIOs, clocks, MAC, DMA) */
    ETH_BSP_Config();



  //INTERRUPTS_ON();

    /*
     * Initialize Contiki and our processes.
     */

    process_init();
/*
#if WITH_SERIAL_LINE_INPUT
  uart1_set_input(serial_line_input_byte);
  serial_line_init();
#endif*/
  /* rtimer and ctimer should be initialized before radio duty cycling layers*/
    rtimer_init();
  /* etimer_process should be initialized before ctimer */
    process_start(&etimer_process, NULL);
    ctimer_init();

    netstack_init();

    procinit_init();

    autostart_start(autostart_processes);

    while (1)
    {
        int r;

        do
        {
            leds_toggle(LEDS_YELLOW);
            r = process_run();
        } while (r > 0);
    }
}
コード例 #6
0
int
main(void)
{

  leds_init();

  leds_on(LEDS_RED);

  /* Initialize USART */
  init_usart();
  
  /* Clock */
  clock_init();

  leds_on(LEDS_GREEN);

  ds2401_init();

  random_init(0);

  rtimer_init();

  /* Process subsystem */
  process_init();

  process_start(&etimer_process, NULL);

  ctimer_init();

  leds_on(LEDS_YELLOW);

  init_net();

  node_id_restore();
  
  printf_P(PSTR(CONTIKI_VERSION_STRING " started. Node id %u, using %s.\n"),
                                                       node_id, rime_mac->name);
  printf_P(PSTR("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n"),
	 ds2401_id[0], ds2401_id[1], ds2401_id[2], ds2401_id[3],
	 ds2401_id[4], ds2401_id[5], ds2401_id[6], ds2401_id[7]);

  leds_off(LEDS_ALL);

  /* Autostart processes */
  autostart_start(autostart_processes);

  /* Main scheduler loop */
  do {

    process_run();

  }while(1);

  return 0;
}
コード例 #7
0
ファイル: contiki-iris-main.c プロジェクト: 21moons/contiki
/*---------------------------------------------------------------------------*/
int
main(void)
{

  leds_init();

  leds_on(LEDS_RED);

  /* Initialize USART */
  init_usart();
  
  /* Clock */
  clock_init();

  leds_on(LEDS_GREEN);

  ds2401_init();
  
  node_id_restore();

  random_init(ds2401_id[0] + node_id);

  rtimer_init();

  /* Process subsystem */
  process_init();

  process_start(&etimer_process, NULL);

  ctimer_init();

  leds_on(LEDS_YELLOW);
  
  init_net();
  
  printf_P(PSTR(CONTIKI_VERSION_STRING " started. Node id %u\n"), node_id);

  leds_off(LEDS_ALL);

  /* Autostart processes */
  autostart_start(autostart_processes);

  mmem_init();
  /* Main scheduler loop */
  do {

    process_run();

  }while(1);

  return 0;
}
コード例 #8
0
/*---------------------------------------------------------------------------*/
int
main(void)
{
	DBGMCU_Config(DBGMCU_SLEEP | DBGMCU_STOP | DBGMCU_STANDBY, ENABLE);

	leds_init();
	//printf("\rStarting Contiki on STM32VL Discovery...\n\r");

	clock_init();
	process_init();

	uip_init();
	uip_fw_init();
	process_start(&tcpip_process, NULL);
	process_start(&uip_fw_process, NULL);

	uip_ipaddr(&hostaddr, 172, 16, 0, 3);
	uip_sethostaddr(&hostaddr);
	uip_ipaddr(&netmask, 255, 255, 0, 0);
	uip_setnetmask(&netmask);
	uip_ipaddr(&netmask, 172, 16, 0, 1);
	uip_setdraddr(&draddr);

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

	/* Networking stack. */
	NETSTACK_RADIO.init();
	NETSTACK_RDC.init();
	NETSTACK_MAC.init();
	NETSTACK_NETWORK.init();
	{
		rimeaddr_t rimeaddr;

		rimeaddr.u8[0] = 0x02;
		rimeaddr.u8[1] = 0x00;
		rimeaddr_set_node_addr(&rimeaddr);
	}

	autostart_start(autostart_processes);

	while (1)
	{
		process_run();
	}

	return 0;
}
コード例 #9
0
/*---------------------------------------------------------------------------*/
int
main(void)
{
  printf("Starting Contiki\n");
  process_init();
  ctimer_init();

  netstack_init();
  
  procinit_init();

  serial_line_init();
  
  //autostart_start(autostart_processes);

  
  /* Make standard output unbuffered. */
  setvbuf(stdout, (char *)NULL, _IONBF, 0);
  
  while(1) {
    fd_set fds;
    int n;
    struct timeval tv;
    
    n = process_run();

    
    tv.tv_sec = 0;
    tv.tv_usec = 1;

    FD_ZERO(&fds);
    FD_SET(STDIN_FILENO, &fds);
    select(1, &fds, NULL, NULL, &tv);

    if(FD_ISSET(STDIN_FILENO, &fds)) {
      char c;
      if(read(STDIN_FILENO, &c, 1) > 0) {
	serial_line_input_byte(c);
      }
    }
    
    etimer_request_poll();
  }
  
  return 0;
}
コード例 #10
0
ファイル: freakz.c プロジェクト: abhinavgupta/IEEE-802.15.4
void freakz_init()
{
    drvr_init();
    mmem_init();
    ctimer_init();
    mac_init();
    nwk_init();
    aps_init();
    af_init();
    zdo_init();
    buf_init();
    slow_clock_init();

#if (TEST_SIM == 1)
    test_app_init();
#endif
}
コード例 #11
0
ファイル: contiki-main.c プロジェクト: 1847123212/contiki
/*---------------------------------------------------------------------------*/
void
app_main(void)
{
  printf("Starting Contiki\n");

  process_init();
  procinit_init();
  ctimer_init();
  eth_init();

  autostart_start(autostart_processes);

  while(1) {
    process_run();
  }

  halt();
}
コード例 #12
0
int main_minimal_net(void) {

	// TODO: Pegar MAC Address do Microchip MRF24J40MA
	clock_init();

	linkaddr_set_node_addr((linkaddr_t*) &addr);
	memcpy(&uip_lladdr.addr, &linkaddr_node_addr.u8, sizeof(uip_lladdr.addr));

#if 1	
	queuebuf_init();
	netstack_init();
#endif  	

	process_init();
	/* procinit_init initializes RPL which sets a ctimer for the first DIS */
	/* We must start etimers and ctimers,before calling it */
	process_start(&etimer_process, NULL);
	ctimer_init();

	procinit_init();

#if AUTOSTART_ENABLE
	autostart_start(autostart_processes);
#endif
	OSSemBinaryCreate(0, &Contiki_Sem);

	PRINTF("\n*******%s online*******\n\r", CONTIKI_VERSION_STRING);

	while (1) {

		int n;
		//char c;
		//INT8U ret,poll;
		//clock_time_t next_event;

		do {
			n = process_run();
			//mrf24j40_get_rssi();
		} while (n > 0);

		OSSemPend(Contiki_Sem, 0);
	}
}
コード例 #13
0
ファイル: net_init.c プロジェクト: pafcndg/ndgIqSoftwareKit
static int network_initialization(void)
{
	/* Initialize and start Contiki uIP stack */
	clock_init();

	rtimer_init();
	ctimer_init();

	process_init();
	tcpip_set_outputfunc(net_tcpip_output);

	process_start(&tcpip_process, NULL);
	process_start(&simple_udp_process, NULL);
	process_start(&etimer_process, NULL);

	slip_start();

	return 0;
}
コード例 #14
0
int another_net(void) {

	clock_init();



	random_init(MOTE_ID);
	init_net(MOTE_ID);


	process_init();

	start_radio_task();

	process_start(&etimer_process, NULL);

	ctimer_init();
	rtimer_init();

	procinit_init();

	autostart_start(autostart_processes);
	start_udp_server_task();

	PRINTF("Processes running\n");

	OSSemBinaryCreate(0, &Contiki_Sem);

	PRINTF("\n*******%s online*******\n\r", CONTIKI_VERSION_STRING);

	while (1) {

		int n;

		do {
			n = process_run();
		} while (n > 0);

		OSSemPend(Contiki_Sem, 0);
	}
}
コード例 #15
0
void SimluateRun(CuTest* tc)
{
 /*
  * Initialize Contiki and our processes.
  */
  process_init();
  process_start(&etimer_process, NULL);
  ctimer_init();

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  window_init(0xff);  

  autostart_start(autostart_processes);

  process_start(&event_process, NULL);
  while(run) {
    int r;
    do {
      /* Reset watchdog. */
      r = process_run();
    } while(r > 0);

#if 0
    int n = etimer_next_expiration_time();
    if (n > 0)
    {
      int p = n - clock_time();
      if (p > 0)
      nanosleep(p);
    }
    else
    {
      nanosleep(1000);
    }
#endif
    etimer_request_poll();
  }
}
コード例 #16
0
ファイル: pal.c プロジェクト: Shatiff/IRtemperature
void pal_startTimers(void) {
	// Initialize the hardware to drive the
	// signal processing layers.
	ctimer_set_callback(pal_captureTimerFn);

	comparator_enablePin(LEFT_PORT, LEFT_PIN);
	comparator_enablePin(VREF_PORT, VREF_PIN);

	comparator_init();
	comparator_setup(
		comparator_getChannel(LEFT_PORT, LEFT_PIN),
		comparator_getChannel(VREF_PORT, VREF_PIN)
	);
	comparator_on();

	ctimer_init();
	ptimer_init();

	ptimer_start(TIMER_TICKS, pal_periodicTimerFn);
	// Wait 100ms for everything to stabalize.
	//util_delayMs(100);
}
コード例 #17
0
ファイル: init-net-uip.c プロジェクト: EDAyele/ptunes
/*---------------------------------------------------------------------------*/
void
init_net(void)
{
  int i;
  uip_ipaddr_t hostaddr, netmask;
  rimeaddr_t rimeaddr;

  /* Init Rime */
  ctimer_init();
  rimeaddr.u8[0] = node_id & 0xff;
  rimeaddr.u8[1] = node_id >> 8;
  rimeaddr_set_node_addr(&rimeaddr);
  printf("Rime started with address: ");
  for(i = 0; i < sizeof(rimeaddr_node_addr.u8) - 1; i++) {
    printf("%d.", rimeaddr_node_addr.u8[i]);
  }
  printf("%d\n", rimeaddr_node_addr.u8[i]);

  /* Init uIPv4 */
  process_start(&tcpip_process, NULL);
  process_start(&uip_fw_process, NULL);
  process_start(&slip_process, NULL);
  uip_init();
  uip_fw_init();
  uip_ipaddr(&hostaddr, 172, 16, rimeaddr_node_addr.u8[1], rimeaddr_node_addr.u8[0]);
  uip_ipaddr(&netmask, 255,255,0,0);
  uip_sethostaddr(&hostaddr);
  uip_setnetmask(&netmask);
  uip_fw_register(&wsn_if);
  uip_fw_default(&slip_if);
  rs232_set_input(slip_input_byte);
  printf("uIP started with IP address: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&hostaddr));

  /* uIPv4 <-> COOJA's packet radio */
  /*tcpip_set_outputfunc(sender);*/
  cooja_radio.set_receive_function(receiver);
}
コード例 #18
0
/*-----------------------------Low level initialization--------------------*/
static void initialize(void) {
  watchdog_init();
  watchdog_start();

#if CONFIG_STACK_MONITOR
  /* Simple stack pointer highwater monitor. The 'm' command in cdc_task.c
   * looks for the first overwritten magic number.
   */
{
extern uint16_t __bss_end;
uint16_t p=(uint16_t)&__bss_end;
    do {
      *(uint16_t *)p = 0x4242;
      p+=100;
    } while (p<RAMEND-100);
}
#endif

  /* Initialize hardware */
  // Checks for "finger", jumps to DFU if present.
  init_lowlevel();
  
  /* Clock */
  clock_init();

#if USB_CONF_RS232
  /* Use rs232 port for serial out (tx, rx, gnd are the three pads behind jackdaw leds */
  rs232_init(RS232_PORT_0, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
  /* Redirect stdout to second port */
  rs232_redirect_stdout(RS232_PORT_0);
#if ANNOUNCE
  printf_P(PSTR("\n\n\n********BOOTING CONTIKI*********\n"));
#endif
#endif
	
	Leds_init();
	
  /* rtimer init needed for low power protocols */
  rtimer_init();

  /* Process subsystem. */
  process_init();

  /* etimer process must be started before ctimer init */
  process_start(&etimer_process, NULL);
  
#if RF230BB
  ctimer_init();
  /* Start radio and radio receive process */
  /* Note this starts RF230 process, so must be done after process_init */
  NETSTACK_RADIO.init();

  /* Set addresses BEFORE starting tcpip process */

  memset(&tmp_addr, 0, sizeof(rimeaddr_t));
  if(!get_eui64_from_eeprom(tmp_addr.u8)) {
#if JACKDAW_CONF_RANDOM_MAC
    // It doesn't look like we have a valid EUI-64 address
	// so let's try to make a new one from scratch.
    Leds_off();
    Led2_on();
    generate_new_eui64(tmp_addr.u8);
	if(!set_eui64_to_eeprom(tmp_addr.u8)) {
		watchdog_periodic();
		int i;
		for(i=0;i<20;i++) {
			Led1_toggle();
			_delay_ms(100);
		}
		Led1_off();
	}
	Led2_off();
#else
	tmp_addr.u8[0]=0x02;
	tmp_addr.u8[1]=0x12;
	tmp_addr.u8[2]=0x13;
	tmp_addr.u8[3]=0xff;
	tmp_addr.u8[4]=0xfe;
	tmp_addr.u8[5]=0x14;
	tmp_addr.u8[6]=0x15;
	tmp_addr.u8[7]=0x16;
#endif /* JACKDAW_CONF_RANDOM_MAC */
  }
  

  //Fix MAC address
  init_net();

#if UIP_CONF_IPV6
  memcpy(&uip_lladdr.addr, &tmp_addr.u8, 8);
#endif

  rf230_set_pan_addr(
	get_panid_from_eeprom(),
	get_panaddr_from_eeprom(),
	(uint8_t *)&tmp_addr.u8
  );
  
#if JACKDAW_CONF_USE_SETTINGS
/* Allow radio code to overrite power for testing miniature Raven mesh */
#ifndef RF230_MAX_TX_POWER
   rf230_set_txpower(settings_get_uint8(SETTINGS_KEY_TXPOWER,0));
#endif
#endif

  rimeaddr_set_node_addr(&tmp_addr); 

  /* Initialize stack protocols */
  queuebuf_init();
  NETSTACK_RDC.init();
  NETSTACK_MAC.init();
  NETSTACK_NETWORK.init();

  rf230_set_channel(get_channel_from_eeprom());

#if ANNOUNCE && USB_CONF_RS232
  printf_P(PSTR("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n\r"),tmp_addr.u8[0],tmp_addr.u8[1],tmp_addr.u8[2],tmp_addr.u8[3],tmp_addr.u8[4],tmp_addr.u8[5],tmp_addr.u8[6],tmp_addr.u8[7]);
  printf_P(PSTR("%s %s, channel %u"),NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel());
  if (NETSTACK_RDC.channel_check_interval) {
    unsigned short tmp;
    tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\
                        NETSTACK_RDC.channel_check_interval());
    if (tmp<65535) printf_P(PSTR(", check rate %u Hz"),tmp);
  }
  printf_P(PSTR("\n"));
#endif

#if UIP_CONF_IPV6_RPL
#if RPL_BORDER_ROUTER
  process_start(&tcpip_process, NULL);
  process_start(&border_router_process, NULL);
  PRINTF ("RPL Border Router Started\n");
#else
  process_start(&tcpip_process, NULL);
  PRINTF ("RPL Started\n");
#endif
#if RPL_HTTPD_SERVER
  extern struct process httpd_process;
  process_start(&httpd_process, NULL);
  PRINTF ("Webserver Started\n");
#endif
#endif /* UIP_CONF_IPV6_RPL */

#else  /* RF230BB */
/* The order of starting these is important! */
  process_start(&mac_process, NULL);
  process_start(&tcpip_process, NULL);
#endif /* RF230BB */

  /* Setup USB */
  process_start(&usb_process, NULL);
#if USB_CONF_SERIAL
  process_start(&cdc_process, NULL);
#endif
  process_start(&usb_eth_process, NULL);
#if USB_CONF_STORAGE
  process_start(&storage_process, NULL);
#endif
  
#if ANNOUNCE
#if USB_CONF_SERIAL&&!USB_CONF_RS232
{unsigned short i;
   printf_P(PSTR("\n\n\n********BOOTING CONTIKI*********\n\r"));
  /* Allow USB CDC to keep up with printfs */
  for (i=0;i<8000;i++) process_run();
#if RF230BB
  printf_P(PSTR("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n\r"),tmp_addr.u8[0],tmp_addr.u8[1],tmp_addr.u8[2],tmp_addr.u8[3],tmp_addr.u8[4],tmp_addr.u8[5],tmp_addr.u8[6],tmp_addr.u8[7]);
  for (i=0;i<8000;i++) process_run();
  printf_P(PSTR("%s %s, channel %u"),NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel());
  if (NETSTACK_RDC.channel_check_interval) {
    i=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\
                      NETSTACK_RDC.channel_check_interval());
    if (i<65535) printf_P(PSTR(", check rate %u Hz"),i);
   }
   printf_P(PSTR("\n\r"));
   for (i=0;i<8000;i++) process_run();
#endif /* RF230BB */
  printf_P(PSTR("System online.\n\r"));
}
#elif USB_CONF_RS232
  printf_P(PSTR("System online.\n"));
#endif
#endif /* ANNOUNCE */
}
コード例 #19
0
ファイル: ota-main.c プロジェクト: songjw0820/contiki_atmel
int
main(int argc, char *argv[])
{
  node_id_restore();
  /* init system: clocks, board etc */
  system_init();
  sio2host_init();

  leds_init();
  leds_on(LEDS_ALL);

  system_interrupt_enable_global();
  flash_init();
  delay_init();

  /* Initialize Contiki and our processes. */
  
  #ifdef LOW_POWER_MODE
  configure_tc3();
  #else
  clock_init();
  #endif

  process_init();
  ctimer_init();
  rtimer_init();
  process_start(&etimer_process, NULL);
  
  /* Set MAC address and node ID */
#ifdef NODEID
  node_id = NODEID;
#ifdef BURN_NODEID
  node_id_burn(node_id);
#endif /* BURN_NODEID */
#else/* NODE_ID */
#endif /* NODE_ID */

  printf("\r\n\n\n\n Starting the SmartConnect-6LoWPAN \r\n Platform : Atmel IoT device \r\n");
  print_reset_causes();
  netstack_init();
 #if BOARD == SAMR21_XPLAINED_PRO
  eui64 = edbg_eui_read_eui64();
  SetIEEEAddr(eui64);
#else
  SetIEEEAddr(node_mac);  
#endif 
  set_link_addr();  
  rf_set_channel(RF_CHANNEL);
  printf("\r\n Configured RF channel: %d\r\n", rf_get_channel());
  leds_off(LEDS_ALL);
  process_start(&sensors_process, NULL);
  energest_init();

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

  /* Setup nullmac-like MAC for 802.15.4 */
#if SAMD
  memcpy(&uip_lladdr.addr, node_mac, sizeof(uip_lladdr.addr));
#else 
  memcpy(&uip_lladdr.addr, eui64, sizeof(uip_lladdr.addr));
#endif
   
  queuebuf_init();
  printf(" %s %lu %d\r\n",
         NETSTACK_RDC.name,
         (uint32_t) (CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
                         NETSTACK_RDC.channel_check_interval())),
         RF_CHANNEL);

  process_start(&tcpip_process, NULL);
  printf(" 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\r\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
  }

  {
    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]);
  }

  print_processes(autostart_processes);

  /* set up AES key */
#if ((THSQ_CONF_NETSTACK) & THSQ_CONF_AES)
#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\n");
#else /* ((THSQ_CONF_NETSTACK) & THSQ_CONF_AES) */
  printf("\r\n Warning: AES encryption is disabled\n");
#endif /* ((THSQ_CONF_NETSTACK) & THSQ_CONF_AES) */

#ifdef ENABLE_LEDCTRL
  ledctrl_init();
#endif
  autostart_start(autostart_processes);


  while(1){
    int r = 0;

	serial_data_handler();

  do {

     
     r = process_run();

    } while(r > 0);

  }
}
コード例 #20
0
void
init_lowlevel(void)
{

  /* Second rs232 port for debugging */
  rs232_init(RS232_PORT_1, USART_BAUD_115200,
             USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);

  /* Redirect stdout to second port */
  rs232_redirect_stdout(RS232_PORT_1);
  
  /* Clock */
  clock_init();
 
 /* rtimers needed for radio cycling */
  rtimer_init();

 /* Initialize process subsystem */
  process_init();
 /* etimers must be started before ctimer_init */
  process_start(&etimer_process, NULL);
  
#if RF230BB

  ctimer_init();
  /* Start radio and radio receive process */
  NETSTACK_RADIO.init();

  /* Set addresses BEFORE starting tcpip process */

  linkaddr_t addr;
  memset(&addr, 0, sizeof(linkaddr_t));
  eeprom_read_block ((void *)&addr.u8,  &mac_address, 8);
 
#if UIP_CONF_IPV6
  memcpy(&uip_lladdr.addr, &addr.u8, 8);
#endif  
  rf230_set_pan_addr(IEEE802154_PANID, 0, (uint8_t *)&addr.u8);
#ifdef CHANNEL_802_15_4
  rf230_set_channel(CHANNEL_802_15_4);
#else
  rf230_set_channel(26);
#endif

  linkaddr_set_node_addr(&addr); 

  PRINTF("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]);

  /* Initialize stack protocols */
  queuebuf_init();
  NETSTACK_RDC.init();
  NETSTACK_MAC.init();
  NETSTACK_NETWORK.init();

#if ANNOUNCE_BOOT
  printf_P(PSTR("%s %s, channel %u"),NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel());
  if (NETSTACK_RDC.channel_check_interval) {//function pointer is zero for sicslowmac
    unsigned short tmp;
    tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\
                                   NETSTACK_RDC.channel_check_interval());
    if (tmp<65535) printf_P(PSTR(", check rate %u Hz"),tmp);
  }
  printf_P(PSTR("\n"));
#endif

#if UIP_CONF_ROUTER
#if ANNOUNCE_BOOT
  printf_P(PSTR("Routing Enabled\n"));
#endif
  rime_init(rime_udp_init(NULL));
  uip_router_register(&rimeroute);
#endif

  process_start(&tcpip_process, NULL);

#else
/* mac process must be started before tcpip process! */
  process_start(&mac_process, NULL);
  process_start(&tcpip_process, NULL);
#endif /*RF230BB*/

}
コード例 #21
0
int main(int argc, char **argv)
{
	int32_t r;

	process_init(); // run before any function that starts a process
	pic32_init();
	watchdog_init();
	leds_init();
	leds_progress_init();
	buzzer_init();

	clock_init();
	rtimer_init();
	ctimer_init();

	leds_on(LEDS_ALL);

        /* Serial line init part 2/3: set up the UART port. */
	uart_console_init(UART_BAUDRATE);

//	usb_serial_init();
//	usb_serial_set_input(serial_line_input_byte);

        /* Serial line init part 3/3: start the OS process. */
	serial_line_init();

	asm volatile("ei");  // enable interrupts

	PRINTF("CPU Clock: %uMhz\n",
	       pic32_clock_get_system_clock() / 1000000);
	PRINTF("Peripheral Clock: %uMhz\n",
	       pic32_clock_get_peripheral_clock() / 1000000);

	random_init(4321);
	process_start(&etimer_process, NULL);
	process_start(&sensors_process, NULL);
	SENSORS_ACTIVATE(button_sensor);

	/* Starting autostarting process */
	print_processes(autostart_processes);
	autostart_start(autostart_processes);

	leds_off(LEDS_ALL);
	watchdog_start();
	PRINTF("Starting the main scheduler loop\n");

	/*
	 * This is the scheduler loop.
	 */
	while (1) {

		do {
			/* Reset watchdog. */
			watchdog_periodic();
			r = process_run();
		} while (r > 0);

#if LPM_MODE > LPM_MODE_NONE
		watchdog_stop();
		/* low-power mode start */
		asm volatile("wait");
		/* low-power mode end */
		watchdog_start();
#endif // LPM_MODE
	}

	return 0;
}
コード例 #22
0
ファイル: contiki-raven-main.c プロジェクト: 1uk3/contiki
/*-----------------------------Low level initialization--------------------*/
static void initialize(void) {

  watchdog_init();
  watchdog_start();

#if CONFIG_STACK_MONITOR
  /* Simple stack pointer highwater monitor. The 'm' command in cdc_task.c
   * looks for the first overwritten magic number.
   */
{
extern uint16_t __bss_end;
uint16_t p=(uint16_t)&__bss_end;
    do {
      *(uint16_t *)p = 0x4242;
      p+=100;
    } while (p<SP-100); //don't overwrite our own stack
}
#endif

  /* Initialize hardware */
  // Checks for "finger", jumps to DFU if present.
  init_lowlevel();
  
  /* Clock */
  clock_init();

  /* Leds are referred to by number to prevent any possible confusion :) */
  /* Led0 Blue Led1 Red Led2 Green Led3 Yellow */
  Leds_init();
  Led1_on();

/* Get a random (or probably different) seed for the 802.15.4 packet sequence number.
 * Some layers will ignore duplicates found in a history (e.g. Contikimac)
 * causing the initial packets to be ignored after a short-cycle restart.
 */
  ADMUX =0x1E;              //Select AREF as reference, measure 1.1 volt bandgap reference.
  ADCSRA=1<<ADEN;           //Enable ADC, not free running, interrupt disabled, fastest clock
  ADCSRA|=1<<ADSC;          //Start conversion
  while (ADCSRA&(1<<ADSC)); //Wait till done
  PRINTD("ADC=%d\n",ADC);
  random_init(ADC);
  ADCSRA=0;                 //Disable ADC
  
#if USB_CONF_RS232
  /* Use rs232 port for serial out (tx, rx, gnd are the three pads behind jackdaw leds */
  rs232_init(RS232_PORT_0, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
  /* Redirect stdout to second port */
  rs232_redirect_stdout(RS232_PORT_0);
#if ANNOUNCE
  PRINTA("\n\n*******Booting %s*******\n",CONTIKI_VERSION_STRING);
#endif
#endif
	
  /* rtimer init needed for low power protocols */
  rtimer_init();

  /* Process subsystem. */
  process_init();

  /* etimer process must be started before USB or ctimer init */
  process_start(&etimer_process, NULL);

  Led2_on();
  /* Now we can start USB enumeration */
  process_start(&usb_process, NULL);

  /* Start CDC enumeration, bearing in mind that it may fail */
  /* Hopefully we'll get a stdout for startup messages, if we don't already */
#if USB_CONF_SERIAL
  process_start(&cdc_process, NULL);
{unsigned short i;
  for (i=0;i<65535;i++) {
    process_run();
    watchdog_periodic();
    if (stdout) break;
  }
#if !USB_CONF_RS232
  PRINTA("\n\n*******Booting %s*******\n",CONTIKI_VERSION_STRING);
#endif
}
#endif
  if (!stdout) Led3_on();
  
#if RF230BB
#if JACKDAW_CONF_USE_SETTINGS
  PRINTA("Settings manager will be used.\n");
#else
{uint8_t x[2];
	*(uint16_t *)x = eeprom_read_word((uint16_t *)&eemem_channel);
	if((uint8_t)x[0]!=(uint8_t)~x[1]) {
        PRINTA("Invalid EEPROM settings detected. Rewriting with default values.\n");
        get_channel_from_eeprom();
    }
}
#endif

  ctimer_init();
  /* Start radio and radio receive process */
  /* Note this starts RF230 process, so must be done after process_init */
  NETSTACK_RADIO.init();

  /* Set addresses BEFORE starting tcpip process */

  memset(&tmp_addr, 0, sizeof(rimeaddr_t));

  if(get_eui64_from_eeprom(tmp_addr.u8));
   
  //Fix MAC address
  init_net();

#if UIP_CONF_IPV6
  memcpy(&uip_lladdr.addr, &tmp_addr.u8, 8);
#endif

  rf230_set_pan_addr(
	get_panid_from_eeprom(),
	get_panaddr_from_eeprom(),
	(uint8_t *)&tmp_addr.u8
  );
  
  rf230_set_channel(get_channel_from_eeprom());
  rf230_set_txpower(get_txpower_from_eeprom());

  rimeaddr_set_node_addr(&tmp_addr); 

  /* Initialize stack protocols */
  queuebuf_init();
  NETSTACK_RDC.init();
  NETSTACK_MAC.init();
  NETSTACK_NETWORK.init();

#if ANNOUNCE
  PRINTA("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n\r",tmp_addr.u8[0],tmp_addr.u8[1],tmp_addr.u8[2],tmp_addr.u8[3],tmp_addr.u8[4],tmp_addr.u8[5],tmp_addr.u8[6],tmp_addr.u8[7]);
  PRINTA("%s %s, channel %u",NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel());
  if (NETSTACK_RDC.channel_check_interval) {
    unsigned short tmp;
    tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\
                        NETSTACK_RDC.channel_check_interval());
    if (tmp<65535) PRINTA(", check rate %u Hz",tmp);
  }
  PRINTA("\n");
#endif

#if UIP_CONF_IPV6_RPL
#if RPL_BORDER_ROUTER
  process_start(&tcpip_process, NULL);
  process_start(&border_router_process, NULL);
  PRINTD ("RPL Border Router Started\n");
#else
  process_start(&tcpip_process, NULL);
  PRINTD ("RPL Started\n");
#endif
#if RPL_HTTPD_SERVER
  extern struct process httpd_process;
  process_start(&httpd_process, NULL);
  PRINTD ("Webserver Started\n");
#endif
#endif /* UIP_CONF_IPV6_RPL */

#else  /* RF230BB */
/* The order of starting these is important! */
  process_start(&mac_process, NULL);
  process_start(&tcpip_process, NULL);
#endif /* RF230BB */

  /* Start ethernet network and storage process */
  process_start(&usb_eth_process, NULL);
#if USB_CONF_STORAGE
  process_start(&storage_process, NULL);
#endif

  /* Autostart other processes */
  /* There are none in the default build so autostart_processes will be unresolved in the link. */
  /* The AUTOSTART_PROCESSES macro which defines it can only be used in the .co module. */
  /* See /examples/ravenusbstick/ravenusb.c for an autostart template. */
#if 0
  autostart_start(autostart_processes);
#endif

#if ANNOUNCE
#if USB_CONF_RS232
  PRINTA("Online.\n");
#else
  PRINTA("Online. Type ? for Jackdaw menu.\n");
#endif
#endif

Leds_off();
}
コード例 #23
0
ファイル: contiki-main.c プロジェクト: yplam/SensorTagUDP
/**
 * \brief Main function for CC26xx-based platforms
 *
 * The same main() is used for all supported boards
 */
int
main(void)
{
  /* Enable flash cache and prefetch. */
  ti_lib_vims_mode_set(VIMS_BASE, VIMS_MODE_ENABLED);
  ti_lib_vims_configure(VIMS_BASE, true, true);

  ti_lib_int_master_disable();

  /* Set the LF XOSC as the LF system clock source */
  oscillators_select_lf_xosc();

  lpm_init();

  board_init();

  gpio_interrupt_init();

  leds_init();

  /*
   * Disable I/O pad sleep mode and open I/O latches in the AON IOC interface
   * This is only relevant when returning from shutdown (which is what froze
   * latches in the first place. Before doing these things though, we should
   * allow software to first regain control of pins
   */
  ti_lib_pwr_ctrl_io_freeze_disable();

  fade(LEDS_RED);

  ti_lib_int_master_enable();

  soc_rtc_init();
  clock_init();
  rtimer_init();

  watchdog_init();
  process_init();

  random_init(0x1234);

  /* Character I/O Initialisation */
#if CC26XX_UART_CONF_ENABLE
  cc26xx_uart_init();
#endif

  serial_line_init();

  printf("Starting " CONTIKI_VERSION_STRING "\n\r");
  printf("With DriverLib v%u.%u\n\r", DRIVERLIB_RELEASE_GROUP,
         DRIVERLIB_RELEASE_BUILD);
  printf(BOARD_STRING "\n\r");

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

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  fade(LEDS_YELLOW);

  printf(" Net: ");
  printf("%s\n\r", NETSTACK_NETWORK.name);
  printf(" MAC: ");
  printf("%s\n\r", NETSTACK_MAC.name);
  printf(" RDC: ");
  printf("%s", NETSTACK_RDC.name);

  if(NETSTACK_RDC.channel_check_interval() != 0) {
    printf(", Channel Check Interval: %u ticks",
           NETSTACK_RDC.channel_check_interval());
  }
  printf("\n\r");

  netstack_init();

  set_rf_params();

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

  fade(LEDS_GREEN);

  process_start(&sensors_process, NULL);

  autostart_start(autostart_processes);

  watchdog_start();

  fade(LEDS_ORANGE);

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

    /* Drop to some low power mode */
    lpm_drop();
  }
}
コード例 #24
0
void lowlevel_init()
{
  rimeaddr_t rimeaddr;
  uint16_t *fsize = (uint16_t *)0x1FF8004C;
  uint16_t *uid96 = (uint16_t *)0x1FF80050;
  uint32_t *dbgmcu_id = (uint32_t *)0xE0042000;
  uint16_t uid16;

  dbg_setup_uart();

  printf("\nInitialising\n");

  printf("Device ID: 0x%03x, silicon rev: 0x%04x\n", 
         (unsigned int)*dbgmcu_id & 0x0fff, 
         (unsigned int)(*dbgmcu_id >> 16) & 0xffff);
  printf("Flash size is %d kB\n", *fsize);
  printf("UID96 is %04x %04x %04x %04x %04x %04x\n", 
         uid96[0], uid96[1], uid96[2], uid96[3], uid96[4], uid96[5]);
  uid16 = u101_chksum(0, (uint8_t *)uid96, 12);
  printf("Pseudo-UID16 is %02x\n", uid16);

  clock_init();
  rtimer_init();
  process_init();
  process_start(&etimer_process, NULL);
  ctimer_init();
  serial_line_init();
  leds_init();

#ifdef U101_RF231
  printf("Low-level networking init\n");
  queuebuf_init();
  NETSTACK_RADIO.init();
  NETSTACK_RADIO.on();
  NETSTACK_MAC.init();
  NETSTACK_RDC.on();
#endif
#if 0
  printf("%s %s, channel check rate %u 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
  //memcpy(&uip_lladdr.addr, ds2411_id, sizeof(uip_lladdr.addr));

#if defined WITH_UIP6

  printf("\nAddresses [%u max]\n", UIP_DS6_ADDR_NB);
  
  for (i=0; i<UIP_DS6_ADDR_NB; i++) {
    if (uip_ds6_if.addr_list[i].isused) {
      uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr);
      printf("\n");
    }
  }
#endif

  /* Temporarily, we use a part of the STM32's UID as address. 
     It seems like uid_0[1] is usable in our batch. Note that
     this does not guarrantee unique addresses.
   */
  rimeaddr.u8[0] = (uint8_t)(uid16 >> 8) & 0xff;
  rimeaddr.u8[1] = (uint8_t)(uid16 & 0xff);
  printf("Rime address is: %02x.%02x\n", 
         rimeaddr.u8[0], rimeaddr.u8[1]);

#if NETSTACK_CONF_RADIO == rf230_driver
  rf230_set_pan_addr(IEEE802154_PANID, 0, (uint8_t *)&rimeaddr.u8);
  rf230_set_channel(CHANNEL_802_15_4);
  rimeaddr_set_node_addr(&rimeaddr);
#endif
  process_start(&tcpip_process, NULL);

#if defined WITH_UIP6

  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]);
  }
  printf("\n");
#endif

  //em_init();

  leds_on(LEDS_ALL);

  print_local_addresses();

#ifdef WITH_UIP
  printf("Starting tcpip and fw\n");
  process_start(&tcpip_process, NULL);
  process_start(&uip_fw_process, NULL);
#endif
#ifdef WITH_USB
  //(void)setup_usb();
  process_start(&usbeth_process, NULL);
#endif
  //process_start(&lsm303_process, NULL);
  //process_start(&eriks_process, NULL);
  printf("Processes running\n");
}
コード例 #25
0
/*---------------------------------------------------------------------------*/
void
contiki_init()
{
  /* Initialize random generator (moved to moteid.c) */

  /* Start process handler */
  process_init();


  /* Start Contiki processes */

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

  /* Print startup information */
  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();
  {
    uint8_t longaddr[8];
    
    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]);
  }

  queuebuf_init();

  /* Initialize communication stack */
  netstack_init();
  printf("%s/%s/%s, channel check rate %lu Hz\n",
	 NETSTACK_NETWORK.name, NETSTACK_MAC.name, NETSTACK_RDC.name,
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
                         NETSTACK_RDC.channel_check_interval()));

#if WITH_UIP
  /* IPv4 CONFIGURATION */
  {
    uip_ipaddr_t hostaddr, netmask;

    process_start(&tcpip_process, NULL);
    process_start(&uip_fw_process, NULL);
    process_start(&slip_process, NULL);

    slip_set_input_callback(set_gateway);

    uip_init();
    uip_fw_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_over_mesh_set_gateway_netif(&slipif);
    uip_fw_default(&meshif);
    uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);

    rs232_set_input(slip_input_byte);
    printf("IPv4 address: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&hostaddr));
  }
#endif /* WITH_UIP */

#if WITH_UIP6
  /* IPv6 CONFIGURATION */
  {
    int i;
    uint8_t addr[sizeof(uip_lladdr.addr)];
    for(i = 0; i < sizeof(uip_lladdr.addr); i += 2) {
      addr[i + 1] = node_id & 0xff;
      addr[i + 0] = node_id >> 8;
    }
    linkaddr_copy((linkaddr_t *)addr, &linkaddr_node_addr);
    memcpy(&uip_lladdr.addr, addr, sizeof(uip_lladdr.addr));

    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(1) {
      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 /* WITH_UIP6 */

  /* Initialize eeprom */
  eeprom_init();
  
  /* Start serial process */
  serial_line_init();

  /* Start autostart processes (defined in Contiki application) */
  print_processes(autostart_processes);
  autostart_start(autostart_processes);
}
コード例 #26
0
ファイル: main.c プロジェクト: ShidoShinji/uipv6-6lowpan
int main(int argc, char **argv)
{
	printf("uIPv6 test project\n");

    uip_ipaddr_t ipaddr;
    uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
    if((ipaddr.u16[0] != 0) ||
       (ipaddr.u16[1] != 0) ||
       (ipaddr.u16[2] != 0) ||
       (ipaddr.u16[3] != 0)) {

      uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0);

      uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
      uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
    }
	
	printf("Process subsystem init\n");
	process_init();
	printf("Ok\n");

	printf("Start etimer process\n");
	process_start(&etimer_process, NULL);
	printf("Ok\n");

	printf("Init ctimer\n");
	ctimer_init();
	printf("Ok\n");

	printf("Init tapdev\n");
	tapdev_init();
	tcpip_set_outputfunc(tapdev_send);
	printf("Ok\n");

	printf("Start tcpip process\n");
	process_start(&tcpip_process, NULL);
	printf("Ok\n");

	printf("Start TCP server on 8080 port\n");
	process_start(&tcp_server, NULL);
	printf("Ok\n");

	uint8_t i;
	for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
		if(uip_ds6_if.addr_list[i].isused) {
			printf("IPV6 Addresss: ");
			printf("%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X",
					uip_ds6_if.addr_list[i].ipaddr.u8[0],
					uip_ds6_if.addr_list[i].ipaddr.u8[1],
					uip_ds6_if.addr_list[i].ipaddr.u8[2],
					uip_ds6_if.addr_list[i].ipaddr.u8[3],
					uip_ds6_if.addr_list[i].ipaddr.u8[4],
					uip_ds6_if.addr_list[i].ipaddr.u8[5],
					uip_ds6_if.addr_list[i].ipaddr.u8[6],
					uip_ds6_if.addr_list[i].ipaddr.u8[7],
					uip_ds6_if.addr_list[i].ipaddr.u8[8],
					uip_ds6_if.addr_list[i].ipaddr.u8[9],
					uip_ds6_if.addr_list[i].ipaddr.u8[10],
					uip_ds6_if.addr_list[i].ipaddr.u8[11],
					uip_ds6_if.addr_list[i].ipaddr.u8[12],
					uip_ds6_if.addr_list[i].ipaddr.u8[13],
					uip_ds6_if.addr_list[i].ipaddr.u8[14],
					uip_ds6_if.addr_list[i].ipaddr.u8[15]);
			printf("\n");
		}
	}

	while(1){
		process_run();
		etimer_request_poll();
		uip_len = tapdev_poll();

		if(uip_len > 0){
			if(BUF->type == uip_htons(UIP_ETHTYPE_IPV6)){
				tcpip_input();
			}
		}
	}
}
コード例 #27
0
/*---------------------------------------------------------------------------*/
int
main(void)
{

  process_init();

  procinit_init();

  ctimer_init();

  autostart_start(autostart_processes);
    
#if !UIP_CONF_IPV6
  uip_ipaddr_t addr;
  uip_ipaddr(&addr, 192,168,1,2);
  printf("IP Address:  %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr));
  uip_sethostaddr(&addr);

  uip_ipaddr(&addr, 255,255,255,0);
  printf("Subnet Mask: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr));
  uip_setnetmask(&addr);

  uip_ipaddr(&addr, 192,168,1,1);
  printf("Def. Router: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr));
  uip_setdraddr(&addr);
#else
  {
    uip_ipaddr_t ipaddr;
    
    uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
    uip_netif_addr_autoconf_set(&ipaddr, &uip_lladdr);
    uip_netif_addr_add(&ipaddr, 16, 0, TENTATIVE);
  }
#endif

  /* Make standard output unbuffered. */
  setvbuf(stdout, (char *)NULL, _IONBF, 0);

  while(1) {
    fd_set fds;
    int n;
    struct timeval tv;
    
    n = process_run();
    /*    if(n > 0) {
      printf("%d processes in queue\n");
      }*/

    tv.tv_sec = 0;
    tv.tv_usec = 1;
    FD_ZERO(&fds);
    FD_SET(STDIN_FILENO, &fds);
    select(1, &fds, NULL, NULL, &tv);

    if(FD_ISSET(STDIN_FILENO, &fds)) {
      char c;
      if(read(STDIN_FILENO, &c, 1) > 0) {
	serial_line_input_byte(c);
      }
    }
    etimer_request_poll();
  }
  
  return 0;
}
コード例 #28
0
/*---------------------------------------------------------------------------*/
int
main(void)
{
    //
    // Enable lazy stacking for interrupt handlers.  This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
    ROM_FPUEnable();
    ROM_FPULazyStackingEnable();

    //
    // Set the clocking to run at 80MHz
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

	leds_init();
	uart0_init(0);
	printf("\rStarting Contiki on LM4F120 Launchpad...\n\r");

	clock_init();
	process_init();

	process_start(&sensors_process, NULL);

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

	/* Networking stack. */
	NETSTACK_RADIO.init();
	NETSTACK_RDC.init();
	NETSTACK_MAC.init();
	NETSTACK_NETWORK.init();
	{
		rimeaddr_t rimeaddr;

		rimeaddr.u8[0] = 0x00;
		rimeaddr.u8[1] = 0x02;
		rimeaddr_set_node_addr(&rimeaddr);
	}

	process_start(&tcpip_process, NULL);
	process_start(&uip_fw_process, NULL);

	uip_init();

	uip_ipaddr(&hostaddr, 172, 16, 0, 2);
	uip_ipaddr_copy(&meshif.ipaddr, &hostaddr);
	uip_sethostaddr(&hostaddr);
	uip_ipaddr(&netmask, 255, 255, 0, 0);
	uip_setnetmask(&netmask);

	uip_over_mesh_set_net(&hostaddr, &netmask);
	uip_fw_default(&meshif);
	//uip_fw_register(&slipif);
	uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);

	autostart_start(autostart_processes);

	while (1)
	{
		process_run();
	}

	return 0;
}
コード例 #29
0
ファイル: contiki-wismote-main.c プロジェクト: 1uk3/contiki
/*---------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
  /*
   * Initalize hardware.
   */

  msp430_cpu_init();
  clock_init();
  leds_init();

  leds_on(LEDS_RED);

  clock_wait(2);

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

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

  clock_wait(1);

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

  node_id = NODE_ID;

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

  init_platform();

  set_rime_addr();

  cc2520_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]);

    cc2520_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
  }
  cc2520_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");
  }

#if WITH_UIP6
  /* memcpy(&uip_lladdr.addr, ds2411_id, sizeof(uip_lladdr.addr)); */
  memcpy(&uip_lladdr.addr, rimeaddr_node_addr.u8,
         UIP_LLADDR_LEN > RIMEADDR_SIZE ? RIMEADDR_SIZE : UIP_LLADDR_LEN);

  /* Setup nullmac-like MAC for 802.15.4 */
/*   sicslowpan_init(sicslowmac_init(&cc2520_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
  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((rimeaddr_node_addr.u8[0] << 4) + 16);
#endif /* TIMESYNCH_CONF_ENABLED */

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

  slip_set_input_callback(set_gateway);

  {
    uip_ipaddr_t hostaddr, netmask;

    uip_init();

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

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

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  watchdog_start();
  /* Stop the watchdog */
  watchdog_stop();

#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.
   */
  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);
    }
  }
}
コード例 #30
0
ファイル: contiki-exp5438-main.c プロジェクト: ADVANSEE/mist
/*--------------------------------------------------------------------------*/
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);
    }
  }
}