示例#1
0
文件: ipv6.c 项目: kiibohd/controller
uint32_t ipv6_init(const ipv6_init_t * p_init)
{
    uint32_t           index;
    uint32_t           err_code;
    ble_6lowpan_init_t init_params;

    NULL_PARAM_CHECK(p_init);
    NULL_PARAM_CHECK(p_init->p_eui64);
    NULL_PARAM_CHECK(p_init->event_handler);

    SDK_MUTEX_INIT(m_ipv6_mutex);
    IPV6_MUTEX_LOCK();

    IPV6_ENTRY();

    // Initialize related modules.
    UNUSED_VARIABLE(nrf_mem_init());
    UNUSED_VARIABLE(iot_pbuffer_init());

    // Initialize submodules of IPv6 stack.
    UNUSED_VARIABLE(udp_init());
    UNUSED_VARIABLE(icmp6_init());

    // Initialize context manager.
    UNUSED_VARIABLE(iot_context_manager_init());

    IPV6_ADDRESS_INITIALIZE(IPV6_ADDR_ANY);

    // Set application event handler.
    m_event_handler = p_init->event_handler;

    // Clear number of interfaces.
    m_interfaces_count = 0;

    // Clear network interfaces.
    for (index = 0; index < IPV6_MAX_INTERFACE; index++)
    {
        interface_reset(&m_interfaces[index]);
    }

    // Clear all addresses.
    for (index = 0; index < IPV6_MAX_ADDRESS_COUNT; index++)
    {
        addr_free(index, false);
    }

    // 6LoWPAN module initialization.
    init_params.p_eui64       = p_init->p_eui64;
    init_params.event_handler = ble_6lowpan_evt_handler;

    err_code = ble_6lowpan_init(&init_params);

    IPV6_EXIT();

    IPV6_MUTEX_UNLOCK();

    return err_code;
}
示例#2
0
void main_entry(void)
{
	uint32_t res;
	uint8_t enabled;
	volatile int t;
	ble_6lowpan_init_t ble;

	/* enabled LED output */
	nrf_gpio_cfg_output(CONFIG_LED_PIN);
	nrf_gpio_pin_set(CONFIG_LED_PIN);

	/* enabled input pin */
	nrf_gpio_cfg_input(CONFIG_SWITCH_PIN, NRF_GPIO_PIN_NOPULL);

	/* initialize UART */
	uart_init();

	if((res = sd_softdevice_enable(
		NRF_CLOCK_LFCLKSRC_XTAL_20_PPM,
		assert_handler))!=NRF_SUCCESS)
	{
		debug_printf("sd_softdevice_enable failed (0x%02X)\n", res);
		while(1);
	}

	debug_printf("Hello\n");
	ble.p_eui64 = (eui64_t*)&g_eui;
	ble.event_handler = event_handler;
	if((res = ble_6lowpan_init(&ble))!=NRF_SUCCESS)
	{
		debug_printf("ble_6lowpan_init failed (0x%02X)\n", res);
		while(1);
	}

	while(1)
	{
		res = sd_softdevice_is_enabled(&enabled);

		debug_printf("Hello World (0x%08X, %i)\n", res, enabled);
		for(t=0; t<100000; t++);

		if(nrf_gpio_pin_read(CONFIG_SWITCH_PIN))
			nrf_gpio_pin_set(CONFIG_LED_PIN);
		else
			nrf_gpio_pin_clear(CONFIG_LED_PIN);
	}
}