libws libws
WSwan hardware library for the Wonderful toolchain
Loading...
Searching...
No Matches
uart.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Adrian "asie" Siekierka
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 *
8 * Permission is granted to anyone to use this software for any purpose,
9 * including commercial applications, and to alter it and redistribute it
10 * freely, subject to the following restrictions:
11 *
12 * 1. The origin of this software must not be misrepresented; you must not
13 * claim that you wrote the original software. If you use this software
14 * in a product, an acknowledgment in the product documentation would be
15 * appreciated but is not required.
16 *
17 * 2. Altered source versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software.
19 *
20 * 3. This notice may not be removed or altered from any source distribution.
21 */
22
26
27#ifndef LIBWS_UART_H_
28#define LIBWS_UART_H_
29
30#include <stdbool.h>
31#include <stdint.h>
32#include "ports.h"
33#include "util.h"
34
39
47
55static inline void ws_uart_open(uint8_t baud_rate) {
57}
58
62static inline void ws_uart_close(void) {
63 outportb(WS_UART_CTRL_PORT, 0x00);
64}
65
69static inline bool ws_uart_is_opened(void) {
70 return inportb(WS_UART_CTRL_PORT) & WS_UART_CTRL_ENABLE;
71}
72
76static inline bool ws_uart_is_rx_overrun(void) {
78}
79
86static inline void ws_uart_ack_rx_overrun(void) {
88}
89
95static inline bool ws_uart_is_rx_ready(void) {
97}
98
104static inline bool ws_uart_is_tx_ready(void) {
106}
107
115uint8_t ws_uart_getc(void);
116
124
132void ws_uart_putc(uint8_t value);
133
135
136#endif /* LIBWS_UART_H_ */
#define WS_UART_CTRL_ENABLE
Definition ports.h:1183
#define WS_UART_CTRL_RX_OVERRUN
Definition ports.h:1205
#define WS_UART_CTRL_BAUD_9600
Definition ports.h:1187
#define WS_UART_CTRL_RX_READY
Definition ports.h:1209
#define WS_UART_CTRL_BAUD_38400
Definition ports.h:1191
#define WS_UART_CTRL_TX_READY
Definition ports.h:1201
#define WS_UART_CTRL_RX_OVERRUN_RESET
Definition ports.h:1197
#define WS_UART_CTRL_PORT
Definition ports.h:1179
uint8_t ws_uart_getc(void)
Read a character from the UART.
ws_uart_baud_rate_t
UART baud rate.
Definition uart.h:43
void ws_uart_putc(uint8_t value)
Write a character to the UART.
static void ws_uart_close(void)
Close the UART (EXT port) connection.
Definition uart.h:62
static void ws_uart_open(uint8_t baud_rate)
Open the UART (EXT port) connection.
Definition uart.h:55
static bool ws_uart_is_opened(void)
Check if an UART connection is currently opened.
Definition uart.h:69
static bool ws_uart_is_tx_ready(void)
Is the UART transmit buffer ready to accept a byte?
Definition uart.h:104
static void ws_uart_ack_rx_overrun(void)
Acknowledge that the UART receive buffer has overflowed.
Definition uart.h:86
static bool ws_uart_is_rx_overrun(void)
Check if the UART receive buffer has overflowed.
Definition uart.h:76
int16_t ws_uart_getc_nonblock(void)
Try to read a character from the UART.
static bool ws_uart_is_rx_ready(void)
Does the UART receive buffer contain a byte?
Definition uart.h:95
@ WS_UART_BAUD_RATE_38400
UART baud rate: 38400 baud (3840 bytes/second).
Definition uart.h:45
@ WS_UART_BAUD_RATE_9600
UART baud rate: 9600 baud (960 bytes/second).
Definition uart.h:44