Sapphire SoC DS Sapphire SoC UG Sapphire HP SoC DS Sapphire HP SoC UG RISC-V Embedded IDE UG Board Support Package
Loading...
Searching...
No Matches
uart.c
Go to the documentation of this file.
1
2// Copyright (C) 2013-2026 Efinix Inc. All rights reserved.
3// Full license header bsp/efinix/EfxSapphireSocRV64/include/LICENSE.MD
5
15
16#include "uart/uart.h"
17
18/*----------------------------------------------------------------------------*/
19/* Function implementations */
20/*----------------------------------------------------------------------------*/
21
23 return ( (inst->hwreg->STATUS >>16) & 0xff );
24}
25
27 return ( inst->hwreg->STATUS >> 24 );
28}
29
30
32{
33 return inst->hwreg->STATUS;
34}
35
36
38{
39 inst->hwreg->STATUS = data;
40}
41
42
44 while(uart_readOccupancy(inst) == 0);
45 return ( inst->hwreg->DATA );
46}
47
48
49void uart_write(uart_instance_t *inst, char data) {
50 while (uart_writeAvailability(inst) == 0);
51 inst->hwreg->DATA = data;
52}
53
54
55void uart_writeStr(uart_instance_t *inst, const char* str){
56 while(*str) uart_write(inst, *str++);
57}
58
59
60void uart_writeHex(uart_instance_t *inst, int value){
61 for(int i = 7; i >= 0; i--){
62 int hex = (value >> i*4) & 0xF;
63 uart_write(inst, hex > 9 ? 'A' + hex - 10 : '0' + hex);
64 }
65}
66
67
69 inst->hwreg->CLOCK_DIVIDER = inst->clockDivider;
70 inst->hwreg->FRAME_CONFIG = ((inst->dataLength-1) << 0 | (inst->parity << 8) | (inst->stop << 16));
71
72}
73
74
76{
77 uart_status_write(inst,(uart_status_read(inst) & 0xFFFFFFFE) | (Ena & 0x01));
78}
79
80
82{
83 uart_status_write(inst,(uart_status_read(inst) & 0xFFFFFFFD) | (Ena << 1));
84}
void uart_writeStr(uart_instance_t *inst, const char *str)
Write string to UART.
Definition uart.c:55
void uart_write(uart_instance_t *inst, char data)
Writes a single character to the UART data register.
Definition uart.c:49
void uart_status_write(uart_instance_t *inst, u32 data)
Writes a value to the UART status register.
Definition uart.c:37
void uart_writeHex(uart_instance_t *inst, int value)
Write integer as decimal to UART.
Definition uart.c:60
u32 uart_status_read(uart_instance_t *inst)
Write 32-bit UART data.
Definition uart.c:31
void uart_RX_NotemptyInterruptEna(uart_instance_t *inst, char Ena)
Enable or Disable UART RX Not Empty Interrupt.
Definition uart.c:81
u32 uart_writeAvailability(uart_instance_t *inst)
Checks the availability of the UART buffer for writing data.
Definition uart.c:22
void uart_TX_emptyInterruptEna(uart_instance_t *inst, char Ena)
Enable or Disable UART TX Empty Interrupt.
Definition uart.c:75
u32 uart_readOccupancy(uart_instance_t *inst)
Checks the occupancy of the UART buffer for reading data.
Definition uart.c:26
u32 uart_read(uart_instance_t *inst)
Read 32-bit UART data.
Definition uart.c:43
void uart_applyConfig(uart_instance_t *inst)
Apply stored UART configuration to hardware.
Definition uart.c:68
u32 CLOCK_DIVIDER
Address Offset: 0x08 - Clock Divider Register *‍/.
Definition uart.h:105
u32 DATA
Address Offset: 0x00 - Data Register *‍/.
Definition uart.h:103
u32 FRAME_CONFIG
Address Offset: 0x0C - Frame Configuration Register *‍/.
Definition uart.h:106
u32 STATUS
Address Offset: 0x04 - Status Register *‍/.
Definition uart.h:104
UART instance. Holds the software registers and hardware pointer.
Definition uart.h:114
cfg_dataParity_t parity
Parity Configuration *‍/.
Definition uart.h:117
cfg_dataLength_t dataLength
Data Length Configuration *‍/.
Definition uart.h:116
uart_hwreg_t * hwreg
Pointer to Hardware Register Map *‍/.
Definition uart.h:115
u32 clockDivider
Clock Divider Value *‍/.
Definition uart.h:119
cfg_stopBits_t stop
Stop Bits Configuration *‍/.
Definition uart.h:118
uint32_t u32
Definition type.h:22
UART driver API definitions.