summaryrefslogtreecommitdiff
path: root/cesar/hal/timer/timer.h
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/hal/timer/timer.h')
-rw-r--r--cesar/hal/timer/timer.h112
1 files changed, 112 insertions, 0 deletions
diff --git a/cesar/hal/timer/timer.h b/cesar/hal/timer/timer.h
new file mode 100644
index 0000000000..d19c92103c
--- /dev/null
+++ b/cesar/hal/timer/timer.h
@@ -0,0 +1,112 @@
+#ifndef hal_timer_timer_h
+#define hal_timer_timer_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hal/timer/timer.h
+ * \brief API function to use a timer with several actors.
+ * \ingroup hal_timer
+ *
+ * To use it, in the module context add a hal_timer_t variable.
+ */
+#include "hal/phy/phy.h"
+#include "lib/heap.h"
+
+#define TIMER_REGISTER_SIZE 24 // 24 bits
+#define TIMER_MAX_TIME (((1 << TIMER_REGISTER_SIZE) - 1) / 3)
+
+/** Call back declaration. */
+typedef void (*hal_timer_instance_cb_t) (void *user_data);
+
+/** forward declarations. */
+typedef struct hal_timer_t hal_timer_t;
+
+struct hal_timer_instance_t
+{
+ /** Status. 0 not armed, 1 armed. */
+ bool status;
+ /** Date to expire the timer. */
+ uint date;
+ /** Function call back to call. */
+ hal_timer_instance_cb_t cb;
+ /** User data to provide. */
+ void *user_data;
+ /** heap node. */
+ heap_node_t node;
+};
+typedef struct hal_timer_instance_t hal_timer_instance_t;
+
+/**
+ * Initialise software timer.
+ * \param phy the phy context.
+ * \return the newly created context
+ */
+hal_timer_t *
+hal_timer_init (phy_t *phy);
+
+/**
+ * Uninitialise the software timer.
+ * \param ctx software timer context
+ *
+ * All timers should be stopped.
+ */
+void
+hal_timer_uninit (hal_timer_t *ctx);
+
+/**
+ * Initialise a new timer instance.
+ * \param  ctx  software timer context
+ * \param  instance  instance to initialise
+ * \param  user_data  user data passed to the callback
+ * \param  cb  timer instance callback, called in DSR context
+ *
+ * The instance is initialised to unprogrammed state.
+ */
+void
+hal_timer_instance_init (hal_timer_t *ctx, hal_timer_instance_t *instance,
+ void *user_data, hal_timer_instance_cb_t cb);
+
+/**
+ * Uninitialise a timer instance.
+ * \param  ctx  software timer context
+ * \param  instance  instance to uninitialise
+ *
+ * The timer instance is canceled if necessary.
+ */
+void
+hal_timer_instance_uninit (hal_timer_t *ctx, hal_timer_instance_t *instance);
+
+/**
+ * Program an instance at the given date.
+ * \param  ctx  software timer context
+ * \param  instance  instance to program
+ * \param  date  instance expiration date
+ */
+void
+hal_timer_instance_program (hal_timer_t *ctx,
+ hal_timer_instance_t *instance, u32 date);
+
+/**
+ * Cancel an instance programmation.
+ * \param  ctx  software timer context
+ * \param  instance  instance to cancel
+ */
+void
+hal_timer_instance_cancel (hal_timer_t *ctx, hal_timer_instance_t *instance);
+
+
+/**
+ * Get the status of the timer intance.
+ *
+ * \return true if the instance is programed.
+ * false if the instance is not programed.
+ */
+bool
+hal_timer_instance_get_status (hal_timer_instance_t *instance);
+
+#endif /* hal_timer_timer_h */