diff --git a/sys/net/ccn_lite/ccn-lite-relay.c b/sys/net/ccn_lite/ccn-lite-relay.c index 3cd15ac1ce..a8c4a89c7b 100644 --- a/sys/net/ccn_lite/ccn-lite-relay.c +++ b/sys/net/ccn_lite/ccn-lite-relay.c @@ -301,15 +301,6 @@ void handle_populate_cache(void) // ---------------------------------------------------------------------- -void ccnl_timeout_callback(void *ptr) -{ - struct ccnl_relay_s *ccnl = ptr; - - msg_t ccnl_timeout_msg; - ccnl_timeout_msg.type = CCNL_RIOT_TIMEOUT; - msg_send(&ccnl_timeout_msg, ccnl->riot_pid, false); -} - int ccnl_io_loop(struct ccnl_relay_s *ccnl) { if (ccnl->ifcount == 0) { @@ -327,25 +318,15 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl) msg_t in; radio_packet_t *p; riot_ccnl_msg_t *m; - struct timeval *timeout; - unsigned long us = CCNL_CHECK_RETRANSMIT_USEC; - int hwtimer_id; while (!ccnl->halt_flag) { - hwtimer_id = hwtimer_set(HWTIMER_TICKS(us), ccnl_timeout_callback, ccnl); - if (hwtimer_id == -1) { - puts("NO MORE TIMERS!"); - } - else { - //DEBUGMSG(1, "hwtimer_id is %d\n", hwtimer_id); - } - msg_receive(&in); - //DEBUGMSG(1, "%s Packet waiting, us was %lu\n", riot_ccnl_event_to_string(in.type), us); + msg_receive(&in); + + mutex_lock(&theRelay.global_lock); switch (in.type) { case PKT_PENDING: /* msg from transceiver */ - hwtimer_remove(hwtimer_id); p = (radio_packet_t *) in.content.ptr; DEBUGMSG(1, "\tLength:\t%u\n", p->length); DEBUGMSG(1, "\tSrc:\t%u\n", p->src); @@ -362,7 +343,6 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl) case (CCNL_RIOT_MSG): /* msg from device local client */ - hwtimer_remove(hwtimer_id); m = (riot_ccnl_msg_t *) in.content.ptr; DEBUGMSG(1, "\tLength:\t%u\n", m->size); DEBUGMSG(1, "\tSrc:\t%u\n", in.sender_pid); @@ -373,7 +353,6 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl) case (CCNL_RIOT_HALT): /* cmd to stop the relay */ - hwtimer_remove(hwtimer_id); DEBUGMSG(1, "\tSrc:\t%u\n", in.sender_pid); DEBUGMSG(1, "\tNumb:\t%" PRIu32 "\n", in.content.value); @@ -383,7 +362,6 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl) #if RIOT_CCNL_POPULATE case (CCNL_RIOT_POPULATE): /* cmd to polulate the cache */ - hwtimer_remove(hwtimer_id); DEBUGMSG(1, "\tSrc:\t%u\n", in.sender_pid); DEBUGMSG(1, "\tNumb:\t%" PRIu32 "\n", in.content.value); @@ -392,28 +370,21 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl) #endif case (CCNL_RIOT_PRINT_STAT): /* cmd to print face statistics */ - hwtimer_remove(hwtimer_id); for (struct ccnl_face_s *f = ccnl->faces; f; f = f->next) { ccnl_face_print_stat(f); } break; - case (CCNL_RIOT_TIMEOUT): - /* ccn timeout from hwtimer, run pending events */ - timeout = ccnl_run_events(); - us = timeout->tv_sec * 1000 * 1000 + timeout->tv_usec; - break; case (ENOBUFFER): /* transceiver has not enough buffer to store incoming packets, one packet is dropped */ - hwtimer_remove(hwtimer_id); DEBUGMSG(1, "transceiver: one packet is dropped because buffers are full\n"); break; default: - hwtimer_remove(hwtimer_id); DEBUGMSG(1, "%s Packet waiting\n", riot_ccnl_event_to_string(in.type)); DEBUGMSG(1, "\tSrc:\t%u\n", in.sender_pid); DEBUGMSG(1, "\tdropping it...\n"); break; } + mutex_unlock(&theRelay.global_lock); } return 0; @@ -428,6 +399,7 @@ void ccnl_riot_relay_start(int max_cache_entries, int fib_threshold_prefix, int { ccnl_get_timeval(&theRelay.startup_time); theRelay.riot_pid = sched_active_pid; + mutex_init(&theRelay.global_lock); DEBUGMSG(1, "This is ccn-lite-relay, starting at %lu:%lu\n", theRelay.startup_time.tv_sec, theRelay.startup_time.tv_usec); DEBUGMSG(1, " compile time: %s %s\n", __DATE__, __TIME__); @@ -437,6 +409,8 @@ void ccnl_riot_relay_start(int max_cache_entries, int fib_threshold_prefix, int ccnl_relay_config(&theRelay, max_cache_entries, fib_threshold_prefix, fib_threshold_aggregate); + theRelay.riot_helper_pid = riot_start_helper_thread(); + ccnl_io_loop(&theRelay); DEBUGMSG(1, "ioloop stopped\n"); @@ -447,4 +421,16 @@ void ccnl_riot_relay_start(int max_cache_entries, int fib_threshold_prefix, int ccnl_core_cleanup(&theRelay); } +void ccnl_riot_relay_helper_start(void) +{ + unsigned long us = CCNL_CHECK_RETRANSMIT_USEC; + while (!theRelay.halt_flag) { + hwtimer_wait(HWTIMER_TICKS(us)); + + mutex_lock(&theRelay.global_lock); + ccnl_run_events(); + mutex_unlock(&theRelay.global_lock); + } +} + // eof diff --git a/sys/net/ccn_lite/ccnl-core.h b/sys/net/ccn_lite/ccnl-core.h index 4abea9d23a..926d2b3890 100644 --- a/sys/net/ccn_lite/ccnl-core.h +++ b/sys/net/ccn_lite/ccnl-core.h @@ -50,6 +50,8 @@ #include #include +#include "mutex.h" + #include "ccnl.h" // ---------------------------------------------------------------------- @@ -103,6 +105,8 @@ struct ccnl_relay_s { int fib_threshold_prefix; /* how may name components should be considdered as dynamic */ int fib_threshold_aggregate; int riot_pid; + int riot_helper_pid; + mutex_t global_lock; }; struct ccnl_buf_s { diff --git a/sys/net/ccn_lite/ccnl-riot-compat.c b/sys/net/ccn_lite/ccnl-riot-compat.c index 1198cbda1a..ffab2090fd 100644 --- a/sys/net/ccn_lite/ccnl-riot-compat.c +++ b/sys/net/ccn_lite/ccnl-riot-compat.c @@ -22,6 +22,7 @@ #include #include "msg.h" +#include "thread.h" #include "ccnl.h" #include "ccnl-core.h" @@ -32,6 +33,8 @@ radio_packet_t p; transceiver_command_t tcmd; msg_t mesg, rep; +char relay_helper_stack[KERNEL_CONF_STACKSIZE_PRINTF]; + int riot_send_transceiver(uint8_t *buf, uint16_t size, uint16_t to) { DEBUGMSG(1, "this is a RIOT TRANSCEIVER based connection\n"); @@ -90,6 +93,13 @@ void riot_send_nack(uint16_t to) msg_send(&m, to, 0); } +void ccnl_riot_relay_helper_start(void); + +int riot_start_helper_thread(void) +{ + return thread_create(relay_helper_stack, KERNEL_CONF_STACKSIZE_PRINTF, PRIORITY_MAIN - 2, CREATE_STACKTEST, ccnl_riot_relay_helper_start, "relay-helper"); +} + char *riot_ccnl_event_to_string(int event) { switch (event) { @@ -105,9 +115,6 @@ char *riot_ccnl_event_to_string(int event) case CCNL_RIOT_POPULATE: return "RIOT_POPULATE"; - case CCNL_RIOT_TIMEOUT: - return "CCNL_RIOT_TIMEOUT"; - case CCNL_RIOT_PRINT_STAT: return "CCNL_RIOT_PRINT_STAT"; diff --git a/sys/net/ccn_lite/ccnl-riot-compat.h b/sys/net/ccn_lite/ccnl-riot-compat.h index 97d95f632b..223b17cd1c 100644 --- a/sys/net/ccn_lite/ccnl-riot-compat.h +++ b/sys/net/ccn_lite/ccnl-riot-compat.h @@ -30,4 +30,5 @@ typedef struct riot_ccnl_msg { int riot_send_transceiver(uint8_t *buf, uint16_t size, uint16_t to); int riot_send_msg(uint8_t *buf, uint16_t size, uint16_t to); void riot_send_nack(uint16_t to); +int riot_start_helper_thread(void); char *riot_ccnl_event_to_string(int event); diff --git a/sys/net/include/ccn_lite/ccnl-riot.h b/sys/net/include/ccn_lite/ccnl-riot.h index 8330d3885e..a20fff8aa2 100644 --- a/sys/net/include/ccn_lite/ccnl-riot.h +++ b/sys/net/include/ccn_lite/ccnl-riot.h @@ -45,9 +45,8 @@ #define CCNL_RIOT_HALT (CCNL_RIOT_EVENT_NUMBER_OFFSET + 1) #define CCNL_RIOT_POPULATE (CCNL_RIOT_EVENT_NUMBER_OFFSET + 2) #define CCNL_RIOT_PRINT_STAT (CCNL_RIOT_EVENT_NUMBER_OFFSET + 3) -#define CCNL_RIOT_TIMEOUT (CCNL_RIOT_EVENT_NUMBER_OFFSET + 4) -#define CCNL_RIOT_NACK (CCNL_RIOT_EVENT_NUMBER_OFFSET + 5) -#define CCNL_RIOT_RESERVED (CCNL_RIOT_EVENT_NUMBER_OFFSET + 6) +#define CCNL_RIOT_NACK (CCNL_RIOT_EVENT_NUMBER_OFFSET + 4) +#define CCNL_RIOT_RESERVED (CCNL_RIOT_EVENT_NUMBER_OFFSET + 5) #define CCNL_HEADER_SIZE (40)