aboutsummaryrefslogtreecommitdiff
path: root/VexRiscvSocSoftware/libs/uart.h
diff options
context:
space:
mode:
Diffstat (limited to 'VexRiscvSocSoftware/libs/uart.h')
-rwxr-xr-xVexRiscvSocSoftware/libs/uart.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/VexRiscvSocSoftware/libs/uart.h b/VexRiscvSocSoftware/libs/uart.h
new file mode 100755
index 0000000..c3a30a5
--- /dev/null
+++ b/VexRiscvSocSoftware/libs/uart.h
@@ -0,0 +1,42 @@
+#ifndef UART_H_
+#define UART_H_
+
+
+typedef struct
+{
+ volatile uint32_t DATA;
+ volatile uint32_t STATUS;
+ volatile uint32_t CLOCK_DIVIDER;
+ volatile uint32_t FRAME_CONFIG;
+} Uart_Reg;
+
+enum UartParity {NONE = 0,EVEN = 1,ODD = 2};
+enum UartStop {ONE = 0,TWO = 1};
+
+typedef struct {
+ uint32_t dataLength;
+ enum UartParity parity;
+ enum UartStop stop;
+ uint32_t clockDivider;
+} Uart_Config;
+
+static uint32_t uart_writeAvailability(Uart_Reg *reg){
+ return (reg->STATUS >> 16) & 0xFF;
+}
+static uint32_t uart_readOccupancy(Uart_Reg *reg){
+ return reg->STATUS >> 24;
+}
+
+static void uart_write(Uart_Reg *reg, uint32_t data){
+ while(uart_writeAvailability(reg) == 0);
+ reg->DATA = data;
+}
+
+static void uart_applyConfig(Uart_Reg *reg, Uart_Config *config){
+ reg->CLOCK_DIVIDER = config->clockDivider;
+ reg->FRAME_CONFIG = ((config->dataLength-1) << 0) | (config->parity << 8) | (config->stop << 16);
+}
+
+#endif /* UART_H_ */
+
+