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 ]

Diff markup

Differences between /sos/time.h (Article 7) and /sos/time.h (Article 6.5)


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

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