Esempio n. 1
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;
}
Esempio n. 2
0
void
init_net(void)
{
  /* load link-layer address */
  memcpy(uip_lladdr.addr,ieee_get_mac(), sizeof(uip_lladdr.addr));
  netstack_init();
}
Esempio n. 3
0
/* Timer callback */
static void 
handle_network_setup_timer(void *ptr) 
{
#ifdef CONTIKI_WAIT_FOR_MAC
  if(CONTIKI_WAIT_FOR_MAC()) {
    /* ok - still need to wait for the MAC */
    printf("*** Waiting for MAC ***\n");
    ctimer_set(&wait_mac_timer, CLOCK_SECOND, &handle_network_setup_timer, NULL);
  } else {
#else
  /* take the hardcoded address */
  set_rime_addr();
#endif
  /* Start up the network stack */
  netstack_init();
  printf("MAC %s RDC %s NETWORK %s\n", NETSTACK_MAC.name, NETSTACK_RDC.name, NETSTACK_NETWORK.name);
#if NETSTACK_CONF_WITH_IPV6
  queuebuf_init();
#endif
  NETSTACK_LLSEC.bootstrap(start_network);

#ifdef CONTIKI_WAIT_FOR_MAC
  }
#endif
}
Esempio n. 4
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;
    
    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;
}
Esempio n. 5
0
/*---------------------------------------------------------------------------*/
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);
    }
}
/*---------------------------------------------------------------------------*/
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;
}
Esempio n. 7
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);
	}
}
Esempio n. 8
0
void
init_net(void)
{
  uip_ipaddr_t ipaddr;
  uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);

  /* load the mac address */
  memcpy(uip_lladdr.addr, ieee_get_mac(), sizeof(uip_lladdr.addr));

#if UIP_CONF_ROUTER
  uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0, 0, 0, 0);
#else /* UIP_CONF_ROUTER */
  uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0);
#endif /* UIP_CONF_ROUTER */
  uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
  uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);

  netstack_init();
}
Esempio n. 9
0
/*---------------------------------------------------------------------------*/
int
main(void)
{
  
  /*
   * Initialize hardware.
   */
  halInit();
  clock_init();
  
  uart1_init(115200);
  
  // Led initialization
  leds_init();
    
  INTERRUPTS_ON(); 

  PRINTF("\r\nStarting ");
  PRINTF(CONTIKI_VERSION_STRING);
  PRINTF(" on %s\r\n",boardDescription->name);

  /*
   * Initialize Contiki and our processes.
   */
  
  process_init();
  
#if WITH_SERIAL_LINE_INPUT
  uart1_set_input(serial_line_input_byte);
  serial_line_init();
#endif
  //etimer_process should be started before ctimer init
  process_start(&etimer_process, NULL);
  //ctimer and rtimer should be initialized before netstack to enable RDC (cxmac, contikimac, lpp)   
  ctimer_init();
  rtimer_init();
  netstack_init();
#if !UIP_CONF_IPV6
  ST_RadioEnableAutoAck(FALSE); // Because frames are not 802.15.4 compatible. 
  ST_RadioEnableAddressFiltering(FALSE);
#endif

  set_rime_addr();
  
  procinit_init();    

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);
  
  autostart_start(autostart_processes);
  
  
  watchdog_start();
  
  while(1){
    
    int r;    
    
    do {
      /* Reset watchdog. */
      watchdog_periodic();
      r = process_run();
    } while(r > 0);
    
    
    
    ENERGEST_OFF(ENERGEST_TYPE_CPU);
    //watchdog_stop();    
    ENERGEST_ON(ENERGEST_TYPE_LPM);
    /* Go to idle mode. */
    halSleepWithOptions(SLEEPMODE_IDLE,0);
    /* We are awake. */
    //watchdog_start();
    ENERGEST_OFF(ENERGEST_TYPE_LPM);
    ENERGEST_ON(ENERGEST_TYPE_CPU);  
    
  }
  
}
Esempio n. 10
0
/**
 * \brief Main function for CC26xx-based platforms
 *
 * The same main() is used for both Srf+CC26xxEM as well as for the SensorTag
 */
int
main(void)
{
  /* Set the LF XOSC as the LF system clock source */
  select_lf_xosc();

  /*
   * Make sure to open the latches - this will be important when returning
   * from shutdown
   */
  ti_lib_pwr_ctrl_io_freeze_disable();

  /* Use DCDC instead of LDO to save current */
  ti_lib_pwr_ctrl_source_set(PWRCTRL_PWRSRC_DCDC);

  lpm_init();

  board_init();

  /* Enable flash cache and prefetch. */
  ti_lib_vims_mode_set(VIMS_BASE, VIMS_MODE_ENABLED);
  ti_lib_vims_configure(VIMS_BASE, true, true);

  gpio_interrupt_init();

  /* Clock must always be enabled for the semaphore module */
  HWREG(AUX_WUC_BASE + AUX_WUC_O_MODCLKEN1) = AUX_WUC_MODCLKEN1_SMPH;

  leds_init();

  fade(LEDS_RED);

  cc26xx_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();
  cc26xx_uart_set_input(serial_line_input_byte);
#endif

  serial_line_init();

  printf("Starting " CONTIKI_VERSION_STRING "\n");
  printf("With DriverLib v%u.%02u.%02u.%u\n", DRIVERLIB_MAJOR_VER,
         DRIVERLIB_MINOR_VER, DRIVERLIB_PATCH_VER, DRIVERLIB_BUILD_ID);
  printf(BOARD_STRING " using CC%u\n", CC26XX_MODEL_CPU_VARIANT);

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

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  fade(LEDS_YELLOW);

  printf(" Net: ");
  printf("%s\n", NETSTACK_NETWORK.name);
  printf(" MAC: ");
  printf("%s\n", 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");

  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();
  }
}
Esempio n. 11
0
int
main(int argc, char **argv)
{
    bool flip_flop = false;

    asm ("di");
    /* Setup clocks */
    CMC = 0x11U;                                        /* Enable XT1, disable X1 */
    CSC = 0x80U;                                        /* Start XT1 and HOCO, stop X1 */
    CKC = 0x00U;
    delay_1sec();
    OSMC = 0x00;                                       /* Supply fsub to peripherals, including Interval Timer */
    uart0_init();

#if __GNUC__
    /* Force linking of custom write() function: */
    write(1, NULL, 0);
#endif

    /* Setup 12-bit interval timer */
    RTCEN = 1;                                              /* Enable 12-bit interval timer and RTC */
    ITMK = 1;                                               /* Disable IT interrupt */
    ITPR0 = 0;                                              /* Set interrupt priority - highest */
    ITPR1 = 0;
    ITMC = 0x8FFFU;                                    /* Set maximum period 4096/32768Hz = 1/8 s, and start timer */
    ITIF = 0;                                               /* Clear interrupt request flag */
    ITMK = 0;                                               /* Enable IT interrupt */
    /* asm ("ei");                                             / * Enable interrupts * / */

    /* Disable analog inputs because they can conflict with the SPI buses: */
    ADPC = 0x01;  /* Configure all analog pins as digital I/O. */
    PMC0 &= 0xF0; /* Disable analog inputs. */

    clock_init();

    /* Initialize Joystick Inputs: */
    PM5 |= BIT(5) | BIT(4) | BIT(3) | BIT(2) | BIT(1); /* Set pins as inputs. */
    PU5 |= BIT(5) | BIT(4) | BIT(3) | BIT(2) | BIT(1); /* Enable internal pull-up resistors. */

    /* Initialize LED outputs: */
#define BIT(n) (1 << (n))
    PM12 &= ~BIT(0); /* LED1 */
    PM4 &= ~BIT(3);  /* LED2 */
    PM1 &= ~BIT(6);  /* LED3 */
    PM1 &= ~BIT(5);  /* LED4 */
    PM0 &= ~BIT(6);  /* LED5 */
    PM0 &= ~BIT(5);  /* LED6 */
    PM3 &= ~BIT(0);  /* LED7 */
    PM5 &= ~BIT(0);  /* LED8 */

#if UIP_CONF_IPV6
#if UIP_CONF_IPV6_RPL
    printf(CONTIKI_VERSION_STRING " started with IPV6, RPL" NEWLINE);
#else
    printf(CONTIKI_VERSION_STRING " started with IPV6" NEWLINE);
#endif
#else
    printf(CONTIKI_VERSION_STRING " started" NEWLINE);
#endif

    /* crappy way of remembering and accessing argc/v */
    contiki_argc = argc;
    contiki_argv = argv;

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

    set_rime_addr();

    queuebuf_init();

    netstack_init();
    printf("MAC %s RDC %s NETWORK %s" NEWLINE, NETSTACK_MAC.name, NETSTACK_RDC.name, NETSTACK_NETWORK.name);

#if WITH_UIP6
    memcpy(&uip_lladdr.addr, serial_id, 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]);
        }
        /* make it hardcoded... */
        lladdr->state = ADDR_AUTOCONF;

        printf("%02x%02x" NEWLINE, lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
    }
#else
    process_start(&tcpip_process, NULL);
#endif

    serial_line_init();

    autostart_start(autostart_processes);

    while(1) {
        watchdog_periodic();

        if(NETSTACK_RADIO.pending_packet()) {
            int len;
            packetbuf_clear();
            len = NETSTACK_RADIO.read(packetbuf_dataptr(), PACKETBUF_SIZE);
            if(len > 0) {
                packetbuf_set_datalen(len);
                NETSTACK_RDC.input();
            }
        }

        while(uart0_can_getchar()) {
            char c;
            UART_RX_LED = 1;
            c = uart0_getchar();
            if(uart0_input_handler) {
                uart0_input_handler(c);
            }
        }
        UART_RX_LED = 0;

        process_run();

        etimer_request_poll();

        HEARTBEAT_LED1 = flip_flop;
        flip_flop = !flip_flop;
        HEARTBEAT_LED2 = flip_flop;
    }

    return 0;
}
Esempio n. 12
0
int
main(int argc, char **argv)
{

  /* crappy way of remembering and accessing argc/v */
  contiki_argc = argc;
  contiki_argv = argv;

  /* native under windows is hardcoded to use the first one or two args */
  /* for wpcap configuration so this needs to be "removed" from         */
  /* contiki_args (used by the native-border-router) */

  //printf("Cgroups -timer\n");
  /*Initalize "hardware".*/
  init_timer();
  clock_init();
  
  rtimer_init();
  

  //printf("Hello glorious world of cheese\n");

/*
   * Hardware initialization done!
   */

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

  set_rime_addr();

  queuebuf_init();

  netstack_init();
  //printf("MAC %s RDC %s NETWORK %s\n", NETSTACK_MAC.name, NETSTACK_RDC.name, NETSTACK_NETWORK.name);
  printf("Hello Rika, I am cgroups in contiki!\n");

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

  select_set_callback(STDIN_FILENO, &stdin_fd);
  /*
   * This is the scheduler loop.
   */
  while(1) {
    fd_set fdr;
    fd_set fdw;
    int maxfd;
    int i;
    int retval;
    struct timeval tv;

    retval = process_run();

    tv.tv_sec = 0;
    tv.tv_usec = retval ? 1 : 1000;

    FD_ZERO(&fdr);
    FD_ZERO(&fdw);
    maxfd = 0;
    for(i = 0; i <= select_max; i++) {
      if(select_callback[i] != NULL && select_callback[i]->set_fd(&fdr, &fdw)) {
        maxfd = i;
      }
    }

    retval = select(maxfd + 1, &fdr, &fdw, NULL, &tv);
    if(retval < 0) {
      perror("select");
    } else if(retval > 0) {
      /* timeout => retval == 0 */
      for(i = 0; i <= maxfd; i++) {
        if(select_callback[i] != NULL) {
          select_callback[i]->handle_fd(&fdr, &fdw);
        }
      }
    }

    etimer_request_poll();
  }

  return 0;
}
Esempio n. 13
0
/*---------------------------------------------------------------------------*/
int
main(void)
{
  
  /*
   * Initialize hardware.
   */
  halInit();
  clock_init();
  
  uart1_init(115200);
  
  // Led initialization
  leds_init();
    
  INTERRUPTS_ON(); 

  PRINTF("\r\nStarting ");
  PRINTF(CONTIKI_VERSION_STRING);
  PRINTF(" on %s\r\n",boardDescription->name);

  /*
   * Initialize Contiki and our processes.
   */
  
  process_init();
  
#if WITH_SERIAL_LINE_INPUT
  uart1_set_input(serial_line_input_byte);
  serial_line_init();
#endif
  
  
  process_start(&etimer_process, NULL);   
  ctimer_init();
  rtimer_init();
  
  netstack_init();
  set_rime_addr();
  
  
PRINTF("ACK enable=%u %s %s, channel check rate=%luHz, check interval %ums, clock second=%u, radio channel %u\r\n",
         ST_RadioAutoAckEnabled(), NETSTACK_MAC.name, NETSTACK_RDC.name,  
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1:
                         NETSTACK_RDC.channel_check_interval()), NETSTACK_RDC.channel_check_interval(), CLOCK_SECOND,
         RF_CHANNEL);
  
#if !UIP_CONF_IPV6
  ST_RadioEnableAutoAck(FALSE); // Because frames are not 802.15.4 compatible. 
  ST_RadioEnableAddressFiltering(FALSE);
#endif
  ST_RadioEnableAutoAck(TRUE);

  
  procinit_init(); 
    


  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);
  
  autostart_start(autostart_processes);
  
  
  watchdog_start();
  
  while(1){
    
    int r;    
    
    do {
      /* Reset watchdog. */
      watchdog_periodic();
      r = process_run();
    } while(r > 0);
    
    
    
    ENERGEST_OFF(ENERGEST_TYPE_CPU);
    //watchdog_stop();    
    ENERGEST_ON(ENERGEST_TYPE_LPM);
    /* Go to idle mode. */
    halSleepWithOptions(SLEEPMODE_IDLE,0);
    /* We are awake. */
    //watchdog_start();
    ENERGEST_OFF(ENERGEST_TYPE_LPM);
    ENERGEST_ON(ENERGEST_TYPE_CPU);  
    
  }
  
}
Esempio n. 14
0
/**
 * \brief Main routine for the cc2538dk platform
 */
int
main(void)
{
  nvic_init();
  ioc_init();
  sys_ctrl_init();
  clock_init();
  lpm_init();
  rtimer_init();
  gpio_init();

  leds_init();
  fade(LEDS_YELLOW);

  process_init();

  watchdog_init();
  button_sensor_init();

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

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

  serial_line_init();

  INTERRUPTS_ENABLE();
  fade(LEDS_GREEN);

  PUTS(CONTIKI_VERSION_STRING);
  PUTS(BOARD_STRING);

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

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

  udma_init();

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

  set_rf_params();

#if CRYPTO_CONF_INIT
  crypto_init();
  crypto_disable();
#endif

  netstack_init();

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

  adc_init();

  process_start(&sensors_process, NULL);

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  autostart_start(autostart_processes);

  watchdog_start();
  fade(LEDS_ORANGE);

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

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

    /* We have serviced all pending events. Enter a Low-Power mode. */
    lpm_enter();
  }
}
/*---------------------------------------------------------------------------*/
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 */
    }
}
/*---------------------------------------------------------------------------*/
void
contiki_init()
{
  /* Initialize random generator (moved to moteid.c) */

  /* Start process handler */
  process_init();

  /* Start Contiki processes */
  procinit_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");
  }

  /* RIME CONFIGURATION */
  {
    int i;
    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 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]);
  }

  queuebuf_init();

  /* Initialize communication stack */
  netstack_init();
  printf("MAC %s RDC %s NETWORK %s\n", NETSTACK_MAC.name, NETSTACK_RDC.name, NETSTACK_NETWORK.name);

#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,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_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++) {
      addr[i] = node_id & 0xff;
    }
    memcpy(&uip_lladdr.addr, addr, sizeof(uip_lladdr.addr));
    process_start(&tcpip_process, NULL);

    printf("Tentative link-local IPv6 address ");
    {
      int i, a;
      for(a = 0; a < UIP_DS6_ADDR_NB; a++) {
        if (uip_ds6_if.addr_list[a].isused) {
      for(i = 0; i < 7; ++i) {
        printf("%02x%02x:",
           uip_ds6_if.addr_list[a].ipaddr.u8[i * 2],
           uip_ds6_if.addr_list[a].ipaddr.u8[i * 2 + 1]);
      }
      printf("%02x%02x\n",
             uip_ds6_if.addr_list[a].ipaddr.u8[14],
             uip_ds6_if.addr_list[a].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 */

  /* Start serial process */
  serial_line_init();

  /* Start autostart processes (defined in Contiki application) */
  print_processes(autostart_processes);
  autostart_start(autostart_processes);
}
Esempio n. 17
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 */
  bus_init();//ʱÖÓ³õʼ»¯
  rtimer_init();//¼ÆʱÆ÷³õʼ»¯

  /* model-specific h/w init. */
  io_port_init();

  /* Init LEDs here */
  leds_init();//LED³õʼ»¯
  /*LEDS_GREEN indicate LEDs Init finished*/
  fade(LEDS_GREEN);

  /* initialize process manager. */
  process_init();//½ø³Ì¹ÜÀí³õʼ»¯

  /* Init UART0
   * Based on the EJOY MCU CC2430 Circuit Design
   *  */
  uart0_init();//UART0´®¿Ú³õʼ»¯

#if DMA_ON
  dma_init();//DMA³õʼ»¯
#endif

#if SLIP_ARCH_CONF_ENABLE
  /* On cc2430, the argument is not used */
  slip_arch_init(0);//SLIP³õʼ»¯
#else
  uart1_set_input(serial_line_input_byte);
  serial_line_init();
#endif

  PUTSTRING("##########################################\n");
  putstring(CONTIKI_VERSION_STRING "\n");
//  putstring(SENSINODE_MODEL " (CC24");
  puthex(((CHIPID >> 3) | 0x20));
  putstring("-" FLASH_SIZE ")\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 cc2430 RNG engine. */
  random_init(0);//Ëæ»úÊýÉú³ÉÆ÷³õʼ»¯

  /* start services */
  process_start(&etimer_process, NULL);//
  ctimer_init();//ctimer³õʼ»¯

  /* initialize the netstack */
  netstack_init();//ÍøÂçµ×²ãÕ»³õʼ»¯
  set_rime_addr();//rimeµØÖ·ÉèÖÃ

//there is no sensor for us maintenance
#if BUTTON_SENSOR_ON || ADC_SENSOR_ON
  process_start(&sensors_process, NULL);
  sensinode_sensors_activate();
#endif

//IPV6,YES!
#if UIP_CONF_IPV6
  memcpy(&uip_lladdr.addr, &rimeaddr_node_addr, sizeof(uip_lladdr.addr));
  queuebuf_init();
  process_start(&tcpip_process, NULL);
//DISCO
#if DISCO_ENABLED
  process_start(&disco_process, NULL);
#endif /* DISCO_ENABLED */
//VIZTOOL
#if VIZTOOL_CONF_ON
  process_start(&viztool_process, NULL);
#endif

#if (!UIP_CONF_IPV6_RPL)
  {
    uip_ipaddr_t ipaddr;
    uip_ip6addr(&ipaddr, 0x2001, 0x630, 0x301, 0x6453, 0, 0, 0, 0);
    uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
    uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);
  }
#endif /* UIP_CONF_IPV6_RPL */
#endif /* UIP_CONF_IPV6 */

  /*
   * Acknowledge the UART1 RX interrupt
   * now that we're sure we are ready to process it
   *
   * We don't need it. by MW
   */
//  model_uart_intr_en();

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  fade(LEDS_RED);

#if BATMON_CONF_ON
  process_start(&batmon_process, NULL);
#endif

  autostart_start(autostart_processes);

  watchdog_start();

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

      /**/
#if !CLOCK_CONF_ACCURATE
      if(sleep_flag) {
        if(etimer_pending() &&
            (etimer_next_expiration_time() - count - 1) > MAX_TICKS) { /*core/sys/etimer.c*/
          etimer_request_poll();
        }
        sleep_flag = 0;
      }
#endif
      r = process_run();
    } while(r > 0);
#if SHORTCUTS_CONF_NETSTACK
    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
#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)
     */
    SLEEP = (SLEEP & 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 (SLEEP & 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 |= 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)
      SLEEP &= ~OSC_PD;            /* Make sure both HS OSCs are on */
      while(!(SLEEP & XOSC_STB));  /* Wait for XOSC to be stable */
      CLKCON &= ~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(CLKCON & OSC);         /* Wait till it's happened */
    }
#endif /* LPM_MODE==LPM_MODE_PM2 */
#endif /* LPM_MODE */
  }
}
Esempio n. 19
0
/*---------------------------------------------------------------------------*/
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 */
  }
}
Esempio n. 20
0
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);

  }
}
Esempio n. 21
0
/*---------------------------------------------------------------------------*/
int
main(void)
{
  
  /*
   * Initialize hardware.
   */
  halInit();
  clock_init();
  
  uart1_init(115200);
  
  // Led initialization
  leds_init();
    
  INTERRUPTS_ON(); 

  PRINTF("\r\nStarting ");
  PRINTF(CONTIKI_VERSION_STRING);
  PRINTF(" on %s\r\n",boardDescription->name);

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

  printf("%s %s, channel check rate %lu Hz\n",
         NETSTACK_MAC.name, NETSTACK_RDC.name,
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
                                  NETSTACK_RDC.channel_check_interval()));
  printf("802.15.4 PAN ID 0x%x, EUI-%d:",
      IEEE802154_CONF_PANID, UIP_CONF_LL_802154?64:16);
  uip_debug_lladdr_print(&rimeaddr_node_addr);
  printf(", radio channel %u\n", RF_CHANNEL);

  procinit_init();    

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);
  
  autostart_start(autostart_processes);
   
  watchdog_start();
  
  while(1){
    
    int r;    
    
    do {
      /* Reset watchdog. */
      watchdog_periodic();
      r = process_run();
    } while(r > 0);
    
    
    
    ENERGEST_OFF(ENERGEST_TYPE_CPU);
    //watchdog_stop();    
    ENERGEST_ON(ENERGEST_TYPE_LPM);
    /* Go to idle mode. */
    halSleepWithOptions(SLEEPMODE_IDLE,0);
    /* We are awake. */
    //watchdog_start();
    ENERGEST_OFF(ENERGEST_TYPE_LPM);
    ENERGEST_ON(ENERGEST_TYPE_CPU);  
    
  }
  
}
Esempio n. 22
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);
}
Esempio n. 23
0
/**
 * \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();
  }
}
Esempio n. 24
0
/*---------------------------------------------------------------------------*/
int
main(void)
{
  
  /*
   * Initalize hardware.
   */
  halInit();
  clock_init();
  
  uart1_init(115200);
  
  /* Led initialization */
  leds_init();
    
  INTERRUPTS_ON(); 

  PRINTF("\r\nStarting ");
  PRINTF(CONTIKI_VERSION_STRING);
  PRINTF(" on %s\r\n", boardDescription->name); 
  boardPrintStringDescription();
  PRINTF("\r\n"); 


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

  set_rime_addr();

  printf("%s %s, channel check rate %lu Hz\n",
         NETSTACK_MAC.name, NETSTACK_RDC.name,
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
                                  NETSTACK_RDC.channel_check_interval()));
  printf("802.15.4 PAN ID 0x%x, EUI-%d:",
      IEEE802154_CONF_PANID, UIP_CONF_LL_802154?64:16);
  uip_debug_lladdr_print(&linkaddr_node_addr);
  printf(", radio channel %u\n", RF_CHANNEL);

  procinit_init();

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  /* Set the Clear Channel Assessment (CCA) threshold of the
     radio. The CCA threshold is used both for sending packets and for
     waking up ContikiMAC nodes. If the CCA threshold is too high,
     ContikiMAC will not wake up from neighbor transmissions. If the
     CCA threshold is too low, transmissions will be too restrictive
     and no packets will be sent. DEFAULT_RADIO_CCA_THRESHOLD is
     defined in this file. */
  ST_RadioSetEdCcaThreshold(DEFAULT_RADIO_CCA_THRESHOLD);
  
  autostart_start(autostart_processes);
#if UIP_CONF_IPV6
  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]);
  }
#endif /* UIP_CONF_IPV6 */
  
  watchdog_start();
  
  while(1) {
    
    int r;    
    
    do {
      /* Reset watchdog. */
      watchdog_periodic();
      r = process_run();
    } while(r > 0);
    
    
    
    ENERGEST_OFF(ENERGEST_TYPE_CPU);
    /* watchdog_stop(); */
    ENERGEST_ON(ENERGEST_TYPE_LPM);
    /* Go to idle mode. */
    halSleepWithOptions(SLEEPMODE_IDLE,0);
    /* We are awake. */
    /* watchdog_start(); */
    ENERGEST_OFF(ENERGEST_TYPE_LPM);
    ENERGEST_ON(ENERGEST_TYPE_CPU);  
    
  }
  
}
Esempio n. 25
0
/*--------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
  /*
   * Initalize hardware.
   */
  msp430_cpu_init();
  clock_init();
  leds_init();

  leds_on(LEDS_RED);

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

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

  lcd_init();

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

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

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

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

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

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

  ctimer_init();

  set_rime_addr();

  random_init(node_id);

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

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

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

  NETSTACK_RADIO.on();

  leds_off(LEDS_ALL);

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

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

  queuebuf_init();

  netstack_init();

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

  process_start(&tcpip_process, NULL);

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

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

#else /* WITH_UIP6 */

  netstack_init();

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

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

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

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


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

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

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

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

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  simple_rpl_init();

  watchdog_start();

  print_processes(autostart_processes);
  autostart_start(autostart_processes);

  duty_cycle_scroller_start(CLOCK_SECOND * 2);

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

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

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

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

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

      /* We get the current processing time for interrupts that was
         done during the LPM and store it for next time around.  */
      dint();
      irq_energest = energest_type_time(ENERGEST_TYPE_IRQ);
      eint();
      watchdog_start();
      ENERGEST_OFF(ENERGEST_TYPE_LPM);
      ENERGEST_ON(ENERGEST_TYPE_CPU);
    }
  }
}
Esempio n. 26
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;
}
Esempio n. 27
0
/**
 * \brief Main routine for the cc2538dk platform
 */
int main(void) {
	// Just for test purposes
	uint16_t temperature = 0;
	uint16_t humidity = 0;
	float* temperature_f;
	float* humidity_f;
	unsigned char* checksum;
	unsigned char status;
	unsigned char temp_data = 0xff;
	/* unsigned char err = 0;  SHT11 disabled */

	nvic_init();
	sys_ctrl_init();
	clock_init();
	lpm_init();
	rtimer_init();
	gpio_init();
	ioc_init();
	i2c_init();

	leds_init();
	fade(LEDS_YELLOW);

	process_init();

	watchdog_init();
	button_sensor_init();

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

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

	serial_line_init();

	INTERRUPTS_ENABLE();
	fade(LEDS_GREEN);

	PUTS(CONTIKI_VERSION_STRING);PUTS(BOARD_STRING);

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

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

	udma_init();

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

	set_rime_addr();
	netstack_init();
	cc2538_rf_set_addr(IEEE802154_PANID);

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

	process_start(&sensors_process, NULL);

	energest_init();
	ENERGEST_ON(ENERGEST_TYPE_CPU);

	autostart_start(autostart_processes);

	watchdog_start();
	fade(LEDS_ORANGE);

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

			r = process_run();
/*
			err = s_measure(&temperature, checksum, TEMP);

			if (err == 0)
			{
				PRINTF("Temperature (ADC value) = 0x%4x\n", temperature);

				err = s_measure(&humidity, checksum, HUMI);

				if (err == 0)
				{
					PRINTF("Humidity (ADC value) = 0x%4x\n", humidity);

					float tc=sht11_TemperatureC(temperature);
					float hc=sht11_Humidity(temperature,humidity);
					printf("temp:%u.%u\nhumidity:%u.%u\n",(int)tc,((int)(tc*10))%10 , (int)hc,((int)(hc*10))%10);
				}
				else
					PRINTF("SHT11 error - could not read humidity!\n");
			}
			else
				PRINTF("SHT11 error - could not read temperature!\n");
*/
			/*err = s_write_statusreg(&temp_data);
			if (err == 0)
			{
				err = s_read_statusreg(&status, checksum);
				if (err == 0)
					PRINTF("STATUS REGISTER = 0x%2x", status);
				else
					PRINTF("SHT11 error - could not read status register!\n");
			}*/

		} while (r > 0);

		/* We have serviced all pending events. Enter a Low-Power mode. */
		lpm_enter();
	}
}
Esempio n. 28
0
/*---------------------------------------------------------------------------*/
void
contiki_init(void)
{
  int i;
  uint8_t addr[sizeof(uip_lladdr.addr)];
  uip_ipaddr_t ipaddr;
  uip_ds6_addr_t *lladdr;
  uip_ip4addr_t ipv4addr, netmask;

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

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

  /* IPv6 CONFIGURATION */


  for(i = 0; i < sizeof(uip_lladdr.addr); i += 2) {
    addr[i + 1] = node_id & 0xff;
    addr[i + 0] = node_id >> 8;
  }
  linkaddr_copy(addr, &linkaddr_node_addr);
  memcpy(&uip_lladdr.addr, addr, sizeof(uip_lladdr.addr));

  process_start(&tcpip_process, NULL);

  printf("Tentative link-local IPv6 address ");

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

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

  /* Start serial process */
  serial_line_init();

  /* Start autostart processes (defined in Contiki application) */
  print_processes(autostart_processes);
  autostart_start(autostart_processes);

  /* Start the SLIP */
  printf("Initiating SLIP with IP address is 172.16.0.2.\n");

  uip_ipaddr(&ipv4addr, 172, 16, 0, 2);
  uip_ipaddr(&netmask, 255, 255, 255, 0);
  ip64_set_ipv4_address(&ipv4addr, &netmask);

  rs232_set_input(slip_input_byte);
  log_set_putchar_with_slip(1);

  uip_ip4addr_t ip4addr;
  uip_ip6addr_t ip6addr;

  uip_ipaddr(&ip4addr, 8,8,8,8);
  ip64_addr_4to6(&ip4addr, &ip6addr);

  uip_nameserver_update((uip_ipaddr_t *)&ip6addr, UIP_NAMESERVER_INFINITE_LIFETIME);
}
Esempio n. 29
0
int
main(int argc, char **argv)
{
#if UIP_CONF_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
#else
  printf(CONTIKI_VERSION_STRING " started\n");
#endif

  /* crappy way of remembering and accessing argc/v */
  contiki_argc = argc;
  contiki_argv = argv;

  /* native under windows is hardcoded to use the first one or two args */
  /* for wpcap configuration so this needs to be "removed" from         */
  /* contiki_args (used by the native-border-router) */
#ifdef __CYGWIN__
  contiki_argc--;
  contiki_argv++;
#ifdef UIP_FALLBACK_INTERFACE
  contiki_argc--;
  contiki_argv++;
#endif
#endif

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

  set_rime_addr();

  queuebuf_init();

  netstack_init();
  printf("MAC %s RDC %s NETWORK %s\n", NETSTACK_MAC.name, NETSTACK_RDC.name, NETSTACK_NETWORK.name);

#if WITH_UIP6
  memcpy(&uip_lladdr.addr, serial_id, sizeof(uip_lladdr.addr));

  process_start(&tcpip_process, NULL);
#ifdef __CYGWIN__
  process_start(&wpcap_process, NULL);
#endif
  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]);
    }
    /* make it hardcoded... */
    lladdr->state = ADDR_AUTOCONF;

    printf("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
  }
#else
  process_start(&tcpip_process, NULL);
#endif

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

  select_set_callback(STDIN_FILENO, &stdin_fd);

  simple_rpl_init();
  ip64_init();

  while(1) {
    fd_set fdr;
    fd_set fdw;
    int maxfd;
    int i;
    int retval;
    struct timeval tv;

    retval = process_run();

    tv.tv_sec = 0;
    tv.tv_usec = retval ? 1 : 1000;

    FD_ZERO(&fdr);
    FD_ZERO(&fdw);
    maxfd = 0;
    for(i = 0; i <= select_max; i++) {
      if(select_callback[i] != NULL && select_callback[i]->set_fd(&fdr, &fdw)) {
        maxfd = i;
      }
    }

    retval = select(maxfd + 1, &fdr, &fdw, NULL, &tv);
    if(retval < 0) {
      perror("select");
    } else if(retval > 0) {
      /* timeout => retval == 0 */
      for(i = 0; i <= maxfd; i++) {
        if(select_callback[i] != NULL) {
          select_callback[i]->handle_fd(&fdr, &fdw);
        }
      }
    }

    etimer_request_poll();
  }

  return 0;
}
Esempio n. 30
-1
/**
 * \brief Main routine for the OpenMote-CC2538 platforms
 */
int
main(void)
{
  nvic_init();
  ioc_init();
  sys_ctrl_init();
  clock_init();
  lpm_init();
  rtimer_init();
  gpio_init();
  leds_init();
  fade(LEDS_RED);
  process_init();
  watchdog_init();

#if UART_CONF_ENABLE
  uart_init(0);
  uart_init(1);
  uart_set_input(SERIAL_LINE_CONF_UART, serial_line_input_byte);
#endif

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

  i2c_init(I2C_SDA_PORT, I2C_SDA_PIN, I2C_SCL_PORT, I2C_SCL_PIN, I2C_SCL_NORMAL_BUS_SPEED);

  serial_line_init();

  INTERRUPTS_ENABLE();
  fade(LEDS_BLUE);

  PUTS(CONTIKI_VERSION_STRING);
  PUTS(BOARD_STRING);
#if STARTUP_CONF_VERBOSE
  soc_print_info();
#endif

  random_init(0);

  udma_init();

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

  board_init();

#if CRYPTO_CONF_INIT
  crypto_init();
  crypto_disable();
#endif

  netstack_init();
  set_rf_params();

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

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

  process_start(&sensors_process, NULL);

  SENSORS_ACTIVATE(button_sensor);

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  autostart_start(autostart_processes);

  watchdog_start();
  fade(LEDS_GREEN);

  while(1) {
    uint8_t r;
    do {
      watchdog_periodic();

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

    lpm_enter();
  }
}