Skip to content
Snippets Groups Projects
Commit 197b04b2 authored by bbartels's avatar bbartels
Browse files

wip: fix more issues in hw_impl_zybo_uart.c

parent 870a1ed9
No related branches found
No related tags found
No related merge requests found
...@@ -8,22 +8,28 @@ void uart_interrupt_handler(XUartPs *InstancePtr); ...@@ -8,22 +8,28 @@ 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);
// Queue has to be global to be accessible to ISR struct UARTState {
static struct Queue queue; struct Queue *queue;
static volatile unsigned char buff[MAX_UART_BUFFER_SIZE]; XUartPs *inst;
static XScuGic xscugic; };
int zybo_uart_reset(struct UARTDriver *self) { int zybo_uart_reset(struct UARTDriver *self) {
// Instantiate the Driver state // Instantiate the Driver state
if (self->state == NULL) { if (self->state == NULL) {
self->state = malloc(sizeof(XUartPs)); self->state = malloc(sizeof(struct UARTState));
if (self->state == NULL) { if (self->state == NULL) return -1;
return -1; self->state->inst = malloc(sizeof(XUartPs));
} if (self->state->inst == NULL) return -1;
queue_init(&queue, buff, 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 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;; XUartPs *inst = self->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);
...@@ -75,7 +81,9 @@ int zybo_uart_write(struct UARTDriver *self, unsigned char c) {\ ...@@ -75,7 +81,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) {
if (queue_remove(&queue, c)) return -1; // We put the queue on the void pointer callback reference
struct Queue *queue = InstancePtr->CallBackRef;
if (queue_remove(queue, c)) return -1;
else return 0; else return 0;
} }
...@@ -191,6 +199,9 @@ int XUartPs_SetBaudRate_ours(XUartPs *InstancePtr, u32 BaudRate) ...@@ -191,6 +199,9 @@ int XUartPs_SetBaudRate_ours(XUartPs *InstancePtr, u32 BaudRate)
void uart_interrupt_handler(XUartPs *InstancePtr) { void uart_interrupt_handler(XUartPs *InstancePtr) {
u32 IsrStatus; u32 IsrStatus;
// We put the queue on the void pointer callback reference
struct Queue *queue = InstancePtr->CallBackRef;
/* /*
* Read the interrupt ID register to determine which * Read the interrupt ID register to determine which
* interrupt is active * interrupt is active
...@@ -211,7 +222,7 @@ void uart_interrupt_handler(XUartPs *InstancePtr) { ...@@ -211,7 +222,7 @@ void uart_interrupt_handler(XUartPs *InstancePtr) {
while (0 == (CsrRegister & XUARTPS_SR_RXEMPTY)) { while (0 == (CsrRegister & XUARTPS_SR_RXEMPTY)) {
u8 byte = XUartPs_ReadReg(InstancePtr->Config.BaseAddress, XUARTPS_FIFO_OFFSET); u8 byte = XUartPs_ReadReg(InstancePtr->Config.BaseAddress, XUARTPS_FIFO_OFFSET);
queue_add(&queue, byte); queue_add(queue, byte);
CsrRegister = XUartPs_ReadReg(InstancePtr->Config.BaseAddress, XUARTPS_SR_OFFSET); CsrRegister = XUartPs_ReadReg(InstancePtr->Config.BaseAddress, XUARTPS_SR_OFFSET);
} }
...@@ -241,7 +252,7 @@ void uart_interrupt_handler(XUartPs *InstancePtr) { ...@@ -241,7 +252,7 @@ void uart_interrupt_handler(XUartPs *InstancePtr) {
int SetupInterruptSystem(XUartPs *UartInstancePtr, u16 UartIntrId, Xil_ExceptionHandler handler) int SetupInterruptSystem(XUartPs *UartInstancePtr, u16 UartIntrId, Xil_ExceptionHandler handler)
{ {
int Status; int Status;
XScuGic xscugic;
XScuGic_Config *IntcConfig; /* Config for interrupt controller */ XScuGic_Config *IntcConfig; /* Config for interrupt controller */
/* Initialize the interrupt controller driver */ /* Initialize the interrupt controller driver */
......
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