aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/osal/lib/osal_vt.h
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2016-12-22 10:36:32 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2016-12-22 10:36:32 +0000
commit70aee6011b8f5fc985140464623019f6d57af540 (patch)
tree120a5bece9718f7d559dd282a59ccf6b1029f3e4 /os/hal/osal/lib/osal_vt.h
parentded823da225a0214cf028cdb79ecfb1cba0df9cd (diff)
downloadChibiOS-70aee6011b8f5fc985140464623019f6d57af540.tar.gz
ChibiOS-70aee6011b8f5fc985140464623019f6d57af540.tar.bz2
ChibiOS-70aee6011b8f5fc985140464623019f6d57af540.zip
Added standalone virtual timers module.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9985 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/osal/lib/osal_vt.h')
-rw-r--r--os/hal/osal/lib/osal_vt.h131
1 files changed, 131 insertions, 0 deletions
diff --git a/os/hal/osal/lib/osal_vt.h b/os/hal/osal/lib/osal_vt.h
new file mode 100644
index 000000000..e46365c37
--- /dev/null
+++ b/os/hal/osal/lib/osal_vt.h
@@ -0,0 +1,131 @@
+/*
+ ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+/**
+ * @file osal_vt.h
+ * @brief OSAL Virtual Timers module header.
+ *
+ * @addtogroup OSAL_VT
+ * @{
+ */
+
+#ifndef _OSAL_VT_H_
+#define _OSAL_VT_H_
+
+/*===========================================================================*/
+/* Module constants. */
+/*===========================================================================*/
+
+/**
+ * @name Special time constants
+ * @{
+ */
+#define TIME_IMMEDIATE ((systime_t)0)
+#define TIME_INFINITE ((systime_t)-1)
+/** @} */
+
+/*===========================================================================*/
+/* Module pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Module data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Type of a Virtual Timer callback function.
+ */
+typedef void (*vtfunc_t)(void *);
+
+/**
+ * @brief Type of a Virtual Timer structure.
+ */
+typedef struct virtual_timer virtual_timer_t;
+
+/**
+ * @brief Virtual timers list header.
+ * @note The content of this structure is not part of the API and should
+ * not be relied upon. Implementers may define this structure in
+ * an entirely different way.
+ * @note The delta list is implemented as a double link bidirectional list
+ * in order to make the unlink time constant, the reset of a virtual
+ * timer is often used in the code.
+ */
+typedef struct {
+ virtual_timer_t *vt_next; /**< @brief Next timer in the timers
+ list. */
+ virtual_timer_t *vt_prev; /**< @brief Last timer in the timers
+ list. */
+ systime_t vt_time; /**< @brief Must be initialized to -1. */
+ volatile systime_t vt_systime; /**< @brief System Time counter. */
+} virtual_timers_list_t;
+
+/**
+ * @extends virtual_timers_list_t
+ *
+ * @brief Virtual Timer descriptor structure.
+ * @note The content of this structure is not part of the API and should
+ * not be relied upon. Implementers may define this structure in
+ * an entirely different way.
+ */
+struct virtual_timer {
+ virtual_timer_t *vt_next; /**< @brief Next timer in the timers
+ list. */
+ virtual_timer_t *vt_prev; /**< @brief Previous timer in the timers
+ list. */
+ systime_t vt_time; /**< @brief Time delta before timeout. */
+ vtfunc_t vt_func; /**< @brief Timer callback function
+ pointer. */
+ void *vt_par; /**< @brief Timer callback function
+ parameter. */
+};
+
+/*===========================================================================*/
+/* Module macros. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#if !defined(__DOXYGEN__)
+extern virtual_timers_list_t vtlist;
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void vtInit(void);
+ bool vtIsArmedI(virtual_timer_t *vtp);
+ void vtDoTickI(void);
+ void vtSetI(virtual_timer_t *vtp, systime_t time,
+ vtfunc_t vtfunc, void *par);
+ void vtResetI(virtual_timer_t *vtp);
+#ifdef __cplusplus
+}
+#endif
+
+/*===========================================================================*/
+/* Module inline functions. */
+/*===========================================================================*/
+
+#endif /* _OSAL_VT_H_ */
+
+/** @} */