Skip to content
Snippets Groups Projects
Commit 594e9249 authored by bbartels's avatar bbartels Committed by dawehr
Browse files

wip: implement hardware tests for timers and uart

parent c377f00e
No related branches found
No related tags found
1 merge request!9Abstract the hardware layer
#!/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.")
#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) {
......
......@@ -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;
}
......@@ -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);
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment