Contiki 2.6
|
00001 /** \addtogroup sys 00002 * @{ */ 00003 00004 /** 00005 * \defgroup rt Real-time task scheduling 00006 * 00007 * The real-time module handles the scheduling and execution of 00008 * real-time tasks (with predictable execution times). 00009 * 00010 * @{ 00011 */ 00012 00013 /** 00014 * \file 00015 * Header file for the real-time timer module. 00016 * \author 00017 * Adam Dunkels <adam@sics.se> 00018 * 00019 */ 00020 00021 /* 00022 * Copyright (c) 2005, Swedish Institute of Computer Science 00023 * All rights reserved. 00024 * 00025 * Redistribution and use in source and binary forms, with or without 00026 * modification, are permitted provided that the following conditions 00027 * are met: 00028 * 1. Redistributions of source code must retain the above copyright 00029 * notice, this list of conditions and the following disclaimer. 00030 * 2. Redistributions in binary form must reproduce the above copyright 00031 * notice, this list of conditions and the following disclaimer in the 00032 * documentation and/or other materials provided with the distribution. 00033 * 3. Neither the name of the Institute nor the names of its contributors 00034 * may be used to endorse or promote products derived from this software 00035 * without specific prior written permission. 00036 * 00037 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00038 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00039 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00040 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 00041 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00042 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00043 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00044 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00045 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00046 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00047 * SUCH DAMAGE. 00048 * 00049 * This file is part of the Contiki operating system. 00050 * 00051 * @(#)$Id: rtimer.h,v 1.12 2010/09/13 20:46:02 nifi Exp $ 00052 */ 00053 #ifndef __RTIMER_H__ 00054 #define __RTIMER_H__ 00055 00056 #include "contiki-conf.h" 00057 00058 #ifndef RTIMER_CLOCK_LT 00059 typedef unsigned short rtimer_clock_t; 00060 #define RTIMER_CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0) 00061 #endif /* RTIMER_CLOCK_LT */ 00062 00063 #include "rtimer-arch.h" 00064 00065 /** 00066 * \brief Initialize the real-time scheduler. 00067 * 00068 * This function initializes the real-time scheduler and 00069 * must be called at boot-up, before any other functions 00070 * from the real-time scheduler is called. 00071 */ 00072 void rtimer_init(void); 00073 00074 struct rtimer; 00075 typedef void (* rtimer_callback_t)(struct rtimer *t, void *ptr); 00076 00077 /** 00078 * \brief Representation of a real-time task 00079 * 00080 * This structure represents a real-time task and is used 00081 * by the real-time module and the architecture specific 00082 * support module for the real-time module. 00083 */ 00084 struct rtimer { 00085 rtimer_clock_t time; 00086 rtimer_callback_t func; 00087 void *ptr; 00088 }; 00089 00090 enum { 00091 RTIMER_OK, 00092 RTIMER_ERR_FULL, 00093 RTIMER_ERR_TIME, 00094 RTIMER_ERR_ALREADY_SCHEDULED, 00095 }; 00096 00097 /** 00098 * \brief Post a real-time task. 00099 * \param task A pointer to the task variable previously declared with RTIMER_TASK(). 00100 * \param time The time when the task is to be executed. 00101 * \param duration Unused argument. 00102 * \param func A function to be called when the task is executed. 00103 * \param ptr An opaque pointer that will be supplied as an argument to the callback function. 00104 * \return Non-zero (true) if the task could be scheduled, zero 00105 * (false) if the task could not be scheduled. 00106 * 00107 * This function schedules a real-time task at a specified 00108 * time in the future. 00109 * 00110 */ 00111 int rtimer_set(struct rtimer *task, rtimer_clock_t time, 00112 rtimer_clock_t duration, rtimer_callback_t func, void *ptr); 00113 00114 /** 00115 * \brief Execute the next real-time task and schedule the next task, if any 00116 * 00117 * This function is called by the architecture dependent 00118 * code to execute and schedule the next real-time task. 00119 * 00120 */ 00121 void rtimer_run_next(void); 00122 00123 /** 00124 * \brief Get the current clock time 00125 * \return The current time 00126 * 00127 * This function returns what the real-time module thinks 00128 * is the current time. The current time is used to set 00129 * the timeouts for real-time tasks. 00130 * 00131 * \hideinitializer 00132 */ 00133 #define RTIMER_NOW() rtimer_arch_now() 00134 00135 /** 00136 * \brief Get the time that a task last was executed 00137 * \param task The task 00138 * \return The time that a task last was executed 00139 * 00140 * This function returns the time that the task was last 00141 * executed. This typically is used to get a periodic 00142 * execution of a task without clock drift. 00143 * 00144 * \hideinitializer 00145 */ 00146 #define RTIMER_TIME(task) ((task)->time) 00147 00148 void rtimer_arch_init(void); 00149 void rtimer_arch_schedule(rtimer_clock_t t); 00150 /*rtimer_clock_t rtimer_arch_now(void);*/ 00151 00152 #define RTIMER_SECOND RTIMER_ARCH_SECOND 00153 00154 #endif /* __RTIMER_H__ */ 00155 00156 /** @} */ 00157 /** @} */