Exemplo n.º 1
0
/*---------------------------------------------------------------------------*/
void
print_stats(void)
{
  PRINTA("S %d.%d clock %lu tx %lu rx %lu rtx %lu rrx %lu rexmit %lu acktx %lu noacktx %lu ackrx %lu timedout %lu badackrx %lu toolong %lu tooshort %lu badsynch %lu badcrc %lu contentiondrop %lu sendingdrop %lu lltx %lu llrx %lu\n",
	 rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
	 clock_seconds(),
	 rimestats.tx, rimestats.rx,
	 rimestats.reliabletx, rimestats.reliablerx,
	 rimestats.rexmit, rimestats.acktx, rimestats.noacktx,
	 rimestats.ackrx, rimestats.timedout, rimestats.badackrx,
	 rimestats.toolong, rimestats.tooshort,
	 rimestats.badsynch, rimestats.badcrc,
	 rimestats.contentiondrop, rimestats.sendingdrop,
	 rimestats.lltx, rimestats.llrx);
#if ENERGEST_CONF_ON
  PRINTA("E %d.%d clock %lu cpu %lu lpm %lu irq %lu gled %lu yled %lu rled %lu tx %lu listen %lu sensors %lu serial %lu\n",
	 rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
	 clock_seconds(),
	 energest_total_time[ENERGEST_TYPE_CPU].current,
	 energest_total_time[ENERGEST_TYPE_LPM].current,
	 energest_total_time[ENERGEST_TYPE_IRQ].current,
	 energest_total_time[ENERGEST_TYPE_LED_GREEN].current,
	 energest_total_time[ENERGEST_TYPE_LED_YELLOW].current,
	 energest_total_time[ENERGEST_TYPE_LED_RED].current,
	 energest_total_time[ENERGEST_TYPE_TRANSMIT].current,
	 energest_total_time[ENERGEST_TYPE_LISTEN].current,
	 energest_total_time[ENERGEST_TYPE_SENSORS].current,
	 energest_total_time[ENERGEST_TYPE_SERIAL].current);
#endif /* ENERGEST_CONF_ON */
}
Exemplo n.º 2
0
/*---------------------------------------------------------------------------*/
void
uip_debug_ipaddr_print(const uip_ipaddr_t *addr)
{
  if(addr == NULL || addr->u8 == NULL) {
    printf("(NULL IP addr)");
    return;
  }
#if UIP_CONF_IPV6
  uint16_t a;
  unsigned int i;
  int f;
  for(i = 0, f = 0; i < sizeof(uip_ipaddr_t); i += 2) {
    a = (addr->u8[i] << 8) + addr->u8[i + 1];
    if(a == 0 && f >= 0) {
      if(f++ == 0) {
        PRINTA("::");
      }
    } else {
      if(f > 0) {
        f = -1;
      } else if(i > 0) {
        PRINTA(":");
      }
      PRINTA("%x", a);
    }
  }
#else /* UIP_CONF_IPV6 */
  PRINTA("%u.%u.%u.%u", addr->u8[0], addr->u8[1], addr->u8[2], addr->u8[3]);
#endif /* UIP_CONF_IPV6 */
}
Exemplo n.º 3
0
/*---------------------------------------------------------------------------*/
void
uip_debug_lladdr_print(const uip_lladdr_t *addr)
{
  unsigned int i;
  for(i = 0; i < sizeof(uip_lladdr_t); i++) {
    if(i > 0) {
      PRINTA(":");
    }
    PRINTA("%02x", addr->addr[i]);
  }
}
Exemplo n.º 4
0
/**
* Effettua la cancel sui thread lanciati
**/
void GEST_THREAD_close_all() {
  int i;
  int num_of_modules=GEST_MODULE_get_num_of_modules();
  PRINTA("Chiamato da %d",pthread_self());
  for (i = 0; i < num_of_modules; ++i)
  { if (gest_thread_state.threads[i].presence) {
      PRINTA("Cancello il %d",gest_thread_state.threads[i].thread);
      pthread_cancel(gest_thread_state.threads[i].thread);
      gest_thread_state.threads[i].presence=FALSE;
    }
  }
}
static void
set_gateway(void)
{
  if(!is_gateway) {
    leds_on(LEDS_RED);
    PRINTA("%d.%d: making myself the IP network gateway.\n\n",
        rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
    PRINTA("IPv4 address of the gateway: %d.%d.%d.%d\n\n",
        uip_ipaddr_to_quad(&uip_hostaddr));
    uip_over_mesh_set_gateway(&rimeaddr_node_addr);
    uip_over_mesh_make_announced_gateway();
    is_gateway = 1;
  }
}
Exemplo n.º 6
0
void terzo_init() {
    PRINTA("TERZO_INIT");
    PRINTA("SET TERZO -> %d",TERZO);
    terzo_state.atan=0;
    terzo_state.data.type=TERZO;	
    //terzo_state.data.unit=mm;
    terzo_state.data.value.atan=terzo_state.atan;
    SUB(TERZO);
    /*
    test1_state.nums=(int*)malloc(sizeof(int)*3);
    test1_state.nums[0]=1;
    test1_state.nums[1]=2;
    test1_state.nums[2]=3;
    */
}
Exemplo n.º 7
0
/*---------------------------------------------------------------------------*/
void
uip_debug_ipaddr_print(const uip_ipaddr_t *addr)
{
#if UIP_CONF_IPV6
  uint16_t a;
  unsigned int i;
  int f;
  for(i = 0, f = 0; i < sizeof(uip_ipaddr_t); i += 2) {
    a = (addr->u8[i] << 8) + addr->u8[i + 1];
    if(a == 0 && f >= 0) {
      if(f++ == 0) {
        putstring("::");
      }
    } else {
      if(f > 0) {
        f = -1;
      } else if(i > 0) {
        putstring(":");
      }
      puthex(a >> 8);
      puthex(a & 0xFF);
    }
  }
#else /* UIP_CONF_IPV6 */
  PRINTA("%u.%u.%u.%u", addr->u8[0], addr->u8[1], addr->u8[2], addr->u8[3]);
#endif /* UIP_CONF_IPV6 */
}
Exemplo n.º 8
0
void terzo_run() {
  PRINTA("TERZO_RUN");
  boolean x_v,y_v;
  data_t x;
  data_t y;
  //x=GET(PRIMO);
  //x_v=ISDATAVALID(x);
  //y=GET(SECONDO);
  //y_v=ISDATAVALID(y);
  /*
  if (x_v && y_v) {
    PRINTE("==> VALORE DI X = %f",x.value.x);
    PRINTE("==> VALORE DI Y = %f",y.value.y);
    terzo_state.data.value.atan=atan2(x.value.x,y.value.y);
    SETDATATIMESTAMP(&terzo_state.data);
    SET(terzo_state.data);
  } else {
    printf("==> qualche dato non valido\n");
  }
  */
   /*
   int i=0;
   for(i=0;i++;i<3) {
   	insertdata(test1_state.nums[i]);
   }
   */
   exit;
};
Exemplo n.º 9
0
/*---------------------------------Main Routine----------------------------*/
int
main(void)
{
  /* GCC depends on register r1 set to 0 (?) */
  asm volatile ("clr r1");
  
  /* Initialize in a subroutine to maximize stack space */
  initialize();

#if DEBUG
{struct process *p;
 for(p = PROCESS_LIST();p != NULL; p = ((struct process *)p->next)) {
  PRINTA("Process=%p Thread=%p  Name=\"%s\" \n",p,p->thread,PROCESS_NAME_STRING(p));
 }
}
#endif

  while(1) {
    process_run();

    watchdog_periodic();

  }
  return 0;
}
Exemplo n.º 10
0
static bool get_eui64_from_eeprom(uint8_t macptr[8]) {
	size_t size = 8;
	if(settings_get(SETTINGS_KEY_EUI64, 0, (unsigned char*)macptr, &size)==SETTINGS_STATUS_OK) {
      PRINTD("<=Get EEPROM MAC address.\n");
      return true;		
    }
#if JACKDAW_CONF_RANDOM_MAC
    PRINTA("--Generating random MAC address.\n");
    generate_new_eui64(macptr);
#else
    {uint8_t i;for (i=0;i<8;i++) macptr[i] = pgm_read_byte_near(default_mac_address+i);}
#endif
    settings_add(SETTINGS_KEY_EUI64,(unsigned char*)macptr,8);
    PRINTA("->Set EEPROM MAC address.\n");
	return true;
}
Exemplo n.º 11
0
/*---------------------------------------------------------------------------*/
static void
print_local_addresses(void)
{
  int i;
  uint8_t state;

  PRINTA("Server IPv6 addresses:\n");
  for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
    state = uip_ds6_if.addr_list[i].state;
    if(uip_ds6_if.addr_list[i].isused &&
       (state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
      PRINTA(" ");
      uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr);
      PRINTA("\n");
    }
  }
}
Exemplo n.º 12
0
int main(int argc, const char *argv[])
{
  DATA->a = 10;
  printf("a:%d\n", DATA->a);
  SETA(2);
  PRINTA();
  return 0;
}
Exemplo n.º 13
0
int
main(void)
{
  initialize();
  
  while(1) {
    process_run();
	
#if TESTRTIMER
/* Timeout can be increased up to 8 seconds maximum.
 * A one second cycle is convenient for triggering the various debug printouts.
 * The triggers are staggered to avoid printing everything at once.
 */
    if (rtimerflag) {
      rtimer_set(&rt, RTIMER_NOW()+ RTIMER_ARCH_SECOND*1UL, 1,(void *) rtimercycle, NULL);
      rtimerflag=0;

#if STAMPS
if ((rtime%STAMPS)==0) {
  PRINTA("%us ",rtime);
}
#endif
      rtime+=1;

#if STACKMONITOR
if ((rtime%STACKMONITOR)==3) {
  extern uint16_t __bss_end;
  uint16_t p=(uint16_t)&__bss_end;
  do {
    if (*(uint16_t *)p != 0x4242) {
      PRINTA("Never-used stack > %d bytes\n",p-(uint16_t)&__bss_end);
      break;
    }
    p+=4;
  } while (p<RAMEND-4);
}
#endif

    }
#endif /* TESTRTIMER */

  }

  return 0;
}
Exemplo n.º 14
0
/*-------------------------------------------------------------------------*/
int
main(void)
{

  initialize();

  while(1)
  {
    process_run();

    //watchdog_periodic();


//Use with RF230BB DEBUGFLOW to show path through driver
#if RF230BB&&0
    extern uint8_t debugflowsize,debugflow[];
    if (debugflowsize)
    {
      debugflow[debugflowsize]=0;
      PRINTA("%s",debugflow);
      debugflowsize=0;
    }
#endif

#if RF230BB&&0
    if (rf230processflag)
    {
      PRINTA("rf230p%d",rf230processflag);
      rf230processflag=0;
    }
#endif

#if RF230BB&&0
    if (rf230_interrupt_flag)
    {
      PRINTA("**RI%u",rf230_interrupt_flag);
      rf230_interrupt_flag=0;
    }
#endif
  }
  return 0;
}
Exemplo n.º 15
0
static uint16_t get_panaddr_from_eeprom(void) {
    uint16_t x;
    if (settings_check(SETTINGS_KEY_PAN_ADDR,0)) {
        x = settings_get_uint16(SETTINGS_KEY_PAN_ADDR,0);
        PRINTD("<-Get EEPROM PAN address of %04x.\n",x);
    } else {
	    x=pgm_read_word_near(&default_panaddr);
        if (settings_add_uint16(SETTINGS_KEY_PAN_ADDR,x)==SETTINGS_STATUS_OK) {
          PRINTA("->Set EEPROM PAN address to %04x.\n",x);
        }
    }        
	return x;
}
Exemplo n.º 16
0
static uint8_t get_txpower_from_eeprom(void) {
    uint8_t x;
    if (settings_check(SETTINGS_KEY_TXPOWER,0)) {
        x = settings_get_uint8(SETTINGS_KEY_TXPOWER,0);
        PRINTD("<-Get EEPROM tx power of %d. (0=max)\n",x);
    } else {
	    x=pgm_read_byte_near(&default_txpower);
        if (settings_add_uint8(SETTINGS_KEY_TXPOWER,x)==SETTINGS_STATUS_OK) {
          PRINTA("->Set EEPROM tx power of %d. (0=max)\n",x);
        }
    }
	return x;
}
Exemplo n.º 17
0
void
rpl_debug_ipaddr_print(struct in6_addr *addr)
{
  uint16_t a;
  unsigned int i;
  int f;
  for(i = 0, f = 0; i < sizeof(struct in6_addr); i += 2) {
    a = (addr->s6_addr[i] << 8) + addr->s6_addr[i + 1];
    if(a == 0 && f >= 0) {
      if(f++ == 0) {
        PRINTA("::");
      }
    } else {
      if(f > 0) {
        f = -1;
      } else if(i > 0) {
        PRINTA(":");
      }
      PRINTA("%x", a);
    }
  }
}
Exemplo n.º 18
0
void
initialize(void)
{
  watchdog_init();
  watchdog_start();
  
#if STACKMONITOR
  /* Simple stack pointer highwater monitor. Checks for magic numbers in the main
   * loop. In conjuction with TESTRTIMER, never-used stack will be printed
   * every STACKMONITOR seconds.
   */
{
extern uint16_t __bss_end;
uint16_t p=(uint16_t)&__bss_end;
    do {
      *(uint16_t *)p = 0x4242;
      p+=4;
    } while (p<SP-4); //don't overwrite our own stack
}
#endif

  /* rtimers needed for radio cycling */
  rtimer_init();

  rs232_init(RS232_PORT_0, BAUD_RATE(38400), USART_DATA_BITS_8 | USART_PARITY_NONE | USART_STOP_BITS_1);
  rs232_redirect_stdout(RS232_PORT_0);

  clock_init();
  sei();

  /* Initialize drivers and event kernel */
  process_init();
 
  led_init();

#if 0
  procinit_init();
#else
  process_start(&etimer_process, NULL);
  process_start(&led_process, NULL);
  process_start(&led2_process, NULL);
#endif

  PRINTA(CONTIKI_VERSION_STRING " started\r\n");

  /* Comment this out if autostart_processes not defined at link */
  /* Note AUTOSTART_PROCESSES(...) is only effective in the .co module */
  autostart_start(autostart_processes);
  
}
Exemplo n.º 19
0
static uint8_t get_channel_from_eeprom() {
	uint8_t x[2];
	*(uint16_t *)x = eeprom_read_word ((uint16_t *)&eemem_channel);
    if((uint8_t)x[0]!=(uint8_t)~x[1]) {//~x[1] can promote comparison to 16 bit
/* Verification fails, rewrite everything */
    uint8_t mac[8];
#if JACKDAW_CONF_RANDOM_MAC
    PRINTA("Generating random MAC address.\n");
    generate_new_eui64(&mac);
#else
    {uint8_t i; for (i=0;i<8;i++) mac[i] = pgm_read_byte_near(default_mac_address+i);}
#endif
	eeprom_write_block(&mac,  &eemem_mac_address, 8);
  	eeprom_write_word(&eemem_panid  , pgm_read_word_near(&default_panid));
   	eeprom_write_word(&eemem_panaddr, pgm_read_word_near(&default_panaddr));
    eeprom_write_byte(&eemem_txpower, pgm_read_byte_near(&default_txpower));
    x[0] = pgm_read_byte_near(&default_channel);
    x[1]= ~x[0];
    eeprom_write_word((uint16_t *)&eemem_channel, *(uint16_t *)x);    
  }
  return x[0];
}
Exemplo n.º 20
0
/*---------------------------------Main Routine----------------------------*/
int
main(void)
{
  /* GCC depends on register r1 set to 0 (?) */
  asm volatile ("clr r1");
  
  /* Initialize in a subroutine to maximize stack space */
  initialize();

#if DEBUG
{struct process *p;
 for(p = PROCESS_LIST();p != NULL; p = ((struct process *)p->next)) {
  PRINTA("Process=%p Thread=%p  Name=\"%s\" \n",p,p->thread,PROCESS_NAME_STRING(p));
 }
}
#endif

  while(1) {
    process_run();

    watchdog_periodic();

/* Print rssi of all received packets, useful for range testing */
#ifdef RF230_MIN_RX_POWER
    uint8_t lastprint;
    if (rf230_last_rssi != lastprint) {        //can be set in halbb.c interrupt routine
        PRINTA("%u ",rf230_last_rssi);
        lastprint=rf230_last_rssi;
    }
#endif

#if 0
/* Clock.c can trigger a periodic PLL calibration in the RF230BB driver.
 * This can show when that happens.
 */
    extern uint8_t rf230_calibrated;
    if (rf230_calibrated) {
      PRINTA("\nRF230 calibrated!\n");
      rf230_calibrated=0;
    }
#endif

#if TESTRTIMER
/* Timeout can be increased up to 8 seconds maximum.
 * A one second cycle is convenient for triggering the various debug printouts.
 * The triggers are staggered to avoid printing everything at once.
 * My Jackdaw is 4% slow.
 */
    if (rtimerflag) {
      rtimer_set(&rt, RTIMER_NOW()+ RTIMER_ARCH_SECOND*1UL, 1,(void *) rtimercycle, NULL);
      rtimerflag=0;

#if STAMPS
if ((rtime%STAMPS)==0) {
  PRINTA("%us ",rtime);
  if (rtime%STAMPS*10) PRINTA("\n");
}
#endif
      rtime+=1;

#if PINGS && UIP_CONF_IPV6_RPL
extern void raven_ping6(void);
if ((rtime%PINGS)==1) {
  PRINTA("**Ping\n");
  raven_ping6();
}
#endif

#if ROUTES && UIP_CONF_IPV6_RPL
if ((rtime%ROUTES)==2) {

extern uip_ds6_netif_t uip_ds6_if;

  uint8_t i,j;
  uip_ds6_nbr_t *nbr;

  PRINTA("\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);
      PRINTA("\n");
    }
  }
  PRINTA("\nNeighbors [%u max]\n",NBR_TABLE_MAX_NEIGHBORS);

  for(nbr = nbr_table_head(ds6_neighbors);
      nbr != NULL;
      nbr = nbr_table_next(ds6_neighbors, nbr)) {
    uip_debug_ipaddr_print(&nbr->ipaddr);
    PRINTA("\n");
    j=0;
  }
  if (j) PRINTA("  <none>");
  PRINTA("\nRoutes [%u max]\n",UIP_DS6_ROUTE_NB);
  uip_ds6_route_t *r;
  for(r = uip_ds6_route_head();
      r != NULL;
      r = uip_ds6_route_next(r)) {
    if(r->isused) {
      uip_debug_ipaddr_print(&r->ipaddr);
      PRINTA("/%u (via ", r->length);
      uip_debug_ipaddr_print(uip_ds6_route_nexthop(r));
 //     if(r->state.lifetime < 600) {
        PRINTA(") %lus\n", r->state.lifetime);
 //     } else {
 //       PRINTA(")\n");
 //     }
      j=0;
    }
  }
  if (j) PRINTA("  <none>");
  PRINTA("\n---------\n");
}
#endif

#if STACKMONITOR && CONFIG_STACK_MONITOR
if ((rtime%STACKMONITOR)==3) {
  extern uint16_t __bss_end;
  uint16_t p=(uint16_t)&__bss_end;
  do {
    if (*(uint16_t *)p != 0x4242) {
      PRINTA("Never-used stack > %d bytes\n",p-(uint16_t)&__bss_end);
      break;
    }
    p+=100;
  } while (p<RAMEND-10);
}
#endif

    }
#endif /* TESTRTIMER */

//Use with RF230BB DEBUGFLOW to show path through driver
#if RF230BB&&0
extern uint8_t debugflowsize,debugflow[];  //in rf230bb.c
  if (debugflowsize) {
    debugflow[debugflowsize]=0;
    PRINTA("%s",debugflow);
    debugflowsize=0;
   }
#endif

  }
  return 0;
}
Exemplo n.º 21
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<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();
}
static void
set_rime_addr(void)
{
#if UIP_CONF_EUI64
  rimeaddr_t addr;
  memset(&addr, 0, sizeof(rimeaddr_t));
  if (params_get_eui64(addr.u8)) {
    PRINTA("Random EUI64 address generated\n");
  }

#if UIP_CONF_IPV6
  memcpy(&uip_lladdr.addr, &addr.u8, sizeof(rimeaddr_t));
  rimeaddr_set_node_addr(&addr);
  rf2xx_set_pan_addr(params_get_panid(), params_get_panaddr(), (uint8_t *)&addr.u8);
#elif WITH_NODE_ID
  node_id = get_panaddr_from_eeprom();
  addr.u8[1] = node_id&0xff;
  addr.u8[0] = (node_id&0xff00) >> 8;
  PRINTA("Node ID from eeprom: %X\n", node_id);
  uint16_t inv_node_id=((node_id & 0xff00) >> 8) + ((node_id & 0xff) << 8); // change order of bytes for rf23x
  rimeaddr_set_node_addr(&addr);
  rf2xx_set_pan_addr(params_get_panid(), inv_node_id, NULL);
#else
  rimeaddr_set_node_addr(&addr);
  rf2xx_set_pan_addr(params_get_panid(), params_get_panaddr(), (uint8_t *)&addr.u8);
#endif



#if UIP_CONF_IPV6
  PRINTA("EUI-64 MAC: %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]);
#else
  PRINTA("MAC address ");
  uint8_t i;
  for (i = sizeof(rimeaddr_t); i > 0; i--){
    PRINTA("%x:", addr.u8[i-1]);
  }
  PRINTA("\n");
#endif
#else
  rimeaddr_t addr;
  int i;

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

#if UIP_CONF_IPV6
  memcpy(addr.u8, ds2401_id, sizeof(addr.u8));
#else
  if(node_id == 0) {
    for(i = 0; i < sizeof(rimeaddr_t); ++i) {
      addr.u8[i] = ds2401_id[7 - i];
    }
  } else {
    addr.u8[0] = node_id & 0xff;
    addr.u8[1] = node_id >> 8;
  }
#endif

  rimeaddr_set_node_addr(&addr);
  PRINTA("Rime started with address ");
  for(i = 0; i < sizeof(addr.u8) - 1; i++) {
    PRINTA("%d.", addr.u8[i]);
  }
  PRINTA("%d\n", addr.u8[i]);

  {
    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);
    PRINTA("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]);
    rf2xx_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
  }

#if UIP_CONF_IPV6
  memcpy(&uip_lladdr.addr, ds2401_id, sizeof(uip_lladdr.addr));
#endif
  //rf2xx_set_channel(params_get_channel());
  //rf2xx_set_txpower(params_get_txpower());

#endif
  rf2xx_set_channel(RF_CHANNEL);
}
void
init_net(void)
{
  /* Start radio and radio receive process */
  NETSTACK_RADIO.init();

  /* Set addresses BEFORE starting tcpip process */
  set_rime_addr();

  /* Setup nullmac-like MAC for 802.15.4 */
  /* sicslowpan_init(sicslowmac_init(&cc2420_driver)); */
  /* printf(" %s channel %u\n", sicslowmac_driver.name, RF_CHANNEL); */

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

  PRINTA("%s %s, channel %u , check rate %u Hz tx power %u\n", NETSTACK_MAC.name, NETSTACK_RDC.name, rf2xx_get_channel(),
      CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1 : NETSTACK_RDC.channel_check_interval()),
      rf2xx_get_txpower());
#if UIP_CONF_IPV6_RPL
  PRINTA("RPL Enabled\n");
#endif
#if UIP_CONF_ROUTER
  PRINTA("Routing Enabled\n");
#endif

  process_start(&tcpip_process, NULL);

#if ANNOUNCE_BOOT && UIP_CONF_IPV6
  PRINTA("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) {
      PRINTA("%02x%02x:", lladdr->ipaddr.u8[i * 2],
          lladdr->ipaddr.u8[i * 2 + 1]);
    }
    PRINTA("%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);
    PRINTA("Tentative global IPv6 address ");
    for(i = 0; i < 7; ++i) {
      PRINTA("%02x%02x:",
          ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
    }
    PRINTA("%02x%02x\n",
        ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
  }
#endif /* ANNOUNCE_BOOT */

#if WITH_UIP
  uip_ipaddr_t hostaddr, netmask;

  uip_init();
  uip_fw_init();

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

  slip_set_input_callback(set_gateway);

  /* Construct ip address from four bytes. */
  uip_ipaddr(&hostaddr, 172, 16, rimeaddr_node_addr.u8[0],
      rimeaddr_node_addr.u8[1]);
  /* Construct netmask from four bytes. */
  uip_ipaddr(&netmask, 255,255,0,0);

  uip_ipaddr_copy(&meshif.ipaddr, &hostaddr);
  /* Set the IP address for this host. */
  uip_sethostaddr(&hostaddr);
  /* Set the netmask for this host. */
  uip_setnetmask(&netmask);

  uip_over_mesh_set_net(&hostaddr, &netmask);

  /* Register slip interface with forwarding module. */
  //uip_fw_register(&slipif);
  uip_over_mesh_set_gateway_netif(&slipif);
  /* Set slip interface to be a default forwarding interface . */
  uip_fw_default(&meshif);
  uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
  PRINTA(PSTR("uIP started with IP address %d.%d.%d.%d\n"),
      uip_ipaddr_to_quad(&hostaddr));
#endif /* WITH_UIP */
}
/*------Done in a subroutine to keep main routine stack usage small--------*/
void
initialize(void)
{
#ifdef BUZZER
  buzz_id();
#endif

  watchdog_init();
  watchdog_start();

  clock_init();

  PRINTD("\n\nChecking MCUSR...\n");
  if(MCUSR & (1<<PORF )) PRINTD("Power-on reset.\n");
  if(MCUSR & (1<<EXTRF)) PRINTD("External reset!\n");
  if(MCUSR & (1<<BORF )) PRINTD("Brownout reset!\n");
  if(MCUSR & (1<<WDRF )) PRINTD("Watchdog reset!\n");
  if(MCUSR & (1<<JTRF )) PRINTD("JTAG reset!\n");
  MCUSR = 0;

  PRINTD("CLOCK_SECOND %d\n",CLOCK_SECOND);
  PRINTD("RTIMER_ARCH_SECOND %lu\n",RTIMER_ARCH_SECOND);
  PRINTD("F_CPU %lu\n",F_CPU);

#if STACKMONITOR
  /* Simple stack pointer highwater monitor. Checks for magic numbers in the main
   * loop. In conjuction with PERIODICPRINTS, never-used stack will be printed
   * every STACKMONITOR seconds.
   */
{
extern uint16_t __bss_end;
uint16_t p=(uint16_t)&__bss_end;
    do {
      *(uint16_t *)p = 0x4242;
      p+=10;
    } while (p<SP-10); //don't overwrite our own stack
}
#endif

/* Calibrate internal mcu clock against external 32768Hz watch crystal */
#define CONF_CALIBRATE_OSCCAL 0
#if CONF_CALIBRATE_OSCCAL
void calibrate_rc_osc_32k();
{
extern uint8_t osccal_calibrated;
uint8_t i;
  PRINTD("\nBefore calibration OSCCAL=%x\n",OSCCAL);
  for (i=0;i<10;i++) {
    calibrate_rc_osc_32k();
    PRINTD("Calibrated=%x\n",osccal_calibrated);
//#include <util/delay_basic.h>
//#define delay_us( us )   ( _delay_loop_2(1+(us*F_CPU)/4000000UL) )
//   delay_us(50000);
 }
   clock_init();
}
#endif 

  PRINTA("\n*******Booting %s*******\n",CONTIKI_VERSION_STRING);

  leds_init();
  leds_on(LEDS_RED);

  /* Initialize USART */
#ifdef CAMERA_INTERFACE
  camera_init();
#else
  init_usart();
#endif

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

  /* Get a random 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.
   */
  random_init(rng_get_uint8());

  ctimer_init();

  init_net();
#else /* !RF2XXBB */
/* Original RF230 combined mac/radio driver */
/* mac process must be started before tcpip process! */
  process_start(&mac_process, NULL);
  process_start(&tcpip_process, NULL);
#endif /* RF2XXBB */

  /* Autostart other processes */
  autostart_start(autostart_processes);

  /*---If using coffee file system create initial web content if necessary---*/
#if COFFEE_FILES
  int fa = cfs_open( "/index.html", CFS_READ);
  if (fa<0) {     //Make some default web content
    PRINTA("No index.html file found, creating upload.html!\n");
    PRINTA("Formatting FLASH file system for coffee...");
    cfs_coffee_format();
    PRINTA("Done!\n");
    fa = cfs_open( "/index.html", CFS_WRITE);
    int r = cfs_write(fa, &"It works!", 9);
    if (r<0) PRINTA("Can''t create /index.html!\n");
    cfs_close(fa);
//  fa = cfs_open("upload.html"), CFW_WRITE);
// <html><body><form action="upload.html" enctype="multipart/form-data" method="post"><input name="userfile" type="file" size="50" /><input value="Upload" type="submit" /></form></body></html>
  }
#endif /* COFFEE_FILES */

/* Add addresses for testing */
#if 0
{
  uip_ip6addr_t ipaddr;
  uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
  uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
//  uip_ds6_prefix_add(&ipaddr,64,0);
}
#endif

/*--------------------------Announce the configuration---------------------*/
#if ANNOUNCE_BOOT
{
#if AVR_WEBSERVER
  uint8_t i;
  char buf1[40],buf[40];
  unsigned int size;

  for (i=0;i<UIP_DS6_ADDR_NB;i++) {
	if (uip_ds6_if.addr_list[i].isused) {
	   httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr,buf);
       PRINTA("IPv6 Address: %s\n",buf);
	}
  }
   cli();
   eeprom_read_block (buf1,eemem_server_name, sizeof(eemem_server_name));
   eeprom_read_block (buf,eemem_domain_name, sizeof(eemem_domain_name));
   sei();
   buf1[sizeof(eemem_server_name)]=0;
   PRINTA("%s",buf1);
   buf[sizeof(eemem_domain_name)]=0;
   size=httpd_fs_get_size();
#ifndef COFFEE_FILES
   PRINTA(".%s online with fixed %u byte web content\n",buf,size);
#elif COFFEE_FILES==1
   PRINTA(".%s online with static %u byte EEPROM file system\n",buf,size);
#elif COFFEE_FILES==2
   PRINTA(".%s online with dynamic %u KB EEPROM file system\n",buf,size>>10);
#elif COFFEE_FILES==3
   PRINTA(".%s online with static %u byte program memory file system\n",buf,size);
#elif COFFEE_FILES==4
   PRINTA(".%s online with dynamic %u KB program memory file system\n",buf,size>>10);
#endif /* COFFEE_FILES */

#else
   PRINTA("Online\n");
#endif /* AVR_WEBSERVER */

#endif /* ANNOUNCE_BOOT */
}
}
Exemplo n.º 25
0
/*---------------------------------------------------------------------------*/
void log_message(char *m1, char *m2)
{
  PRINTA("%s%s\n", m1, m2);
}
/*---------------------------------------------------------------------------*/
static void
print_network_status(void)
{
  int i;
  uint8_t state;
  uip_ds6_defrt_t *default_route;
  uip_ds6_route_t *route;

  PRINTA("--- Network status ---\n");
  
  /* Our IPv6 addresses */
  PRINTA("- Server IPv6 addresses:\n");
  for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
    state = uip_ds6_if.addr_list[i].state;
    if(uip_ds6_if.addr_list[i].isused &&
       (state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
      PRINTA("-%d- ",i);
      uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr);
      PRINTA("\n");
    }
  }
  
  /* Our default route */
  PRINTA("- Default route:\n");
  default_route = uip_ds6_defrt_lookup(uip_ds6_defrt_choose());
  if(default_route != NULL) {
    PRINTA("-- ");
    uip_debug_ipaddr_print(&default_route->ipaddr);;
    PRINTA(" (lifetime: %lu seconds)\n", (unsigned long)default_route->lifetime.interval);
  } else {
    PRINTA("-- None\n");
  }

  /* Our routing entries */
  PRINTA("- Routing entries (%u in total):\n", uip_ds6_route_num_routes());
  route = uip_ds6_route_head();
  while(route != NULL) {
    PRINTA("-- ");
    uip_debug_ipaddr_print(&route->ipaddr);
    PRINTA(" via ");
    uip_debug_ipaddr_print(uip_ds6_route_nexthop(route));
    PRINTA(" (lifetime: %lu seconds)\n", (unsigned long)route->state.lifetime);
    route = uip_ds6_route_next(route); 
  }
  
  PRINTA("----------------------\n");
}
Exemplo n.º 27
0
void terzo_close() {
  PRINTA("TERZO_CLOSE");
  UNSUB(TERZO);
}
Exemplo n.º 28
0
/*-----------------------------Low level initialization--------------------*/
static void initialize(void) {

  asm volatile ("clr r1");

  watchdog_init();
  watchdog_start();
  
  /* Clock */
  clock_init();

  /* Initialize hardware */
  init_lowlevel();

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


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

  generate_random_pan_id_and_aes_key();

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

  rf212_set_pan_addr(
 	get_panid_from_eeprom(),
 	get_panaddr_from_eeprom(),
 	(uint8_t *)&tmp_addr.u8
   );

	extern uint16_t mac_dst_pan_id;
	extern uint16_t mac_src_pan_id;
	//set pan_id for frame creation
	mac_dst_pan_id = get_panid_from_eeprom();
	mac_src_pan_id = mac_dst_pan_id;

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

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

/* Start ethernet network and storage process */
  process_start(&usb_eth_process, NULL);

#if USB_CONF_STORAGE
//  process_start(&storage_process, NULL);
#endif

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

  /* Button Process */
  process_start(&button_pressed_process, NULL);

  leds_on(LEDS_GREEN); //normal state indication
}
Exemplo n.º 29
0
/*------Done in a subroutine to keep main routine stack usage small--------*/
void initialize(void)
{
#if WITH_SLIP
  //Slip border router on uart0
  rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
#else
  /* First rs232 port for debugging */
  rs232_init(RS232_PORT_0, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);

  /* Redirect stdout to first port */
  rs232_redirect_stdout(RS232_PORT_0);

  /* Get input from first port */
  rs232_set_input(RS232_PORT_0, serial_line_input_byte);
#endif

  clock_init();

  if(MCUSR & (1<<PORF )) PRINTA("Power-on reset.\n");
  if(MCUSR & (1<<EXTRF)) PRINTA("External reset!\n");
  if(MCUSR & (1<<BORF )) PRINTA("Brownout reset!\n");
  if(MCUSR & (1<<WDRF )) PRINTA("Watchdog reset!\n");
  if(MCUSR & (1<<JTRF )) PRINTA("JTAG reset!\n");

#if ANNOUNCE_BOOT
  PRINTA("\n*******Booting %s*******\n",CONTIKI_VERSION_STRING);
#endif

  /* Initialize process subsystem */
  process_init();

  /* etimers must be started before ctimer_init */
  process_start(&etimer_process, NULL);

  /* Initilaize serial line for input */
  serial_line_init();

  /* Initialize board LEDs */
  leds_init();

  /* When used for testing, we should start with them off */
  leds_off(LEDS_GREEN|LEDS_YELLOW);

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

  /* Set addresses BEFORE starting tcpip process */

  rimeaddr_t addr;
  memset(&addr, 0, sizeof(rimeaddr_t));
  get_mac_from_eeprom(addr.u8);

  memcpy(&uip_lladdr.addr, &addr.u8, 8);

// Is this required with IPv6, I wonder?
#if 1
  rf230_set_pan_addr(
    IEEE802154_PANID,
    0,
    (uint8_t *)&addr.u8
  );
  rf230_set_channel(26);

  rimeaddr_set_node_addr(&addr);
#endif

  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
  PRINTA("%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) PRINTA(", check rate %u Hz",tmp);
  }
  PRINTA("\n");
#endif

#if UIP_CONF_ROUTER
//#warning Zigduino has not been tested with UIP_CONF_ROUTER
#if ANNOUNCE_BOOT
  PRINTA("Routing Enabled\n");
#endif
#endif

  /* Sensors process means all processes will get an event posted whenever sensors change.
     Not always desired, so may want to put this on a compile switch. */
  process_start(&sensors_process, NULL);
  SENSORS_ACTIVATE(button_sensor);

  process_start(&tcpip_process, NULL);

  //Give ourselves a prefix
  // init_net();

  /* Add easy addresses for testing */
  uip_ip6addr_t ipaddr;
  uip_ip6addr(&ipaddr, 0xfe80, 0, 0, 0, 0, 0, 0, addr.u8[7]);
  uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
#if UIP_CONF_ROUTER
  uip_ds6_prefix_add(&ipaddr,64,0,0,0,0);
#else
  uip_ds6_prefix_add(&ipaddr,64,0);
#endif

  /* Create a route through the border router for site-local addresses, fec0::/64. */
  uip_ds6_route_t *rep;
  uip_ip6addr_t next_hop;
  uip_ip6addr(&ipaddr, 0xfec0, 0, 0, 0, 0, 0, 0, 0);
  uip_ip6addr(&next_hop, 0xaaaa, 0, 0, 0, 0, 0, 0, 1);
  if((rep = uip_ds6_route_add(&ipaddr, 64, &next_hop, 0)) == NULL)
  {
    printf("*** Failed to add a route to fec0::/64\n");
  }
 
  printf("Autostart other processes\n");
  /* Autostart other processes */
  autostart_start(autostart_processes);

  /*--------------------------Announce the configuration---------------------*/
#if ANNOUNCE_BOOT

  extern uip_ds6_netif_t uip_ds6_if;

  uint8_t i;
  PRINTA("\nIP addresses [%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);
      PRINTA("\n");
    }
  }
#endif /* ANNOUNCE_BOOT */
}
Exemplo n.º 30
0
/*---------------------------------------------------------------------------*/
void
uip_debug_ipaddr_print(const uip_ipaddr_t *addr)
{
  PRINTA("%u.%u.%u.%u", addr->u8[0], addr->u8[1], addr->u8[2], addr->u8[3]);
}