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 <sys/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 Set serial parameters.
38 \param baud The bitrate to set.
39 \param fifo 1 to enable FIFO mode.
40*/
41void scif_set_parameters(int baud, int fifo);
42
43// The rest of these are the standard dbgio interface.
44
45/** \brief Enable or disable SCIF IRQ usage.
46 \param on 1 to enable IRQ usage, 0 for polled I/O.
47 \retval 0 On success (no error conditions defined).
48*/
50
51/** \brief Is the SCIF port detected? Of course it is!
52 \return 1
53*/
54int scif_detected(void);
55
56/** \brief Initialize the SCIF port.
57
58 This function initializes the SCIF port to a sane state. If dcload-serial is
59 in use, this is effectively a no-op.
60
61 \retval 0 On success (no error conditions defined).
62*/
63int scif_init(void);
64
65/** \brief Shutdown the SCIF port.
66
67 This function disables SCIF IRQs, if they were enabled and cleans up.
68
69 \retval 0 On success (no error conditions defined).
70*/
71int scif_shutdown(void);
72
73/** \brief Read a single character from the SCIF port.
74 \return The character read if one is available, otherwise -1
75 and errno is set to EAGAIN.
76*/
77int scif_read(void);
78
79/** \brief Write a single character to the SCIF port.
80 \param c The character to write (only the low 8-bits are
81 written).
82 \retval 1 On success.
83 \retval -1 If the SCIF port is disabled (errno set to EIO).
84*/
85int scif_write(int c);
86
87/** \brief Flush any FIFO'd bytes out of the buffer.
88
89 This function sends any bytes that have been queued up for transmission but
90 have not left yet in FIFO mode.
91
92 \retval 0 On success.
93 \retval -1 If the SCIF port is disabled (errno set to EIO).
94*/
95int scif_flush(void);
96
97/** \brief Write a whole buffer of data to the SCIF port.
98
99 This function writes a whole buffer of data to the SCIF port, optionally
100 making all newlines into carriage return + newline pairs.
101
102 \param data The buffer to write.
103 \param len The length of the buffer, in bytes.
104 \param xlat If set to 1, all newlines will be written as CRLF.
105 \return The number of bytes written on success, -1 on error.
106*/
107int scif_write_buffer(const uint8 *data, int len, int xlat);
108
109/** \brief Read a buffer of data from the SCIF port.
110
111 This function reads a whole buffer of data from the SCIF port, blocking
112 until it has been filled.
113
114 \param data The buffer to read into.
115 \param len The number of bytes to read.
116 \return The number of bytes read on success, -1 on error.
117*/
118int scif_read_buffer(uint8 *data, int len);
119
120/** \brief SCIF debug I/O handler. Do not modify! */
122
123/* Low-level SPI related functionality below here... */
124/** \brief Initialize the SCIF port for use of an SPI peripheral.
125
126 This function initializes the SCIF port for accessing the an SPI peripheral
127 that has been connected to the serial port. The design of the SCIF->SPI
128 wiring follows the wiring of the SD card adapter which is (at least now)
129 somewhat commonly available online and is the same as the one designed by
130 jj1odm.
131
132 \retval 0 On success.
133 \retval -1 On error (if dcload-serial is detected).
134*/
136
137/** \brief Shut down SPI card support over the SCIF port.
138
139 This function shuts down SPI support on the SCIF port. If you want to get
140 regular usage of the port back, you must call scif_init() after shutting
141 down SPI support.
142
143 \retval 0 On success (no errors defined).
144*/
146
147/** \brief Set or clear the SPI /CS line.
148
149 This function sets or clears the /CS line (connected to the RTS line of the
150 SCIF port).
151
152 \param v Non-zero to output 1 on the line, zero to output 0.
153*/
154void scif_spi_set_cs(int v);
155
156/** \brief Read and write one byte from the SPI port.
157
158 This function writes one byte and reads one back from the SPI device
159 simultaneously.
160
161 \param b The byte to write out to the port.
162 \return The byte returned from the card.
163*/
165
166/** \brief Read and write one byte from the SPI device, slowly.
167
168 This function does the same thing as the scif_sd_rw_byte() function, but
169 with a 1.5usec delay between asserting the CLK line and reading back the bit
170 and a 1.5usec delay between clearing the CLK line and writing the next bit
171 out.
172
173 This ends up working out to a clock of about 333khz, or so.
174
175 \param b The byte to write out to the port.
176 \return The byte returned from the card.
177*/
179
180
181/** \brief Write a byte to the SPI device.
182
183 This function writes out the specified byte to the SPI device, one bit at a
184 time. The timing follows that of the scif_spi_rw_byte() function.
185
186 \param b The byte to write out to the port.
187*/
189
190/** \brief Read a byte from the SPI device.
191
192 This function reads a byte from the SPI device, one bit at a time. Timing
193 is similar to (but slightly faster than) the scif_spi_rw_byte() function.
194
195 \return The byte returned from the device.
196*/
198
199/** \brief Read a data from the SPI device.
200
201 This function reads data from the SPI device. If the buffer is aligned and
202 len is divisible by 4, optimizations are applied.
203
204 \param buffer Buffer to store read data into.
205 \param len Number of bytes to read from the device.
206*/
207void scif_spi_read_data(uint8 *buffer, size_t len);
208
209/** @} */
210
211__END_DECLS
212
213#endif /* __DC_SCIF_H */
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.