rtimer-arch.c

00001 /*
00002  * Copyright (c) 2010, Swedish Institute of Computer Science.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the Institute nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  *
00029  * This file is part of the Contiki operating system.
00030  *
00031  * $Id: rtimer-arch.c,v 1.4 2010/03/23 13:13:17 fros4943 Exp $
00032  */
00033 
00034 #include <signal.h>
00035 #include <sys/time.h>
00036 #include <stddef.h>
00037 
00038 #include "sys/rtimer.h"
00039 #include "sys/clock.h"
00040 #include "sys/cooja_mt.h"
00041 
00042 #include "lib/simEnvChange.h"
00043 
00044 #define DEBUG 0
00045 #if DEBUG
00046 #include <stdio.h>
00047 #define PRINTF(...) printf(__VA_ARGS__)
00048 #else
00049 #define PRINTF(...)
00050 #endif
00051 
00052 extern clock_time_t simCurrentTime;
00053 
00054 static int pending_rtimer = 0;
00055 static rtimer_clock_t next_rtimer = 0;
00056 static clock_time_t last_rtimer_now = 0;
00057 
00058 /*---------------------------------------------------------------------------*/
00059 void
00060 rtimer_arch_init(void)
00061 {
00062   next_rtimer = 0;
00063   last_rtimer_now = 0;
00064   pending_rtimer = 0;
00065 }
00066 /*---------------------------------------------------------------------------*/
00067 void
00068 rtimer_arch_schedule(rtimer_clock_t t)
00069 {
00070   next_rtimer = t;
00071   pending_rtimer = 1;
00072 }
00073 /*---------------------------------------------------------------------------*/
00074 rtimer_clock_t
00075 rtimer_arch_next(void)
00076 {
00077   return next_rtimer;
00078 }
00079 /*---------------------------------------------------------------------------*/
00080 int
00081 rtimer_arch_pending(void)
00082 {
00083   return pending_rtimer;
00084 }
00085 /*---------------------------------------------------------------------------*/
00086 int
00087 rtimer_arch_check(void)
00088 {
00089   if (simCurrentTime == next_rtimer) {
00090     /* Execute rtimer */
00091     pending_rtimer = 0;
00092     rtimer_run_next();
00093     return 1;
00094   }
00095   return 0;
00096 }
00097 /*---------------------------------------------------------------------------*/
00098 rtimer_clock_t
00099 rtimer_arch_now(void)
00100 {
00101   if(last_rtimer_now == simCurrentTime) {
00102     /* Yield to COOJA, to allow time to change */
00103     simProcessRunValue = 1;
00104     simNextExpirationTime = simCurrentTime + 1;
00105     cooja_mt_yield();
00106   }
00107   last_rtimer_now = simCurrentTime;
00108   return simCurrentTime;
00109 }
00110 /*---------------------------------------------------------------------------*/
00111 

Generated on Mon Apr 11 14:23:34 2011 for Contiki 2.5 by  doxygen 1.6.1