Revision 23ec8223
| 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; |
| core/src/aos_timer.c | ||
|---|---|---|
| 51 | 51 |
* forward declarations |
| 52 | 52 |
*/ |
| 53 | 53 |
static void _intermediateCb(void* timer); |
| 54 |
static void _fireCb(void *timer); |
|
| 55 |
static void _periodicCb(void* ptimer); |
|
| 54 |
static void _triggerCb(void *timer); |
|
| 56 | 55 |
|
| 57 | 56 |
/** |
| 58 | 57 |
* @brief Setup a timer according to its configuration. |
| ... | ... | |
| 61 | 60 |
*/ |
| 62 | 61 |
static void _setupTimer(aos_timer_t* timer) |
| 63 | 62 |
{
|
| 63 |
// local variables |
|
| 64 | 64 |
aos_timestamp_t uptime; |
| 65 |
aos_timestamp_t timedelta; |
|
| 65 | 66 |
|
| 66 | 67 |
// get current system uptime |
| 67 | 68 |
aosSysGetUptimeX(&uptime); |
| 68 | 69 |
|
| 69 |
// if the wakeup time is more than TIME_IMMEDIATE in the future |
|
| 70 |
if ( (timer->wkuptime > uptime) && ((timer->wkuptime - uptime) > TIME_IMMEDIATE) ) {
|
|
| 71 |
// split the time delta if necessary |
|
| 72 |
if ((timer->wkuptime - uptime) > AOS_TIMER_MAX_INTERVAL_US) {
|
|
| 73 |
chVTSetI(&(timer->vt), chTimeUS2I(AOS_TIMER_MAX_INTERVAL_US), _intermediateCb, timer); |
|
| 74 |
} else {
|
|
| 75 |
chVTSetI(&(timer->vt), chTimeUS2I(timer->wkuptime - uptime), _fireCb, timer); |
|
| 70 |
// if this is a periodic timer |
|
| 71 |
if (timer->interval > 0) {
|
|
| 72 |
// if the periodic timer is already initialized |
|
| 73 |
if (timer->triggertime > 0) {
|
|
| 74 |
timer->triggertime += timer->interval; |
|
| 75 |
} |
|
| 76 |
// if the periodic timer is not initialized yet |
|
| 77 |
else {
|
|
| 78 |
timer->triggertime = uptime + timer->interval; |
|
| 76 | 79 |
} |
| 77 |
} else {
|
|
| 78 |
vtfunc_t fn = timer->callback; |
|
| 79 |
timer->callback = NULL; |
|
| 80 |
fn(timer->cbparam); |
|
| 81 | 80 |
} |
| 82 | 81 |
|
| 83 |
return; |
|
| 84 |
} |
|
| 85 |
|
|
| 86 |
/** |
|
| 87 |
* @brief Setup a periodic timer according to its configuration. |
|
| 88 |
* |
|
| 89 |
* @param[in] ptimer Pointer to the periodic timer to setup. |
|
| 90 |
*/ |
|
| 91 |
static void _setupPeriodicTimer(aos_periodictimer_t *ptimer) |
|
| 92 |
{
|
|
| 93 |
// if the periodic timer is being initialized |
|
| 94 |
if (ptimer->timer.wkuptime == 0) {
|
|
| 95 |
aos_timestamp_t uptime; |
|
| 82 |
// calculate the time delta (may be 'negative' at this point) |
|
| 83 |
timedelta = timer->triggertime - uptime; |
|
| 96 | 84 |
|
| 97 |
// get current system uptime |
|
| 98 |
aosSysGetUptimeX(&uptime); |
|
| 99 |
ptimer->timer.wkuptime = uptime + ptimer->interval; |
|
| 100 |
} |
|
| 101 |
// if the peridic timer is reactivated after it has fired |
|
| 102 |
else {
|
|
| 103 |
ptimer->timer.wkuptime += ptimer->interval; |
|
| 85 |
// if the trigger time is more than TIME_IMMEDIATE in the future |
|
| 86 |
if ((timer->triggertime > uptime) && (timedelta > chTimeI2US(TIME_IMMEDIATE))) {
|
|
| 87 |
// split the time delta if necessary |
|
| 88 |
if (timedelta > AOS_TIMER_MAX_INTERVAL_US) {
|
|
| 89 |
chVTSetI(&timer->vt, chTimeUS2I(AOS_TIMER_MAX_INTERVAL_US), _intermediateCb, timer); |
|
| 90 |
} else {
|
|
| 91 |
chVTSetI(&timer->vt, chTimeUS2I(timedelta), _triggerCb, timer); |
|
| 92 |
} |
|
| 93 |
} else {
|
|
| 94 |
// trigger immediately |
|
| 95 |
timer->callback(timer->cbparam); |
|
| 104 | 96 |
} |
| 105 | 97 |
|
| 106 |
// set the callback and parameters |
|
| 107 |
ptimer->timer.callback = _periodicCb; |
|
| 108 |
ptimer->timer.cbparam = ptimer; |
|
| 109 |
|
|
| 110 |
// setup the timer |
|
| 111 |
_setupTimer(&(ptimer->timer)); |
|
| 112 |
|
|
| 113 | 98 |
return; |
| 114 | 99 |
} |
| 115 | 100 |
|
| 116 | 101 |
/** |
| 117 | 102 |
* @brief Callback function for intermediate interrupts. |
| 118 |
* @details This is required if the desired time to fire is too far in the future so that the interval must be split.
|
|
| 103 |
* @details This is required if the desired time to trigger is too far in the future so that the interval must be split.
|
|
| 119 | 104 |
* |
| 120 | 105 |
* @param[in] timer Pointer to a aos_timer_t to reactivate. |
| 121 | 106 |
*/ |
| ... | ... | |
| 127 | 112 |
} |
| 128 | 113 |
|
| 129 | 114 |
/** |
| 130 |
* @brief Callback function for the final fire event of the timer.
|
|
| 115 |
* @brief Callback function for the trigger event of the timer.
|
|
| 131 | 116 |
* |
| 132 | 117 |
* @param[in] timer Pointer to a aos_timer_t to call its callback. |
| 133 | 118 |
*/ |
| 134 |
static void _fireCb(void *timer)
|
|
| 119 |
static void _triggerCb(void *timer)
|
|
| 135 | 120 |
{
|
| 136 | 121 |
chSysLockFromISR(); |
| 137 | 122 |
((aos_timer_t*)timer)->callback(((aos_timer_t*)timer)->cbparam); |
| 123 |
// reenable periodic timers |
|
| 124 |
if (((aos_timer_t*)timer)->interval > 0) {
|
|
| 125 |
_setupTimer((aos_timer_t*)timer); |
|
| 126 |
} |
|
| 138 | 127 |
chSysUnlockFromISR(); |
| 139 | 128 |
} |
| 140 | 129 |
|
| 141 |
/** |
|
| 142 |
* @brief Callback function for periodic timer interrupts. |
|
| 143 |
* @details This function calls the original callback and reenables the timer afterwards. |
|
| 144 |
* |
|
| 145 |
* @param[in] ptimer Pointer to a aos_periodictimer_t to reactivate. |
|
| 146 |
*/ |
|
| 147 |
static void _periodicCb(void* ptimer) |
|
| 148 |
{
|
|
| 149 |
((aos_periodictimer_t*)ptimer)->callback(((aos_periodictimer_t*)ptimer)->cbparam); |
|
| 150 |
_setupPeriodicTimer((aos_periodictimer_t*)ptimer); |
|
| 151 |
} |
|
| 152 |
|
|
| 153 | 130 |
/******************************************************************************/ |
| 154 | 131 |
/* EXPORTED FUNCTIONS */ |
| 155 | 132 |
/******************************************************************************/ |
| ... | ... | |
| 164 | 141 |
aosDbgAssert(timer != NULL); |
| 165 | 142 |
|
| 166 | 143 |
chVTObjectInit(&(timer->vt)); |
| 167 |
timer->wkuptime = 0; |
|
| 144 |
timer->triggertime = 0; |
|
| 145 |
timer->interval = 0; |
|
| 168 | 146 |
timer->callback = NULL; |
| 169 | 147 |
timer->cbparam = NULL; |
| 170 | 148 |
|
| ... | ... | |
| 172 | 150 |
} |
| 173 | 151 |
|
| 174 | 152 |
/** |
| 175 |
* @brief Set timer to fire at an absolute system time.
|
|
| 153 |
* @brief Set timer to trigger at an absolute system time.
|
|
| 176 | 154 |
* |
| 177 | 155 |
* @param[in] timer Pointer to the timer to set. |
| 178 |
* @param[in] uptime Pointer to the absolute system time for the timer to fire.
|
|
| 156 |
* @param[in] uptime Absolute system time for the timer to trigger.
|
|
| 179 | 157 |
* @param[in] cb Pointer to a callback function to be called. |
| 180 | 158 |
* In contrast to ChibiOS callback functions, this gets called from an already ISR locked context. |
| 181 | 159 |
* Thus it may not contain any chSysLockX() or chSysUnlockX() calls and so forth. |
| 182 |
* @param[in] par Pointer to a parameter fpr the callback function (may be NULL).
|
|
| 160 |
* @param[in] par Pointer to a parameter for the callback function (may be NULL).
|
|
| 183 | 161 |
*/ |
| 184 |
void aosTimerSetAbsoluteI(aos_timer_t *timer, aos_timestamp_t *uptime, vtfunc_t cb, void *par)
|
|
| 162 |
void aosTimerSetAbsoluteI(aos_timer_t *timer, const aos_timestamp_t uptime, vtfunc_t cb, void *par)
|
|
| 185 | 163 |
{
|
| 186 | 164 |
aosDbgCheck(timer != NULL); |
| 187 |
aosDbgCheck(uptime != NULL); |
|
| 188 | 165 |
aosDbgCheck(cb != NULL); |
| 189 | 166 |
|
| 190 |
timer->wkuptime = *uptime; |
|
| 167 |
timer->triggertime = uptime; |
|
| 168 |
timer->interval = 0; |
|
| 191 | 169 |
timer->callback = cb; |
| 192 | 170 |
timer->cbparam = par; |
| 193 | 171 |
_setupTimer(timer); |
| ... | ... | |
| 196 | 174 |
} |
| 197 | 175 |
|
| 198 | 176 |
/** |
| 199 |
* @brief Set timer to fire after a relative interval.
|
|
| 177 |
* @brief Set timer to trigger after a relative interval.
|
|
| 200 | 178 |
* |
| 201 | 179 |
* @param[in] timer Pointer to the timer to set. |
| 202 |
* @param[in] offset Relative interval to set for the timer to fire.
|
|
| 180 |
* @param[in] offset Relative interval to set for the timer to trigger.
|
|
| 203 | 181 |
* @param[in] cb Pointer to a callback function to be called. |
| 204 | 182 |
* In contrast to ChibiOS callback functions, this gets called from an already ISR locked context. |
| 205 | 183 |
* Thus it may not contain any chSysLockX() or chSysUnlockX() calls and so forth. |
| 206 | 184 |
* @param[in] par Pointer to a parameter for the callback function (may be NULL). |
| 207 | 185 |
*/ |
| 208 |
void aosTimerSetIntervalI(aos_timer_t *timer, aos_interval_t offset, vtfunc_t cb, void *par) |
|
| 186 |
void aosTimerSetIntervalI(aos_timer_t *timer, const aos_interval_t offset, vtfunc_t cb, void *par)
|
|
| 209 | 187 |
{
|
| 210 | 188 |
aosDbgCheck(timer != NULL); |
| 211 | 189 |
aosDbgCheck(cb != NULL); |
| ... | ... | |
| 213 | 191 |
aos_timestamp_t uptime; |
| 214 | 192 |
|
| 215 | 193 |
aosSysGetUptimeX(&uptime); |
| 216 |
timer->wkuptime = uptime + offset; |
|
| 194 |
timer->triggertime = uptime + offset; |
|
| 195 |
timer->interval = 0; |
|
| 217 | 196 |
timer->callback = cb; |
| 218 | 197 |
timer->cbparam = par; |
| 219 | 198 |
_setupTimer(timer); |
| ... | ... | |
| 222 | 201 |
} |
| 223 | 202 |
|
| 224 | 203 |
/** |
| 225 |
* @brief Set timer to fire after a long relative interval.
|
|
| 204 |
* @brief Set timer to trigger after a long relative interval.
|
|
| 226 | 205 |
* |
| 227 | 206 |
* @param[in] timer Pointer to the timer to set. |
| 228 |
* @param[in] offset Pointer to a long interval value to set for the timer to fire.
|
|
| 207 |
* @param[in] offset Long interval value to set for the timer to trigger.
|
|
| 229 | 208 |
* @param[in] cb Pointer to a callback function to be called. |
| 230 | 209 |
* In contrast to ChibiOS callback functions, this gets called from an already ISR locked context. |
| 231 | 210 |
* Thus it may not contain any chSysLockX() or chSysUnlockX() calls and so forth. |
| 232 | 211 |
* @param[in] par Pointer to a parameter for the callback function (may be NULL). |
| 233 | 212 |
*/ |
| 234 |
void aosTimerSetLongIntervalI(aos_timer_t *timer, aos_longinterval_t *offset, vtfunc_t cb, void *par)
|
|
| 213 |
void aosTimerSetLongIntervalI(aos_timer_t *timer, const aos_longinterval_t offset, vtfunc_t cb, void *par)
|
|
| 235 | 214 |
{
|
| 236 | 215 |
aosDbgCheck(timer != NULL); |
| 237 |
aosDbgCheck(offset != NULL); |
|
| 238 | 216 |
aosDbgCheck(cb != NULL); |
| 239 | 217 |
|
| 240 | 218 |
aos_timestamp_t uptime; |
| 241 | 219 |
|
| 242 | 220 |
aosSysGetUptimeX(&uptime); |
| 243 |
timer->wkuptime = uptime + *offset; |
|
| 221 |
timer->triggertime = uptime + offset; |
|
| 222 |
timer->interval = 0; |
|
| 244 | 223 |
timer->callback = cb; |
| 245 | 224 |
timer->cbparam = par; |
| 246 | 225 |
_setupTimer(timer); |
| ... | ... | |
| 249 | 228 |
} |
| 250 | 229 |
|
| 251 | 230 |
/** |
| 252 |
* @brief Initialize a aos_periodictimer_t object. |
|
| 253 |
* |
|
| 254 |
* @param[in] timer The periodic timer to initialize. |
|
| 255 |
*/ |
|
| 256 |
void aosPeriodicTimerInit(aos_periodictimer_t *ptimer) |
|
| 257 |
{
|
|
| 258 |
aosDbgAssert(ptimer != NULL); |
|
| 259 |
|
|
| 260 |
aosTimerInit(&(ptimer->timer)); |
|
| 261 |
ptimer->interval = 0; |
|
| 262 |
|
|
| 263 |
return; |
|
| 264 |
} |
|
| 265 |
|
|
| 266 |
/** |
|
| 267 |
* @brief Set a periodic timer to fire in the specified interval. |
|
| 231 |
* @brief Set timer to trigger periodically in the specified interval. |
|
| 268 | 232 |
* |
| 269 |
* @param[in] ptimer Pointer to the periodic timer to set.
|
|
| 270 |
* @param[in] interval Interval for the periodic timer to fire,
|
|
| 233 |
* @param[in] timer Pointer to the periodic timer to set.
|
|
| 234 |
* @param[in] interval Interval for the periodic timer to trigger periodically.
|
|
| 271 | 235 |
* @param[in] cb Pointer to a callback function to be called. |
| 272 | 236 |
* In contrast to ChibiOS callback functions, this gets called from an already ISR locked context. |
| 273 | 237 |
* Thus it may not contain any chSysLockX() or chSysUnlockX() calls and so forth. |
| 274 | 238 |
* @param[in] par Pointer to a parameter for the callback function (may be NULL). |
| 275 | 239 |
*/ |
| 276 |
void aosPeriodicTimerSetI(aos_periodictimer_t* ptimer, aos_interval_t interval, vtfunc_t cb, void* par)
|
|
| 240 |
void aosTimerPeriodicIntervalI(aos_timer_t* timer, const aos_interval_t interval, vtfunc_t cb, void* par)
|
|
| 277 | 241 |
{
|
| 278 |
aosDbgCheck(ptimer != NULL);
|
|
| 242 |
aosDbgCheck(timer != NULL); |
|
| 279 | 243 |
aosDbgCheck(interval > TIME_IMMEDIATE); |
| 280 | 244 |
aosDbgCheck(cb != NULL); |
| 281 | 245 |
|
| 282 |
ptimer->timer.wkuptime = 0;
|
|
| 283 |
ptimer->interval = interval;
|
|
| 284 |
ptimer->callback = cb;
|
|
| 285 |
ptimer->cbparam = par;
|
|
| 286 |
_setupPeriodicTimer(ptimer);
|
|
| 246 |
timer->triggertime = 0;
|
|
| 247 |
timer->interval = interval; |
|
| 248 |
timer->callback = cb; |
|
| 249 |
timer->cbparam = par; |
|
| 250 |
_setupTimer(timer);
|
|
| 287 | 251 |
|
| 288 | 252 |
return; |
| 289 | 253 |
} |
| 290 | 254 |
|
| 291 | 255 |
/** |
| 292 |
* @brief Set a periodic timer to fire in the specified interval.
|
|
| 256 |
* @brief Set timer to trigger periodically in the specified interval.
|
|
| 293 | 257 |
* |
| 294 |
* @param[in] ptimer Pointer to the periodic timer to set.
|
|
| 295 |
* @param[in] interval Pointer to a long interval value for the periodic timer to fire,
|
|
| 258 |
* @param[in] timer Pointer to the periodic timer to set.
|
|
| 259 |
* @param[in] interval Long interval value for the periodic timer to trigger periodically.
|
|
| 296 | 260 |
* @param[in] cb Pointer to a callback function to be called. |
| 297 | 261 |
* In contrast to other callback functions, this get called from an already ISR locked context. |
| 298 | 262 |
* This it may not contain any chSysLockX() or chSysUnlockX() calls. |
| 299 | 263 |
* @param[in] par Pointer to a parameter for the callback function (may be NULL). |
| 300 | 264 |
*/ |
| 301 |
void aosPeriodicTimerSetLongI(aos_periodictimer_t* ptimer, aos_longinterval_t* interval, vtfunc_t cb, void* par)
|
|
| 265 |
void aosTimerPeriodicLongIntervalI(aos_timer_t* timer, const aos_longinterval_t interval, vtfunc_t cb, void* par)
|
|
| 302 | 266 |
{
|
| 303 |
aosDbgCheck(ptimer != NULL);
|
|
| 304 |
aosDbgCheck(*interval > TIME_IMMEDIATE);
|
|
| 267 |
aosDbgCheck(timer != NULL); |
|
| 268 |
aosDbgCheck(interval > TIME_IMMEDIATE); |
|
| 305 | 269 |
aosDbgCheck(cb != NULL); |
| 306 | 270 |
|
| 307 |
ptimer->timer.wkuptime = 0;
|
|
| 308 |
ptimer->interval = *interval;
|
|
| 309 |
ptimer->callback = cb;
|
|
| 310 |
ptimer->cbparam = par;
|
|
| 311 |
_setupPeriodicTimer(ptimer);
|
|
| 271 |
timer->triggertime = 0;
|
|
| 272 |
timer->interval = interval;
|
|
| 273 |
timer->callback = cb; |
|
| 274 |
timer->cbparam = par; |
|
| 275 |
_setupTimer(timer);
|
|
| 312 | 276 |
|
| 313 | 277 |
return; |
| 314 | 278 |
} |
Also available in: Unified diff