From 7c871871deedc555d41cbaff5adbbc39a18aee2f Mon Sep 17 00:00:00 2001 From: Jesus Sanchez-Palencia Date: Fri, 3 Jul 2015 19:21:21 -0300 Subject: [PATCH] galileo: Add support for Etimer and Ctimer libraries This patch adds support for the Etimer and Ctimer libraries. To support the Etimer library, we should poll the etimer process every time the system clock is updated. To do this more efficiently, by taking advantage of etimer_next_expiration_time() API, we poll the etimer process only when an 'Event Timer' has expired. We don't need any platform specific support in order to enable the Ctimer library since it relies completely on Etimer. The others timer libraries (Timer and Stime) don't required any specific platform support as well since they rely on the system Clock module only. --- platform/galileo/clock.c | 8 ++++++++ platform/galileo/contiki-main.c | 2 ++ 2 files changed, 10 insertions(+) diff --git a/platform/galileo/clock.c b/platform/galileo/clock.c index e000f1db5..d81ba835f 100644 --- a/platform/galileo/clock.c +++ b/platform/galileo/clock.c @@ -29,6 +29,7 @@ */ #include "sys/clock.h" +#include "sys/etimer.h" #include "contiki-conf.h" #include "drivers/rtc.h" @@ -69,7 +70,14 @@ static volatile clock_time_t tick_count = 0; static void update_ticks(void) { + clock_time_t expire = etimer_next_expiration_time(); + tick_count++; + + /* Notify etimer library if the next event timer has expired */ + if(expire != 0 && tick_count >= expire) { + etimer_request_poll(); + } } /*---------------------------------------------------------------------------*/ void diff --git a/platform/galileo/contiki-main.c b/platform/galileo/contiki-main.c index 69387ead5..53b7f9cb1 100644 --- a/platform/galileo/contiki-main.c +++ b/platform/galileo/contiki-main.c @@ -41,6 +41,8 @@ main(void) ENABLE_IRQ(); process_init(); + process_start(&etimer_process, NULL); + ctimer_init(); autostart_start(autostart_processes); while(1) {