Flute_Hello_World/src/drivers/xilinx_uartlite.c

27 lines
973 B
C

#include "drivers/xilinx_uartlite.h"
sys_ret_t xilinx_uartlite_init(xilinx_uartlite_handle_t *handle) {
handle->instance->CTRL |= 0x03; // Reset FIFO
return RET_OK;
}
sys_ret_t xilinx_uartlite_send(xilinx_uartlite_handle_t *handle, uint8_t *data, uint32_t len) {
for(uint32_t i = 0; i < len; i++) {
while(handle->instance->STAT & (1U << 0x03) || !(handle->instance->STAT & (1U << 0x02))) { // Check if TX FIFO is full
// TODO: Unless we figure out where systick should be.
}
handle->instance->TX_FIFO = data[i];
}
return RET_OK;
}
sys_ret_t xilinx_uartlite_receive(xilinx_uartlite_handle_t *handle, uint8_t *data, uint32_t len) {
for(uint32_t i = 0; i < len; i++) {
while((handle->instance->STAT & 0x01U) == 0) { // Check if RX FIFO is empty
// TODO: Unless we figure out where our systick should be.
}
data[i] = handle->instance->RX_FIFO & 0xFF;
}
return RET_OK;
}