Skip to content
Snippets Groups Projects
Commit 98262966 authored by dawehr's avatar dawehr
Browse files

Fixed issue with UART timeout interrupt not firing. Added BENCH_TEST mode for...

Fixed issue with UART timeout interrupt not firing. Added BENCH_TEST mode for testing communication.
parent 3689efc8
No related branches found
No related tags found
No related merge requests found
#!/
import sys
print(sys.version_info)
import serial
if __name__ == '__main__':
data = bytes.fromhex('be040002001c0002000000d80471be5732703f9d16093f8bf7a03d0586ab3d006d3a40c1')
with serial.Serial('/dev/ttyUSB0', 115200) as ser:
ser.write(data)
#!/usr/bin/python
import sys
print(sys.version_info)
import serial
if __name__ == '__main__':
data = bytes.fromhex('be040002001c0002000000d80471be5732703f9d16093f8bf7a03d0586ab3d006d3a40c1')
with serial.Serial('/dev/ttyUSB0', 921600) as ser:
ser.write(data)
#!/bin/bash
# Use the usb port on this machine that you are using for UART
USB_UART=ttyUSB0
MSG="\xbe\x04\x00\x02\x00\x1c\x00\x02\x00\x00\x00\xd8\x04\x71\xbe\x57\x32\x70\x3f\x9d\x16\x09\x3f\x8b\xf7\xa0\x3d\x05\x86\xab\x3d\x00\x6d\x3a\x40\xc1"
#MSG="\xbe\x04\x00\x02\x00\x1c\x00\x02\x00\x00\x00"
#MSG="hello"
echo -en $MSG > /dev/$USB_UART
\ No newline at end of file
#!/bin/bash
# The USB device that you are using for UART
USB_DEV=ttyUSB0
stty -F /dev/$USB_DEV raw speed 115200
#!/usr/bin/python
import sys
print(sys.version_info)
import serial
def create_msg(main_type, subtype, msg_id, data):
msg = bytes()
msg += b'\xBE'
msg += main_type.to_bytes(1, 'little')
msg += subtype.to_bytes(1, 'little')
msg += msg_id.to_bytes(2, 'little')
msg += len(data).to_bytes(2, 'little')
msg += data
checksum = 0
for b in msg:
checksum ^= b
msg += checksum.to_bytes(1, 'little')
return msg
def create_test_packet(size=8):
data = bytes((i % 256 for i in range(size)))
return create_msg(0, 2, 0, data)
def read_packet(ser):
header = ser.read(7)
length = int.from_bytes(header[5:7], byteorder='little')
data = ser.read(length)
checksum = ser.read()
return data
def query_received(ser):
# Send request
query_msg = create_msg(0, 3, 0, b'')
ser.write(query_msg)
ser.flush()
resp = read_packet(ser)
received_str = resp[:-1].decode()
return tuple(map(int, received_str.split(',')))
if __name__ == '__main__':
with serial.Serial('/dev/ttyUSB0', 921600, timeout=5) as ser:
ser.write(create_test_packet(8))
ser.flush()
print(query_received(ser))
#!/usr/bin/python
import sys
print(sys.version_info)
import serial
def create_msg(main_type, subtype, msg_id, data):
msg = bytes()
msg += b'\xBE'
msg += main_type.to_bytes(1, 'little')
msg += subtype.to_bytes(1, 'little')
msg += msg_id.to_bytes(2, 'little')
msg += len(data).to_bytes(2, 'little')
msg += data
checksum = 0
for b in msg:
checksum ^= b
msg += checksum.to_bytes(1, 'little')
return msg
def create_test_packet(size=8):
data = bytes((i % 256 for i in range(size)))
return create_msg(0, 2, 0, data)
def read_packet(ser):
header = ser.read(7)
length = int.from_bytes(header[5:7], byteorder='little')
data = ser.read(length)
checksum = ser.read()
return data
def query_received(ser):
# Send request
query_msg = create_msg(0, 3, 0, b'')
ser.write(query_msg)
ser.flush()
resp = read_packet(ser)
received_str = resp[:-1].decode()
return tuple(map(int, received_str.split(',')))
if __name__ == '__main__':
with serial.Serial('/dev/ttyUSB0', 921600, timeout=5) as ser:
ser.write(create_test_packet(500))
ser.flush()
print(query_received(ser))
......@@ -62,7 +62,7 @@ int initUartComms() {
* Increase the time out value if baud rate is high, decrease it if
* baud rate is low.
*/
XUartPs_SetRecvTimeout(uartInstPtr, 4);
XUartPs_SetRecvTimeout(uartInstPtr, 8);
// Second argument is the number of bytes to trigger an interrupt at
XUartPs_SetFifoThreshold(uartInstPtr, 48);
......@@ -160,6 +160,7 @@ void process_received(modular_structs_t *structs) {
recv_buf_end = unprocessed_size;
restore_interrupts(intr_state);
//XUartPs_SetRecvTimeout(uartInstPtr, 8);
//unsigned char in_fifo = XUartPs_ReadReg(uartInstPtr->Config.BaseAddress, XUARTPS_FIFO_OFFSET);
return;
}
......
......@@ -8,6 +8,8 @@
#include "initialize_components.h"
#include "communication.h"
#define BENCH_TEST
extern int Xil_AssertWait;
int protection_loops(modular_structs_t *structs)
......@@ -59,8 +61,6 @@ int initializeAllComponents(user_input_t * user_input_struct, log_t * log_struct
return -1;
}
uart0_clearFIFOs();
// Initialize I2C controller and start the sensor board
if (initI2C0() == -1) {
return -1;
......@@ -77,9 +77,11 @@ int initializeAllComponents(user_input_t * user_input_struct, log_t * log_struct
//manual flight mode
user_defined_struct->flight_mode = MANUAL_FLIGHT_MODE;
#ifndef BENCH_TEST
// Get the first loop data from accelerometer for the gyroscope to use
if(sensor_init(raw_sensor_struct, sensor_struct) == -1)
return -1;
#endif
return 0;
}
......@@ -16,6 +16,8 @@
#include "send_actuator_commands.h"
#include "update_gui.h"
#define BENCH_TEST
int main()
{
// Structures to be used throughout
......@@ -34,8 +36,10 @@ int main()
return -1;
}
#ifndef BENCH_TEST
// Loops to make sure the quad is responding correctly before starting the control loop
protection_loops(&structs);
#endif
printf("The quad loop is now beginning.\n");
......@@ -45,6 +49,10 @@ int main()
// Processing of loop timer at the beginning of the control loop
timer_start_loop();
// Process all received data
process_received(&structs);
#ifndef BENCH_TEST
// Get the user input and put it into user_input_struct
get_user_input(&(structs.log_struct), &(structs.user_input_struct));
......@@ -66,7 +74,7 @@ int main()
// update the GUI
update_GUI(&(structs.log_struct));
#endif
// Processing of loop timer at the end of the control loop
timer_end_loop(&(structs.log_struct));
......@@ -94,7 +102,13 @@ int main()
if(structs.user_defined_struct.flight_mode == MANUAL_FLIGHT_MODE)
MIO7_led_on();
} while(!kill_condition(&(structs.user_input_struct)));
} while(
#ifndef BENCH_TEST
!kill_condition(&(structs.user_input_struct))
#else
1
#endif
);
pwm_kill();
......
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