示例#1
0
__interrupt void port_1_isr(void) 
{
  EA = 0;
  ENERGEST_ON(ENERGEST_TYPE_IRQ);

  /* This ISR is for the entire port. Check if the interrupt was caused by our
   * button's pin. */
  if(BUTTON_IRQ_CHECK(1)) {
    if(timer_expired(&debouncetimer)) {
      timer_set(&debouncetimer, CLOCK_SECOND / 8);
      sensors_changed(&button_1_sensor);
    }
  }
  if(BUTTON_IRQ_CHECK(2)) {
    if(timer_expired(&debouncetimer)) {
      timer_set(&debouncetimer, CLOCK_SECOND / 8);
#if CC2531_CONF_B2_REBOOTS
      watchdog_reboot();
#else /* General Purpose */
      sensors_changed(&button_2_sensor);
#endif
    }
  }

  BUTTON_IRQ_FLAG_OFF(1);
  BUTTON_IRQ_FLAG_OFF(2);

  ENERGEST_OFF(ENERGEST_TYPE_IRQ);
  EA = 1;
}
示例#2
0
文件: bootloader.c 项目: 1uk3/contiki
void
Jump_To_Bootloader(void)
{
  /* Disable all interrupts */
  cli();

#ifdef UDCON
  /* If USB is used, detach from the bus */
  Usb_detach();

  uint8_t i;

  /* Wait two seconds for the USB detachment to register on the host */
  for(i = 0; i < 200; i++) {
    _delay_ms(10);
    watchdog_periodic();
  }
#endif

  /* Set the bootloader key to the magic value and force a reset */
  Boot_Key = MAGIC_BOOT_KEY;

  eeprom_write_byte(EEPROM_MAGIC_BYTE_ADDR, 0xFF);

  /* Enable interrupts */
  sei();

  watchdog_reboot();
}
示例#3
0
文件: slip-radio.c 项目: Jakl555/6lbr
/*---------------------------------------------------------------------------*/
static int
slip_radio_cmd_handler(const uint8_t *data, int len)
{
  int i;
  if(data[0] == '!') {
    /* should send out stuff to the radio - ignore it as IP */
    /* --- s e n d --- */
    if(data[1] == 'S') {
      int pos;
      packet_ids[packet_pos] = data[2];

      packetbuf_clear();
      pos = packetutils_deserialize_atts(&data[3], len - 3);
      if(pos < 0) {
        PRINTF("slip-radio: illegal packet attributes\n");
        return 1;
      }
      pos += 3;
      len -= pos;
      if(len > PACKETBUF_SIZE) {
        len = PACKETBUF_SIZE;
      }
      memcpy(packetbuf_dataptr(), &data[pos], len);
      packetbuf_set_datalen(len);

      PRINTF("slip-radio: sending %u (%d bytes)\n",
             data[2], packetbuf_datalen());

      /* parse frame before sending to get addresses, etc. */
      no_framer.parse();
      NETSTACK_MAC.send(packet_sent, &packet_ids[packet_pos]);

      packet_pos++;
      if(packet_pos >= sizeof(packet_ids)) {
	packet_pos = 0;
      }
      return 1;
    } else if(data[1] == 'R' && len == 2) {
#if !CONTIKI_TARGET_CC2538DK
      PRINTF("Rebooting\n");
      watchdog_reboot();
#endif
      return 1;
    }
  } else if(uip_buf[0] == '?') {
    PRINTF("Got request message of type %c\n", uip_buf[1]);
    if(data[1] == 'M' && len == 2) {
      /* this is just a test so far... just to see if it works */
      uip_buf[0] = '!';
      uip_buf[1] = 'M';
      for(i = 0; i < 8; i++) {
        uip_buf[2 + i] = uip_lladdr.addr[i];
      }
      uip_len = 10;
      cmd_send(uip_buf, uip_len);
      return 1;
    }
  }
  return 0;
}
watchdog_interrupt(void)
{
#ifdef CONTIKI_TARGET_SKY
#if PRINT_STACK_ON_REBOOT
  uint8_t dummy;
  static uint8_t *ptr;
  static int i;

  ptr = &dummy;
  printstring("Watchdog reset");
  printstring("\nStack at $");
  hexprint(((int)ptr) >> 8);
  hexprint(((int)ptr) & 0xff);
  printstring(":\n");

  for(i = 0; i < 64; ++i) {
    hexprint(ptr[i]);
    printchar(' ');
    if((i & 0x0f) == 0x0f) {
      printchar('\n');
    }
  }
  printchar('\n');
#endif /* PRINT_STACK_ON_REBOOT */
#endif /* CONTIKI_TARGET_SKY */

  watchdog_reboot();
}
示例#5
0
/*-----------------------------------------------------------------------------------*/
static short
parse_hello_reply(uint8_t *buf)
{
	if(buf[0] != HELLO_ACK) {
		return 0;
	}

	if(buf[1] != SEC_ARP_REPLY) {
		return 0;
	}

#if DEBUG
	uint8_t i;
	PRINTF("sec-arp: buf ");
	for(i=0; i<(KEY_SIZE*3); i++) PRINTF("%02x ", buf[3+i]);
	PRINTF("\n");
#endif

	/* Write security data to Flash */
	xmem_erase(XMEM_ERASE_UNIT_SIZE, MAC_SECURITY_DATA);
	xmem_pwrite(&buf[3], (KEY_SIZE*3), MAC_SECURITY_DATA);

	PRINTF("sec-arp: parse OK\n");

	watchdog_reboot();

	return 1;
}
示例#6
0
/*---------------------------------------------------------------------------*/
void
adaptivesec_add_security_header(struct anti_replay_info *receiver_info)
{
  if(!anti_replay_set_counter(receiver_info)) {
    watchdog_reboot();
  }
#if ANTI_REPLAY_WITH_SUPPRESSION
  anti_replay_suppress_counter();
#else /* ANTI_REPLAY_WITH_SUPPRESSION */
  packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL, adaptivesec_get_sec_lvl());
#endif /* ANTI_REPLAY_WITH_SUPPRESSION */
}
示例#7
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(network_reboot_process, ev, data)
{
  static struct etimer periodic_timer;
  static struct etimer send_timer;
  static struct etimer countdown_timer;

  PROCESS_BEGIN();

  /* Wait for a while before starting to listen to the reboot code. */

  etimer_set(&periodic_timer, STARTUP_GRACE_PERIOD);
  PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));

  simple_udp_register(&broadcast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);

  etimer_set(&periodic_timer, SEND_INTERVAL);
  etimer_set(&send_timer, SEND_TIME);
  etimer_set(&countdown_timer, CLOCK_SECOND);
  while(1) {
    PROCESS_WAIT_EVENT();

    if(data == &countdown_timer) {
      etimer_reset(&countdown_timer);
      if(seconds_until_reboot > 0) {
	printf("Seconds until reboot %d\n", seconds_until_reboot);
	leds_toggle(LEDS_ALL);
	seconds_until_reboot--;
	if(seconds_until_reboot == 0) {
	  printf("Rebooting\n");
	  watchdog_reboot();
	}
      }
    }

    if(data == &periodic_timer) {
      etimer_reset(&periodic_timer);
      etimer_set(&send_timer, SEND_TIME);
    }

    if(data == &send_timer) {
      if(seconds_until_reboot > 0) {
	send_msg(&broadcast_connection, seconds_until_reboot);
      }
    }
  }

  PROCESS_END();
}
示例#8
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_server_process, ev, data)
{
#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON)
  static struct sensors_sensor *b1;
  static struct sensors_sensor *b2;
#endif

  PROCESS_BEGIN();
  putstring("Starting UDP server\n");

#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON)
  putstring("Button 1: Print RIME stats\n");
  putstring("Button 2: Reboot\n");
#endif

#if SERVER_RPL_ROOT
  create_dag();
#endif

  server_conn = udp_new(NULL, UIP_HTONS(0), NULL);
  udp_bind(server_conn, UIP_HTONS(3000));

  PRINTF("Listen port: 3000, TTL=%u\n", server_conn->ttl);

#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON)
  b1 = sensors_find(BUTTON_1_SENSOR);
  b2 = sensors_find(BUTTON_2_SENSOR);
#endif

  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      tcpip_handler();
#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON)
    } else if(ev == sensors_event && data != NULL) {
      if(data == b1) {
        print_stats();
      } else if(data == b2) {
        watchdog_reboot();
      }
#endif /* (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) */
    }
  }

  PROCESS_END();
}
示例#9
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(reboot_app_process, ev, data)
{
  struct sensors_sensor *sensor;
  PROCESS_BEGIN();

  SENSORS_ACTIVATE(button_sensor);

  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event);
    sensor = (struct sensors_sensor *) data;
    if(sensor == &button_sensor) {
      watchdog_reboot();
    }
  }
  
  PROCESS_END();
}
示例#10
0
文件: disco.c 项目: 1uk3/contiki
/*---------------------------------------------------------------------------*/
static void
timer_handler(void *p)
{
  uint8_t *s = p;
  uint8_t wip;

  PRINTF("Disco: @ %lu, s: %u\n", clock_seconds(), *s);

  if(*s == DISCO_STATE_PREPARING) {
    n740_analog_deactivate();
    wip = M25P16_WIP();
    n740_analog_activate();

    if(wip) {
      restart_timer(DISCO_TIMEOUT_PREPARE);
    } else {
      PRINTF("Disco: Erased %u\n", sector);
      if((sector & 1) == 0) {
        sector++;
        PRINTF("Disco: Next %u\n", sector);
        n740_analog_deactivate();
        m25p16_se(sector);
        n740_analog_activate();
        restart_timer(DISCO_TIMEOUT_PREPARE);
      } else {
        PRINTF("Disco: Ready\n");
        *s = DISCO_STATE_READY;
        resp.status = DISCO_CMD_INIT;
        restart_timer(DISCO_TIMEOUT_ABORT);
        server_conn->rport = seed.port;
        uip_ipaddr_copy(&server_conn->ripaddr, &seed.addr);
        uip_udp_packet_send(server_conn, &resp, DISCO_RESP_LEN_INIT);

        /* Restore server connection to allow data from any node */
        uip_create_unspecified(&server_conn->ripaddr);
        server_conn->rport = 0;
      }
    }
  } else if(*s == DISCO_STATE_READY) {
    abort();
  } else if(*s == DISCO_STATE_REBOOTING) {
    watchdog_reboot();
  }
}
示例#11
0
PROCESS_THREAD(buttons_test_process, ev, data)
{
  struct sensors_sensor *sensor;

  PROCESS_BEGIN();

  while (1) {

    PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event);

    /* If we woke up after a sensor event, inform what happened */
    sensor = (struct sensors_sensor *)data;
    if(sensor == &button_1_sensor) {
      leds_toggle(LEDS_GREEN);
    } else if(sensor == &button_2_sensor) {
      watchdog_reboot();
    }
  }

  PROCESS_END();
}
示例#12
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_reboot_process, ev, data)
{
  static struct etimer etimer;
  PROCESS_BEGIN();

  shell_output_str(&reboot_command,
		   "Rebooting the node in four seconds...", "");

  etimer_set(&etimer, CLOCK_SECOND);
  PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
  leds_on(LEDS_RED);
  etimer_reset(&etimer);
  PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
  leds_on(LEDS_GREEN);
  etimer_reset(&etimer);
  PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
  leds_on(LEDS_BLUE);
  etimer_reset(&etimer);
  PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
  
  watchdog_reboot();

  PROCESS_END();
}
示例#13
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
  static struct etimer periodic;
  static struct ctimer backoff_timer;
#if WITH_COMPOWER
  static int print = 0;
#endif

  PROCESS_BEGIN();

  PROCESS_PAUSE();

  SENSORS_ACTIVATE(button_sensor);

  set_global_address();
  
  PRINTF("UDP client process started\n");

  print_local_addresses();

  /* new connection with remote host */
  client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); 
  if(client_conn == NULL) {
    PRINTF("No UDP connection available, exiting the process!\n");
    PROCESS_EXIT();
  }
  udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); 

  PRINTF("Created a connection with the server ");
  PRINT6ADDR(&client_conn->ripaddr);
  PRINTF(" local/remote port %u/%u\n",
	UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));

#if WITH_COMPOWER
  powertrace_sniff(POWERTRACE_ON);
#endif

  etimer_set(&periodic, SEND_INTERVAL);
  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      tcpip_handler();
    }
else if (ev == sensors_event && data == &button_sensor) {
    	PRINTF("Erase keys\n");
    	xmem_erase(XMEM_ERASE_UNIT_SIZE, MAC_SECURITY_DATA);
    	watchdog_reboot();

//    	uint8_t i;
//    	for(i=0; i<16; i++) {temp_sec_device_list[i+16] = 8;}
//    	temp_sec_device_list[15] = 2;
//    	temp_sec_device_list[32] = 1;
//    	for(i=0; i<16; i++) {temp_sec_device_list[i+49] = 9;}
//    	temp_sec_device_list[48] = 3;
//    	temp_sec_device_list[65] = 4;
//
//
//    	PRINTF("App mem set\n");
//    	xmem_erase(XMEM_ERASE_UNIT_SIZE, APP_SECURITY_DATA);
//    	xmem_pwrite(temp_sec_device_list, 66, APP_SECURITY_DATA);
    }
    
    if(etimer_expired(&periodic)) {
      etimer_reset(&periodic);
      ctimer_set(&backoff_timer, SEND_TIME, send_packet, NULL);

#if WITH_COMPOWER
      if (print == 0) {
	powertrace_print("#P");
      }
      if (++print == 3) {
	print = 0;
      }
#endif

    }
  }

  PROCESS_END();
}
示例#14
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(cc2538_demo_process, ev, data)
{

  PROCESS_EXITHANDLER(broadcast_close(&bc))

  PROCESS_BEGIN();

  counter = 0;
  broadcast_open(&bc, BROADCAST_CHANNEL, &bc_rx);
  printf("temp:%u.%u\nhumidity:%u.%u\n",(int)tc,((int)(tc*10))%10 , (int)hc,((int)(hc*10))%10);
  while(1) {
    etimer_set(&et, CLOCK_SECOND*10);

    //ivanm
    // Configure ADC, Internal reference, 512 decimation rate (12bit)
    //
    SOCADCSingleConfigure(SOCADC_12_BIT, SOCADC_REF_INTERNAL);
    //
    // Trigger single conversion on AIN6 (connected to LV_ALS_OUT).
    //
    SOCADCSingleStart(SOCADC_VDD);
    //
    // Wait until conversion is completed
    //
    while(!SOCADCEndOfCOnversionGet())
    {
    }
    //
    // Get data and shift down based on decimation rate
    //
    ui1Dummy = SOCADCDataGet() >> SOCADC_12_BIT_RSHIFT;
    printf("konverzija(ADC) = 0x%08x\n",ui1Dummy);
    PROCESS_YIELD();

    if(ev == PROCESS_EVENT_TIMER) {
      leds_on(LEDS_PERIODIC);
      printf("Counter = 0x%08x\n", counter);
      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);

             	  					//tc=sht11_TemperatureC(temperature);
             	  					//hc=sht11_Humidity(temperature,humidity);
             	  					tc=0;
             	  					hc=0;
             	  					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");

      etimer_set(&et, CLOCK_SECOND);
      rtimer_set(&rt, RTIMER_NOW() + LEDS_OFF_HYSTERISIS, 1,
                 rt_callback, NULL);
    } else if(ev == sensors_event) {
      if(data == &button_select_sensor) {
    	  if (swt==0)
    	  {
    		packetbuf_copyfrom(&temperature, sizeof(temperature));
    	  	broadcast_send(&bc);
        	swt=1;
    	  }
          else
          {
        	packetbuf_copyfrom(&humidity, sizeof(humidity));
    	  	broadcast_send(&bc);
        	swt=0;
          }

      } else if(data == &button_left_sensor || data == &button_right_sensor) {
        leds_toggle(LEDS_BUTTON);
      } else if(data == &button_down_sensor) {
        cpu_cpsid();
        leds_on(LEDS_REBOOT);
        watchdog_reboot();
      } else if(data == &button_up_sensor) {
        sys_ctrl_reset();
      }
    } else if(ev == serial_line_event_message) {
      leds_toggle(LEDS_SERIAL_IN);
    }
    counter++;
    /* put measaruement sht11 here*/

  }

  PROCESS_END();
}
示例#15
0
void menu_process(char c)
{
  static enum menustate_enum            /* Defines an enumeration type    */
  {
      normal,
      channel,
      txpower
  } menustate = normal;

  static char channel_string[3];
  static uint8_t channel_string_i;// = 0;

  int tempchannel;

  if (menustate == channel) {

    switch(c) {
    case '\r':
    case '\n':
      if (channel_string_i) {
        channel_string[channel_string_i] = 0;
        tempchannel = atoi(channel_string);

        if ((tempchannel < 11) || (tempchannel > 26)) {
          PRINTF_P(PSTR("\n\rInvalid input\n\r"));
        } else {
          rf230_set_channel(tempchannel);

#if CONTIKI_CONF_SETTINGS_MANAGER
          if(settings_set_uint8(SETTINGS_KEY_CHANNEL, tempchannel) == SETTINGS_STATUS_OK) {
            PRINTF_P(PSTR("\n\rChannel changed to %d and stored in EEPROM.\n\r"), tempchannel);
          } else {
            PRINTF_P(PSTR("\n\rChannel changed to %d, but unable to store in EEPROM!\n\r"), tempchannel);
          }
#else
          PRINTF_P(PSTR("\n\rChannel changed to %d.\n\r"), tempchannel);
#endif
        }
      } else {
        PRINTF_P(PSTR("\n\rChannel unchanged.\n\r"));
      }

      menustate = normal;
      break;

    case '\b':
      if (channel_string_i) {
        channel_string_i--;
        PRINTF_P(PSTR("\b \b"));
      }
      break;

    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
      if (channel_string_i > 1) {
        // This time the user has gone too far.
        // Beep at them.
        putc('\a', stdout);
        break;
      }
      putc(c, stdout);
      channel_string[channel_string_i] = c;
      channel_string_i++;
      break;

    default:
      break;
    }

  } else if (menustate == txpower) {

    switch(c) {
    case '\r':
    case '\n':
      if (channel_string_i) {
        channel_string[channel_string_i] = 0;
        tempchannel = atoi(channel_string);

        if ((tempchannel < 0) || (tempchannel > 15))  {
          PRINTF_P(PSTR("\n\rInvalid input\n\r"));
        } else {
          PRINTF_P(PSTR(" ")); //for some reason needs a print here to clear the string input...
          rf230_set_txpower(tempchannel);

#if CONTIKI_CONF_SETTINGS_MANAGER
          if(settings_set_uint8(SETTINGS_KEY_TXPOWER, tempchannel) == SETTINGS_STATUS_OK) {
            PRINTF_P(PSTR("\n\rTransmit power changed to %d, and stored in EEPROM.\n\r"), tempchannel);
          } else {
            PRINTF_P(PSTR("\n\rTransmit power changed to %d, but unable to store in EEPROM!\n\r"), tempchannel);
          }
#else
          PRINTF_P(PSTR("\n\rTransmit power changed to %d.\n\r"), tempchannel);
#endif
        }
      } else {
        PRINTF_P(PSTR("\n\rTransmit power unchanged.\n\r"));
      }

      menustate = normal;
      break;

    case '\b':
      if (channel_string_i) {
        channel_string_i--;
        PRINTF_P(PSTR("\b \b"));
      }
      break;

    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
      if (channel_string_i > 1) {
        // This time the user has gone too far.
        // Beep at them.
        putc('\a', stdout);
        break;
      }
      putc(c, stdout);
      channel_string[channel_string_i] = c;
      channel_string_i++;
      break;

    default:
      break;
    }

  } else {
    uint8_t i;

    switch(c) {
    case '\r':
    case '\n':
      break;

    case 'h':
    case '?':
      menu_print();
      break;

    case 'd':
      if (mx_console_mode.debugOn) {
        PRINTF_P(PSTR("Node does not output debug strings\n\r"));
        mx_console_mode.debugOn = 0;
      } else {
        PRINTF_P(PSTR("Node now outputs debug strings\n\r"));
        mx_console_mode.debugOn = 1;
      }
      break;

    case 'c':
      PRINTF_P(PSTR("\nSelect 802.15.4 Channel in range 11-26 [%d]: "), rf230_get_channel());
      menustate = channel;
      channel_string_i = 0;
      break;
    case 'p':
      PRINTF_P(PSTR("\nSelect transmit power (0=+3dBm 15=-17.2dBm) [%d]: "), rf230_get_txpower());
      menustate = txpower;
      channel_string_i = 0;
      break;

#if UIP_CONF_IPV6_RPL
#include "rpl.h"
extern uip_ds6_nbr_t uip_ds6_nbr_cache[];
extern uip_ds6_netif_t uip_ds6_if;

    case 'N':
    {
      uint8_t i,j;
      PRINTF_P(PSTR("\n\rAddresses [%u max]\n\r"),UIP_DS6_ADDR_NB);
      for (i=0;i<UIP_DS6_ADDR_NB;i++) {
        if (uip_ds6_if.addr_list[i].isused) {
          ipaddr_add(&uip_ds6_if.addr_list[i].ipaddr);
          PRINTF_P(PSTR("\n\r"));
        }
      }
      PRINTF_P(PSTR("\n\rNeighbors [%u max]\n\r"),UIP_DS6_NBR_NB);
      for(i = 0,j=1; i < UIP_DS6_NBR_NB; i++) {
        if(uip_ds6_nbr_cache[i].isused) {
          ipaddr_add(&uip_ds6_nbr_cache[i].ipaddr);
          PRINTF_P(PSTR("\n\r"));
          j=0;
        }
      }
      if (j) PRINTF_P(PSTR("  <none>"));
      PRINTF_P(PSTR("\n\rRoutes [%u max]\n\r"),UIP_DS6_ROUTE_NB);
      {
        uip_ds6_route_t *r;
        j = 1;
        for(r = uip_ds6_route_list_head();
            r != NULL;
            r = list_item_next(r)) {
          ipaddr_add(&r->ipaddr);
          PRINTF_P(PSTR("/%u (via "), r->length);
          ipaddr_add(&r->nexthop);
          if(r->state.lifetime < 600) {
            PRINTF_P(PSTR(") %lus\n\r"), r->state.lifetime);
          } else {
            PRINTF_P(PSTR(")\n\r"));
          }
          j = 0;
        }
      }

      if (j) PRINTF_P(PSTR("  <none>"));
      PRINTF_P(PSTR("\n\r---------\n\r"));
      break;
    }

    case 'G':
      PRINTF_P(PSTR("Global repair returns %d\n\r"),rpl_repair_root(RPL_DEFAULT_INSTANCE));
      break;

    case 'L':
      rpl_local_repair(rpl_get_any_dag());
      PRINTF_P(PSTR("Local repair initiated\n\r"));
      break;

#endif

    case 'm':
      PRINTF_P(PSTR("Currently running on\n\r"));
      PRINTF_P(PSTR("  * %s\n\r"), CONTIKI_VERSION_STRING);
      PRINTF_P(PSTR("  * NETSTACK_MAC: %s, NETSTACK_RDC: %s\n\r"), NETSTACK_MAC.name, NETSTACK_RDC.name);
#if 1
      {
        int i;
        PRINTF_P(PSTR("  * Address: "));
        for (i = 0; i < 6; i += 2) {
          PRINTF_P(PSTR("%02x%02x:"), uip_lladdr.addr[i], uip_lladdr.addr[i + 1]);
        }
        PRINTF_P(PSTR("%02x%02x\n\r"), uip_lladdr.addr[6], uip_lladdr.addr[7]);
      }
#endif
#if UIP_CONF_IPV6_RPL
      PRINTF_P(PSTR("  * RPL Enabled\n\r"));
#endif
#if UIP_CONF_ROUTER
      PRINTF_P(PSTR("  * Routing Enabled\n\r"));
#endif
#if CONVERTTXPOWER
      PRINTF_P(PSTR("  * Operates on channel %d with TX power "),rf230_get_channel());
      printtxpower();
      PRINTF_P(PSTR("\n\r"));
#else  //just show the raw value
      PRINTF_P(PSTR("  * Operates on channel %d\n\r"), rf230_get_channel());
      PRINTF_P(PSTR("  * TX Power(0=+3dBm, 15=-17.2dBm): %d\n\r"), rf230_get_txpower());
#endif
      if (rf230_smallest_rssi) {
        PRINTF_P(PSTR("  * Current/Last/Smallest RSSI: %d/%d/%ddBm\n\r"), -91+(rf230_rssi()-1), -91+(rf230_last_rssi-1),-91+(rf230_smallest_rssi-1));
        rf230_smallest_rssi=0;
      } else {
        PRINTF_P(PSTR("  * Current/Last/Smallest RSSI: %d/%d/--dBm\n\r"), -91+(rf230_rssi()-1), -91+(rf230_last_rssi-1));
      }

#if CONFIG_STACK_MONITOR
      /* See contiki-raven-main.c for initialization of the magic numbers */
      {
        extern uint16_t __bss_end;
        uint16_t p=(uint16_t)&__bss_end;
        do {
          if (*(uint16_t *)p != 0x4242) {
            printf_P(PSTR("  * Never-used stack > %d bytes\n\r"),p-(uint16_t)&__bss_end);
            break;
          }
          p+=100;
        } while (p<RAMEND-100);
      }
#endif

      break;

    case 'e':
      PRINTF_P(PSTR("Energy Scan:\n"));
      {
        uint8_t i;
        uint16_t j;
        uint8_t previous_channel = rf230_get_channel();
        int8_t RSSI, maxRSSI[17];
        uint16_t accRSSI[17];

        bzero((void*)accRSSI,sizeof(accRSSI));
        bzero((void*)maxRSSI,sizeof(maxRSSI));

        for(j=0;j<(1<<12);j++) {
          for(i=11;i<=26;i++) {
            rf230_listen_channel(i);

            _delay_us(3*10);
            RSSI = rf230_rssi();  //multiplies rssi register by 3 for consistency with energy-detect register
            maxRSSI[i-11]=Max(maxRSSI[i-11],RSSI);
            accRSSI[i-11]+=RSSI;
          }

          if(j&(1<<7)) {
            leds_on(LEDS_RED);
            if(!(j&((1<<7)-1))) {
              PRINTF_P(PSTR("."));
            }
          } else {
            leds_off(LEDS_RED);
          }

          watchdog_periodic();
        }

        rf230_set_channel(previous_channel);

        PRINTF_P(PSTR("\n"));
        for(i=11;i<=26;i++) {
          uint8_t activity=Min(maxRSSI[i-11],accRSSI[i-11]/(1<<7));
          PRINTF_P(PSTR(" %d: %02ddB "),i, -91+(maxRSSI[i-11]-1));
          for(;activity--;maxRSSI[i-11]--) {
            PRINTF_P(PSTR("#"));
          }
          for(;maxRSSI[i-11]>0;maxRSSI[i-11]--) {
            PRINTF_P(PSTR(":"));
          }
          PRINTF_P(PSTR("\n"));
        }
      }

      PRINTF_P(PSTR("Done.\n"));
      break;

    case 'R':
      PRINTF_P(PSTR("Resetting...\n\r"));
      leds_on(LEDS_ALL);
      for(i = 0; i < 20; i++) _delay_ms(100);
      watchdog_reboot();
      break;

    default:
      PRINTF_P(PSTR("%c is not a valid option! h for menu\n\r"), c);
      break;
    }

  }
}
PROCESS_THREAD(component_topologycontrol, ev, data) {
	PROCESS_BEGIN();

	memb_init(&memb_nodelist);
	list_init(list_nodelist);

	BOOT_COMPONENT_WAIT(component_topologycontrol);

	static struct etimer waittime;
	etimer_set(&waittime, CLOCK_SECOND * COMPONENT_TOPOLOGYCONTROL_LMST_UPDATEINTERVAL);
	while(1) {
		PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&waittime));
		etimer_reset(&waittime);

		// with a large neighbourhood the algorithm may take a looong time, so stop the watchdog
		// that the node is not rebooted because the CPU thinks there's an endless loop running
		watchdog_stop();

		// Prim algorithm
		// (connects edge of every node except the graph's root node - the node this code is running on=
		_lmst_nodelist_reconstruct();
		while(_lmst_nodelist_hasunconnected()) {

			// find best edge according to PRIM and LMST algorithm
			neighbor_t *edge_actual, *edge_best = NULL;
			for(edge_actual = list_head(component_neighbordiscovery_neighbors()); edge_actual != NULL; edge_actual = list_item_next(edge_actual)) {
				bool node1_connected = _lmst_nodelist_isconnected(edge_actual->node1) && !_lmst_nodelist_isconnected(edge_actual->node2);
				bool node2_connected = _lmst_nodelist_isconnected(edge_actual->node2) && !_lmst_nodelist_isconnected(edge_actual->node1);
				if(node1_connected ^ node2_connected) {
					bool criteria1 = (edge_best == NULL || MAX(edge_actual->weight_node1_to_node2, edge_actual->weight_node2_to_node1) < MAX(edge_best->weight_node1_to_node2, edge_best->weight_node2_to_node1));
					bool criteria2 = (MAX(edge_actual->weight_node1_to_node2, edge_actual->weight_node2_to_node1) == MAX(edge_best->weight_node1_to_node2, edge_best->weight_node2_to_node1) && networkaddr_cmp(NETWORKADDR_MAX(edge_actual), NETWORKADDR_MAX(edge_best)) < 0);
					if(criteria1 || criteria2)
						edge_best = edge_actual;
				}
			}
			if(edge_best == NULL) {
				printf("ERROR[topologycontrol-lmst]: no edge for spanning tree found\n");
				watchdog_reboot(); // we would end in an endless loop
			}

			_lmst_nodelist_connect(edge_best);
		}

#if DEBUG
		node_t *item_node;
		PRINTF("DEBUG: [topologycontrol-lmst] spanning tree: ");
		for(item_node = list_head(list_nodelist); item_node != NULL; item_node = list_item_next(item_node)) {
			if(networkaddr_equal(item_node->address, networkaddr_node_addr()))
				continue;

			PRINTF("%s<->", networkaddr2string_buffered(item_node->edge->node1));
			PRINTF("%s", networkaddr2string_buffered(item_node->edge->node2));
			PRINTF("%s", item_node->next == NULL ? "\n" : ", ");
		}
#endif

		// ignore every node which is not directly connected in the spanning tree
		node_t *node;
		for(node = list_head(list_nodelist); node != NULL; node = list_item_next(node)) {
			if(!networkaddr_equal(node->address, networkaddr_node_addr()) && !networkaddr_equal(node->edge->node1, networkaddr_node_addr()) && !networkaddr_equal(node->edge->node2, networkaddr_node_addr())) {
				component_network_ignoredlinks_add(node->address);
			}
		}

		watchdog_start();

		// LMST is only run once because if links have been ignored they are no longer available in the neighbor discovery
		// and hence a spanning tree can no longer be built
		PRINTF("DEBUG: [topologycontrol-lmst] LMST algorithm is finished and will run no more\n");
		break;
	}

	PROCESS_END();
}
示例#17
0
文件: triumviMain.c 项目: lab11/G2
static void resetcallBack(uint8_t port, uint8_t pin){
    watchdog_reboot();
}
示例#18
0
文件: triumviMain.c 项目: lab11/G2
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(mainProcess, ev, data) {
    PROCESS_BEGIN();

    GPIO_SET_OUTPUT(GPIO_A_BASE, 0xf8);
    GPIO_SET_OUTPUT(GPIO_B_BASE, 0x0f);
    GPIO_SET_OUTPUT(GPIO_C_BASE, 0x02);
    GPIO_CLR_PIN(GPIO_A_BASE, 0xf8);
    GPIO_CLR_PIN(GPIO_B_BASE, 0x07);
    GPIO_SET_PIN(EDISON_WAKEUP_BASE, EDISON_WAKEUP_PIN_MASK); // edison WAKEUP

    GPIO_SET_INPUT(RESET_PORT_BASE, RESET_PIN_MASK); // reset
    ioc_set_over(RESET_PORT, RESET_PIN, IOC_OVERRIDE_PUE);

    leds_off(LEDS_RED);
    leds_off(LEDS_GREEN);
    leds_off(LEDS_BLUE);

    // RESET interrupt, active low
    GPIO_DETECT_EDGE(RESET_PORT_BASE, RESET_PIN_MASK);
    GPIO_DETECT_FALLING(RESET_PORT_BASE, RESET_PIN_MASK);
    GPIO_TRIGGER_SINGLE_EDGE(RESET_PORT_BASE, RESET_PIN_MASK);
    gpio_register_callback(resetcallBack, RESET_PORT, RESET_PIN);
    GPIO_ENABLE_INTERRUPT(RESET_PORT_BASE, RESET_PIN_MASK);
    nvic_interrupt_enable(RESET_NVIC_PORT);

    GPIO_CLR_PIN(TRIUMVI_DATA_READY_PORT_BASE, TRIUMVI_DATA_READY_MASK);

    // SPI CS interrupt
    GPIO_DETECT_EDGE(SPI0_CS_PORT_BASE, SPI0_CS_PIN_MASK);
    GPIO_DETECT_RISING(SPI0_CS_PORT_BASE, SPI0_CS_PIN_MASK);
    GPIO_TRIGGER_SINGLE_EDGE(SPI0_CS_PORT_BASE, SPI0_CS_PIN_MASK);
    gpio_register_callback(spiCScallBack, SPI0_CS_PORT, SPI0_CS_PIN);
    GPIO_ENABLE_INTERRUPT(SPI0_CS_PORT_BASE, SPI0_CS_PIN_MASK);

    // SPI interface
    spix_slave_init(SPIDEV);
    spix_txdma_enable(SPIDEV);
    spi_register_callback(spiFIFOcallBack);
    spix_interrupt_enable(SPIDEV, SSI_IM_RXIM_M); // RX FIFO half full
    nvic_interrupt_enable(NVIC_INT_SSI0);

    // uDMA SPI0 TX
    udma_channel_disable(CC2538_SPI0_TX_DMA_CHAN);
    udma_channel_prio_set_default(CC2538_SPI0_TX_DMA_CHAN);
    udma_channel_use_primary(CC2538_SPI0_TX_DMA_CHAN);
    udma_channel_use_single(CC2538_SPI0_TX_DMA_CHAN);
    udma_channel_mask_clr(CC2538_SPI0_TX_DMA_CHAN);
    udma_set_channel_dst(CC2538_SPI0_TX_DMA_CHAN, SPI0DR);
    udma_set_channel_assignment(CC2538_SPI0_TX_DMA_CHAN, UDMA_CH11_SSI0TX);


    simple_network_set_callback(&rf_rx_handler);
    //NETSTACK_RADIO.off();
    
    process_start(&decryptProcess, NULL);
    process_start(&spiProcess, NULL);


    while (1){
        PROCESS_YIELD();
        // buffer is not empty, spi is not in use
        //if ((spiInUse==0) && (spix_busy(SPIDEV)==0) && ((triumviAvailIDX!=triumviFullIDX) || (triumviRXBufFull==1))){
        if ((spiInUse==0) && ((triumviAvailIDX!=triumviFullIDX) || (triumviRXBufFull==1))){
            GPIO_SET_PIN(TRIUMVI_DATA_READY_PORT_BASE, TRIUMVI_DATA_READY_MASK);
            if (triumviRXBufFull==1){
                resetCnt += 1;
                if (resetCnt==RESET_THRESHOLD){
                    watchdog_reboot();
                }
            }
            #ifdef LED_DEBUG
            leds_off(LEDS_RED);
            leds_off(LEDS_GREEN);
            leds_off(LEDS_BLUE);
            #endif
        }
        // Fail safe, CC2538 missing some SPI commands, reset spi state
        else if (triumviRXBufFull==1){
            spiState = SPI_RESET;
            process_poll(&spiProcess);
            #ifdef LED_DEBUG
            leds_off(LEDS_RED);
            leds_off(LEDS_GREEN);
            leds_on(LEDS_BLUE);
            #endif
        }
    }
    PROCESS_END();
}
示例#19
0
void
platform_restart(void)
{
  LOG6LBR_INFO("Rebooting...\n");
  watchdog_reboot();
}
示例#20
0
void MXBMESH::handlerftx()
{
	////send data
	//_delay_ms(RELAYDELAY);
	byte packdataindex_tx=txqueue.peerqueue(); //maybe empty
	if (packdataindex_tx==RFQUENEMAX) return;
	if (!NODEINFO.islowpower || txqueue.RfData[packdataindex_tx].value.destaddress==SINKADDRESS)
	{
		needchecksenddone=true;
		if (txqueue.RfData[packdataindex_tx].value.destaddress==0xff)
		{
			if (txqueue.RfData[packdataindex_tx].rbuf[0]==MSGTYPE_RB )
				_delay_ms(RELAYDELAY);
			MxRadio.beginTransmission();
		}

		else
		{
			if (txqueue.RfData[packdataindex_tx].rbuf[INDEX_SRCADDR]==NODEINFO.localAddress) //start from me
				_delay_ms(random(RELAYDELAY));
			MxRadio.beginTransmission(txqueue.RfData[packdataindex_tx].value.destaddress);
		}
		MxRadio.write(txqueue.RfData[packdataindex_tx].rbuf,txqueue.RfData[packdataindex_tx].length);
		MxRadio.endTransmission();
	}
	else //send wakeup packet
	{
		if (txqueue.RfData[packdataindex_tx].value.destaddress!=0xff)
		{
			//if (txqueue.RfData[packdataindex_tx].rbuf[INDEX_SRCADDR]==NODEINFO.localAddress &&  NODEINFO.localAddress!=SINKADDRESS)
			//	_delay_ms(random(RELAYDELAY));
			MxRadio.beginTransmission(txqueue.RfData[packdataindex_tx].value.destaddress);
			MxRadio.write(txqueue.RfData[packdataindex_tx].rbuf,txqueue.RfData[packdataindex_tx].length);
			needchecksenddone=true;
			MxRadio.endTransmission();
		}
		else //oxff
		{
			//if (txqueue.RfData[packdataindex_tx].rbuf[0]==MSGTYPE_RB)
			//_delay_ms(WAKEUP_PREAMBLE_MS+random(RELAYDELAY));
			needchecksenddone=false;
			byte msgtype=txqueue.RfData[packdataindex_tx].rbuf[0];
			unsigned long _startMillis = millis();
			do
			{
				MxRadio.beginTransmission();
				txqueue.RfData[packdataindex_tx].rbuf[0]=MSGTYPE_WAKEUP_SHIFT+msgtype;
				MxRadio.write(txqueue.RfData[packdataindex_tx].rbuf,txqueue.RfData[packdataindex_tx].length);
				MxRadio.endTransmission();
			} while(millis() - _startMillis < WAKEUP_PREAMBLE_MS+WAKEUP_PREAMBLE_RELAY_MS);

			MxRadio.beginTransmission();
			txqueue.RfData[packdataindex_tx].rbuf[0]=msgtype;
			MxRadio.write(txqueue.RfData[packdataindex_tx].rbuf,txqueue.RfData[packdataindex_tx].length);
			needchecksenddone=true;
			MxRadio.endTransmission();
		}

	}
	if (txqueue.RfData[packdataindex_tx].rbuf[0]==MSGTYPE_CMD_ACK && txqueue.RfData[packdataindex_tx].rbuf[INDEX_PATHCOUNT-INDEX_MSGTYPE+1+txqueue.RfData[packdataindex_tx].rbuf[INDEX_PATHCOUNT-INDEX_MSGTYPE]]==MSGTYPE_CMD_REBOOT)
	{
		watchdog_reboot();
	}
	//*sinkSerial.write(0);
	//*sinkSerial.write(txqueue.RfData[packdataindex_tx].value.destaddress);
	//*sinkSerial.write(0);
	//*sinkSerial.write(txqueue.RfData[packdataindex_tx].rbuf,txqueue.RfData[packdataindex_tx].length);
}
示例#21
0
PROCESS_THREAD(cetic_6lbr_process, ev, data)
{
  PROCESS_BEGIN();

  cetic_6lbr_restart_event = process_alloc_event();
  cetic_6lbr_startup = clock_seconds();

#if CONTIKI_TARGET_NATIVE
  slip_config_handle_arguments(contiki_argc, contiki_argv);
  if (watchdog_interval) {
    process_start(&native_6lbr_watchdog, NULL);
  } else {
    LOG6LBR_WARN("6LBR Watchdog disabled\n");
  }
#endif

  LOG6LBR_INFO("Starting 6LBR version " CETIC_6LBR_VERSION " (" CONTIKI_VERSION_STRING ")\n");

  load_nvm_config();

  platform_init();

  process_start(&eth_drv_process, NULL);

  while(!ethernet_ready) {
    PROCESS_PAUSE();
  }

  //clean up any early packet
  uip_len = 0;
  process_start(&tcpip_process, NULL);

  PROCESS_PAUSE();

#if CETIC_NODE_INFO
  node_info_init();
#endif

  packet_filter_init();
  cetic_6lbr_init();

#if WEBSERVER
  process_start(&webserver_nogui_process, NULL);
#endif
#if UDPSERVER
  process_start(&udp_server_process, NULL);
#endif
#if UDPCLIENT
  process_start(&udp_client_process, NULL);
#endif
#if WITH_COAP
  process_start(&coap_server_process, NULL);
#endif

#if WITH_NVM_PROXY
  nvm_proxy_init();
#endif

#if CONTIKI_TARGET_NATIVE
  plugins_load();
#endif

  LOG6LBR_INFO("CETIC 6LBR Started\n");

  PROCESS_WAIT_EVENT_UNTIL(ev == cetic_6lbr_restart_event);
  etimer_set(&reboot_timer, CLOCK_SECOND);
  PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);
#if CONTIKI_TARGET_NATIVE
  switch (cetic_6lbr_restart_type) {
    case CETIC_6LBR_RESTART:
      LOG6LBR_INFO("Exiting...\n");
      exit(0);
      break;
    case CETIC_6LBR_REBOOT:
      LOG6LBR_INFO("Rebooting...\n");
      system("reboot");
      break;
    case CETIC_6LBR_HALT:
      LOG6LBR_INFO("Halting...\n");
      system("halt");
      break;
    default:
      //We should never end up here...
      exit(1);
  }
  //We should never end up here...
  exit(1);
#else
  LOG6LBR_INFO("Rebooting...\n");
  watchdog_reboot();
#endif

  PROCESS_END();
}
示例#22
0
/*----------------------------------------------------------------------------*/
  void
  handle_config(packet_t* p)
  {
    if (is_my_address(&(p->header.dst)))
    {    
#if SINK
      if (!is_my_address(&(p->header.src))){
        print_packet_uart(p);
      } else {
#endif
      uint8_t i = 0;
      uint8_t id = p->payload[i] & 127;
      if ((p->payload[i] & 128) == CNF_READ)
      {
        //READ
        switch (id)
        {
          // TODO
          case RESET:
          case GET_ALIAS:
          case GET_RULE:
          case GET_FUNCTION:
          break;


          case MY_NET:
          case MY_ADDRESS:
          case PACKET_TTL:
          case RSSI_MIN:
          case BEACON_PERIOD:
          case REPORT_PERIOD:
          case RULE_TTL:
          // TODO check payload size
          if (conf_size[id] == 1){
            memcpy(&(p->payload[i+1]), conf_ptr[id], conf_size[id]);
          } else if (conf_size[id] == 2) {
            uint16_t value = *((uint16_t*)conf_ptr[id]);
            p->payload[i+1] = value >> 8;
            p->payload[i+2] = value & 0xFF; 
          }
          break;

          default:
          break;
        }
        swap_addresses(&(p->header.src),&(p->header.dst));
        p->header.len += conf_size[id];
        match_packet(p);
      } else {
        //WRITE
        switch (id)
        {
          // TODO
          case ADD_ALIAS:
          case REM_ALIAS:
          case ADD_RULE:
          case REM_RULE:
          case ADD_FUNCTION:
          case REM_FUNCTION:
          break;

          case RESET:
          watchdog_reboot();
          break;

          case MY_NET:
          case MY_ADDRESS:
          case PACKET_TTL:
          case RSSI_MIN:
          case BEACON_PERIOD:
          case REPORT_PERIOD:
          case RULE_TTL:
          if (conf_size[id] == 1){
            memcpy((uint8_t*)conf_ptr[id], &(p->payload[i+1]), conf_size[id]);
          } else if (conf_size[id] == 2) {
            uint16_t h = p->payload[i+1] << 8;
            uint16_t l = p->payload[i+2];            
            *((uint16_t*)conf_ptr[id]) = h + l;
          }
          break;

          default:
          break;
        }
        packet_deallocate(p);
      }
#if SINK
    }