diff --git a/quad/sw/comm_dev/Debug/comm_dev.elf b/quad/sw/comm_dev/Debug/comm_dev.elf index aaaed755a18e2062afa26e19d010e4bee5f05457..4df52521f1166a0acb7c9ca5a658baab7cf7dd21 100755 Binary files a/quad/sw/comm_dev/Debug/comm_dev.elf and b/quad/sw/comm_dev/Debug/comm_dev.elf differ diff --git a/quad/sw/comm_dev/Debug/comm_dev.elf.size b/quad/sw/comm_dev/Debug/comm_dev.elf.size index b9055a946ae75b49369e83a3860ddbf3c0b62b9f..aab0779e17a9821726441d8f100fc94045285814 100644 --- a/quad/sw/comm_dev/Debug/comm_dev.elf.size +++ b/quad/sw/comm_dev/Debug/comm_dev.elf.size @@ -1,2 +1,2 @@ text data bss dec hex filename - 165412 68080 119152504 119385996 71daf8c comm_dev.elf + 166044 68080 119152840 119386964 71db354 comm_dev.elf diff --git a/quad/sw/comm_dev/Debug/src/commands.o b/quad/sw/comm_dev/Debug/src/commands.o index 03ddc8e02dc171e75118595e4f0d5dda690acef3..63ba9b4b21830f7ef7e9e5957874cd1170401182 100644 Binary files a/quad/sw/comm_dev/Debug/src/commands.o and b/quad/sw/comm_dev/Debug/src/commands.o differ diff --git a/quad/sw/comm_dev/Debug/src/initialize_components.d b/quad/sw/comm_dev/Debug/src/initialize_components.d index 03ae362ba4e55a875ade28b9b2fac4fce4619ef1..a8b84eee2940d41e35f0787ce72fc5cb20ef6bb5 100644 --- a/quad/sw/comm_dev/Debug/src/initialize_components.d +++ b/quad/sw/comm_dev/Debug/src/initialize_components.d @@ -17,23 +17,22 @@ src/initialize_components.d: ../src/initialize_components.c \ ../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/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/xtmrctr.h \ ../../system_bsp/ps7_cortexa9_0/include/xtmrctr_l.h \ ../src/control_algorithm.h ../src/sensor_processing.h ../src/sensor.h \ - ../src/user_input.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/quadposition.h ../src/iic_mpu9150_utils.h \ + ../src/user_input.h ../src/util.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/xiicps.h \ ../../system_bsp/ps7_cortexa9_0/include/xiicps_hw.h \ ../src/packet_processing.h ../src/conversion.h ../src/platform.h \ - ../src/platform_config.h ../src/communication.h ../src/commands.h \ - ../src/new_comm.h \ - ../../system_bsp/ps7_cortexa9_0/include/xil_exception.h \ - ../src/mio7_led.h + ../src/platform_config.h ../src/communication.h ../src/initialize_components.h: @@ -81,8 +80,20 @@ src/initialize_components.d: ../src/initialize_components.c \ ../../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: +../src/commands.h: + ../../system_bsp/ps7_cortexa9_0/include/xtime_l.h: ../../system_bsp/ps7_cortexa9_0/include/xtmrctr.h: @@ -99,10 +110,6 @@ src/initialize_components.d: ../src/initialize_components.c \ ../src/util.h: -../../system_bsp/ps7_cortexa9_0/include/xgpiops.h: - -../../system_bsp/ps7_cortexa9_0/include/xgpiops_hw.h: - ../src/controllers.h: ../src/quadposition.h: @@ -124,11 +131,3 @@ src/initialize_components.d: ../src/initialize_components.c \ ../src/platform_config.h: ../src/communication.h: - -../src/commands.h: - -../src/new_comm.h: - -../../system_bsp/ps7_cortexa9_0/include/xil_exception.h: - -../src/mio7_led.h: diff --git a/quad/sw/comm_dev/Debug/src/initialize_components.o b/quad/sw/comm_dev/Debug/src/initialize_components.o index 1f1db58a17268c870461176aa01962830536259b..73082cf9c06fcb6023be2222943a440382091c9b 100644 Binary files a/quad/sw/comm_dev/Debug/src/initialize_components.o and b/quad/sw/comm_dev/Debug/src/initialize_components.o differ diff --git a/quad/sw/comm_dev/Debug/src/main.d b/quad/sw/comm_dev/Debug/src/main.d index e8e6bc83e25eb3dcb9e536c298bcabed80145fc6..3cedd86789408d284e16b1e9ae4af3b271affb35 100644 --- a/quad/sw/comm_dev/Debug/src/main.d +++ b/quad/sw/comm_dev/Debug/src/main.d @@ -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 \ ../../system_bsp/ps7_cortexa9_0/include/xscugic_hw.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/xtmrctr.h \ ../../system_bsp/ps7_cortexa9_0/include/xtmrctr_l.h \ ../src/initialize_components.h ../src/control_algorithm.h \ ../src/sensor_processing.h ../src/sensor.h ../src/user_input.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/quadposition.h ../src/iic_mpu9150_utils.h \ + ../src/util.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/xiicps.h \ ../../system_bsp/ps7_cortexa9_0/include/xiicps_hw.h \ ../src/packet_processing.h ../src/conversion.h ../src/platform.h \ ../src/platform_config.h ../src/actuator_command_processing.h \ - ../src/send_actuator_commands.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 + ../src/send_actuator_commands.h ../src/update_gui.h ../src/timer.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: +../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/xtmrctr.h: @@ -98,10 +111,6 @@ src/main.d: ../src/main.c ../src/timer.h ../src/log_data.h ../src/PID.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/quadposition.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/update_gui.h: - -../src/new_comm.h: - -../../system_bsp/ps7_cortexa9_0/include/xil_exception.h: - -../src/mio7_led.h: - -../src/commands.h: diff --git a/quad/sw/comm_dev/Debug/src/main.o b/quad/sw/comm_dev/Debug/src/main.o index 5008a65c8650cb6970d5730ef371e75cf7b31a11..0c7b5537899499b352c725f6b0c0a718d49e02da 100644 Binary files a/quad/sw/comm_dev/Debug/src/main.o and b/quad/sw/comm_dev/Debug/src/main.o differ diff --git a/quad/sw/comm_dev/Debug/src/new_comm.o b/quad/sw/comm_dev/Debug/src/new_comm.o index eaa46c58ac60f9b7ffb931c0b2843bc58bcdfc7d..4ccc3ae365be17af927a1f106ebe1941ab7a88b2 100644 Binary files a/quad/sw/comm_dev/Debug/src/new_comm.o and b/quad/sw/comm_dev/Debug/src/new_comm.o differ diff --git a/quad/sw/comm_dev/Debug/src/timer.d b/quad/sw/comm_dev/Debug/src/timer.d index 1d2b5a016f8ea150f49147baaf2260cb8f6276ea..3454b48df86a9b86bebb41037b4a9bd6f4a081ea 100644 --- a/quad/sw/comm_dev/Debug/src/timer.d +++ b/quad/sw/comm_dev/Debug/src/timer.d @@ -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 \ ../../system_bsp/ps7_cortexa9_0/include/xscugic_hw.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/xtmrctr.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 \ ../../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: +../src/commands.h: + ../../system_bsp/ps7_cortexa9_0/include/xtime_l.h: ../../system_bsp/ps7_cortexa9_0/include/xtmrctr.h: diff --git a/quad/sw/comm_dev/Debug/src/timer.o b/quad/sw/comm_dev/Debug/src/timer.o index 7ae0c8fb2998588898662a2c0573d71fb93df2a8..0bb7485fe4df11625c08d205d4b80d8e871c2691 100644 Binary files a/quad/sw/comm_dev/Debug/src/timer.o and b/quad/sw/comm_dev/Debug/src/timer.o differ diff --git a/quad/sw/comm_dev/src/commands.c b/quad/sw/comm_dev/src/commands.c index c6ca889e751848251b98e31ce47a9bafc38ba74c..4044ce9952430431fcf7591e4e8b12ab72b48c59 100644 --- a/quad/sw/comm_dev/src/commands.c +++ b/quad/sw/comm_dev/src/commands.c @@ -344,6 +344,11 @@ struct MessageType MessageTypes[MAX_TYPE] = } } }, + // HERE FOR SPACING + { + 0x02, + {} + }, // RESPONSE { // Message Type ID @@ -474,7 +479,14 @@ int debug(unsigned char *packet, int dataLen, modular_structs_t *structs) control algorithm in order to get this to work. */ 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)); return 0; } diff --git a/quad/sw/comm_dev/src/initialize_components.c b/quad/sw/comm_dev/src/initialize_components.c index 7bcae721bb209f45c0dcca9893abf51f6f628205..7ef4413b4a28b3ce2036f7c5e2b878d5d28fc17b 100644 --- a/quad/sw/comm_dev/src/initialize_components.c +++ b/quad/sw/comm_dev/src/initialize_components.c @@ -101,7 +101,10 @@ int initializeAllComponents(user_input_t * user_input_struct, log_t * log_struct return -1; } // Initialize loop timers - timer_init(); + if (timer_init()) { + return -1; + } + return 0; // Initialize I2C controller and start the sensor board diff --git a/quad/sw/comm_dev/src/main.c b/quad/sw/comm_dev/src/main.c index a648a6a836ac9ca8a96480541f8642b7d1bf7548..e5ab6dec09f1184bcd6e20c4a695f0c376953203 100644 --- a/quad/sw/comm_dev/src/main.c +++ b/quad/sw/comm_dev/src/main.c @@ -68,7 +68,7 @@ int main() // // 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)); // -// // send the actuator commands +// // send the 004\000\002actuator commands // send_actuator_commands(&(structs.log_struct), &(structs.actuator_command_struct)); // // // update the GUI diff --git a/quad/sw/comm_dev/src/new_comm.c b/quad/sw/comm_dev/src/new_comm.c index 17a9274a4f0c1549234267e1ba9c3bf171f38f9e..8559b7d88e998d712cf9f7e38169418e88f2ff74 100644 --- a/quad/sw/comm_dev/src/new_comm.c +++ b/quad/sw/comm_dev/src/new_comm.c @@ -11,11 +11,13 @@ #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 BAUD_RATE 115200 -// Maximum number of bytes to be received within our loop time, plus 64 for a little buffer +#define BAUD_RATE 921600 +// 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) -#define UART_BUF_SIZE (((BAUD_RATE * (DESIRED_USEC_PER_LOOP / 1000) / 1000) / 10) + 64) #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 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 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() { uartInstPtr = uart0_init(COMM_UART_DEVICE_ID, BAUD_RATE); @@ -39,7 +39,7 @@ int initUartComms() { 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; } @@ -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 * will not be received. By default it is disabled. * Timeout duration = RecvTimeout x 4 x Bit Period. 0 disables the @@ -71,13 +71,10 @@ int initUartComms() { XUartPs_SetRecvTimeout(uartInstPtr, 4); // Second argument is the number of bytes to trigger an interrupt at - XUartPs_SetFifoThreshold(uartInstPtr, 12); - - //XUartPs_Recv(uartInstPtr, recvBuf, UART_BUF_SIZE); + XUartPs_SetFifoThreshold(uartInstPtr, 48); return 0; } -// TODO: Be consistent with underscore_names or camelCase int process_packet(unsigned char* packet, modular_structs_t *structs) { metadata_t meta_data; @@ -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); return 0; + } 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) - int min_packet_size = sizeof(metadata_t) + 1; - // TODO: Loop limit? - while (secondaryEnd - secondaryBegin >= min_packet_size) { - unsigned char* packet_header = secondaryBuf + secondaryBegin; + int min_packet_size = 8; + // TODO: Loop limits? + while (recv_buf_end - recv_buf_begin >= min_packet_size) { + // 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]); - if (secondaryEnd - secondaryBegin >= min_packet_size + packet_len) { - process_packet(secondaryBuf + secondaryBegin, structs); - secondaryBegin += min_packet_size + packet_len; + // Determine if we have received the entire packet. If so, process it. + if (recv_buf_end - recv_buf_begin >= min_packet_size + packet_len) { + process_packet(recvBuf + recv_buf_begin, structs); + recv_buf_begin += min_packet_size + packet_len; } else { // Not enough data for a packet @@ -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 ImrRegister; ImrRegister = XUartPs_ReadReg(uartInstPtr->Config.BaseAddress, XUARTPS_IMR_OFFSET); @@ -138,50 +145,32 @@ u32 disable_interrupts() { return ImrRegister; } +/* + * Restores the interrupt state, saved from disable_interrupts + */ void restore_interrupts(u32 intr_state) { XUartPs_WriteReg(uartInstPtr->Config.BaseAddress, XUARTPS_IER_OFFSET, intr_state); } void process_received(modular_structs_t *structs) { -// // Move unprocessed bytes to front of secondary buffer -// 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 as many packets as possible parse_available(structs); + // Disable interrupts while moving data around u32 intr_state = disable_interrupts(); // Move unprocessed bytes to front of secondary buffer - size_t unprocessed_size = secondaryEnd - secondaryBegin; - memmove(secondaryBuf, secondaryBuf + secondaryBegin, unprocessed_size); - secondaryBegin = 0; - secondaryEnd = unprocessed_size; + size_t unprocessed_size = recv_buf_end - recv_buf_begin; + memmove(recvBuf, recvBuf + recv_buf_begin, unprocessed_size); + recv_buf_begin = 0; + recv_buf_end = unprocessed_size; restore_interrupts(intr_state); //unsigned char in_fifo = XUartPs_ReadReg(uartInstPtr->Config.BaseAddress, XUARTPS_FIFO_OFFSET); return; } -void uartInterruptHandler(XUartPs *InstancePtr) { +void uart_interrupt_handler(XUartPs *InstancePtr) { u32 IsrStatus; /* @@ -194,19 +183,18 @@ void uartInterruptHandler(XUartPs *InstancePtr) { IsrStatus &= XUartPs_ReadReg(InstancePtr->Config.BaseAddress, XUARTPS_ISR_OFFSET); - u32 CsrRegister; /* * Read the Channel Status Register to determine if there is any data in * the RX FIFO */ - CsrRegister = XUartPs_ReadReg(InstancePtr->Config.BaseAddress, + + u32 CsrRegister = XUartPs_ReadReg(InstancePtr->Config.BaseAddress, XUARTPS_SR_OFFSET); - while (0 == (CsrRegister & XUARTPS_SR_RXEMPTY)) { - secondaryBuf[secondaryEnd] = XUartPs_ReadReg(InstancePtr->Config.BaseAddress, XUARTPS_FIFO_OFFSET); - secondaryEnd += 1; + while (0 == (CsrRegister & XUARTPS_SR_RXEMPTY) && recv_buf_end <= UART_BUF_SIZE) { + recvBuf[recv_buf_end] = XUartPs_ReadReg(InstancePtr->Config.BaseAddress, XUARTPS_FIFO_OFFSET); + recv_buf_end += 1; CsrRegister = XUartPs_ReadReg(InstancePtr->Config.BaseAddress, XUARTPS_SR_OFFSET); - MIO7_led_on(); } // Clear the interrupt status. @@ -214,33 +202,3 @@ void uartInterruptHandler(XUartPs *InstancePtr) { 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; - } -} - diff --git a/quad/sw/comm_dev/src/new_comm.h b/quad/sw/comm_dev/src/new_comm.h index 7044d6cb685bcab2e4269fc96f6b690a29be9a2d..5ee7603319e4001756b8b6f716813f9764cda8a7 100644 --- a/quad/sw/comm_dev/src/new_comm.h +++ b/quad/sw/comm_dev/src/new_comm.h @@ -21,6 +21,6 @@ int initUartComms(); void process_received(modular_structs_t *structs); -void uartInterruptHandler(XUartPs *InstancePtr); +void uart_interrupt_handler(XUartPs *InstancePtr); #endif /* NEW_COMM_H_ */ diff --git a/quad/sw/comm_dev/src/timer.c b/quad/sw/comm_dev/src/timer.c index 8c99522c50366d83084f44ba4903266db66d311b..7d5f3b11bb2c28c42deabc3ea56209f39c84afb7 100644 --- a/quad/sw/comm_dev/src/timer.c +++ b/quad/sw/comm_dev/src/timer.c @@ -18,9 +18,7 @@ int timer_init() { // 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 0; + return XTmrCtr_Initialize(&axi_timer, XPAR_AXI_TIMER_0_DEVICE_ID); } int timer_start_loop() diff --git a/quad/sw/comm_dev/src/type_def.h b/quad/sw/comm_dev/src/type_def.h index 55dca9e8fb27c26397b00961b7dbec8bbe0d4136..15db8f9eb62e820933e117099d74bca8eb9bf8b6 100644 --- a/quad/sw/comm_dev/src/type_def.h +++ b/quad/sw/comm_dev/src/type_def.h @@ -8,6 +8,8 @@ #ifndef TYPE_DEF_H_ #define TYPE_DEF_H_ +#include <stdint.h> + /** * @brief * The modes for autonomous and manual flight. @@ -26,11 +28,11 @@ enum flight_mode{ // bytes|| 1 | 1 | 1 | 2 | 2 | var | 1 | //---------------------------------------------------------------------------------------------- typedef struct { - char begin_char; - char msg_type; - char msg_subtype; - int msg_id; - int data_len; + unsigned char begin_char; + unsigned char msg_type; + unsigned char msg_subtype; + uint16_t msg_id; + uint16_t data_len; } metadata_t;