コード例 #1
0
ファイル: thread_tasklet.c プロジェクト: sg-/mbed-os
/*
 * \brief A function which will be eventually called by NanoStack OS when ever the OS has an event to deliver.
 * @param event, describes the sender, receiver and event type.
 *
 * NOTE: Interrupts requested by HW are possible during this function!
 */
void thread_tasklet_main(arm_event_s *event)
{
    arm_library_event_type_e event_type;
    event_type = (arm_library_event_type_e) event->event_type;

    switch (event_type) {
        case ARM_LIB_NWK_INTERFACE_EVENT:
            /* This event is delivered every and each time when there is new
             * information of network connectivity.
             */
            thread_tasklet_parse_network_event(event);
            break;

        case ARM_LIB_TASKLET_INIT_EVENT:
            /* Event with type EV_INIT is an initializer event of NanoStack OS.
             * The event is delivered when the NanoStack OS is running fine.
             * This event should be delivered ONLY ONCE.
             */
            mesh_system_send_connect_event(thread_tasklet_data_ptr->tasklet);
            break;

        case ARM_LIB_SYSTEM_TIMER_EVENT:
            eventOS_event_timer_cancel(event->event_id,
                                       thread_tasklet_data_ptr->tasklet);

            if (event->event_id == TIMER_EVENT_START_BOOTSTRAP) {
                int8_t status;
                tr_debug("Restart bootstrap");
                status = arm_nwk_interface_up(thread_tasklet_data_ptr->nwk_if_id);

                if (status >= 0) {
                    thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_STARTED;
                    tr_info("Start Thread bootstrap (%s mode)", thread_tasklet_data_ptr->operating_mode == NET_6LOWPAN_SLEEPY_HOST ? "SED" : "Router");
                    thread_tasklet_network_state_changed(MESH_BOOTSTRAP_STARTED);
                } else {
                    thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_FAILED;
                    tr_err("Bootstrap start failed, %d", status);
                    thread_tasklet_network_state_changed(MESH_BOOTSTRAP_START_FAILED);
                }
            }
            break;

        case APPLICATION_EVENT:
            if (event->event_id == APPL_EVENT_CONNECT) {
                thread_tasklet_configure_and_connect_to_network();
            }
            break;

        default:
            break;
    } // switch(event_type)
}
コード例 #2
0
/*
 * \brief A function which will be eventually called by NanoStack OS when ever the OS has an event to deliver.
 * @param event, describes the sender, receiver and event type.
 *
 * NOTE: Interrupts requested by HW are possible during this function!
 */
void nd_tasklet_main(arm_event_s *event)
{
    arm_library_event_type_e event_type;
    event_type = (arm_library_event_type_e) event->event_type;

    switch (event_type) {
        case ARM_LIB_NWK_INTERFACE_EVENT:
            /* This event is delivered every and each time when there is new
             * information of network connectivity.
             */
            nd_tasklet_parse_network_event(event);
            break;

        case ARM_LIB_TASKLET_INIT_EVENT:
            /* Event with type EV_INIT is an initializer event of NanoStack OS.
             * The event is delivered when the NanoStack OS is running fine.
             * This event should be delivered ONLY ONCE.
             */
            tasklet_data_ptr->node_main_tasklet_id = event->receiver;
            mesh_system_send_connect_event(tasklet_data_ptr->tasklet);
            break;

        case ARM_LIB_SYSTEM_TIMER_EVENT:
            eventOS_event_timer_cancel(event->event_id,
                                       tasklet_data_ptr->node_main_tasklet_id);

            if (event->event_id == TIMER_EVENT_START_BOOTSTRAP) {
                tr_debug("Restart bootstrap");
                nd_tasklet_configure_and_connect_to_network();
            }
            break;

        case APPLICATION_EVENT:
            if (event->event_id == APPL_EVENT_CONNECT) {
                nd_tasklet_configure_and_connect_to_network();
            }
            break;

        default:
            break;
    } // switch(event_type)
}
コード例 #3
0
/*
 * \brief A function which will be eventually called by NanoStack OS when ever the OS has an event to deliver.
 * @param event, describes the sender, receiver and event type.
 *
 * NOTE: Interrupts requested by HW are possible during this function!
 */
void tasklet_main(arm_event_s *event)
{
	uint8_t  master_key[16];
	/**Border Router ND setup*/
    static link_configuration_s link_setup;
    device_configuration_s device_config;
    uint8_t networkid[16];
    uint32_t channel_mask;
    channel_mask = (uint32_t) 1 << RF_CHANNEL;
    char psdK[] = "Kukkuu!";
    device_config.PSKd_ptr = psdK;
	device_config.leaderCap = true;

	int8_t retval;
	if (event->sender == 0)
	{
		arm_library_event_type_e event_type;
		event_type = (arm_library_event_type_e) event->event_type;
		switch (event_type)
		{
			//This event is delivered every and each time when there is new information of network connectivity.
			case ARM_LIB_NWK_INTERFACE_EVENT:
				/* Network Event state event handler */
				app_parse_network_event(event);
				break;

			case ARM_LIB_TASKLET_INIT_EVENT:
				/*Event with type EV_INIT is an initialiser event of NanoStack OS.
				 * The event is delivered when the NanoStack OS is running fine. This event should be delivered ONLY ONCE.
				 */

				node_main_tasklet_id = event->receiver;

				/* Bootsrapping Thread network */
				arm_nwk_interface_configure_6lowpan_bootstrap_set(net_rf_id, NET_6LOWPAN_ROUTER, NET_6LOWPAN_THREAD);

				arm_nwk_6lowpan_link_scan_paramameter_set(net_rf_id, channel_list, 5);

				rf_read_mac_address(link_setup.extended_random_mac);
				link_setup.extended_random_mac[0] |= 0x02;

				//Initialize Thread stack to leader mode
				link_setup.steering_data_len = 0;

                memcpy(networkid, "Arm Powered Core", 16);
                memcpy(link_setup.name, networkid, 16);

                link_setup.panId = THREAD_NTW_PAN_ID;
            	link_setup.rfChannel = RF_CHANNEL;

				link_setup.Protocol_id = THREAD_PROTOCOL_ID;
            	link_setup.version = THREAD_PROTOCOL_VERSION;
            	memcpy(link_setup.mesh_local_ula_prefix,br_thread_ml_prefix, 8);

                arm_nwk_6lowpan_gp_address_mode(net_rf_id, NET_6LOWPAN_GP16_ADDRESS, 0xffff, 1);

				memcpy(master_key, default_net_security_key, 16);
				memcpy(link_setup.master_key,default_net_security_key, 16 );
				link_setup.key_rotation = 3600;
				link_setup.key_sequence = 0;
				memcpy(link_setup.mesh_local_ula_prefix,br_thread_ml_prefix, 8);
				thread_managenet_node_init(net_rf_id, channel_mask, &device_config, &link_setup);

				retval = arm_nwk_interface_up(net_rf_id);
				if (retval != 0)
				{
					//debug_int(retval);
					tr_debug("Start Fail code: %d", retval);
				}
				else
				{
					tr_debug("6LoWPAN IP Bootstrap started");
					network_ready();
				}
				break;
				case ARM_LIB_SYSTEM_TIMER_EVENT:
					eventOS_event_timer_cancel(event->event_id, node_main_tasklet_id);

					if(event->event_id == 1)
					{
						if(arm_nwk_interface_up(net_rf_id) == 0)
						{
							tr_debug("Start Network bootstrap Again");
						}

					}
				break;
				default:
				break;
		}
	}
}