implemented rtimer library for simulated contiki motes
This commit is contained in:
parent
49526e100f
commit
c66dd0b1bf
2 changed files with 59 additions and 10 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007, Swedish Institute of Computer Science.
|
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* 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>
|
#include <signal.h>
|
||||||
|
@ -37,6 +37,9 @@
|
||||||
|
|
||||||
#include "sys/rtimer.h"
|
#include "sys/rtimer.h"
|
||||||
#include "sys/clock.h"
|
#include "sys/clock.h"
|
||||||
|
#include "sys/cooja_mt.h"
|
||||||
|
|
||||||
|
#include "lib/simEnvChange.h"
|
||||||
|
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
@ -46,19 +49,63 @@
|
||||||
#define PRINTF(...)
|
#define PRINTF(...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
extern clock_time_t simCurrentTime;
|
||||||
static void
|
|
||||||
interrupt(int sig)
|
static int pending_rtimer = 0;
|
||||||
{
|
static rtimer_clock_t next_rtimer = 0;
|
||||||
}
|
static clock_time_t last_rtimer_now = 0;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
rtimer_arch_init(void)
|
rtimer_arch_init(void)
|
||||||
{
|
{
|
||||||
|
next_rtimer = 0;
|
||||||
|
last_rtimer_now = 0;
|
||||||
|
pending_rtimer = 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
rtimer_arch_schedule(rtimer_clock_t t)
|
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;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* 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__
|
#ifndef __RTIMER_ARCH_H__
|
||||||
|
@ -39,7 +39,9 @@
|
||||||
|
|
||||||
#define RTIMER_ARCH_SECOND CLOCK_CONF_SECOND
|
#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__ */
|
#endif /* __RTIMER_ARCH_H__ */
|
||||||
|
|
Loading…
Reference in a new issue