aboutsummaryrefslogtreecommitdiffstats
path: root/os/various
diff options
context:
space:
mode:
Diffstat (limited to 'os/various')
-rw-r--r--os/various/evtimer.c59
-rw-r--r--os/various/evtimer.h58
2 files changed, 82 insertions, 35 deletions
diff --git a/os/various/evtimer.c b/os/various/evtimer.c
index a077529da..38c8cb872 100644
--- a/os/various/evtimer.c
+++ b/os/various/evtimer.c
@@ -25,40 +25,61 @@
#include "ch.h"
#include "evtimer.h"
+/*===========================================================================*/
+/* Module local definitions. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Module exported variables. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Module local types. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Module local variables. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Module local functions. */
+/*===========================================================================*/
+
static void tmrcb(void *p) {
- EvTimer *etp = p;
+ event_timer_t *etp = p;
- chSysLockFromIsr();
+ chSysLockFromISR();
chEvtBroadcastI(&etp->et_es);
- chVTSetI(&etp->et_vt, etp->et_interval, tmrcb, etp);
- chSysUnlockFromIsr();
+ chVTDoSetI(&etp->et_vt, etp->et_interval, tmrcb, etp);
+ chSysUnlockFromISR();
}
+/*===========================================================================*/
+/* Module exported functions. */
+/*===========================================================================*/
+
/**
- * @brief Starts the timer
- * @details If the timer was already running then the function has no effect.
+ * @brief Initializes an @p event_timer_t structure.
*
- * @param etp pointer to an initialized @p EvTimer structure.
+ * @param[out] etp the @p event_timer_t structure to be initialized
+ * @param[in] time the interval in system ticks
*/
-void evtStart(EvTimer *etp) {
-
- chSysLock();
+void evtObjectInit(event_timer_t *etp, systime_t time) {
- if (!chVTIsArmedI(&etp->et_vt))
- chVTSetI(&etp->et_vt, etp->et_interval, tmrcb, etp);
-
- chSysUnlock();
+ chEvtObjectInit(&etp->et_es);
+ chVTObjectInit(&etp->et_vt);
+ etp->et_interval = time;
}
/**
- * @brief Stops the timer.
- * @details If the timer was already stopped then the function has no effect.
+ * @brief Starts the timer
+ * @details If the timer was already running then the function has no effect.
*
- * @param etp pointer to an initialized @p EvTimer structure.
+ * @param[in] etp pointer to an initialized @p event_timer_t structure.
*/
-void evtStop(EvTimer *etp) {
+void evtStart(event_timer_t *etp) {
- chVTReset(&etp->et_vt);
+ chVTSet(&etp->et_vt, etp->et_interval, tmrcb, etp);
}
/** @} */
diff --git a/os/various/evtimer.h b/os/various/evtimer.h
index 613c688a6..bb67691ba 100644
--- a/os/various/evtimer.h
+++ b/os/various/evtimer.h
@@ -25,42 +25,68 @@
#ifndef _EVTIMER_H_
#define _EVTIMER_H_
+/*===========================================================================*/
+/* Module constants. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Module pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
/*
* Module dependencies check.
*/
-#if !CH_USE_EVENTS
-#error "Event Timers require CH_USE_EVENTS"
+#if !CH_CFG_USE_EVENTS
+#error "Event Timers require CH_CFG_USE_EVENTS"
#endif
+/*===========================================================================*/
+/* Module data structures and types. */
+/*===========================================================================*/
+
/**
- * @brief Event timer structure.
+ * @brief Type of a event timer structure.
*/
typedef struct {
- VirtualTimer et_vt;
- EventSource et_es;
- systime_t et_interval;
-} EvTimer;
+ virtual_timer_t et_vt;
+ event_source_t et_es;
+ systime_t et_interval;
+} event_timer_t;
+
+/*===========================================================================*/
+/* Module macros. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
#ifdef __cplusplus
extern "C" {
#endif
- void evtStart(EvTimer *etp);
- void evtStop(EvTimer *etp);
+ void evtObjectInit(event_timer_t *etp, systime_t time);
+ void evtStart(event_timer_t *etp);
#ifdef __cplusplus
}
#endif
+/*===========================================================================*/
+/* Module inline functions. */
+/*===========================================================================*/
+
/**
- * @brief Initializes an @p EvTimer structure.
+ * @brief Stops the timer.
+ * @details If the timer was already stopped then the function has no effect.
*
- * @param etp the EvTimer structure to be initialized
- * @param time the interval in system ticks
+ * @param[in] etp pointer to an initialized @p event_timer_t structure.
*/
-#define evtInit(etp, time) { \
- chEvtInit(&(etp)->et_es); \
- (etp)->et_vt.vt_func = NULL; \
- (etp)->et_interval = (time); \
+static inline void vevtStop(event_timer_t *etp) {
+
+ chVTReset(&etp->et_vt);
}
#endif /* _EVTIMER_H_ */