/** * Function executed by NHDP thread receiving messages in an endless loop */ static void *_nhdp_runner(void *arg) { nhdp_if_entry_t *if_entry; msg_t msg_rcvd, msg_queue[NHDP_MSG_QUEUE_SIZE]; (void)arg; msg_init_queue(msg_queue, NHDP_MSG_QUEUE_SIZE); while (1) { msg_receive(&msg_rcvd); switch (msg_rcvd.type) { case HELLO_TIMER: mutex_lock(&send_rcv_mutex); if_entry = msg_rcvd.content.ptr; nhdp_writer_send_hello(if_entry); /* TODO: Add jitter */ /* Schedule next sending */ xtimer_set_msg64(&if_entry->if_timer, timex_uint64(if_entry->hello_interval), &msg_rcvd, thread_getpid()); mutex_unlock(&send_rcv_mutex); break; #if (NHDP_METRIC_NEEDS_TIMER) case NHDP_METRIC_TIMER: mutex_lock(&send_rcv_mutex); /* Process necessary metric computations */ iib_process_metric_refresh(); /* Schedule next sending */ metric_msg.type = NHDP_METRIC_TIMER; metric_msg.content.ptr = NULL; xtimer_set_msg64(&metric_timer, timex_uint64(metric_interval), metric_msg, thread_getpid()); mutex_unlock(&send_rcv_mutex); break; #endif default: break; } } return 0; }
void gnrc_rpl_long_delay_dao(gnrc_rpl_dodag_t *dodag) { dodag->dao_time = GNRC_RPL_REGULAR_DAO_INTERVAL * SEC_IN_USEC; dodag->dao_counter = 0; dodag->dao_ack_received = false; xtimer_set_msg64(&dodag->dao_timer, dodag->dao_time, &dodag->dao_msg, gnrc_rpl_pid); }
void gnrc_rpl_delay_dao(gnrc_rpl_dodag_t *dodag) { dodag->dao_time = GNRC_RPL_DEFAULT_DAO_DELAY * SEC_IN_USEC; dodag->dao_counter = 0; dodag->dao_ack_received = false; xtimer_set_msg64(&dodag->dao_timer, dodag->dao_time, &dodag->dao_msg, gnrc_rpl_pid); }
void _dao_handle_send(gnrc_rpl_dodag_t *dodag) { if ((dodag->dao_ack_received == false) && (dodag->dao_counter < GNRC_RPL_DAO_SEND_RETRIES)) { dodag->dao_counter++; gnrc_rpl_send_DAO(dodag, NULL, dodag->default_lifetime); dodag->dao_time = GNRC_RPL_DEFAULT_WAIT_FOR_DAO_ACK * SEC_IN_USEC; xtimer_set_msg64(&dodag->dao_timer, dodag->dao_time, &dodag->dao_msg, gnrc_rpl_pid); } else if (dodag->dao_ack_received == false) { gnrc_rpl_long_delay_dao(dodag); } }
kernel_pid_t nhdp_start(void) { if (nhdp_pid == KERNEL_PID_UNDEF) { /* Init destination address for NHDP's packets */ /* Start the NHDP thread */ nhdp_pid = thread_create(nhdp_stack, sizeof(nhdp_stack), THREAD_PRIORITY_MAIN - 1, THREAD_CREATE_STACKTEST, _nhdp_runner, NULL, "NHDP"); #if (NHDP_METRIC_NEEDS_TIMER) /* Configure periodic timer message to refresh metric values */ if (nhdp_pid != KERNEL_PID_UNDEF) { metric_interval = timex_from_uint64(DAT_REFRESH_INTERVAL * SEC_IN_USEC); metric_msg.type = NHDP_METRIC_TIMER; metric_msg.content.ptr = NULL; xtimer_set_msg64(&metric_timer, timex_uint64(metric_interval), metric_msg, nhdp_pid); } #endif } return nhdp_pid; }