Revision 23ec8223 core/inc/aos_timer.h

View differences:

core/inc/aos_timer.h
66 66
/******************************************************************************/
67 67

  
68 68
/**
69
 * @brief   Timer stucture.
69
 * @brief   Timer structure.
70 70
 */
71 71
typedef struct aos_timer {
72 72
  /**
......
75 75
  virtual_timer_t vt;
76 76

  
77 77
  /**
78
   * @brief   Time to wake up.
78
   * @brief   Absolute time to trigger.
79 79
   */
80
  aos_timestamp_t wkuptime;
80
  aos_timestamp_t triggertime;
81 81

  
82 82
  /**
83
   * @brief   Pointer to a callback function.
84
   */
85
  vtfunc_t callback;
86

  
87
  /**
88
   * @brief   Pointer to a parameter for the callback function.
89
   */
90
  void* cbparam;
91
} aos_timer_t;
92

  
93
/**
94
 * @brief   Periodic timer structure.
95
 */
96
typedef struct aos_periodictimer {
97
  /**
98
   * @brief   AMiRo-OS timer.
99
   */
100
  aos_timer_t timer;
101

  
102
  /**
103
   * @brief   Period interval.
83
   * @brief   Relative interval for periodic timers.
84
   * @note    A value of 0 indicates single shot timing.
104 85
   */
105 86
  aos_longinterval_t interval;
106 87

  
......
113 94
   * @brief   Pointer to a parameter for the callback function.
114 95
   */
115 96
  void* cbparam;
116
} aos_periodictimer_t;
97
} aos_timer_t;
117 98

  
118 99
/******************************************************************************/
119 100
/* MACROS                                                                     */
......
127 108
extern "C" {
128 109
#endif /* defined(__cplusplus) */
129 110
  void aosTimerInit(aos_timer_t* timer);
130
  void aosTimerSetAbsoluteI(aos_timer_t* timer, aos_timestamp_t* uptime, vtfunc_t cb, void* par);
131
  void aosTimerSetIntervalI(aos_timer_t* timer, aos_interval_t offset, vtfunc_t cb, void* par);
132
  void aosTimerSetLongIntervalI(aos_timer_t* timer, aos_longinterval_t* offset, vtfunc_t cb, void* par);
133
  void aosPeriodicTimerInit(aos_periodictimer_t* ptimer);
134
  void aosPeriodicTimerSetI(aos_periodictimer_t* ptimer, aos_interval_t interval, vtfunc_t cb, void* par);
135
  void aosPeriodicTimerSetLongI(aos_periodictimer_t* ptimer, aos_longinterval_t* interval, vtfunc_t cb, void* par);
111
  void aosTimerSetAbsoluteI(aos_timer_t* timer, const aos_timestamp_t uptime, vtfunc_t cb, void* par);
112
  void aosTimerSetIntervalI(aos_timer_t* timer, const aos_interval_t offset, vtfunc_t cb, void* par);
113
  void aosTimerSetLongIntervalI(aos_timer_t* timer, const aos_longinterval_t offset, vtfunc_t cb, void* par);
114
  void aosTimerPeriodicIntervalI(aos_timer_t* timer, const aos_interval_t interval, vtfunc_t cb, void* par);
115
  void aosTimerPeriodicLongIntervalI(aos_timer_t* timer, const aos_longinterval_t interval, vtfunc_t cb, void* par);
136 116
#if defined(__cplusplus)
137 117
}
138 118
#endif /* defined(__cplusplus) */
......
142 122
/******************************************************************************/
143 123

  
144 124
/**
145
 * @brief   Set timer to fire at an absolute system time.
125
 * @brief   Set timer to trigger at an absolute system time.
146 126
 *
147 127
 * @param[in] timer   Pointer to the timer to set.
148
 * @param[in] uptime  Pointer to the absolute uptime for the timer to fire.
128
 * @param[in] uptime  Absolute uptime for the timer to trigger.
149 129
 * @param[in] cb      Pointer to a callback function to be called.
150
 * @param[in] par     Pointer to a parameter fpr the callback function (may be NULL).
130
 * @param[in] par     Pointer to a parameter for the callback function (may be NULL).
151 131
 */
152
static inline void aosTimerSetAbsolute(aos_timer_t* timer, aos_timestamp_t* uptime, vtfunc_t cb, void* par)
132
static inline void aosTimerSetAbsolute(aos_timer_t* timer, const aos_timestamp_t uptime, vtfunc_t cb, void* par)
153 133
{
154 134
  chSysLock();
155 135
  aosTimerSetAbsoluteI(timer, uptime, cb, par);
......
159 139
}
160 140

  
161 141
/**
162
 * @brief   Set timer to fire after a relative interval.
142
 * @brief   Set timer to trigger after a relative interval.
163 143
 *
164 144
 * @param[in] timer   Pointer to the timer to set.
165
 * @param[in] offset  Relative interval to set for the timer to fire.
145
 * @param[in] offset  Relative interval to set for the timer to trigger.
166 146
 * @param[in] cb      Pointer to a callback function to be called.
167
 * @param[in] par     Pointer to a parameter fpr the callback function (may be NULL).
147
 *                    In contrast to other callback functions, this gets called from an already ISR locked context.
148
 *                    Thus it may not contain any chSysLockX() or chSysUnlockX() calls.
149
 * @param[in] par     Pointer to a parameter for the callback function (may be NULL).
168 150
 */
169
static inline void aosTimerSetInterval(aos_timer_t* timer, aos_interval_t offset, vtfunc_t cb, void* par)
151
static inline void aosTimerSetInterval(aos_timer_t* timer, const aos_interval_t offset, vtfunc_t cb, void* par)
170 152
{
171 153
  chSysLock();
172 154
  aosTimerSetIntervalI(timer, offset, cb, par);
......
174 156
}
175 157

  
176 158
/**
177
 * @brief   Set timer to fire after a long relative interval.
159
 * @brief   Set timer to trigger after a long relative interval.
178 160
 *
179 161
 * @param[in] timer   Pointer to the timer to set.
180
 * @param[in] offset  Pointer to a long interval value to set for the timer to fire.
162
 * @param[in] offset  Long interval value to set for the timer to trigger.
181 163
 * @param[in] cb      Pointer to a callback function to be called.
182
 * @param[in] par     Pointer to a parameter fpr the callback function (may be NULL).
164
 *                    In contrast to other callback functions, this gets called from an already ISR locked context.
165
 *                    Thus it may not contain any chSysLockX() or chSysUnlockX() calls.
166
 * @param[in] par     Pointer to a parameter for the callback function (may be NULL).
183 167
 */
184
static inline void aosTimerSetLongInterval(aos_timer_t* timer, aos_longinterval_t* offset, vtfunc_t cb, void* par)
168
static inline void aosTimerSetLongInterval(aos_timer_t* timer, const aos_longinterval_t offset, vtfunc_t cb, void* par)
185 169
{
186 170
  chSysLock();
187 171
  aosTimerSetLongIntervalI(timer, offset, cb, par);
......
189 173
}
190 174

  
191 175
/**
192
 * @brief   Reset a timer.
176
 * @brief   Set timer to trigger periodically in the specified interval.
193 177
 *
194
 * @param[in] timer   Pointer to the timer to reset.
178
 * @param[in] timer     Pointer to the timer to set.
179
 * @param[in] interval  Interval for the timer to trigger periodically.
180
 * @param[in] cb        Pointer to a callback function to be called.
181
 *                      In contrast to other callback functions, this gets called from an already ISR locked context.
182
 *                      Thus it may not contain any chSysLockX() or chSysUnlockX() calls.
183
 * @param[in] par       Pointer to a parameter for the callback function (may be NULL).
195 184
 */
196
static inline void aosTimerResetI(aos_timer_t* timer)
185
static inline void aosTimerPeriodicInterval(aos_timer_t *timer, const aos_interval_t interval, vtfunc_t cb, void *par)
197 186
{
198
  chVTResetI(&(timer->vt));
187
  chSysLock();
188
  aosTimerPeriodicIntervalI(timer, interval, cb, par);
189
  chSysUnlock();
199 190

  
200 191
  return;
201 192
}
202 193

  
203 194
/**
204
 * @brief   Reset a timer.
195
 * @brief   Set timer to trigger periodically in the specified interval.
205 196
 *
206
 * @param[in] timer   Pointer to the timer to reset.
197
 * @param[in] timer     Pointer to the timer to set.
198
 * @param[in] interval  Long interval value for the periodic timer to trigger periodically.
199
 * @param[in] cb        Pointer to a callback function to be called.
200
 *                      In contrast to other callback functions, this get called from an already ISR locked context.
201
 *                      This it may not contain any chSysLockX() or chSysUnlockX() calls.
202
 * @param[in] par       Pointer to a parameter for the callback function (may be NULL).
207 203
 */
208
static inline void aosTimerReset(aos_timer_t* timer)
204
static inline void aosTimerPeriodicLongInterval(aos_timer_t* timer, const aos_longinterval_t interval, vtfunc_t cb, void* par)
209 205
{
210 206
  chSysLock();
211
  aosTimerResetI(timer);
207
  aosTimerPeriodicLongIntervalI(timer, interval, cb, par);
212 208
  chSysUnlock();
213 209

  
214 210
  return;
......
245 241
}
246 242

  
247 243
/**
248
 * @brief   Set a periodic timer to fire in the specified interval.
244
 * @brief   Reset a timer.
249 245
 *
250
 * @param[in] ptimer    Pointer to the periodic timer to set.
251
 * @param[in] interval  Interval for the periodic timer to fire,
252
 * @param[in] cb        Pointer to a callback function to be called.
253
 *                      In contrast to other callback functions, this get called from an already ISR locked context.
254
 *                      This it may not contain any chSysLockX() or chSysUnlockX() calls.
255
 * @param[in] par       Pointer to a parameter for the callback function (may be NULL).
246
 * @param[in] timer   Pointer to the timer to reset.
256 247
 */
257
static inline void aosPeriodicTimerSet(aos_periodictimer_t *ptimer, aos_interval_t interval, vtfunc_t cb, void *par)
248
static inline void aosTimerResetI(aos_timer_t* timer)
258 249
{
259
  chSysLock();
260
  aosPeriodicTimerSetI(ptimer, interval, cb, par);
261
  chSysUnlock();
250
  chVTResetI(&(timer->vt));
251
  timer->interval = 0;
262 252

  
263 253
  return;
264 254
}
265 255

  
266 256
/**
267
 * @brief   Set a periodic timer to fire in the specified interval.
257
 * @brief   Reset a timer.
268 258
 *
269
 * @param[in] ptimer    Pointer to the periodic timer to set.
270
 * @param[in] interval  Pointer to a long interval value for the periodic timer to fire,
271
 * @param[in] cb        Pointer to a callback function to be called.
272
 *                      In contrast to other callback functions, this get called from an already ISR locked context.
273
 *                      This it may not contain any chSysLockX() or chSysUnlockX() calls.
274
 * @param[in] par       Pointer to a parameter for the callback function (may be NULL).
259
 * @param[in] timer   Pointer to the timer to reset.
275 260
 */
276
static inline void aosPeriodicTimerSetLong(aos_periodictimer_t* ptimer, aos_longinterval_t* interval, vtfunc_t cb, void* par)
261
static inline void aosTimerReset(aos_timer_t* timer)
277 262
{
278 263
  chSysLock();
279
  aosPeriodicTimerSetLongI(ptimer, interval, cb, par);
264
  aosTimerResetI(timer);
280 265
  chSysUnlock();
281 266

  
282 267
  return;

Also available in: Unified diff