From 3c8f04c81eadfef6fe42a0ba5ac60ae70e89b649 Mon Sep 17 00:00:00 2001
From: Brendan Bartels <bbartels@iastate.edu>
Date: Sun, 12 Mar 2017 14:57:58 -0500
Subject: [PATCH] wip: add hardware tests for PWMInputDriver

---
 .../modular_quad_pid/src/hw_impl_zybo.h       |  1 +
 .../modular_quad_pid/src/hw_impl_zybo_tests.c | 29 +++++++++++++++++++
 .../modular_quad_pid/src/main.c               |  5 ++--
 3 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo.h b/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo.h
index 9e30ddb02..aef58b58e 100644
--- a/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo.h
+++ b/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo.h
@@ -64,5 +64,6 @@ struct SystemDriver create_zybo_system();
 
 int test_zybo_i2c();
 int test_zybo_mio7_led_and_system();
+int test_zybo_pwm_inputs();
 
 #endif
diff --git a/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo_tests.c b/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo_tests.c
index 7ec8c2ed5..4cf1ae4d8 100644
--- a/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo_tests.c
+++ b/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo_tests.c
@@ -70,4 +70,33 @@ int test_zybo_i2c() {
   return 0;
 }
 
+/**
+ * Test for the PWMInputDriver.
+ *
+ * Instructions:
+ * 1) Connect the quad Zybo board to computer using USB.
+ * 2) Move jump on Zybo board to use JTAG instead of SD.
+ * 3) Turn on Zybo board and turn on Spektrum handheld controller.
+ *   - Verify receiver on quad pairs with controller (orange LED should turn on)
+ * 3) Place breakpoint somewhere in the while loop of this function.
+ * 4) Set the RUN_TESTS macro in main.c
+ * 5) Uncomment only this test in main.c
+ * 6) Debug main.
+ * 7) Observe the values of pwm_inputs in debugger chaning as you use the
+ *    Spektrum RC controller.
+ */
+int test_zybo_pwm_inputs() {
+  struct PWMInputDriver pwm_inputs = create_zybo_pwm_inputs();
+  pwm_inputs.reset(&pwm_inputs);
+
+  unsigned long pwms[6];
+  while (1) {
+    int i;
+    for (i = 0; i < 6; i += 1) {
+      pwm_inputs.read(&pwm_inputs, i, &pwms[i]);
+    }
+    int temp = 0;
+  }
+}
+
 
diff --git a/quad/xsdk_workspace/modular_quad_pid/src/main.c b/quad/xsdk_workspace/modular_quad_pid/src/main.c
index c62e717ed..b0b7ccf45 100644
--- a/quad/xsdk_workspace/modular_quad_pid/src/main.c
+++ b/quad/xsdk_workspace/modular_quad_pid/src/main.c
@@ -14,6 +14,7 @@ int setup_hardware(hardware_t *hardware) {
   hardware->global_timer = create_zybo_global_timer();
   hardware->axi_timer = create_zybo_axi_timer();
   hardware->mio7_led = create_zybo_mio7_led();
+  hardware->sys = create_zybo_system();
   return 0;
 }
 
@@ -23,9 +24,9 @@ int main()
   init_platform();
 
 #ifdef RUN_TESTS
-  test_zybo_mio7_led_and_system();
+  //test_zybo_mio7_led_and_system();
   //test_zybo_i2c();
-  //test_zybo_pwm_inputs();
+  test_zybo_pwm_inputs();
   //test_zybo_pwm_outputs();
   //test_zybo_uart();
   //test_zybo_axi_timer();
-- 
GitLab