Skip to content
Snippets Groups Projects
Commit 57dfb34d authored by bbartels's avatar bbartels
Browse files

Merge branch 'master' of git.ece.iastate.edu:danc/MicroCART_17-18

parents 44beab39 9ae0df84
No related branches found
No related tags found
No related merge requests found
Showing
with 132 additions and 143 deletions
No preview for this file type
text data bss dec hex filename text data bss dec hex filename
165412 68080 119152504 119385996 71daf8c comm_dev.elf 166044 68080 119152840 119386964 71db354 comm_dev.elf
No preview for this file type
...@@ -17,23 +17,22 @@ src/initialize_components.d: ../src/initialize_components.c \ ...@@ -17,23 +17,22 @@ src/initialize_components.d: ../src/initialize_components.c \
../src/stringBuilder.h ../../system_bsp/ps7_cortexa9_0/include/xscugic.h \ ../src/stringBuilder.h ../../system_bsp/ps7_cortexa9_0/include/xscugic.h \
../../system_bsp/ps7_cortexa9_0/include/xscugic_hw.h \ ../../system_bsp/ps7_cortexa9_0/include/xscugic_hw.h \
../../system_bsp/ps7_cortexa9_0/include/xil_exception.h \ ../../system_bsp/ps7_cortexa9_0/include/xil_exception.h \
../../system_bsp/ps7_cortexa9_0/include/sleep.h \ ../src/new_comm.h \
../../system_bsp/ps7_cortexa9_0/include/xil_exception.h \
../src/mio7_led.h ../../system_bsp/ps7_cortexa9_0/include/xgpiops.h \
../../system_bsp/ps7_cortexa9_0/include/xgpiops_hw.h \
../../system_bsp/ps7_cortexa9_0/include/sleep.h ../src/commands.h \
../../system_bsp/ps7_cortexa9_0/include/xtime_l.h \ ../../system_bsp/ps7_cortexa9_0/include/xtime_l.h \
../../system_bsp/ps7_cortexa9_0/include/xtmrctr.h \ ../../system_bsp/ps7_cortexa9_0/include/xtmrctr.h \
../../system_bsp/ps7_cortexa9_0/include/xtmrctr_l.h \ ../../system_bsp/ps7_cortexa9_0/include/xtmrctr_l.h \
../src/control_algorithm.h ../src/sensor_processing.h ../src/sensor.h \ ../src/control_algorithm.h ../src/sensor_processing.h ../src/sensor.h \
../src/user_input.h ../src/util.h \ ../src/user_input.h ../src/util.h ../src/controllers.h \
../../system_bsp/ps7_cortexa9_0/include/xgpiops.h \ ../src/quadposition.h ../src/iic_mpu9150_utils.h \
../../system_bsp/ps7_cortexa9_0/include/xgpiops_hw.h \
../src/controllers.h ../src/quadposition.h ../src/iic_mpu9150_utils.h \
../../system_bsp/ps7_cortexa9_0/include/xbasic_types.h \ ../../system_bsp/ps7_cortexa9_0/include/xbasic_types.h \
../../system_bsp/ps7_cortexa9_0/include/xiicps.h \ ../../system_bsp/ps7_cortexa9_0/include/xiicps.h \
../../system_bsp/ps7_cortexa9_0/include/xiicps_hw.h \ ../../system_bsp/ps7_cortexa9_0/include/xiicps_hw.h \
../src/packet_processing.h ../src/conversion.h ../src/platform.h \ ../src/packet_processing.h ../src/conversion.h ../src/platform.h \
../src/platform_config.h ../src/communication.h ../src/commands.h \ ../src/platform_config.h ../src/communication.h
../src/new_comm.h \
../../system_bsp/ps7_cortexa9_0/include/xil_exception.h \
../src/mio7_led.h
../src/initialize_components.h: ../src/initialize_components.h:
...@@ -81,8 +80,20 @@ src/initialize_components.d: ../src/initialize_components.c \ ...@@ -81,8 +80,20 @@ src/initialize_components.d: ../src/initialize_components.c \
../../system_bsp/ps7_cortexa9_0/include/xil_exception.h: ../../system_bsp/ps7_cortexa9_0/include/xil_exception.h:
../src/new_comm.h:
../../system_bsp/ps7_cortexa9_0/include/xil_exception.h:
../src/mio7_led.h:
../../system_bsp/ps7_cortexa9_0/include/xgpiops.h:
../../system_bsp/ps7_cortexa9_0/include/xgpiops_hw.h:
../../system_bsp/ps7_cortexa9_0/include/sleep.h: ../../system_bsp/ps7_cortexa9_0/include/sleep.h:
../src/commands.h:
../../system_bsp/ps7_cortexa9_0/include/xtime_l.h: ../../system_bsp/ps7_cortexa9_0/include/xtime_l.h:
../../system_bsp/ps7_cortexa9_0/include/xtmrctr.h: ../../system_bsp/ps7_cortexa9_0/include/xtmrctr.h:
...@@ -99,10 +110,6 @@ src/initialize_components.d: ../src/initialize_components.c \ ...@@ -99,10 +110,6 @@ src/initialize_components.d: ../src/initialize_components.c \
../src/util.h: ../src/util.h:
../../system_bsp/ps7_cortexa9_0/include/xgpiops.h:
../../system_bsp/ps7_cortexa9_0/include/xgpiops_hw.h:
../src/controllers.h: ../src/controllers.h:
../src/quadposition.h: ../src/quadposition.h:
...@@ -124,11 +131,3 @@ src/initialize_components.d: ../src/initialize_components.c \ ...@@ -124,11 +131,3 @@ src/initialize_components.d: ../src/initialize_components.c \
../src/platform_config.h: ../src/platform_config.h:
../src/communication.h: ../src/communication.h:
../src/commands.h:
../src/new_comm.h:
../../system_bsp/ps7_cortexa9_0/include/xil_exception.h:
../src/mio7_led.h:
No preview for this file type
...@@ -16,23 +16,24 @@ src/main.d: ../src/main.c ../src/timer.h ../src/log_data.h ../src/PID.h \ ...@@ -16,23 +16,24 @@ src/main.d: ../src/main.c ../src/timer.h ../src/log_data.h ../src/PID.h \
../src/stringBuilder.h ../../system_bsp/ps7_cortexa9_0/include/xscugic.h \ ../src/stringBuilder.h ../../system_bsp/ps7_cortexa9_0/include/xscugic.h \
../../system_bsp/ps7_cortexa9_0/include/xscugic_hw.h \ ../../system_bsp/ps7_cortexa9_0/include/xscugic_hw.h \
../../system_bsp/ps7_cortexa9_0/include/xil_exception.h \ ../../system_bsp/ps7_cortexa9_0/include/xil_exception.h \
../../system_bsp/ps7_cortexa9_0/include/sleep.h \ ../src/new_comm.h \
../../system_bsp/ps7_cortexa9_0/include/xil_exception.h \
../src/mio7_led.h ../../system_bsp/ps7_cortexa9_0/include/xgpiops.h \
../../system_bsp/ps7_cortexa9_0/include/xgpiops_hw.h \
../../system_bsp/ps7_cortexa9_0/include/sleep.h ../src/commands.h \
../../system_bsp/ps7_cortexa9_0/include/xtime_l.h \ ../../system_bsp/ps7_cortexa9_0/include/xtime_l.h \
../../system_bsp/ps7_cortexa9_0/include/xtmrctr.h \ ../../system_bsp/ps7_cortexa9_0/include/xtmrctr.h \
../../system_bsp/ps7_cortexa9_0/include/xtmrctr_l.h \ ../../system_bsp/ps7_cortexa9_0/include/xtmrctr_l.h \
../src/initialize_components.h ../src/control_algorithm.h \ ../src/initialize_components.h ../src/control_algorithm.h \
../src/sensor_processing.h ../src/sensor.h ../src/user_input.h \ ../src/sensor_processing.h ../src/sensor.h ../src/user_input.h \
../src/util.h ../../system_bsp/ps7_cortexa9_0/include/xgpiops.h \ ../src/util.h ../src/controllers.h ../src/quadposition.h \
../../system_bsp/ps7_cortexa9_0/include/xgpiops_hw.h \ ../src/iic_mpu9150_utils.h \
../src/controllers.h ../src/quadposition.h ../src/iic_mpu9150_utils.h \
../../system_bsp/ps7_cortexa9_0/include/xbasic_types.h \ ../../system_bsp/ps7_cortexa9_0/include/xbasic_types.h \
../../system_bsp/ps7_cortexa9_0/include/xiicps.h \ ../../system_bsp/ps7_cortexa9_0/include/xiicps.h \
../../system_bsp/ps7_cortexa9_0/include/xiicps_hw.h \ ../../system_bsp/ps7_cortexa9_0/include/xiicps_hw.h \
../src/packet_processing.h ../src/conversion.h ../src/platform.h \ ../src/packet_processing.h ../src/conversion.h ../src/platform.h \
../src/platform_config.h ../src/actuator_command_processing.h \ ../src/platform_config.h ../src/actuator_command_processing.h \
../src/send_actuator_commands.h ../src/update_gui.h ../src/new_comm.h \ ../src/send_actuator_commands.h ../src/update_gui.h
../../system_bsp/ps7_cortexa9_0/include/xil_exception.h \
../src/mio7_led.h ../src/commands.h
../src/timer.h: ../src/timer.h:
...@@ -78,8 +79,20 @@ src/main.d: ../src/main.c ../src/timer.h ../src/log_data.h ../src/PID.h \ ...@@ -78,8 +79,20 @@ src/main.d: ../src/main.c ../src/timer.h ../src/log_data.h ../src/PID.h \
../../system_bsp/ps7_cortexa9_0/include/xil_exception.h: ../../system_bsp/ps7_cortexa9_0/include/xil_exception.h:
../src/new_comm.h:
../../system_bsp/ps7_cortexa9_0/include/xil_exception.h:
../src/mio7_led.h:
../../system_bsp/ps7_cortexa9_0/include/xgpiops.h:
../../system_bsp/ps7_cortexa9_0/include/xgpiops_hw.h:
../../system_bsp/ps7_cortexa9_0/include/sleep.h: ../../system_bsp/ps7_cortexa9_0/include/sleep.h:
../src/commands.h:
../../system_bsp/ps7_cortexa9_0/include/xtime_l.h: ../../system_bsp/ps7_cortexa9_0/include/xtime_l.h:
../../system_bsp/ps7_cortexa9_0/include/xtmrctr.h: ../../system_bsp/ps7_cortexa9_0/include/xtmrctr.h:
...@@ -98,10 +111,6 @@ src/main.d: ../src/main.c ../src/timer.h ../src/log_data.h ../src/PID.h \ ...@@ -98,10 +111,6 @@ src/main.d: ../src/main.c ../src/timer.h ../src/log_data.h ../src/PID.h \
../src/util.h: ../src/util.h:
../../system_bsp/ps7_cortexa9_0/include/xgpiops.h:
../../system_bsp/ps7_cortexa9_0/include/xgpiops_hw.h:
../src/controllers.h: ../src/controllers.h:
../src/quadposition.h: ../src/quadposition.h:
...@@ -127,11 +136,3 @@ src/main.d: ../src/main.c ../src/timer.h ../src/log_data.h ../src/PID.h \ ...@@ -127,11 +136,3 @@ src/main.d: ../src/main.c ../src/timer.h ../src/log_data.h ../src/PID.h \
../src/send_actuator_commands.h: ../src/send_actuator_commands.h:
../src/update_gui.h: ../src/update_gui.h:
../src/new_comm.h:
../../system_bsp/ps7_cortexa9_0/include/xil_exception.h:
../src/mio7_led.h:
../src/commands.h:
No preview for this file type
No preview for this file type
...@@ -16,7 +16,11 @@ src/timer.d: ../src/timer.c ../src/timer.h ../src/log_data.h ../src/PID.h \ ...@@ -16,7 +16,11 @@ src/timer.d: ../src/timer.c ../src/timer.h ../src/log_data.h ../src/PID.h \
../src/stringBuilder.h ../../system_bsp/ps7_cortexa9_0/include/xscugic.h \ ../src/stringBuilder.h ../../system_bsp/ps7_cortexa9_0/include/xscugic.h \
../../system_bsp/ps7_cortexa9_0/include/xscugic_hw.h \ ../../system_bsp/ps7_cortexa9_0/include/xscugic_hw.h \
../../system_bsp/ps7_cortexa9_0/include/xil_exception.h \ ../../system_bsp/ps7_cortexa9_0/include/xil_exception.h \
../../system_bsp/ps7_cortexa9_0/include/sleep.h \ ../src/new_comm.h \
../../system_bsp/ps7_cortexa9_0/include/xil_exception.h \
../src/mio7_led.h ../../system_bsp/ps7_cortexa9_0/include/xgpiops.h \
../../system_bsp/ps7_cortexa9_0/include/xgpiops_hw.h \
../../system_bsp/ps7_cortexa9_0/include/sleep.h ../src/commands.h \
../../system_bsp/ps7_cortexa9_0/include/xtime_l.h \ ../../system_bsp/ps7_cortexa9_0/include/xtime_l.h \
../../system_bsp/ps7_cortexa9_0/include/xtmrctr.h \ ../../system_bsp/ps7_cortexa9_0/include/xtmrctr.h \
../../system_bsp/ps7_cortexa9_0/include/xtmrctr_l.h ../../system_bsp/ps7_cortexa9_0/include/xtmrctr_l.h
...@@ -65,8 +69,20 @@ src/timer.d: ../src/timer.c ../src/timer.h ../src/log_data.h ../src/PID.h \ ...@@ -65,8 +69,20 @@ src/timer.d: ../src/timer.c ../src/timer.h ../src/log_data.h ../src/PID.h \
../../system_bsp/ps7_cortexa9_0/include/xil_exception.h: ../../system_bsp/ps7_cortexa9_0/include/xil_exception.h:
../src/new_comm.h:
../../system_bsp/ps7_cortexa9_0/include/xil_exception.h:
../src/mio7_led.h:
../../system_bsp/ps7_cortexa9_0/include/xgpiops.h:
../../system_bsp/ps7_cortexa9_0/include/xgpiops_hw.h:
../../system_bsp/ps7_cortexa9_0/include/sleep.h: ../../system_bsp/ps7_cortexa9_0/include/sleep.h:
../src/commands.h:
../../system_bsp/ps7_cortexa9_0/include/xtime_l.h: ../../system_bsp/ps7_cortexa9_0/include/xtime_l.h:
../../system_bsp/ps7_cortexa9_0/include/xtmrctr.h: ../../system_bsp/ps7_cortexa9_0/include/xtmrctr.h:
......
No preview for this file type
...@@ -344,6 +344,11 @@ struct MessageType MessageTypes[MAX_TYPE] = ...@@ -344,6 +344,11 @@ struct MessageType MessageTypes[MAX_TYPE] =
} }
} }
}, },
// HERE FOR SPACING
{
0x02,
{}
},
// RESPONSE // RESPONSE
{ {
// Message Type ID // Message Type ID
...@@ -474,7 +479,14 @@ int debug(unsigned char *packet, int dataLen, modular_structs_t *structs) ...@@ -474,7 +479,14 @@ int debug(unsigned char *packet, int dataLen, modular_structs_t *structs)
control algorithm in order to get this to work. */ control algorithm in order to get this to work. */
int update(unsigned char *packet, int dataLen, modular_structs_t *structs) int update(unsigned char *packet, int dataLen, modular_structs_t *structs)
{ {
//MIO7_led_on(); static int on = 0;
if (on) {
MIO7_led_off();
on = 1 - on;
}else {
MIO7_led_on();
on = 1 - on;
}
processUpdate(packet, &(structs->raw_sensor_struct.currentQuadPosition)); processUpdate(packet, &(structs->raw_sensor_struct.currentQuadPosition));
return 0; return 0;
} }
......
...@@ -101,7 +101,10 @@ int initializeAllComponents(user_input_t * user_input_struct, log_t * log_struct ...@@ -101,7 +101,10 @@ int initializeAllComponents(user_input_t * user_input_struct, log_t * log_struct
return -1; return -1;
} }
// Initialize loop timers // Initialize loop timers
timer_init(); if (timer_init()) {
return -1;
}
return 0; return 0;
// Initialize I2C controller and start the sensor board // Initialize I2C controller and start the sensor board
......
...@@ -68,7 +68,7 @@ int main() ...@@ -68,7 +68,7 @@ int main()
// // Process the commands going to the actuators // // Process the commands going to the actuators
// actuator_command_processing(&(structs.log_struct), &(structs.user_input_struct), &(structs.raw_actuator_struct), &(structs.actuator_command_struct)); // actuator_command_processing(&(structs.log_struct), &(structs.user_input_struct), &(structs.raw_actuator_struct), &(structs.actuator_command_struct));
// //
// // send the actuator commands // // send the 004\000\002actuator commands
// send_actuator_commands(&(structs.log_struct), &(structs.actuator_command_struct)); // send_actuator_commands(&(structs.log_struct), &(structs.actuator_command_struct));
// //
// // update the GUI // // update the GUI
......
...@@ -11,11 +11,13 @@ ...@@ -11,11 +11,13 @@
#define COMM_INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID #define COMM_INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID
#define COMM_UART_INT_IRQ_ID XPAR_PS7_UART_0_INTR//XPAR_XUARTPS_0_INTR #define COMM_UART_INT_IRQ_ID XPAR_PS7_UART_0_INTR//XPAR_XUARTPS_0_INTR
#define BAUD_RATE 115200 #define BAUD_RATE 921600
// Maximum number of bytes to be received within our loop time, plus 64 for a little buffer // Maximum number of bytes to be received within our loop time,
// plus the maximum packet size that might be carried over from the last call,
// plus 128 for a little buffer
// (bit/s) * (seconds) / (10 bits / byte for UART) // (bit/s) * (seconds) / (10 bits / byte for UART)
#define UART_BUF_SIZE (((BAUD_RATE * (DESIRED_USEC_PER_LOOP / 1000) / 1000) / 10) + 64)
#define MAX_PACKET_SIZE 256 #define MAX_PACKET_SIZE 256
#define UART_BUF_SIZE (((BAUD_RATE * (DESIRED_USEC_PER_LOOP / 1000) / 1000) / 10) + MAX_PACKET_SIZE + 128)
// Declaration of interrupt handler // Declaration of interrupt handler
void Handler(void *CallBackRef, u32 Event, unsigned int EventData); void Handler(void *CallBackRef, u32 Event, unsigned int EventData);
...@@ -24,11 +26,9 @@ void Handler(void *CallBackRef, u32 Event, unsigned int EventData); ...@@ -24,11 +26,9 @@ void Handler(void *CallBackRef, u32 Event, unsigned int EventData);
static XUartPs* uartInstPtr; static XUartPs* uartInstPtr;
static u8 recvBuf[UART_BUF_SIZE]; static u8 recvBuf[UART_BUF_SIZE];
static volatile size_t received_in_buf = 0; static volatile size_t recv_buf_begin = 0; // Index of start of valid packets in buffer
static volatile size_t recv_buf_end = 0; // One past end of valid packets in buffer
static u8 secondaryBuf[UART_BUF_SIZE + MAX_PACKET_SIZE];
static volatile size_t secondaryEnd = 0; // Index of start of valid data in the secondary buffer
static size_t secondaryBegin = 0; // Index of one past end of valid data in the secondary buffer
int initUartComms() { int initUartComms() {
uartInstPtr = uart0_init(COMM_UART_DEVICE_ID, BAUD_RATE); uartInstPtr = uart0_init(COMM_UART_DEVICE_ID, BAUD_RATE);
...@@ -39,7 +39,7 @@ int initUartComms() { ...@@ -39,7 +39,7 @@ int initUartComms() {
uart0_clearFIFOs(); uart0_clearFIFOs();
if (uart0_int_init(COMM_UART_INT_IRQ_ID, (Xil_ExceptionHandler) uartInterruptHandler) != XST_SUCCESS) { if (uart0_int_init(COMM_UART_INT_IRQ_ID, (Xil_ExceptionHandler) uart_interrupt_handler) != XST_SUCCESS) {
return -1; return -1;
} }
...@@ -58,7 +58,7 @@ int initUartComms() { ...@@ -58,7 +58,7 @@ int initUartComms() {
/* /*
* Set the receiver timeout. If it is noDidn'tt set, and the last few bytes * Set the receiver timeout. If it is not set, and the last few bytes
* of data do not trigger the over-water or full interrupt, the bytes * of data do not trigger the over-water or full interrupt, the bytes
* will not be received. By default it is disabled. * will not be received. By default it is disabled.
* Timeout duration = RecvTimeout x 4 x Bit Period. 0 disables the * Timeout duration = RecvTimeout x 4 x Bit Period. 0 disables the
...@@ -71,13 +71,10 @@ int initUartComms() { ...@@ -71,13 +71,10 @@ int initUartComms() {
XUartPs_SetRecvTimeout(uartInstPtr, 4); XUartPs_SetRecvTimeout(uartInstPtr, 4);
// Second argument is the number of bytes to trigger an interrupt at // Second argument is the number of bytes to trigger an interrupt at
XUartPs_SetFifoThreshold(uartInstPtr, 12); XUartPs_SetFifoThreshold(uartInstPtr, 48);
//XUartPs_Recv(uartInstPtr, recvBuf, UART_BUF_SIZE);
return 0; return 0;
} }
// TODO: Be consistent with underscore_names or camelCase
int process_packet(unsigned char* packet, modular_structs_t *structs) { int process_packet(unsigned char* packet, modular_structs_t *structs) {
metadata_t meta_data; metadata_t meta_data;
...@@ -106,23 +103,30 @@ int process_packet(unsigned char* packet, modular_structs_t *structs) { ...@@ -106,23 +103,30 @@ int process_packet(unsigned char* packet, modular_structs_t *structs) {
(* (MessageTypes[meta_data.msg_type].subtypes[meta_data.msg_subtype].functionPtr))(packet_data, meta_data.data_len, structs); (* (MessageTypes[meta_data.msg_type].subtypes[meta_data.msg_subtype].functionPtr))(packet_data, meta_data.data_len, structs);
return 0; return 0;
} }
void parse_available(modular_structs_t *structs) { void parse_available(modular_structs_t *structs) {
// Discard all data before packet begin character
while (secondaryBegin < secondaryEnd && secondaryBuf[secondaryBegin] != BEGIN_CHAR) {
secondaryBegin++;
}
// Minimum size of a packet (header + checksum) // Minimum size of a packet (header + checksum)
int min_packet_size = sizeof(metadata_t) + 1; int min_packet_size = 8;
// TODO: Loop limit? // TODO: Loop limits?
while (secondaryEnd - secondaryBegin >= min_packet_size) { while (recv_buf_end - recv_buf_begin >= min_packet_size) {
unsigned char* packet_header = secondaryBuf + secondaryBegin; // Discard all data before packet begin character
while (recv_buf_begin < recv_buf_end && recvBuf[recv_buf_begin] != BEGIN_CHAR) {
recv_buf_begin++;
}
// If, after discarding everything before header, not enough is left, don't parse
if (recv_buf_end - recv_buf_begin < min_packet_size) {
break;
}
unsigned char* packet_header = recvBuf + recv_buf_begin;
// Read out the payload size information from the header
size_t packet_len = (packet_header[6] << 8) | (packet_header[5]); size_t packet_len = (packet_header[6] << 8) | (packet_header[5]);
if (secondaryEnd - secondaryBegin >= min_packet_size + packet_len) { // Determine if we have received the entire packet. If so, process it.
process_packet(secondaryBuf + secondaryBegin, structs); if (recv_buf_end - recv_buf_begin >= min_packet_size + packet_len) {
secondaryBegin += min_packet_size + packet_len; process_packet(recvBuf + recv_buf_begin, structs);
recv_buf_begin += min_packet_size + packet_len;
} }
else { else {
// Not enough data for a packet // Not enough data for a packet
...@@ -131,6 +135,9 @@ void parse_available(modular_structs_t *structs) { ...@@ -131,6 +135,9 @@ void parse_available(modular_structs_t *structs) {
} }
} }
/*
* Temporarily disables interrupts and returns the interrupt state, for restoring them
*/
u32 disable_interrupts() { u32 disable_interrupts() {
u32 ImrRegister; u32 ImrRegister;
ImrRegister = XUartPs_ReadReg(uartInstPtr->Config.BaseAddress, XUARTPS_IMR_OFFSET); ImrRegister = XUartPs_ReadReg(uartInstPtr->Config.BaseAddress, XUARTPS_IMR_OFFSET);
...@@ -138,50 +145,32 @@ u32 disable_interrupts() { ...@@ -138,50 +145,32 @@ u32 disable_interrupts() {
return ImrRegister; return ImrRegister;
} }
/*
* Restores the interrupt state, saved from disable_interrupts
*/
void restore_interrupts(u32 intr_state) { void restore_interrupts(u32 intr_state) {
XUartPs_WriteReg(uartInstPtr->Config.BaseAddress, XUARTPS_IER_OFFSET, intr_state); XUartPs_WriteReg(uartInstPtr->Config.BaseAddress, XUARTPS_IER_OFFSET, intr_state);
} }
void process_received(modular_structs_t *structs) { void process_received(modular_structs_t *structs) {
// // Move unprocessed bytes to front of secondary buffer // Parse as many packets as possible
// size_t unprocessed_size = secondaryEnd - secondaryBegin;
// memmove(secondaryBuf, secondaryBuf + secondaryBegin, unprocessed_size);
// secondaryBegin = 0;
// secondaryEnd = unprocessed_size;
//
// // Temporarily disable the receive interrupt
// XUartPs_Recv(uartInstPtr, recvBuf, 0);
// if (received_in_buf) {
// volatile int a = 3;
// }
// // Put received data into secondary buffer
// memcpy(secondaryBuf + secondaryEnd, recvBuf, received_in_buf);
//
// secondaryEnd += received_in_buf;
// received_in_buf = 0;
// // Re-enable interrupts and process copied data
// XUartPs_Recv(uartInstPtr, recvBuf, UART_BUF_SIZE);
if (secondaryEnd != 0) {
volatile int asdasdf = 3;
MIO7_led_off();
}
parse_available(structs); parse_available(structs);
// Disable interrupts while moving data around
u32 intr_state = disable_interrupts(); u32 intr_state = disable_interrupts();
// Move unprocessed bytes to front of secondary buffer // Move unprocessed bytes to front of secondary buffer
size_t unprocessed_size = secondaryEnd - secondaryBegin; size_t unprocessed_size = recv_buf_end - recv_buf_begin;
memmove(secondaryBuf, secondaryBuf + secondaryBegin, unprocessed_size); memmove(recvBuf, recvBuf + recv_buf_begin, unprocessed_size);
secondaryBegin = 0; recv_buf_begin = 0;
secondaryEnd = unprocessed_size; recv_buf_end = unprocessed_size;
restore_interrupts(intr_state); restore_interrupts(intr_state);
//unsigned char in_fifo = XUartPs_ReadReg(uartInstPtr->Config.BaseAddress, XUARTPS_FIFO_OFFSET); //unsigned char in_fifo = XUartPs_ReadReg(uartInstPtr->Config.BaseAddress, XUARTPS_FIFO_OFFSET);
return; return;
} }
void uartInterruptHandler(XUartPs *InstancePtr) { void uart_interrupt_handler(XUartPs *InstancePtr) {
u32 IsrStatus; u32 IsrStatus;
/* /*
...@@ -194,19 +183,18 @@ void uartInterruptHandler(XUartPs *InstancePtr) { ...@@ -194,19 +183,18 @@ void uartInterruptHandler(XUartPs *InstancePtr) {
IsrStatus &= XUartPs_ReadReg(InstancePtr->Config.BaseAddress, IsrStatus &= XUartPs_ReadReg(InstancePtr->Config.BaseAddress,
XUARTPS_ISR_OFFSET); XUARTPS_ISR_OFFSET);
u32 CsrRegister;
/* /*
* Read the Channel Status Register to determine if there is any data in * Read the Channel Status Register to determine if there is any data in
* the RX FIFO * the RX FIFO
*/ */
CsrRegister = XUartPs_ReadReg(InstancePtr->Config.BaseAddress,
u32 CsrRegister = XUartPs_ReadReg(InstancePtr->Config.BaseAddress,
XUARTPS_SR_OFFSET); XUARTPS_SR_OFFSET);
while (0 == (CsrRegister & XUARTPS_SR_RXEMPTY)) { while (0 == (CsrRegister & XUARTPS_SR_RXEMPTY) && recv_buf_end <= UART_BUF_SIZE) {
secondaryBuf[secondaryEnd] = XUartPs_ReadReg(InstancePtr->Config.BaseAddress, XUARTPS_FIFO_OFFSET); recvBuf[recv_buf_end] = XUartPs_ReadReg(InstancePtr->Config.BaseAddress, XUARTPS_FIFO_OFFSET);
secondaryEnd += 1; recv_buf_end += 1;
CsrRegister = XUartPs_ReadReg(InstancePtr->Config.BaseAddress, XUARTPS_SR_OFFSET); CsrRegister = XUartPs_ReadReg(InstancePtr->Config.BaseAddress, XUARTPS_SR_OFFSET);
MIO7_led_on();
} }
// Clear the interrupt status. // Clear the interrupt status.
...@@ -214,33 +202,3 @@ void uartInterruptHandler(XUartPs *InstancePtr) { ...@@ -214,33 +202,3 @@ void uartInterruptHandler(XUartPs *InstancePtr) {
IsrStatus); IsrStatus);
} }
/**************************************************************************/
/**
*
* This function is the handler which performs processing to handle data events
* from the device. It is called from an interrupt context. so the amount of
* processing should be minimal.
*
* This handler provides an example of how to handle data for the device and
* is application specific.
*
* @param CallBackRef contains a callback reference from the driver,
* in this case it is the instance pointer for the XUartPs driver.
* @param Event contains the specific kind of event that has occurred.
* @param EventData contains the number of bytes sent or received for sent
* and receive events.
*
* @return None.
*
* @note None.
*
***************************************************************************/
void Handler(void *CallBackRef, u32 Event, unsigned int EventData)
{
/* data has been received */
if (Event == XUARTPS_EVENT_RECV_DATA || Event == XUARTPS_EVENT_RECV_TOUT
|| Event == XUARTPS_IXR_RXOVR || Event == XUARTPS_IXR_RXFULL) {
received_in_buf = EventData;
}
}
...@@ -21,6 +21,6 @@ ...@@ -21,6 +21,6 @@
int initUartComms(); int initUartComms();
void process_received(modular_structs_t *structs); void process_received(modular_structs_t *structs);
void uartInterruptHandler(XUartPs *InstancePtr); void uart_interrupt_handler(XUartPs *InstancePtr);
#endif /* NEW_COMM_H_ */ #endif /* NEW_COMM_H_ */
...@@ -18,9 +18,7 @@ int timer_init() ...@@ -18,9 +18,7 @@ int timer_init()
{ {
// using a axi_timer core because we've had problems with the Global Timer // using a axi_timer core because we've had problems with the Global Timer
XTmrCtr_Initialize(&axi_timer, XPAR_AXI_TIMER_0_DEVICE_ID); return XTmrCtr_Initialize(&axi_timer, XPAR_AXI_TIMER_0_DEVICE_ID);
return 0;
} }
int timer_start_loop() int timer_start_loop()
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#ifndef TYPE_DEF_H_ #ifndef TYPE_DEF_H_
#define TYPE_DEF_H_ #define TYPE_DEF_H_
#include <stdint.h>
/** /**
* @brief * @brief
* The modes for autonomous and manual flight. * The modes for autonomous and manual flight.
...@@ -26,11 +28,11 @@ enum flight_mode{ ...@@ -26,11 +28,11 @@ enum flight_mode{
// bytes|| 1 | 1 | 1 | 2 | 2 | var | 1 | // bytes|| 1 | 1 | 1 | 2 | 2 | var | 1 |
//---------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------
typedef struct { typedef struct {
char begin_char; unsigned char begin_char;
char msg_type; unsigned char msg_type;
char msg_subtype; unsigned char msg_subtype;
int msg_id; uint16_t msg_id;
int data_len; uint16_t data_len;
} metadata_t; } metadata_t;
......
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