MOS Source Code
Loading...
Searching...
No Matches
serial.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#pragma once
4
5#include <mos/types.h>
6
7typedef enum
8{
9 OFFSET_INTERRUPT_ENABLE = 1, // Interrupt Enable Register
10 OFFSET_INTERRUPT_ID_FIFO = 2, // Interrupt ID Register and FIFO Control Register
11 OFFSET_LINE_CONTROL = 3, // Line Control Register
12 OFFSET_MODEM_CONTROL = 4, // Modem Control Register
13 OFFSET_LINE_STATUS = 5, // Line Status Register
14 OFFSET_MODEM_STATUS = 6, // Modem Status Register
15 OFFSET_SCRATCH = 7, // Scratch Register
16
17 OFFSET_DLAB_DIVISOR_LSB = 0, // With DLAB set to 1, this is the least significant byte of the divisor value for setting the baud rate.
18 OFFSET_DLAB_DIVISOR_MSB = 1, // With DLAB set to 1, this is the most significant byte of the divisor value.
20
28
29typedef enum
30{
31 STOP_BITS_1, // 1 stop bit
32 STOP_BITS_15_OR_2, // 1.5 or 2 stop bits
34
35typedef enum
36{
37 PARITY_NONE = 0, // No parity
38 PARITY_ODD = 1, // Odd parity
39 PARITY_EVEN = 2, // Even parity
40 PARITY_MARK = 3, // Parity bit always 1
41 PARITY_SPACE = 4, // Parity bit always 0
43
44typedef enum
45{
46 INTERRUPT_DATA_AVAILABLE = 1 << 0, // Data ready interrupt
47 INTERRUPT_TRANSMITTER_EMPTY = 1 << 1, // Transmitter empty interrupt
48 INTERRUPT_BREAK_ERROR = 1 << 2, // Break error interrupt
49 INTERRUPT_STATUS_CHANGE = 1 << 3, // Status change interrupt
50 INTERRUPT_NONE = 0, // No interrupts
53
68
69typedef struct _serial_device serial_device_t;
70
71typedef struct _serial_driver
72{
73 u8 (*read_data)(serial_device_t *dev);
74 void (*write_data)(serial_device_t *dev, u8 data);
75
76 u8 (*read_register)(serial_device_t *dev, serial_register_t offset);
77 void (*write_register)(serial_device_t *dev, serial_register_t offset, u8 value);
79
90
92
93int serial_device_read(serial_device_t *device, char *data, size_t length);
94
95int serial_device_write(serial_device_t *device, const char *data, size_t length);
96
MOSAPI void(1, 2) fatal_abort(const char *fmt
int serial_device_read(serial_device_t *device, char *data, size_t length)
Definition serial.c:169
serial_stopbits_t
Definition serial.h:30
@ STOP_BITS_15_OR_2
Definition serial.h:32
@ STOP_BITS_1
Definition serial.h:31
bool serial_dev_get_data_ready(serial_device_t *device)
Definition serial.c:141
struct _serial_device serial_device_t
Definition serial.h:69
serial_interrupt_t
Definition serial.h:45
@ INTERRUPT_DATA_AVAILABLE
Definition serial.h:46
@ INTERRUPT_NONE
Definition serial.h:50
@ INTERRUPT_ALL
Definition serial.h:51
@ INTERRUPT_TRANSMITTER_EMPTY
Definition serial.h:47
@ INTERRUPT_BREAK_ERROR
Definition serial.h:48
@ INTERRUPT_STATUS_CHANGE
Definition serial.h:49
serial_charlength_t
Definition serial.h:22
@ CHAR_LENGTH_6
Definition serial.h:24
@ CHAR_LENGTH_5
Definition serial.h:23
@ CHAR_LENGTH_8
Definition serial.h:26
@ CHAR_LENGTH_7
Definition serial.h:25
serial_baudrate_t
Definition serial.h:55
@ BAUD_RATE_19200
Definition serial.h:59
@ BAUD_RATE_57600
Definition serial.h:57
@ BAUD_RATE_110
Definition serial.h:66
@ BAUD_RATE_9600
Definition serial.h:60
@ BAUD_RATE_38400
Definition serial.h:58
@ BAUD_RATE_600
Definition serial.h:64
@ BAUD_RATE_4800
Definition serial.h:61
@ BAUD_RATE_300
Definition serial.h:65
@ BAUD_RATE_115200
Definition serial.h:56
@ BAUD_RATE_2400
Definition serial.h:62
@ BAUD_RATE_1200
Definition serial.h:63
serial_register_t
Definition serial.h:8
@ OFFSET_LINE_STATUS
Definition serial.h:13
@ OFFSET_DLAB_DIVISOR_LSB
Definition serial.h:17
@ OFFSET_MODEM_CONTROL
Definition serial.h:12
@ OFFSET_INTERRUPT_ENABLE
Definition serial.h:9
@ OFFSET_DLAB_DIVISOR_MSB
Definition serial.h:18
@ OFFSET_MODEM_STATUS
Definition serial.h:14
@ OFFSET_LINE_CONTROL
Definition serial.h:11
@ OFFSET_INTERRUPT_ID_FIFO
Definition serial.h:10
@ OFFSET_SCRATCH
Definition serial.h:15
bool serial_device_setup(serial_device_t *device)
Definition serial.c:112
int serial_device_write(serial_device_t *device, const char *data, size_t length)
Definition serial.c:158
serial_parity_t
Definition serial.h:36
@ PARITY_SPACE
Definition serial.h:41
@ PARITY_ODD
Definition serial.h:38
@ PARITY_MARK
Definition serial.h:40
@ PARITY_NONE
Definition serial.h:37
@ PARITY_EVEN
Definition serial.h:39
serial_baudrate_t baudrate_divisor
Definition serial.h:85
serial_parity_t parity
Definition serial.h:88
serial_charlength_t char_length
Definition serial.h:86
const serial_driver_t * driver
Definition serial.h:82
void * driver_data
Definition serial.h:83
serial_stopbits_t stop_bits
Definition serial.h:87
unsigned char u8
Definition types.h:19