summaryrefslogtreecommitdiff
path: root/cesar/hal/leon/unit-test
diff options
context:
space:
mode:
authorsave2008-04-07 14:17:42 +0000
committersave2008-04-07 14:17:42 +0000
commit3d58a62727346b7ac1a6cb36fed1a06ed72228dd (patch)
treed7788c3cf9f76426aef0286d0202e2097f0fa0eb /cesar/hal/leon/unit-test
parent095dca4b0a8d4924093bab424f71f588fdd84613 (diff)
Moved the complete svn base into the cesar directory.
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@1769 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/hal/leon/unit-test')
-rw-r--r--cesar/hal/leon/unit-test/Module1
-rw-r--r--cesar/hal/leon/unit-test/src/leon_timer.c136
2 files changed, 137 insertions, 0 deletions
diff --git a/cesar/hal/leon/unit-test/Module b/cesar/hal/leon/unit-test/Module
new file mode 100644
index 0000000000..4095bcd911
--- /dev/null
+++ b/cesar/hal/leon/unit-test/Module
@@ -0,0 +1 @@
+SOURCES:=leon_timer.c
diff --git a/cesar/hal/leon/unit-test/src/leon_timer.c b/cesar/hal/leon/unit-test/src/leon_timer.c
new file mode 100644
index 0000000000..8b5ffb27db
--- /dev/null
+++ b/cesar/hal/leon/unit-test/src/leon_timer.c
@@ -0,0 +1,136 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hal/leon/unit-test/src/leon_timer.c
+ * \brief Test API timer
+ * \ingroup hal_leon
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#include "hal/leon/timer.h"
+#include "hal/phy/phy.h"
+
+#include "mac/common/timings.h"
+
+#include <cyg/hal/hal_arch.h>
+#include <cyg/kernel/kapi.h>
+
+#define STACK_SIZE CYGNUM_HAL_STACK_SIZE_TYPICAL
+
+struct leon_timer_t
+{
+ leon_timer_cb_t cb;
+ void *user_data;
+ phy_t *phy;
+ uint delay;
+ uint status;
+};
+
+
+static leon_timer_t leon_timer_global;
+static int my_leon_stack[STACK_SIZE];
+static cyg_handle_t my_leon_handle;
+static cyg_thread my_leon_obj;
+
+/**
+ * my leon empty function for the leon thread
+ */
+void
+my_leon (cyg_addrword_t data)
+{
+ while (true)
+ {
+ if (leon_timer_global.status)
+ {
+ cyg_resolution_t res;
+ uint tck_per_rtc;
+
+ cyg_thread_delay (leon_timer_global.delay);
+ res = cyg_clock_get_resolution (cyg_real_time_clock ());
+ tck_per_rtc = MAC_MS_TO_TCK (1000LL) * res.dividend / res.divisor / 1000000000LL;
+ cyg_thread_delay (tck_per_rtc);
+
+ leon_timer_global.status = false;
+ (*leon_timer_global.cb) (leon_timer_global.user_data);
+ }
+ else
+ cyg_thread_suspend (my_leon_handle);
+ }
+}
+
+/**
+ * Initialise Leon timer.
+ * \param user_data user data passed to the callback
+ * \param cb timer callback, called in ISR context
+ * \param phy phy context used to get the phy date
+ * \return the newly created context
+ */
+leon_timer_t *
+leon_timer_init (void *user_data, leon_timer_cb_t cb, phy_t *phy)
+{
+ dbg_assert (cb);
+ dbg_assert (phy);
+
+ leon_timer_global.phy = phy;
+ leon_timer_global.cb = cb;
+ leon_timer_global.user_data = user_data;
+
+ // Thread Creation
+ cyg_thread_create(12, my_leon, (cyg_addrword_t) 0,
+ "Leon Timer Thread", &my_leon_stack, STACK_SIZE,
+ &my_leon_handle, &my_leon_obj);
+
+ leon_timer_global.status = false;
+ return &leon_timer_global;
+}
+
+/**
+ * Uninitialise the Leon timer.
+ * \param ctx Leon timer context
+ */
+void
+leon_timer_uninit (leon_timer_t *ctx)
+{
+ dbg_assert (ctx);
+
+ cyg_thread_suspend (my_leon_handle);
+ cyg_thread_delete (my_leon_handle);
+}
+
+/**
+ * Program the timer to the given date.
+ * \param ctx Leon timer context
+ * \param sysdate timer expiration date
+ */
+void
+leon_timer_program (leon_timer_t *ctx, u32 sysdate)
+{
+ dbg_assert (ctx);
+ dbg_assert (sysdate > phy_date(ctx->phy));
+
+ ctx->delay = sysdate - phy_date (ctx->phy);
+ ctx->status = true;
+ cyg_thread_resume (my_leon_handle);
+}
+
+/**
+ * Cancel timer programmation.
+ * \param ctx Leon timer context
+ */
+void
+leon_timer_cancel (leon_timer_t *ctx)
+{
+ dbg_assert (ctx);
+
+ ctx->status = false;
+ if (leon_timer_global.status == true)
+ cyg_thread_suspend(my_leon_handle);
+}
+
+