From c66dd0b1bfb8dfa8642b67533a88e85984631554 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Tue, 23 Mar 2010 13:13:17 +0000 Subject: [PATCH] implemented rtimer library for simulated contiki motes --- platform/cooja/rtimer-arch.c | 61 +++++++++++++++++++++++++++++++----- platform/cooja/rtimer-arch.h | 8 +++-- 2 files changed, 59 insertions(+), 10 deletions(-) diff --git a/platform/cooja/rtimer-arch.c b/platform/cooja/rtimer-arch.c index 3c4eb002d..6d16e561e 100644 --- a/platform/cooja/rtimer-arch.c +++ b/platform/cooja/rtimer-arch.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Swedish Institute of Computer Science. + * Copyright (c) 2010, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: rtimer-arch.c,v 1.3 2009/03/26 16:22:36 fros4943 Exp $ + * $Id: rtimer-arch.c,v 1.4 2010/03/23 13:13:17 fros4943 Exp $ */ #include @@ -37,6 +37,9 @@ #include "sys/rtimer.h" #include "sys/clock.h" +#include "sys/cooja_mt.h" + +#include "lib/simEnvChange.h" #define DEBUG 0 #if DEBUG @@ -46,19 +49,63 @@ #define PRINTF(...) #endif -/*---------------------------------------------------------------------------*/ -static void -interrupt(int sig) -{ -} +extern clock_time_t simCurrentTime; + +static int pending_rtimer = 0; +static rtimer_clock_t next_rtimer = 0; +static clock_time_t last_rtimer_now = 0; + /*---------------------------------------------------------------------------*/ void rtimer_arch_init(void) { + next_rtimer = 0; + last_rtimer_now = 0; + pending_rtimer = 0; } /*---------------------------------------------------------------------------*/ void rtimer_arch_schedule(rtimer_clock_t t) { + next_rtimer = t; + pending_rtimer = 1; } /*---------------------------------------------------------------------------*/ +rtimer_clock_t +rtimer_arch_next(void) +{ + return next_rtimer; +} +/*---------------------------------------------------------------------------*/ +int +rtimer_arch_pending(void) +{ + return pending_rtimer; +} +/*---------------------------------------------------------------------------*/ +int +rtimer_arch_check(void) +{ + if (simCurrentTime == next_rtimer) { + /* Execute rtimer */ + pending_rtimer = 0; + rtimer_run_next(); + return 1; + } + return 0; +} +/*---------------------------------------------------------------------------*/ +rtimer_clock_t +rtimer_arch_now(void) +{ + if(last_rtimer_now == simCurrentTime) { + /* Yield to COOJA, to allow time to change */ + simProcessRunValue = 1; + simNextExpirationTime = simCurrentTime + 1; + cooja_mt_yield(); + } + last_rtimer_now = simCurrentTime; + return simCurrentTime; +} +/*---------------------------------------------------------------------------*/ + diff --git a/platform/cooja/rtimer-arch.h b/platform/cooja/rtimer-arch.h index 19063c5ea..4c5cbd27c 100644 --- a/platform/cooja/rtimer-arch.h +++ b/platform/cooja/rtimer-arch.h @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: rtimer-arch.h,v 1.2 2009/03/26 16:22:36 fros4943 Exp $ + * $Id: rtimer-arch.h,v 1.3 2010/03/23 13:13:17 fros4943 Exp $ */ #ifndef __RTIMER_ARCH_H__ @@ -39,7 +39,9 @@ #define RTIMER_ARCH_SECOND CLOCK_CONF_SECOND -#define rtimer_arch_now() -1 - +rtimer_clock_t rtimer_arch_now(void); +int rtimer_arch_check(void); +int rtimer_arch_pending(void); +rtimer_clock_t rtimer_arch_next(void); #endif /* __RTIMER_ARCH_H__ */