implemented rtimer library for simulated contiki motes

This commit is contained in:
fros4943 2010-03-23 13:13:17 +00:00
parent 49526e100f
commit c66dd0b1bf
2 changed files with 59 additions and 10 deletions

View file

@ -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 <signal.h>
@ -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;
}
/*---------------------------------------------------------------------------*/

View file

@ -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__ */