SimpleOS

LXR

Navigation



Site hébergé par : enix

The LXR Cross Referencer for SOS

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Article:1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 6.5 ] [ 7 ] [ 7.5 ] [ 8 ] [ 9 ] [ 9.5 ]

001 /* Copyright (C) 2004 David Decotigny
002 
003    This program is free software; you can redistribute it and/or
004    modify it under the terms of the GNU General Public License
005    as published by the Free Software Foundation; either version 2
006    of the License, or (at your option) any later version.
007    
008    This program is distributed in the hope that it will be useful,
009    but WITHOUT ANY WARRANTY; without even the implied warranty of
010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
011    GNU General Public License for more details.
012    
013    You should have received a copy of the GNU General Public License
014    along with this program; if not, write to the Free Software
015    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
016    USA. 
017 */
018 #ifndef _SOS_TIME_H_
019 #define _SOS_TIME_H_
020 
021 /**
022  * @file time.h
023  *
024  * Primitives and callbacks related to kernel time management (timer
025  * IRQ)
026  */
027 
028 #include <sos/types.h>
029 #include <sos/errno.h>
030 #include <sos/klibc.h>
031 
032 
033 /* =======================================================================
034  * Library of time manipulation functions
035  */
036 struct sos_time
037 {
038   sos_ui32_t sec;
039   sos_ui32_t nanosec;
040 };
041 
042 sos_ret_t sos_time_inc(struct sos_time *dest,
043                        const struct sos_time *to_add);
044 
045 sos_ret_t sos_time_dec(struct sos_time *dest,
046                        const struct sos_time *to_dec);
047 
048 int sos_time_cmp(const struct sos_time *t1,
049                  const struct sos_time *t2);
050 
051 sos_bool_t sos_time_is_zero(const struct sos_time *tm);
052 
053 
054 
055 /* =======================================================================
056  * Kernel time management. This is not the same as the "system-time",
057  * ie it does not not take into account the system-time adjustments
058  * (NTP, daylight saving times, etc...): this is the job of a
059  * system-time subsystem.
060  */
061 
062 
063 /**
064  * Initialize kernel time subsystem.
065  *
066  * @param initial_resolution The initial time resolution. MUST be
067  * consistent with that of the hardware timer
068  */
069 sos_ret_t sos_time_subsysem_setup(const struct sos_time *initial_resolution);
070 
071 
072 /**
073  * Value of the interval between 2 time ticks. Should be consistent
074  * with the configuration of the hardware timer.
075  */
076 sos_ret_t sos_time_get_tick_resolution(struct sos_time *resolution);
077 
078 
079 /**
080  * Change the value of the interval between 2 time ticks. Must be
081  * called each time the hardware timer is reconfigured.
082  *
083  * @note MUST be consistent with that of the hardware timer
084  */
085 sos_ret_t sos_time_set_tick_resolution(const struct sos_time *resolution);
086 
087 
088 /**
089  * Get the time elapsed since system boot. Does not take into account
090  * the system-time adjustment (NTP, daylight saving times, etc...):
091  * this is the job of a system-time subsystem.
092  */
093 sos_ret_t sos_time_get_now(struct sos_time *now);
094 
095 
096 
097 /* =======================================================================
098  * Routines to schedule future execution of routines: "timeout" actions
099  */
100 
101 /* Forward declaration */
102 struct sos_timeout_action;
103 
104 /**
105  * Prototype of a timeout routine. Called with IRQ disabled !
106  */
107 typedef void (sos_timeout_routine_t)(struct sos_timeout_action *);
108 
109 
110 /**
111  * The structure of a timeout action. This structure should have been
112  * opaque to the other parts of the kernel. We keep it public here so
113  * that struct sos_timeout_action can be allocated on the stack from
114  * other source files in the kernel. However, all the fields should be
115  * considered read-only for modules others than time.{ch}.
116  *
117  * @note After an action has been allocated (on the stack or kmalloc),
118  * it MUST be initialized with sos_time_init_action below !
119  */
120 struct sos_timeout_action
121 {
122   /** PUBLIC: Address of the timeout routine */
123   sos_timeout_routine_t *routine;
124 
125   /** PUBLIC: (Custom) data available for this routine */
126   void                  *routine_data;
127   
128   /** PUBLIC: 2 meanings:
129    *  - before and while in the timeout list: absolute due date of the
130    *    timeout action
131    *  - once removed from timeout list: the time remaining in the
132    *    initial timeout (might be 0 if timeout expired) at removal
133    *    time
134    */
135   struct sos_time           timeout;
136 
137   /** PRIVATE: To chain the timeout actions */
138   struct sos_timeout_action *tmo_prev, *tmo_next;
139 };
140 
141 
142 /**
143  * Initialize a timeout action. MUST be called immediately after
144  * (stack or kmalloc) allocation of the action.
145  *
146  * @param ptr_act Pointer to the action to initialize.
147  */
148 #define sos_time_init_action(ptr_act) \
149   ({ (ptr_act)->tmo_prev = (ptr_act)->tmo_next = NULL; /* return */ SOS_OK; })
150 
151 
152 /**
153  * Add the given action in the timeout list, so that it will be
154  * triggered after the specified delay RELATIVE to the time when the
155  * function gets called. The action is always inserted in the list.
156  *
157  * @param act The action to be initialized by the function upon
158  * insertion in the timeout list.
159  *
160  * @param delay Delay until the action is fired. If 0, then it is
161  * fired at next timer IRQ. The action will be fired in X ticks, with
162  * X integer and >= delay.
163  *
164  * @param routine The timeout routine to call when the timeout will be
165  * triggered.
166  *
167  * @param routine_data The data available to the routine when it will
168  * be called.
169  *
170  * @note 'act' MUST remain valid until it is either fired or removed
171  * (with sos_time_remove_action)
172  */
173 sos_ret_t
174 sos_time_register_action_relative(struct sos_timeout_action *act,
175                                   const struct sos_time *delay,
176                                   sos_timeout_routine_t *routine,
177                                   void *routine_data);
178 
179 
180 /**
181  * Add the given action in the timeout list, so that it will be
182  * triggered after the specified ABSOLUTE date (relative to system
183  * boot time). The action is always inserted in the list.
184  *
185  * @param act The action to be initialized by the function upon
186  * insertion in the timeout list.
187  *
188  * @param date Absolute date (relative to system boot time) when the
189  * action will be triggered.
190  *
191  * @param routine The timeout routine to call when the timeout will be
192  * triggered.
193  *
194  * @param routine_data The data available to the routine when it will
195  * be called.
196  *
197  * @note 'act' MUST remain valid until it is either fired or removed
198  * (with sos_time_remove_action)
199  */
200 sos_ret_t
201 sos_time_register_action_absolute(struct sos_timeout_action *act,
202                                   const struct sos_time *date,
203                                   sos_timeout_routine_t *routine,
204                                   void *routine_data);
205 
206 
207 /**
208  * The action is removed and its timeout is updated to reflect the
209  * time remaining.
210  */
211 sos_ret_t sos_time_unregister_action(struct sos_timeout_action *act);
212 
213 
214 /**
215  * Timer IRQ callback. Call and remove expired actions from the list.
216  *
217  * @note The use of this function is RESERVED (to timer IRQ)
218  */
219 sos_ret_t sos_time_do_tick();
220 
221 
222 #endif /* _SOS_TIME_H_ */

source navigation ] diff markup ] identifier search ] general search ]