KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
dbgio.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 kos/include/dbgio.h
4 Copyright (C)2000,2004 Megan Potter
5
6*/
7
8/** \file kos/dbgio.h
9 \brief Debug I/O.
10 \ingroup logging
11
12 This file contains the Debug I/O system, which abstracts things so that
13 various types of debugging tools can be used by programs in KOS. Included
14 among these tools is the dcload console (dcload-serial, dcload-ip, and
15 fs_dclsocket), a raw serial console, and a framebuffer based console.
16
17 \author Megan Potter
18*/
19
20#ifndef __KOS_DBGIO_H
21#define __KOS_DBGIO_H
22
23#include <kos/cdefs.h>
24__BEGIN_DECLS
25
26#include <arch/types.h>
27
28/** \brief Debug I/O Interface.
29 \ingroup logging
30
31 This struct represents a single dbgio interface. This should represent
32 a generic pollable console interface. We will store an ordered list of
33 these statically linked into the program and fall back from one to the
34 next until one returns true for detected(). Note that the last device in
35 this chain is the null console, which will always return true.
36
37 \headerfile kos/dbgio.h
38*/
39typedef struct dbgio_handler {
40 /** \brief Name of the dbgio handler */
41 const char * name;
42
43 /** \brief Detect this debug interface.
44 \retval 1 If the device is available and usable
45 \retval 0 If the device is unavailable
46 */
47 int (*detected)(void);
48
49 /** \brief Initialize this debug interface with default parameters.
50 \retval 0 On success
51 \retval -1 On failure
52 */
53 int (*init)(void);
54
55 /** \brief Shutdown this debug interface.
56 \retval 0 On success
57 \retval -1 On failure
58 */
59 int (*shutdown)(void);
60
61 /** \brief Set either polled or IRQ usage for this interface.
62 \param mode 1 for IRQ-based usage, 0 for polled I/O
63 \retval 0 On success
64 \retval -1 On failure
65 */
66 int (*set_irq_usage)(int mode);
67
68 /** \brief Read one character from the console.
69 \retval 0 On success
70 \retval -1 On failure (set errno as appropriate)
71 */
72 int (*read)(void);
73
74 /** \brief Write one character to the console.
75 \param c The character to write
76 \retval 1 On success
77 \retval -1 On error (set errno as appropriate)
78 \note Interfaces may require a call to flush() before the
79 output is actually flushed to the console.
80 */
81 int (*write)(int c);
82
83 /** \brief Flush any queued output.
84 \retval 0 On success
85 \retval -1 On error (set errno as appropriate)
86 */
87 int (*flush)(void);
88
89 /** \brief Write an entire buffer of data to the console.
90 \param data The buffer to write
91 \param len The length of the buffer
92 \param xlat If non-zero, newline transformations may occur
93 \return Number of characters written on success, or -1 on
94 failure (set errno as appropriate)
95 */
96 int (*write_buffer)(const uint8 *data, int len, int xlat);
97
98 /** \brief Read an entire buffer of data from the console.
99 \param data The buffer to read into
100 \param len The length of the buffer
101 \return Number of characters read on success, or -1 on
102 failure (set errno as appropriate)
103 */
104 int (*read_buffer)(uint8 *data, int len);
106
107/** \cond */
108/* These two should be initialized in arch. */
109extern dbgio_handler_t * dbgio_handlers[];
110extern int dbgio_handler_cnt;
111
112/* This is defined by the shared code, in case there's no valid handler. */
113extern dbgio_handler_t dbgio_null;
114/** \endcond */
115
116/** \brief Select a new dbgio interface by name.
117 \ingroup logging
118
119 This function manually selects a new dbgio interface by name. This function
120 will allow you to select a device, even if it is not detected.
121
122 \param name The dbgio interface to select
123 \retval 0 On success
124
125 \retval -1 On error
126
127 \par Error Conditions:
128 \em ENODEV - The specified device could not be initialized
129*/
130int dbgio_dev_select(const char * name);
131
132/** \brief Fetch the name of the currently selected dbgio interface.
133 \ingroup logging
134
135 \return The name of the current dbgio interface (or NULL if
136 no device is selected)
137*/
138const char * dbgio_dev_get(void);
139
140/** \brief Initialize the dbgio console.
141 \ingroup logging
142
143 This function is called internally, and shouldn't need to be called by any
144 user programs.
145
146 \retval 0 On success
147
148 \retval -1 On error
149
150 \par Error Conditions:
151 \em ENODEV - No devices could be detected/initialized
152*/
153int dbgio_init(void);
154
155/** \brief Set IRQ usage.
156 \ingroup logging
157
158 The dbgio system defaults to polled usage. Some devices may not support IRQ
159 mode at all.
160
161 \param mode The mode to use
162
163 \retval 0 On success
164 \retval -1 On error (errno should be set as appropriate)
165*/
167
168/** \brief Polled I/O mode.
169 \ingroup logging
170
171 \see dbgio_set_irq_usage()
172*/
173#define DBGIO_MODE_POLLED 0
174
175/** \brief IRQ-based I/O mode.
176 \ingroup logging
177
178 \see dbgio_set_irq_usage()
179*/
180#define DBGIO_MODE_IRQ 1
181
182/** \brief Read one character from the console.
183 \ingroup logging
184
185 \retval 0 On success
186 \retval -1 On error (errno should be set as appropriate)
187*/
188int dbgio_read(void);
189
190/** \brief Write one character to the console.
191 \ingroup logging
192
193 \note Interfaces may require a call to flush() before the
194 output is actually flushed to the console.
195
196 \param c The character to write
197
198 \retval 1 On success (number of characters written)
199 \retval -1 On error (errno should be set as appropriate)
200*/
201int dbgio_write(int c);
202
203/** \brief Flush any queued output.
204 \ingroup logging
205
206 \retval 0 On success
207 \retval -1 On error (errno should be set as appropriate)
208*/
209int dbgio_flush(void);
210
211/** \brief Write an entire buffer of data to the console.
212 \ingroup logging
213
214 \param data The buffer to write
215 \param len The length of the buffer
216
217 \return Number of characters written on success, or -1 on
218 failure (errno should be set as appropriate)
219*/
220int dbgio_write_buffer(const uint8 *data, int len);
221
222/** \brief Read an entire buffer of data from the console.
223 \ingroup logging
224
225 \param data The buffer to read into
226 \param len The length of the buffer
227
228 \return Number of characters read on success, or -1 on
229 failure (errno should be set as appropriate)
230*/
231int dbgio_read_buffer(uint8 *data, int len);
232
233/** \brief Write an entire buffer of data to the console (potentially with
234 newline transformations).
235 \ingroup logging
236
237 \param data The buffer to write
238 \param len The length of the buffer
239
240 \return Number of characters written on success, or -1 on
241 failure (errno should be set as appropriate)
242*/
243int dbgio_write_buffer_xlat(const uint8 *data, int len);
244
245/** \brief Write a NUL-terminated string to the console.
246 \ingroup logging
247
248 \param str The string to write
249
250 \return Number of characters written on success, or -1 on
251 failure (errno should be set as appropriate)
252*/
253int dbgio_write_str(const char *str);
254
255/** \brief Disable debug I/O globally.
256 \ingroup logging
257*/
258void dbgio_disable(void);
259
260/** \brief Enable debug I/O globally.
261 \ingroup logging
262*/
263void dbgio_enable(void);
264
265/** \brief Built-in debug I/O printf function.
266 \ingroup logging
267
268 \param fmt A printf() style format string
269 \param ... Format arguments
270
271 \return The number of bytes written, or <0 on error (errno
272 should be set as appropriate)
273*/
274int dbgio_printf(const char *fmt, ...) __printflike(1, 2);
275
276__END_DECLS
277
278#endif /* __KOS_DBGIO_H */
279
Definitions for builtin attributes and compiler directives.
int dbgio_set_irq_usage(int mode)
Set IRQ usage.
int dbgio_init(void)
Initialize the dbgio console.
int dbgio_write_buffer(const uint8 *data, int len)
Write an entire buffer of data to the console.
int dbgio_write_buffer_xlat(const uint8 *data, int len)
Write an entire buffer of data to the console (potentially with newline transformations).
int dbgio_printf(const char *fmt,...) __printflike(1
Built-in debug I/O printf function.
void dbgio_enable(void)
Enable debug I/O globally.
const char * dbgio_dev_get(void)
Fetch the name of the currently selected dbgio interface.
void dbgio_disable(void)
Disable debug I/O globally.
int dbgio_read(void)
Read one character from the console.
int dbgio_write_str(const char *str)
Write a NUL-terminated string to the console.
int dbgio_read_buffer(uint8 *data, int len)
Read an entire buffer of data from the console.
int dbgio_dev_select(const char *name)
Select a new dbgio interface by name.
int dbgio_flush(void)
Flush any queued output.
int dbgio_write(int c)
Write one character to the console.
int shutdown(int socket, int how)
Shutdown socket send and receive operations.
#define __printflike(fmtarg, firstvararg)
Identify a function as accepting formatting like printf().
Definition cdefs.h:132
unsigned char uint8
8-bit unsigned integer
Definition types.h:35
Debug I/O Interface.
Definition dbgio.h:39
const char * name
Name of the dbgio handler.
Definition dbgio.h:41
Common integer types.