summaryrefslogtreecommitdiff
path: root/cesar/hal/timer/test/src/timer.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/hal/timer/test/src/timer.c')
-rw-r--r--cesar/hal/timer/test/src/timer.c178
1 files changed, 178 insertions, 0 deletions
diff --git a/cesar/hal/timer/test/src/timer.c b/cesar/hal/timer/test/src/timer.c
new file mode 100644
index 0000000000..0d412031ce
--- /dev/null
+++ b/cesar/hal/timer/test/src/timer.c
@@ -0,0 +1,178 @@
+/* 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 <cyg/kernel/kapi.h>
+
+#include "hal/timer/inc/context.h"
+#include <string.h>
+
+#define INSTANCE1_DATE 350
+#define INSTANCE2_DATE 250
+#define INSTANCE3_DATE 400
+#define INSTANCE4_DATE 375
+#define INSTANCE5_DATE 500
+#define INSTANCE6_DATE 251
+
+hal_timer_t *timer;
+
+test_t test;
+
+static int my_thread_stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
+static cyg_handle_t my_thread_handle;
+static cyg_thread my_thread_obj;
+
+bool test_instance1;
+bool test_instance2;
+bool test_instance3;
+
+bool test_instance4;
+bool test_instance5;
+bool test_instance6;
+
+uint total_nb = 0;
+uint my_phy_clock;
+
+hal_timer_instance_t instance1;
+hal_timer_instance_t instance2;
+hal_timer_instance_t instance3;
+
+hal_timer_instance_t instance4;
+hal_timer_instance_t instance5;
+hal_timer_instance_t instance6;
+
+void
+test_call_back (void *user_data)
+{
+ hal_timer_instance_t *instance;
+ dbg_assert (user_data);
+
+ instance = (hal_timer_instance_t *) user_data;
+
+ switch (instance->date)
+ {
+ case INSTANCE1_DATE:
+ test_instance1 = true;
+ my_phy_clock = INSTANCE1_DATE + 5;
+ break;
+ case INSTANCE2_DATE:
+ test_instance2 = true;
+ my_phy_clock = INSTANCE2_DATE + 5;
+ hal_timer_instance_cancel (timer, &instance4);
+ break;
+ case INSTANCE3_DATE:
+ test_instance3 = true;
+ my_phy_clock = INSTANCE3_DATE + 5;
+ hal_timer_instance_cancel (timer, &instance5);
+ break;
+ case INSTANCE4_DATE:
+ test_instance4 = true;
+ my_phy_clock = INSTANCE4_DATE + 5;
+ break;
+ case INSTANCE5_DATE:
+ test_instance5 = true;
+ my_phy_clock = INSTANCE5_DATE + 5;
+ break;
+ case INSTANCE6_DATE:
+ test_instance6 = true;
+ my_phy_clock = INSTANCE6_DATE + 5;
+ break;
+ }
+
+ total_nb++;
+ if (instance->date == INSTANCE3_DATE)
+ {
+ cyg_thread_resume (my_thread_handle);
+ }
+}
+
+void
+my_thread(cyg_addrword_t index)
+{
+ cyg_thread_delay (250);
+
+ // uninitiase the test.
+ hal_timer_uninit (timer);
+
+ test_begin (test, "call back....")
+ {
+ test_fail_if (test_instance1 != true, "Instance 1 never timed out");
+ test_fail_if (test_instance2 != true, "Instance 2 never timed out");
+ test_fail_if (test_instance3 != true, "Instance 3 never timed out");
+
+ test_fail_if (test_instance4 != false, "Instance 4 shall never time out");
+ test_fail_if (test_instance5 != false, "Instance 5 shall never time out");
+ test_fail_if (test_instance6 != true, "Instance 6 never timed out");
+
+ }
+ test_end;
+
+ test_result (test);
+ HAL_PLATFORM_EXIT (test_nb_failed (test) == 0 ? 0 : 1);
+}
+
+int
+cyg_user_start (void)
+{
+ test_instance1 = false;
+ test_instance2 = false;
+ test_instance3 = false;
+
+ test_instance4 = false;
+ test_instance5 = false;
+ test_instance6 = false;
+
+ test_init (test, 0, NULL);
+
+ my_phy_clock = 0;
+ timer = hal_timer_init ((phy_t *) &my_phy_clock);
+
+ hal_timer_instance_init (timer, &instance1, &instance1, test_call_back);
+ hal_timer_instance_program (timer, &instance1, INSTANCE1_DATE);
+
+ hal_timer_instance_init (timer, &instance4, &instance4, test_call_back);
+ hal_timer_instance_program (timer, &instance4, INSTANCE4_DATE);
+
+ hal_timer_instance_init (timer, &instance2, &instance2, test_call_back);
+ hal_timer_instance_program (timer, &instance2, INSTANCE2_DATE);
+
+ hal_timer_instance_init (timer, &instance3, &instance3, test_call_back);
+ hal_timer_instance_program (timer, &instance3, INSTANCE3_DATE);
+
+ hal_timer_instance_init (timer, &instance5, &instance5, test_call_back);
+ hal_timer_instance_program (timer, &instance5, INSTANCE5_DATE);
+
+ hal_timer_instance_init (timer, &instance6, &instance6, test_call_back);
+ hal_timer_instance_program (timer, &instance6, INSTANCE6_DATE);
+
+ // Thread Creation
+ cyg_thread_create(12, my_thread, (cyg_addrword_t) 0,
+ "My Thread", &my_thread_stack, CYGNUM_HAL_STACK_SIZE_TYPICAL,
+ &my_thread_handle, &my_thread_obj);
+
+ return true;
+}
+
+u32
+phy_date (phy_t *phy)
+{
+ return *(uint *)phy;
+}
+