Exemplo n.º 1
0
Arquivo: nhdp.c Projeto: cococolo/RIOT
/**
 * 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 MSG_TIMER:
                mutex_lock(&send_rcv_mutex);
                if_entry = (nhdp_if_entry_t *) msg_rcvd.content.ptr;

                nhdp_writer_send_hello(if_entry);

                /* TODO: Add jitter */

                /* Schedule next sending */
                vtimer_set_msg(&if_entry->if_timer, if_entry->hello_interval,
                               thread_getpid(), MSG_TIMER, (void *) if_entry);
                mutex_unlock(&send_rcv_mutex);
                break;

            default:
                break;
        }
    }

    return 0;
}
Exemplo n.º 2
0
/**
 * 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;
}