KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
scif.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 dc/scif.h
4 Copyright (C) 2000,2001,2004 Megan Potter
5 Copyright (C) 2012 Lawrence Sebald
6 Copyright (C) 2023 Ruslan Rostovtsev
7
8*/
9
10/** \file dc/scif.h
11 \brief Serial port functionality.
12 \ingroup system_scif
13
14 This file deals with raw access to the serial port on the Dreamcast.
15
16 \author Megan Potter
17 \author Lawrence Sebald
18 \author Ruslan Rostovtsev
19*/
20
21#ifndef __DC_SCIF_H
22#define __DC_SCIF_H
23
24#include <kos/cdefs.h>
25__BEGIN_DECLS
26
27#include <arch/types.h>
28#include <kos/dbgio.h>
29
30/** \defgroup system_scif SCIF
31 \brief Driver for managing the serial port
32 \ingroup system
33
34 @{
35*/
36
37/** \brief Default serial bitrate. */
38#define DEFAULT_SERIAL_BAUD 115200
39
40/** \brief Default serial FIFO behavior. */
41#define DEFAULT_SERIAL_FIFO 1
42
43/** \brief Set serial parameters.
44 \param baud The bitrate to set.
45 \param fifo 1 to enable FIFO mode.
46*/
47void scif_set_parameters(int baud, int fifo);
48
49/* The rest of these are the standard dbgio interface. */
50
51/** \brief Enable or disable SCIF IRQ usage.
52 \param on 1 to enable IRQ usage, 0 for polled I/O.
53 \retval 0 On success (no error conditions defined).
54*/
56
57/** \brief Is the SCIF port detected? Of course it is!
58 \return 1
59*/
60int scif_detected(void);
61
62/** \brief Initialize the SCIF port.
63
64 This function initializes the SCIF port to a sane state. If dcload-serial is
65 in use, this is effectively a no-op.
66
67 \retval 0 On success (no error conditions defined).
68*/
69int scif_init(void);
70
71/** \brief Shutdown the SCIF port.
72
73 This function disables SCIF IRQs, if they were enabled and cleans up.
74
75 \retval 0 On success (no error conditions defined).
76*/
77int scif_shutdown(void);
78
79/** \brief Read a single character from the SCIF port.
80 \return The character read if one is available, otherwise -1
81 and errno is set to EAGAIN.
82*/
83int scif_read(void);
84
85/** \brief Write a single character to the SCIF port.
86 \param c The character to write (only the low 8-bits are
87 written).
88 \retval 1 On success.
89 \retval -1 If the SCIF port is disabled (errno set to EIO).
90*/
91int scif_write(int c);
92
93/** \brief Flush any FIFO'd bytes out of the buffer.
94
95 This function sends any bytes that have been queued up for transmission but
96 have not left yet in FIFO mode.
97
98 \retval 0 On success.
99 \retval -1 If the SCIF port is disabled (errno set to EIO).
100*/
101int scif_flush(void);
102
103/** \brief Write a whole buffer of data to the SCIF port.
104
105 This function writes a whole buffer of data to the SCIF port, optionally
106 making all newlines into carriage return + newline pairs.
107
108 \param data The buffer to write.
109 \param len The length of the buffer, in bytes.
110 \param xlat If set to 1, all newlines will be written as CRLF.
111 \return The number of bytes written on success, -1 on error.
112*/
113int scif_write_buffer(const uint8 *data, int len, int xlat);
114
115/** \brief Read a buffer of data from the SCIF port.
116
117 This function reads a whole buffer of data from the SCIF port, blocking
118 until it has been filled.
119
120 \param data The buffer to read into.
121 \param len The number of bytes to read.
122 \return The number of bytes read on success, -1 on error.
123*/
124int scif_read_buffer(uint8 *data, int len);
125
126/** \brief SCIF debug I/O handler. Do not modify! */
128
129/* Low-level SPI related functionality below here... */
130/** \brief Initialize the SCIF port for use of an SPI peripheral.
131
132 This function initializes the SCIF port for accessing the an SPI peripheral
133 that has been connected to the serial port. The design of the SCIF->SPI
134 wiring follows the wiring of the SD card adapter which is (at least now)
135 somewhat commonly available online and is the same as the one designed by
136 jj1odm.
137
138 \retval 0 On success.
139 \retval -1 On error (if dcload-serial is detected).
140*/
142
143/** \brief Shut down SPI card support over the SCIF port.
144
145 This function shuts down SPI support on the SCIF port. If you want to get
146 regular usage of the port back, you must call scif_init() after shutting
147 down SPI support.
148
149 \retval 0 On success (no errors defined).
150*/
152
153/** \brief Set or clear the SPI /CS line.
154
155 This function sets or clears the /CS line (connected to the RTS line of the
156 SCIF port).
157
158 \param v Non-zero to output 1 on the line, zero to output 0.
159*/
160void scif_spi_set_cs(int v);
161
162/** \brief Read and write one byte from the SPI port.
163
164 This function writes one byte and reads one back from the SPI device
165 simultaneously.
166
167 \param b The byte to write out to the port.
168 \return The byte returned from the card.
169*/
171
172/** \brief Read and write one byte from the SPI device, slowly.
173
174 This function does the same thing as the scif_sd_rw_byte() function, but
175 with a 1.5usec delay between asserting the CLK line and reading back the bit
176 and a 1.5usec delay between clearing the CLK line and writing the next bit
177 out.
178
179 This ends up working out to a clock of about 333khz, or so.
180
181 \param b The byte to write out to the port.
182 \return The byte returned from the card.
183*/
185
186
187/** \brief Write a byte to the SPI device.
188
189 This function writes out the specified byte to the SPI device, one bit at a
190 time. The timing follows that of the scif_spi_rw_byte() function.
191
192 \param b The byte to write out to the port.
193*/
195
196/** \brief Read a byte from the SPI device.
197
198 This function reads a byte from the SPI device, one bit at a time. Timing
199 is similar to (but slightly faster than) the scif_spi_rw_byte() function.
200
201 \return The byte returned from the device.
202*/
204
205/** \brief Read a data from the SPI device.
206
207 This function reads data from the SPI device. If the buffer is aligned and
208 len is divisible by 4, optimizations are applied.
209
210 \param buffer Buffer to store read data into.
211 \param len Number of bytes to read from the device.
212*/
213void scif_spi_read_data(uint8 *buffer, size_t len);
214
215/** @} */
216
217__END_DECLS
218
219#endif /* __DC_SCIF_H */
Various common macros used throughout the codebase.
Debug I/O.
int scif_set_irq_usage(int on)
Enable or disable SCIF IRQ usage.
int scif_write_buffer(const uint8 *data, int len, int xlat)
Write a whole buffer of data to the SCIF port.
uint8 scif_spi_slow_rw_byte(uint8 b)
Read and write one byte from the SPI device, slowly.
int scif_read_buffer(uint8 *data, int len)
Read a buffer of data from the SCIF port.
dbgio_handler_t dbgio_scif
SCIF debug I/O handler.
int scif_detected(void)
Is the SCIF port detected? Of course it is!
void scif_spi_write_byte(uint8 b)
Write a byte to the SPI device.
int scif_spi_init(void)
Initialize the SCIF port for use of an SPI peripheral.
void scif_set_parameters(int baud, int fifo)
Set serial parameters.
int scif_shutdown(void)
Shutdown the SCIF port.
int scif_init(void)
Initialize the SCIF port.
void scif_spi_set_cs(int v)
Set or clear the SPI /CS line.
int scif_write(int c)
Write a single character to the SCIF port.
int scif_spi_shutdown(void)
Shut down SPI card support over the SCIF port.
uint8 scif_spi_rw_byte(uint8 b)
Read and write one byte from the SPI port.
int scif_read(void)
Read a single character from the SCIF port.
void scif_spi_read_data(uint8 *buffer, size_t len)
Read a data from the SPI device.
int scif_flush(void)
Flush any FIFO'd bytes out of the buffer.
uint8 scif_spi_read_byte(void)
Read a byte from the SPI device.
unsigned char uint8
8-bit unsigned integer
Definition types.h:35
Debug I/O Interface.
Definition dbgio.h:39
Common integer types.