From 594e924942496940909c86741f45f5e2a7f91ea2 Mon Sep 17 00:00:00 2001 From: Brendan Bartels <bbartels@iastate.edu> Date: Tue, 14 Mar 2017 19:11:00 -0500 Subject: [PATCH] wip: implement hardware tests for timers and uart --- quad/scripts/test_zybo_uart.py | 24 ++++ .../src/hw_impl_zybo_axi_timer.c | 1 - .../modular_quad_pid/src/hw_impl_zybo_tests.c | 124 ++++++++++++++++-- .../modular_quad_pid/src/hw_impl_zybo_uart.c | 4 +- .../modular_quad_pid/src/main.c | 3 +- 5 files changed, 143 insertions(+), 13 deletions(-) create mode 100755 quad/scripts/test_zybo_uart.py diff --git a/quad/scripts/test_zybo_uart.py b/quad/scripts/test_zybo_uart.py new file mode 100755 index 000000000..0ccd93c66 --- /dev/null +++ b/quad/scripts/test_zybo_uart.py @@ -0,0 +1,24 @@ +#!/usr/local/bin/python3.6 + +import sys +import time + +import serial + +if __name__ == '__main__': + with serial.Serial('/dev/ttyUSB0', 921600, timeout=5) as ser: + ser.reset_input_buffer() + send_bytes = b'sdflouirgaorifa;eofija;ogijasfhluiasflawieufzxcvwe' + ser.write(send_bytes) + print("Sending {} bytes".format(len(send_bytes))) + time.sleep(1) + recv_bytes = bytes() + while ser.in_waiting != 0: + recv_bytes = ser.read(len(send_bytes)) + if recv_bytes == send_bytes: + print(recv_bytes); + print("Test Successful") + else: + print(recv_bytes); + print("Test Failed.") + diff --git a/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo_axi_timer.c b/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo_axi_timer.c index 399c819fa..bbbb5e3a3 100644 --- a/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo_axi_timer.c +++ b/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo_axi_timer.c @@ -1,6 +1,5 @@ #include "hw_impl_zybo.h" -// Apparently, this is number of counts per usec #define PL_CLK_CNTS_PER_USEC 100 int zybo_axi_timer_reset(struct TimerDriver *self) { 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 0bff80a1f..530c5afe0 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 @@ -75,7 +75,7 @@ int test_zybo_i2c() { * * Instructions: * 1) Connect the quad Zybo board to computer using USB. - * 2) Move jump on Zybo board to use JTAG instead of SD. + * 2) Move jumper 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. @@ -100,19 +100,16 @@ int test_zybo_pwm_inputs() { } /** - * Test for the PWMInputDriver. + * Test for the PWMOutputDriver. * * 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. + * 2) Move jumper on Zybo board to use JTAG instead of SD. + * 3) Get an oscilloscope and observe PMOD outputs JE7-JE10 * 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. + * 6) Run main. + * 7) Observe the PWM width of those PMOD pins changing with time */ int test_zybo_pwm_outputs() { struct PWMOutputDriver pwm_outputs = create_zybo_pwm_outputs(); @@ -134,6 +131,115 @@ int test_zybo_pwm_outputs() { } continue; } + return 0; +} + +/** + * Test for the AXI timer, using LEDDriver. + * + * This is essentially a basic "blink" program, using the mio7 LED + * on the Zybo board. + * + * Instructions: + * 1) Connect Zybo board to computer by USB cable. + * 2) Set the RUN_TESTS macro in main.c + * 3) Uncomment only this test in main.c + * 4) Run main.c + * 5) Observe MIO7 LED on board blinking at 1 second intervals. + */ +int test_zybo_axi_timer() { + struct TimerDriver axi = create_zybo_axi_timer(); + struct LEDDriver led = create_zybo_mio7_led(); + axi.reset(&axi); + led.reset(&led); + + unsigned long time; + + while (1) { + axi.restart(&axi); + time = 0; + while (time < 1000000) { + axi.read(&axi, &time); + } + led.turn_off(&led); + while (time < 2000000) { + axi.read(&axi, &time); + } + led.turn_on(&led); + } +} + +/** + * Test for the Global timer, using LEDDriver. + * + * This is essentially a basic "blink" program, using the mio7 LED + * on the Zybo board. + * + * Instructions: + * 1) Connect Zybo board to computer by USB cable. + * 2) Set the RUN_TESTS macro in main.c + * 3) Uncomment only this test in main.c + * 4) Run main.c + * 5) Observe MIO7 LED on board blinking at 1 second intervals. + */ +int test_zybo_global_timer() { + struct TimerDriver global = create_zybo_global_timer(); + struct LEDDriver led = create_zybo_mio7_led(); + global.reset(&global); + led.reset(&led); + + unsigned long time; + + while (1) { + global.restart(&global); + time = 0; + while (time < 1000000) { + global.read(&global, &time); + } + led.turn_off(&led); + while (time < 2000000) { + global.read(&global, &time); + } + led.turn_on(&led); + } +} + +/** + * Test for the UARTDriver. + * + * Instructions: + * 1) Connect Zybo board to computer by USB cable. + * 2) Get a FTDI Basic Sparkfun board in order to connect the UART pins + * on the Zybo to the computer by USB. + * - Zybo PMOD JC2 (TX) <-> Sparkfun Board RX + * - Zybo PMOD JC3 (RX) <-> sparkfun Board Tx + * - Zybo PMOD JC5 (GND) <-> Sparkfun Board GDN + * 2) Set the RUN_TESTS macro in main.c + * 3) Uncomment only this test in main.c + * 4) Run main.c + * 5) Execute quad/scripts/test_zybo_uart.py + * - Observe test results on terminal + * - You might be able to see LED MIO7 blink when it receives bytes + */ +int test_zybo_uart() { + struct UARTDriver uart = create_zybo_uart(); + struct LEDDriver led = create_zybo_mio7_led(); + uart.reset(&uart); + led.reset(&led); + + unsigned char c; + while (1) { + if (uart.read(&uart, &c)) { + // read failed + led.turn_off(&led); + } else { + // read successful + led.turn_on(&led); + uart.write(&uart, c); + } + } + + return 0; } diff --git a/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo_uart.c b/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo_uart.c index 58594ab6f..18c17af0a 100644 --- a/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo_uart.c +++ b/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo_uart.c @@ -75,7 +75,7 @@ int zybo_uart_write(struct UARTDriver *self, unsigned char c) {\ } int zybo_uart_read(struct UARTDriver *self, unsigned char *c) { - if (!queue_remove(&queue, c)) return -1; + if (queue_remove(&queue, c)) return -1; else return 0; } @@ -209,7 +209,7 @@ void uart_interrupt_handler(XUartPs *InstancePtr) { u32 CsrRegister = XUartPs_ReadReg(InstancePtr->Config.BaseAddress, XUARTPS_SR_OFFSET); - while (0 == (CsrRegister & XUARTPS_SR_RXEMPTY) && !queue_full(&queue)) { + while (0 == (CsrRegister & XUARTPS_SR_RXEMPTY)) { u8 byte = XUartPs_ReadReg(InstancePtr->Config.BaseAddress, XUARTPS_FIFO_OFFSET); queue_add(&queue, byte); CsrRegister = XUartPs_ReadReg(InstancePtr->Config.BaseAddress, XUARTPS_SR_OFFSET); diff --git a/quad/xsdk_workspace/modular_quad_pid/src/main.c b/quad/xsdk_workspace/modular_quad_pid/src/main.c index c49e2bed8..03612577d 100644 --- a/quad/xsdk_workspace/modular_quad_pid/src/main.c +++ b/quad/xsdk_workspace/modular_quad_pid/src/main.c @@ -27,9 +27,10 @@ int main() //test_zybo_mio7_led_and_system(); //test_zybo_i2c(); //test_zybo_pwm_inputs(); - test_zybo_pwm_outputs(); + //test_zybo_pwm_outputs(); //test_zybo_uart(); //test_zybo_axi_timer(); + test_zybo_uart(); return 0; #endif -- GitLab