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

wip: addressing more issues with new uart

parent ba8d9d9a
No related branches found
No related tags found
No related merge requests found
...@@ -5,12 +5,7 @@ struct UARTDriver create_zybo_uart(int devId) { ...@@ -5,12 +5,7 @@ struct UARTDriver create_zybo_uart(int devId) {
uart.state = malloc(sizeof(struct ZyboUARTState)); uart.state = malloc(sizeof(struct ZyboUARTState));
struct ZyboUARTState *state = uart.state; struct ZyboUARTState *state = uart.state;
state->inst = malloc(sizeof(XUartPs)); state->inst = malloc(sizeof(XUartPs));
state->queue = queue_malloc(MAX_UART_BUFFER_SIZE);
// 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; state->devId = devId;
uart.reset = zybo_uart_reset; uart.reset = zybo_uart_reset;
......
...@@ -57,8 +57,7 @@ int mpu9150_read_mag(struct IMUDriver *self, gam_t* gam); ...@@ -57,8 +57,7 @@ int mpu9150_read_mag(struct IMUDriver *self, gam_t* gam);
int mpu9150_read_gyro_accel(gam_t* gam); int mpu9150_read_gyro_accel(gam_t* gam);
int zybo_imu_reset(struct IMUDriver *self, gam_t *gam) { int zybo_imu_reset(struct IMUDriver *self, gam_t *gam) {
// TODO: initialize gam memset(gam, 0, sizeof(gam_t));
memset(gam, 0, sizeof(gam_t));
struct I2CDriver *i2c = self->i2c; struct I2CDriver *i2c = self->i2c;
...@@ -143,7 +142,7 @@ int mpu9150_write(struct I2CDriver *i2c, u8 register_addr, u8 data){ ...@@ -143,7 +142,7 @@ int mpu9150_write(struct I2CDriver *i2c, u8 register_addr, u8 data){
// Check if within register range // Check if within register range
if(register_addr < 0 || register_addr > 0x75){ if(register_addr < 0 || register_addr > 0x75){
return; return -1;
} }
if(register_addr <= 0x12){ if(register_addr <= 0x12){
......
...@@ -4,9 +4,8 @@ ...@@ -4,9 +4,8 @@
int XUartPs_SetBaudRate_ours(XUartPs *InstancePtr, u32 BaudRate); int XUartPs_SetBaudRate_ours(XUartPs *InstancePtr, u32 BaudRate);
void uart_interrupt_handler(XUartPs *InstancePtr); int SetupInterruptSystem(XUartPs *UartInstancePtr, u16 UartIntrId, Xil_ExceptionHandler handler, struct ZyboUARTState *state);
int SetupInterruptSystem(XUartPs *UartInstancePtr, u16 UartIntrId, Xil_ExceptionHandler handler); void uart_interrupt_handler(struct ZyboUARTState *state);
void uart_interrupt_handler(XUartPs *InstancePtr);
int zybo_uart_reset(struct UARTDriver *self) { int zybo_uart_reset(struct UARTDriver *self) {
// Ensure all required memory is allocated // Ensure all required memory is allocated
...@@ -33,7 +32,7 @@ int zybo_uart_reset(struct UARTDriver *self) { ...@@ -33,7 +32,7 @@ int zybo_uart_reset(struct UARTDriver *self) {
*uart_ctrl_reg |= 0x00000003; // clear TX & RX *uart_ctrl_reg |= 0x00000003; // clear TX & RX
// Setup Interrupts // Setup Interrupts
if (SetupInterruptSystem(inst, XPAR_PS7_UART_0_INTR, (Xil_ExceptionHandler) uart_interrupt_handler) != XST_SUCCESS) { if (SetupInterruptSystem(inst, XPAR_PS7_UART_0_INTR, (Xil_ExceptionHandler) uart_interrupt_handler, state) != XST_SUCCESS) {
return -1; return -1;
} }
...@@ -60,16 +59,16 @@ int zybo_uart_reset(struct UARTDriver *self) { ...@@ -60,16 +59,16 @@ int zybo_uart_reset(struct UARTDriver *self) {
return 0; return 0;
} }
int zybo_uart_write(struct UARTDriver *self, unsigned char c) {\ int zybo_uart_write(struct UARTDriver *self, unsigned char c) {
XUartPs *inst = self->state; struct ZyboUARTState *state = self->state;
XUartPs *inst = state->inst;
XUartPs_SendByte(inst->Config.BaseAddress, c); XUartPs_SendByte(inst->Config.BaseAddress, c);
return 0; return 0;
} }
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; struct ZyboUARTState *state = self->state;
// We put the queue on the void pointer callback reference struct Queue *queue = state->queue;
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;
} }
...@@ -183,11 +182,10 @@ int XUartPs_SetBaudRate_ours(XUartPs *InstancePtr, u32 BaudRate) ...@@ -183,11 +182,10 @@ int XUartPs_SetBaudRate_ours(XUartPs *InstancePtr, u32 BaudRate)
} }
void uart_interrupt_handler(XUartPs *InstancePtr) { void uart_interrupt_handler(struct ZyboUARTState *state) {
u32 IsrStatus; u32 IsrStatus;
XUartPs *InstancePtr = state->inst;
// We put the queue on the void pointer callback reference struct Queue *queue = state->queue;
struct Queue *queue = InstancePtr->CallBackRef;
/* /*
* Read the interrupt ID register to determine which * Read the interrupt ID register to determine which
...@@ -236,7 +234,7 @@ void uart_interrupt_handler(XUartPs *InstancePtr) { ...@@ -236,7 +234,7 @@ void uart_interrupt_handler(XUartPs *InstancePtr) {
* @note None. * @note None.
* *
****************************************************************************/ ****************************************************************************/
int SetupInterruptSystem(XUartPs *UartInstancePtr, u16 UartIntrId, Xil_ExceptionHandler handler) int SetupInterruptSystem(XUartPs *UartInstancePtr, u16 UartIntrId, Xil_ExceptionHandler handler, struct ZyboUARTState *state)
{ {
int Status; int Status;
XScuGic xscugic; XScuGic xscugic;
...@@ -269,7 +267,7 @@ int SetupInterruptSystem(XUartPs *UartInstancePtr, u16 UartIntrId, Xil_Exception ...@@ -269,7 +267,7 @@ int SetupInterruptSystem(XUartPs *UartInstancePtr, u16 UartIntrId, Xil_Exception
*/ */
Status = XScuGic_Connect(&xscugic, UartIntrId, Status = XScuGic_Connect(&xscugic, UartIntrId,
handler, handler,
(void *) UartInstancePtr); (void *) state);
if (Status != XST_SUCCESS) { if (Status != XST_SUCCESS) {
return XST_FAILURE; return XST_FAILURE;
} }
......
...@@ -51,12 +51,12 @@ int main() ...@@ -51,12 +51,12 @@ int main()
//test_zybo_i2c_imu(); //test_zybo_i2c_imu();
//test_zybo_i2c_px4flow(); //test_zybo_i2c_px4flow();
//test_zybo_i2c_lidar(); //test_zybo_i2c_lidar();
test_zybo_i2c_all(); //test_zybo_i2c_all();
//test_zybo_rc_receiver(); //test_zybo_rc_receiver();
//test_zybo_motors(); //test_zybo_motors();
//test_zybo_uart(); //test_zybo_uart();
//test_zybo_axi_timer(); //test_zybo_axi_timer();
//test_zybo_uart(); test_zybo_uart_comm();
return 0; return 0;
#endif #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