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

wip: fix compilation errors on new uart architecture

parent 197b04b2
No related branches found
No related tags found
No related merge requests found
...@@ -28,7 +28,7 @@ int cb_debug(struct modular_structs *structs, struct metadata *meta, unsigned ch ...@@ -28,7 +28,7 @@ int cb_debug(struct modular_structs *structs, struct metadata *meta, unsigned ch
float param_val = graph_get_output(graph, node_id, 0); float param_val = graph_get_output(graph, node_id, 0);
int len = snprintf((char*)buf, sizeof buf, "%f", param_val); int len = snprintf((char*)buf, sizeof buf, "%f", param_val);
send_data(&structs->hardware_struct.uart, DEBUG_ID, 0, buf, len >= sizeof(buf) ? 255 : length + 1); send_data(structs->hardware_struct.comm.uart, DEBUG_ID, 0, buf, len >= sizeof(buf) ? 255 : length + 1);
return 0; return 0;
} }
...@@ -40,7 +40,7 @@ int cb_packetlog(struct modular_structs* structs, struct metadata *meta, u8 *dat ...@@ -40,7 +40,7 @@ int cb_packetlog(struct modular_structs* structs, struct metadata *meta, u8 *dat
n_msg_received += 1; n_msg_received += 1;
total_payload_received += length; total_payload_received += length;
int len = sprintf(buf, "Packets received: %d", n_msg_received); int len = sprintf(buf, "Packets received: %d", n_msg_received);
send_data(&structs->hardware_struct.uart, PACKETLOG_ID, 0, buf, len); send_data(structs->hardware_struct.comm.uart, PACKETLOG_ID, 0, buf, len);
return 0; return 0;
} }
...@@ -54,7 +54,7 @@ int cb_getpacketlogs(struct modular_structs* structs, struct metadata *meta, u8 ...@@ -54,7 +54,7 @@ int cb_getpacketlogs(struct modular_structs* structs, struct metadata *meta, u8
// Message logging number of messages received and size of payload received // Message logging number of messages received and size of payload received
int len = snprintf((char*)buf, sizeof buf, "%d,%lu", n_msg_received, total_payload_received); int len = snprintf((char*)buf, sizeof buf, "%d,%lu", n_msg_received, total_payload_received);
send_data(&structs->hardware_struct.uart, LOG_ID, 0, buf, len >= sizeof(buf) ? 255 : len + 1); send_data(structs->hardware_struct.comm.uart, LOG_ID, 0, buf, len >= sizeof(buf) ? 255 : len + 1);
return 0; return 0;
} }
...@@ -202,7 +202,7 @@ int cb_getparam(struct modular_structs *structs, struct metadata *meta, unsigned ...@@ -202,7 +202,7 @@ int cb_getparam(struct modular_structs *structs, struct metadata *meta, unsigned
pack_float(param_val, resp_data + 4); pack_float(param_val, resp_data + 4);
// Send the response // Send the response
send_data(&structs->hardware_struct.uart, RESPPARAM_ID, msg_id, resp_data, sizeof(resp_data)); send_data(structs->hardware_struct.comm.uart, RESPPARAM_ID, msg_id, resp_data, sizeof(resp_data));
return 5; return 5;
} }
...@@ -274,7 +274,7 @@ int cb_getsource(struct modular_structs *structs, struct metadata *meta, unsigne ...@@ -274,7 +274,7 @@ int cb_getsource(struct modular_structs *structs, struct metadata *meta, unsigne
pack_short(source.controller_id, resp_data + 4); pack_short(source.controller_id, resp_data + 4);
pack_short(source.controller_output, resp_data + 6); pack_short(source.controller_output, resp_data + 6);
send_data(&structs->hardware_struct.uart, RESPSOURCE_ID, msg_id, resp_data, sizeof(resp_data)); send_data(structs->hardware_struct.comm.uart, RESPSOURCE_ID, msg_id, resp_data, sizeof(resp_data));
return 0; return 0;
} }
...@@ -303,7 +303,7 @@ int cb_getoutput(struct modular_structs *structs, struct metadata *meta, unsigne ...@@ -303,7 +303,7 @@ int cb_getoutput(struct modular_structs *structs, struct metadata *meta, unsigne
pack_float(output_val, resp_data + 4); pack_float(output_val, resp_data + 4);
// Send the response // Send the response
send_data(&structs->hardware_struct.uart, RESPOUTPUT_ID, msg_id, resp_data, sizeof(resp_data)); send_data(structs->hardware_struct.comm.uart, RESPOUTPUT_ID, msg_id, resp_data, sizeof(resp_data));
return 0; return 0;
} }
...@@ -325,7 +325,7 @@ int cb_getnodes(struct modular_structs *structs, struct metadata *meta, unsigned ...@@ -325,7 +325,7 @@ int cb_getnodes(struct modular_structs *structs, struct metadata *meta, unsigned
const struct computation_graph* graph = structs->parameter_struct.graph; const struct computation_graph* graph = structs->parameter_struct.graph;
if (graph->n_nodes >= 150) { if (graph->n_nodes >= 150) {
static char* error_msg = "Over 150 nodes. Not responding to cb_getnodes for fear of buffer overflow."; static char* error_msg = "Over 150 nodes. Not responding to cb_getnodes for fear of buffer overflow.";
send_data(&structs->hardware_struct.uart, DEBUG_ID, 0, send_data(structs->hardware_struct.comm.uart, DEBUG_ID, 0,
(u8*)error_msg, sizeof(error_msg)); (u8*)error_msg, sizeof(error_msg));
return -1; return -1;
} }
...@@ -369,7 +369,7 @@ int cb_getnodes(struct modular_structs *structs, struct metadata *meta, unsigned ...@@ -369,7 +369,7 @@ int cb_getnodes(struct modular_structs *structs, struct metadata *meta, unsigned
} }
} }
send_data(&structs->hardware_struct.uart, RESPNODES_ID, meta->msg_id, resp_buf, offset); send_data(structs->hardware_struct.comm.uart, RESPNODES_ID, meta->msg_id, resp_buf, offset);
return 0; return 0;
} }
...@@ -406,6 +406,6 @@ int cb_addnode(struct modular_structs *structs, struct metadata *meta, unsigned ...@@ -406,6 +406,6 @@ int cb_addnode(struct modular_structs *structs, struct metadata *meta, unsigned
u8 resp_buf[2]; u8 resp_buf[2];
pack_short(new_node_id, resp_buf); pack_short(new_node_id, resp_buf);
send_data(&structs->hardware_struct.uart, RESPADDNODE_ID, meta->msg_id, resp_buf, sizeof(resp_buf)); send_data(structs->hardware_struct.comm.uart, RESPADDNODE_ID, meta->msg_id, resp_buf, sizeof(resp_buf));
return 0; return 0;
} }
...@@ -96,7 +96,7 @@ int process_packet(modular_structs_t *structs) { ...@@ -96,7 +96,7 @@ int process_packet(modular_structs_t *structs) {
void process_received(modular_structs_t *structs) { void process_received(modular_structs_t *structs) {
// Parse as many packets as possible // Parse as many packets as possible
struct UARTDriver *uart = &structs->hardware_struct.comm->uart; struct UARTDriver *uart = structs->hardware_struct.comm.uart;
while (!try_receive_packet(uart)) { while (!try_receive_packet(uart)) {
process_packet(structs); process_packet(structs);
} }
......
...@@ -64,7 +64,7 @@ int init_structs(modular_structs_t *structs) { ...@@ -64,7 +64,7 @@ int init_structs(modular_structs_t *structs) {
timer_init_globals(global_timer, axi_timer); timer_init_globals(global_timer, axi_timer);
// Initialize UART0 // Initialize UART0
struct UARTDriver *uart = &structs->hardware_struct.uart; struct UARTDriver *uart = &structs->hardware_struct.uart_0;
if (uart->reset(uart)) { if (uart->reset(uart)) {
return -1; return -1;
} }
......
...@@ -116,7 +116,7 @@ int quad_main(int (*setup_hardware)(hardware_t *hardware_struct)) ...@@ -116,7 +116,7 @@ int quad_main(int (*setup_hardware)(hardware_t *hardware_struct))
if (structs.raw_sensor_struct.gam.error.consErrorCount > 10) { if (structs.raw_sensor_struct.gam.error.consErrorCount > 10) {
kill_motors(&(structs.hardware_struct.motors)); kill_motors(&(structs.hardware_struct.motors));
char err_msg[] = "More than 10 IMU errors"; char err_msg[] = "More than 10 IMU errors";
send_data(structs.hardware_struct.comm->uart, DEBUG_ID, 0, (u8*)err_msg, sizeof(err_msg)); send_data(structs.hardware_struct.comm.uart, DEBUG_ID, 0, (u8*)err_msg, sizeof(err_msg));
printLogging(&structs.hardware_struct.comm, &(structs.log_struct), &(structs.parameter_struct), &structs.raw_sensor_struct); printLogging(&structs.hardware_struct.comm, &(structs.log_struct), &(structs.parameter_struct), &structs.raw_sensor_struct);
break; break;
} }
......
...@@ -2,7 +2,17 @@ ...@@ -2,7 +2,17 @@
struct UARTDriver create_zybo_uart(int devId) { struct UARTDriver create_zybo_uart(int devId) {
struct UARTDriver uart; struct UARTDriver uart;
uart.state = NULL; uart.state = malloc(sizeof(struct ZyboUARTState));
struct ZyboUARTState *state = uart.state;
state->inst = malloc(sizeof(XUartPs));
// We are cheating. We put the Queue on the callback field,
// because that was the only way we could get the Queue
// into the interupt handler. And the callback field was a void
// pointer so we can do whatever we want with it...
state->inst->CallBackRef = queue_malloc(MAX_UART_BUFFER_SIZE);
state->devId = devId;
uart.reset = zybo_uart_reset; uart.reset = zybo_uart_reset;
uart.write = zybo_uart_write; uart.write = zybo_uart_write;
uart.read = zybo_uart_read; uart.read = zybo_uart_read;
...@@ -41,7 +51,10 @@ struct RCReceiverDriver create_zybo_rc_receiver() { ...@@ -41,7 +51,10 @@ struct RCReceiverDriver create_zybo_rc_receiver() {
struct I2CDriver create_zybo_i2c(int busId) { struct I2CDriver create_zybo_i2c(int busId) {
struct I2CDriver i2c; struct I2CDriver i2c;
i2c.state = NULL; i2c.state = malloc(sizeof(struct ZyboI2CState));
struct ZyboI2CState *state = i2c.state;
state->inst = malloc(sizeof(XIicPs));
state->busId = busId;
i2c.reset = zybo_i2c_reset; i2c.reset = zybo_i2c_reset;
i2c.write = zybo_i2c_write; i2c.write = zybo_i2c_write;
i2c.read = zybo_i2c_read; i2c.read = zybo_i2c_read;
......
...@@ -24,6 +24,19 @@ ...@@ -24,6 +24,19 @@
#define PX4FLOW_DEVICE_ADDR 0x42 #define PX4FLOW_DEVICE_ADDR 0x42
#define PX4FLOW_QUAL_MIN (100) #define PX4FLOW_QUAL_MIN (100)
#define MAX_UART_BUFFER_SIZE 2048
struct ZyboI2CState {
XIicPs *inst;
int busId;
};
struct ZyboUARTState {
struct Queue *queue;
XUartPs *inst;
int devId;
};
int zybo_uart_reset(struct UARTDriver *self); int zybo_uart_reset(struct UARTDriver *self);
int zybo_uart_write(struct UARTDriver *self, unsigned char c); int zybo_uart_write(struct UARTDriver *self, unsigned char c);
int zybo_uart_read(struct UARTDriver *self, unsigned char *c); int zybo_uart_read(struct UARTDriver *self, unsigned char *c);
...@@ -68,7 +81,12 @@ int zybo_lidar_read(struct LidarDriver *self, struct lidar *lidar); ...@@ -68,7 +81,12 @@ int zybo_lidar_read(struct LidarDriver *self, struct lidar *lidar);
int zybo_optical_flow_reset(struct OpticalFlowDriver *self, struct px4flow *of); int zybo_optical_flow_reset(struct OpticalFlowDriver *self, struct px4flow *of);
int zybo_optical_flow_read(struct OpticalFlowDriver *self, struct px4flow *of); int zybo_optical_flow_read(struct OpticalFlowDriver *self, struct px4flow *of);
struct UARTDriver create_zybo_uart(); int zybo_gps_reset(struct GPSDriver *self, gps_t *gps);
int zybo_gps_read(struct GPSDriver *self, gps_t *gps);
struct UARTDriver create_zybo_uart(int devId);
struct CommDriver create_zybo_comm(struct UARTDriver *uart);
struct GPSDriver create_zybo_gps(struct UARTDriver *uart);
struct MotorDriver create_zybo_motors(); struct MotorDriver create_zybo_motors();
struct RCReceiverDriver create_zybo_rc_receiver(); struct RCReceiverDriver create_zybo_rc_receiver();
struct I2CDriver create_zybo_i2c(int busId); struct I2CDriver create_zybo_i2c(int busId);
......
#include "hw_iface.h"
#include "hw_impl_zybo.h"
int zybo_gps_reset(struct GPSDriver *self, gps_t *gps) {
// TODO
return -1;
}
int zybo_gps_read(struct GPSDriver *self, gps_t *gps) {
// TODO
return -1;
}
...@@ -42,18 +42,10 @@ int XIicPs_MasterRecvPolled_ours(XIicPs *InstancePtr, u8 *MsgPtr, ...@@ -42,18 +42,10 @@ int XIicPs_MasterRecvPolled_ours(XIicPs *InstancePtr, u8 *MsgPtr,
int ByteCount, u16 SlaveAddr); int ByteCount, u16 SlaveAddr);
int XIicPs_SetupMaster(XIicPs *InstancePtr, int Role); int XIicPs_SetupMaster(XIicPs *InstancePtr, int Role);
struct ZyboI2CState {
XIcPs *inst;
int busId;
};
int zybo_i2c_reset(struct I2CDriver *self) { int zybo_i2c_reset(struct I2CDriver *self) {
if (self->state == NULL) { struct ZyboI2CState *state = self->state;
self->state = malloc(sizeof(struct ZyboI2CState)); int i2cID = state->busId;
self->state->inst = malloc(sizeof(XIcPs)); XIicPs *inst = state->inst;
}
int i2cID = self->state.busId;
XIicPs *inst = self->state->inst;
//Make sure CPU_1x clk is enabled fostatusr I2C controller //Make sure CPU_1x clk is enabled fostatusr I2C controller
u16 *aper_ctrl = (u16 *) IO_CLK_CONTROL_REG_ADDR; u16 *aper_ctrl = (u16 *) IO_CLK_CONTROL_REG_ADDR;
......
...@@ -280,7 +280,7 @@ int test_zybo_global_timer() { ...@@ -280,7 +280,7 @@ int test_zybo_global_timer() {
} }
/** /**
* Test for the UARTDriver. * Communication tests using the UARTDriver.
* *
* Instructions: * Instructions:
* 1) Connect Zybo board to computer by USB cable. * 1) Connect Zybo board to computer by USB cable.
...@@ -296,15 +296,16 @@ int test_zybo_global_timer() { ...@@ -296,15 +296,16 @@ int test_zybo_global_timer() {
* - Observe test results on terminal * - Observe test results on terminal
* - You might be able to see LED MIO7 blink when it receives bytes * - You might be able to see LED MIO7 blink when it receives bytes
*/ */
int test_zybo_uart() { int test_zybo_uart_comm() {
struct UARTDriver uart = create_zybo_uart(); struct UARTDriver uart = create_zybo_uart(0);
struct CommDriver comm = create_zybo_comm(&uart);
struct LEDDriver led = create_zybo_mio7_led(); struct LEDDriver led = create_zybo_mio7_led();
uart.reset(&uart); uart.reset(&uart);
led.reset(&led); led.reset(&led);
unsigned char c; unsigned char c;
while (1) { while (1) {
if (uart.read(&uart, &c)) { if (comm.uart->read(comm.uart, &c)) {
// read failed // read failed
led.turn_off(&led); led.turn_off(&led);
} else { } else {
......
#include "hw_impl_zybo.h" #include "hw_impl_zybo.h"
#define BAUD_RATE 921600 #define BAUD_RATE 921600
#define MAX_UART_BUFFER_SIZE 2048
int XUartPs_SetBaudRate_ours(XUartPs *InstancePtr, u32 BaudRate); int XUartPs_SetBaudRate_ours(XUartPs *InstancePtr, u32 BaudRate);
void uart_interrupt_handler(XUartPs *InstancePtr); void uart_interrupt_handler(XUartPs *InstancePtr);
int SetupInterruptSystem(XUartPs *UartInstancePtr, u16 UartIntrId, Xil_ExceptionHandler handler); int SetupInterruptSystem(XUartPs *UartInstancePtr, u16 UartIntrId, Xil_ExceptionHandler handler);
void uart_interrupt_handler(XUartPs *InstancePtr); void uart_interrupt_handler(XUartPs *InstancePtr);
struct UARTState {
struct Queue *queue;
XUartPs *inst;
};
int zybo_uart_reset(struct UARTDriver *self) { int zybo_uart_reset(struct UARTDriver *self) {
// Instantiate the Driver state // Ensure all required memory is allocated
if (self->state == NULL) { struct ZyboUARTState *state = self->state;
self->state = malloc(sizeof(struct UARTState)); if (state == NULL) return -1;
if (self->state == NULL) return -1; if (state->inst == NULL) return -1;
self->state->inst = malloc(sizeof(XUartPs)); if (state->inst->CallBackRef == NULL) return -1;
if (self->state->inst == NULL) return -1;
// We are cheating. We put the Queue on the callback field,
// because that was the only way we could get the Queue
// into this interupt handler. And the callback field was a void
// pointer so we can do whatever we want with it...
self->state->inst->CallBackRef = queue_malloc(MAX_UART_BUFFER_SIZE);
if (self->state->inst->CallBackRef == NULL) return -1;
}
XUartPs *inst = self->state->inst; XUartPs *inst = state->inst;
// Configure XUartPs instance // Configure XUartPs instance
XUartPs_Config* config = XUartPs_LookupConfig(XPAR_PS7_UART_0_DEVICE_ID); XUartPs_Config* config = XUartPs_LookupConfig(XPAR_PS7_UART_0_DEVICE_ID);
...@@ -81,8 +67,9 @@ int zybo_uart_write(struct UARTDriver *self, unsigned char c) {\ ...@@ -81,8 +67,9 @@ int zybo_uart_write(struct UARTDriver *self, unsigned char c) {\
} }
int zybo_uart_read(struct UARTDriver *self, unsigned char *c) { int zybo_uart_read(struct UARTDriver *self, unsigned char *c) {
struct ZyboUARTState *state = self->state;
// We put the queue on the void pointer callback reference // We put the queue on the void pointer callback reference
struct Queue *queue = InstancePtr->CallBackRef; struct Queue *queue = state->inst->CallBackRef;
if (queue_remove(queue, c)) return -1; if (queue_remove(queue, c)) return -1;
else return 0; else return 0;
} }
......
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