static int init(const bt_hc_callbacks_t* p_cb, unsigned char *local_bdaddr)
{
    int result;

    ALOGI("init");

    if (p_cb == NULL)
    {
        ALOGE("init failed with no user callbacks!");
        return BT_HC_STATUS_FAIL;
    }

    hc_cb.epilog_timer_created = false;
    fwcfg_acked = false;
    has_cleaned_up = false;

    pthread_mutex_init(&hc_cb.worker_thread_lock, NULL);

    /* store reference to user callbacks */
    bt_hc_cbacks = (bt_hc_callbacks_t *) p_cb;

    vendor_open(local_bdaddr);

    utils_init();
#ifdef HCI_USE_MCT
    extern tHCI_IF hci_mct_func_table;
    p_hci_if = &hci_mct_func_table;
#else
    extern tHCI_IF hci_h4_func_table;
    p_hci_if = &hci_h4_func_table;
#endif

    p_hci_if->init();

    userial_init();
    lpm_init();

    utils_queue_init(&tx_q);

    if (hc_cb.worker_thread)
    {
        ALOGW("init has been called repeatedly without calling cleanup ?");
    }

    // Set prio here and let hci worker thread inherit prio
    // remove once new thread api (thread_set_priority() ?)
    // can switch prio
    raise_priority_a2dp(TASK_HIGH_HCI_WORKER);

    hc_cb.worker_thread = thread_new("bt_hc_worker");
    if (!hc_cb.worker_thread) {
        ALOGE("%s unable to create worker thread.", __func__);
        return BT_HC_STATUS_FAIL;
    }

    return BT_HC_STATUS_SUCCESS;
}
Beispiel #2
0
RRDVisAnalyzer::RRDVisAnalyzer(const ConfigObject& configObject, ReporterBase& reporter)
	: AnalyzerBase(configObject, reporter), configSection("rrdvisualizer"), firstFlow(true), lastFlowStart(0)
{
	configFile = configObject.getConfString(configSection, "configfile");
	rrdPath    = configObject.getConfString(configSection, "rrdtool_path");
	rrdDbPath  = configObject.getConfString(configSection, "db_path");

	// parse subnet config file
	std::ifstream subnetConfig(configFile.c_str());
	std::string token;
	bool subnet = true;
	std::string subnet_string;

	tree = lpm_init();

	std::vector<std::string> subnetList;

	while (subnetConfig) {
		subnetConfig >> token;
		if (subnet) {
			subnet_string = token;
			subnet = false;
		} else {
			size_t pos = subnet_string.find("/");
			if (pos == std::string::npos) {
				throw std::runtime_error("Error: Cannot parse subnet \"" + subnet_string + "\"");
			}
			std::string ip   = subnet_string.substr(0, pos);
			std::string mask = subnet_string.substr(pos + 1, subnet_string.size());

			rrdDBMap[subnet_string] = token;

			lpm_insert(tree, ip.c_str(), atoi(mask.c_str()));
			
			subnet = true;
		}
	}

	// define the number of values that need to be aggregated
	// by the rrdtools
	intervals.push_back(1);
	intervals.push_back(5);
	intervals.push_back(30);
	intervals.push_back(120);
	intervals.push_back(24*60);

	// graph time spans
	graphTimeSpans.push_back("-1d");
	graphTimeSpans.push_back("-1w");
	graphTimeSpans.push_back("-1m");
	graphTimeSpans.push_back("-1y");
}
Beispiel #3
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();
  }
}
Beispiel #4
0
int main(int argc, char* argv[])
{
	char* input;
	int opt;
	struct lpm_tree* tree;
	FILE* in;
	char* ifile = "/dev/stdin";

	/* Check inputs; print usage and exit if something is clearly
	   wrong. */
	if (argc < 3) {
		print_usage(argv[0]);
		exit(EXIT_FAILURE);
	}

	/* Parse options */
	while ((opt = getopt(argc, argv, "df:")) != -1) {
		switch (opt) {
		case 'd':
			debug = 1;
			break;
		case 'f':
			input = optarg;
			break;
		default: /* '?' */
			print_usage(argv[0]);
			exit(EXIT_FAILURE);
		}
	}

	/* Create a fresh tree. */
	tree = lpm_init();

	/* Read in all prefixes. */
	in = fopen(input, "r");
	while (1) {
		char *line = NULL;
		size_t linecap = 0;
		ssize_t linelen;
		char ip_string[INET6_ADDRSTRLEN];
		int mask;
		uint8_t rt;

		linelen = getline(&line, &linecap, in);
		if (linelen < 0) {
			break;
		}
		rt = sscanf(line, "%39s %d%*[^\n]", ip_string, &mask);
		if (rt < 2) {
			continue;
		}

		lpm_insert(tree, ip_string, mask);
	}
	fclose(in);

	lpm_debug_print(tree);

	/* Begin reading from standard input the lines of text to
	   convert. */
	in = fopen(ifile, "r");
	while (1) {
		char *line = NULL;
		size_t linecap = 0;
		ssize_t linelen;
		char address_string[16];
		char output[16];
		char* pointer;
		char* strstart;
		char* strend;
		int rt;

		/* Read line. */
		linelen = getline(&line, &linecap, in);
		if (linelen < 0) {
			break;
		}

		line[strlen(line)-1] = '\0';

		pointer = line;
		strstart = pointer;
		strend = strstr(strstart, " ");

		while (strend != NULL) {
			memset(address_string, '\0', 16);
			memcpy(address_string, strstart, strend - strstart);

			memset(output,         '\0', 16);
			rt = lpm_lookup(tree, address_string, output);

			if (rt) {
				printf("%s ", output);
			}
			else {
				printf("%s ", address_string);
			}

			strstart = strend + 1;
			strend = strstr(strstart, " ");
		}

		memset(output, '\0', 16);
		rt = lpm_lookup(tree, strstart, output);
		if (rt) {
			printf("%s\n", output);
		}
		else {
			printf("%s\n", strstart);
		}

		free(line);
	}

	lpm_destroy(tree);

	fclose(in);
	return 1;
}
Beispiel #5
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();
	}
}
Beispiel #6
0
static int init(const bt_hc_callbacks_t* p_cb, unsigned char *local_bdaddr)
{
    pthread_attr_t thread_attr;
    struct sched_param param;
    int policy, result;

    ALOGI("init");

    if (p_cb == NULL)
    {
        ALOGE("init failed with no user callbacks!");
        return BT_HC_STATUS_FAIL;
    }

    hc_cb.epilog_timer_created = 0;
    fwcfg_acked = FALSE;

    /* store reference to user callbacks */
    bt_hc_cbacks = (bt_hc_callbacks_t *) p_cb;

    init_vnd_if(local_bdaddr);

    utils_init();

   if(is_bt_transport_smd())
   {
       extern tHCI_IF hci_mct_func_table;
       extern tUSERIAL_IF userial_mct_func_table;
       p_hci_if = &hci_mct_func_table;
       p_userial_if = &userial_mct_func_table;
   }
   else
   {
       extern tHCI_IF hci_h4_func_table;
       extern tUSERIAL_IF userial_h4_func_table;
       p_hci_if = &hci_h4_func_table;
       p_userial_if = &userial_h4_func_table;
   }

    p_hci_if->init();

    p_userial_if->init();
    lpm_init();

    utils_queue_init(&tx_q);

    if (lib_running)
    {
        ALOGW("init has been called repeatedly without calling cleanup ?");
    }

    lib_running = 1;
    ready_events = 0;
    pthread_mutex_init(&hc_cb.mutex, NULL);
    pthread_cond_init(&hc_cb.cond, NULL);
    pthread_attr_init(&thread_attr);

    if (pthread_create(&hc_cb.worker_thread, &thread_attr, \
                       bt_hc_worker_thread, NULL) != 0)
    {
        ALOGE("pthread_create failed!");
        lib_running = 0;
        return BT_HC_STATUS_FAIL;
    }

    if(pthread_getschedparam(hc_cb.worker_thread, &policy, &param)==0)
    {
        policy = BTHC_LINUX_BASE_POLICY;
#if (BTHC_LINUX_BASE_POLICY!=SCHED_NORMAL)
        param.sched_priority = BTHC_MAIN_THREAD_PRIORITY;
#endif
        result = pthread_setschedparam(hc_cb.worker_thread, policy, &param);
        if (result != 0)
        {
            ALOGW("libbt-hci init: pthread_setschedparam failed (%s)", \
                  strerror(result));
        }
    }

    return BT_HC_STATUS_SUCCESS;
}
Beispiel #7
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();
  }
}
Beispiel #8
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();
  }
}
static struct lpm_tree* read_prefix_file(const char* prefix_file)
{
	struct lpm_tree* tree = lpm_init(); 
	if (tree == NULL){
		fprintf(stderr, "ERROR: Could not allocate lpm_tree()\n");
		return NULL;
	}
	FILE* f = fopen(prefix_file, "r");
	if (f == NULL) {
		fprintf(stderr, "ERROR: coult not open prefix file %s\n",
			prefix_file);
		goto out1;
	}

	char line[LINE_SIZE];
	char tmp_line[LINE_SIZE];
	char delimiter[] = " ";
	while (fgets(line, LINE_SIZE, f)) {
		// tokenize the subnet list. The expected format is
		// <NET_ID> <subnet1> <subnet2> ...

		// remove trailing \n
		if (line[strlen(line) - 1] == '\n') {
			line[strlen(line) - 1] = 0;
		}

		// duplicate string for parsing. we need the original
		// line for error messages
		strcpy(tmp_line, line);

		char* ptr = strtok(tmp_line, delimiter);
		uint32_t id;
		int is_first = 1;
		while (ptr) {
			if (is_first) {
				id = atoi(ptr);
				is_first = 0;
			} else {
				// extract the ip and the subnet string
				// expected format: ip/subnetmask
				char* slash_pos = strchr(ptr, '/');
				char* netmask;
				if (slash_pos == NULL) {
					fprintf(stderr, "ERROR parsing line "
					"\"%s\". Could not find / in token "
					"%s\n", line, ptr);
					// there is an error in the file format
					// we do the only thing we can and drop
					// out
					goto out2;
				}
				if (strlen(slash_pos) == 1) {
					// there is no subnetmask behind the
					// slash. drop out
					fprintf(stderr, "ERROR parsing line "
					"\"%s\". Found / in token %s but no "
					"following subnet mask!\n", line, ptr);
					goto out2;
				}
				*slash_pos = 0;
				netmask = slash_pos + 1;
				if (0 == lpm_insert(tree, ptr, atoi(netmask),
							id))
				{
					fprintf(stderr, "ERROR inserting %s "
					"into the subnet tree!\n", ptr);
					goto out2;
				}
			}
			ptr = strtok(NULL, delimiter);
		}
	}

	// We are done without errors. 
	goto out1;
out2:
	lpm_destroy(tree);
	tree = NULL;
out1:
	fclose(f);
out:
	return tree;
}
/**
 * \brief Main routine for the cc2538dk platform
 */
int
main(void)
{
  nvic_init();
  sys_ctrl_init();
  clock_init();
  dint();
  /*Init Watchdog*/
  watchdog_init();//Need to check the watchdog on 123gxl

  rtimer_init();
  lpm_init();  
  gpio_init();
  ioc_init();

  leds_init();
  fade(LEDS_YELLOW);
  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();

  /*Enable EA*/
  eint();
  INTERRUPTS_ENABLE();
  fade(LEDS_GREEN);
  PRINTF("=================================\r\n");
  PUTS(CONTIKI_VERSION_STRING);
  PRINTF("======================\r\n");  
  PRINTF("\r\n");
  PUTS(BOARD_STRING);
  PRINTF("\r\n");

#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(&sensors_process, NULL);
  button_sensor_init();

  process_start(&etimer_process, NULL);

  ctimer_init();

  set_rime_addr();
  printf("finish addr seting\r\n");

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

  udma_init();

  if(node_id > 0) {
    printf("Node id %u.\r\n", node_id);
  } else {
    printf("Node id not set.\r\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("CC2538 IEEE802154 PANID %d\r\n", IEEE802154_PANID);  
  cc2538_rf_set_addr(IEEE802154_PANID);

  printf("%s/%s %lu %u\r\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\r\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\r\n",
           ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
  }

#else /* WITH_UIP6 */

  netstack_init();
  PRINTF("CC2538 IEEE802154 PANID %d\r\n", IEEE802154_PANID);  
  cc2538_rf_set_addr(IEEE802154_PANID);
  
  printf("%s %lu %u\r\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\r\n");
#else /* NETSTACK_AES_H */
  printf("Warning: AES encryption is disabled\r\n");
#endif /* NETSTACK_AES_H */

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

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  simple_rpl_init();
  /*Watch dog configuration*/
  watchdog_periodic();
  watchdog_start();

  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...\r\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 */

  fade(LEDS_ORANGE);

  /*
   * This is the scheduler loop.
   */
  while(1) {
    uint8_t r;
    do {
      /* Reset watchdog and handle polls and events */
      // printf("reset watchdog\r\n");
      watchdog_periodic();

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

    /* We have serviced all pending events. Enter a Low-Power mode. */
    lpm_enter();
  }
}
Beispiel #11
-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();
  }
}