summaryrefslogtreecommitdiff
path: root/cesar/hal/timer/test/src/timer2.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/hal/timer/test/src/timer2.c')
-rw-r--r--cesar/hal/timer/test/src/timer2.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/cesar/hal/timer/test/src/timer2.c b/cesar/hal/timer/test/src/timer2.c
new file mode 100644
index 0000000000..9903bbd2a7
--- /dev/null
+++ b/cesar/hal/timer/test/src/timer2.c
@@ -0,0 +1,95 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hal/timer/test/src/timer.c
+ * \brief Test the API timer.
+ * \ingroup hal/timer.
+ *
+ *
+ * Implement three threads to simulate 3 actors.
+ */
+#include "common/std.h"
+#include "lib/test.h"
+#include "lib/blk.h"
+
+#include "hal/timer/timer.h"
+#include "hal/timer/inc/context.h"
+#include <cyg/kernel/kapi.h>
+#include <cyg/infra/diag.h>
+
+#include <string.h>
+
+#define THREAD_PRIO 10
+
+static test_t test;
+static hal_timer_t *hal_timer;
+static phy_t *phy;
+
+/* Thread 1. */
+u8 thread1_stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
+cyg_handle_t handle_thread1;
+cyg_thread thread1;
+hal_timer_instance_t t1_instance;
+
+void
+timer_cb (void *nothing)
+{
+ diag_printf ("Reprogram timer for 30350 ticks.\n");
+
+ hal_timer_instance_program (hal_timer, &t1_instance,
+ phy_date (phy) + 30350);
+}
+
+void
+thread1_entry_function(cyg_addrword_t data)
+{
+ hal_timer_instance_init (hal_timer, &t1_instance, NULL, &timer_cb);
+
+ hal_timer_instance_program (hal_timer, &t1_instance,
+ phy_date (phy) + 30250);
+
+ diag_printf ("Current instance prgmed : %p\n",
+ hal_timer->current_instance);
+ diag_printf ("This instance : %p\n", &t1_instance);
+ diag_printf ("Going to a rest\n");
+ cyg_thread_delay (10000);
+ diag_printf ("Test ended\n");
+ cyg_thread_suspend (handle_thread1);
+ hal_timer_uninit (hal_timer);
+ test_result (test);
+
+#ifndef __sparc__
+ HAL_PLATFORM_EXIT (test_nb_failed (test) == 0 ? 0 : 1);
+#endif
+}
+
+int
+cyg_user_start (void)
+{
+ test_init (test, 0, NULL);
+
+ phy = (phy_t *) 123;
+ hal_timer = hal_timer_init (phy);
+
+ cyg_thread_create(THREAD_PRIO, &thread1_entry_function,
+ 0, "Thread 1", thread1_stack,
+ CYGNUM_HAL_STACK_SIZE_TYPICAL,
+ &handle_thread1, &thread1);
+
+ cyg_thread_resume (handle_thread1);
+
+ return 0;
+}
+
+#ifndef __sparc__
+u32
+phy_date (phy_t *phy_useless)
+{
+ return cyg_current_time ();
+}
+#endif