KallistiOS  ##version##
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
modem.h
Go to the documentation of this file.
1 /* KallistiOS ##version##
2 
3  modem.h
4  Copyright (C)2002, 2004 Nick Kochakian
5 
6  Distributed under the terms of the KOS license.
7 
8 */
9 
10 /** \file dc/modem/modem.h
11  \brief Definitions to use the Dreamcast modem.
12 
13  This file contains functions and constants to be used with the Dreamcast
14  modem driver.
15 
16  \author Nick Kochakian
17 */
18 
19 #ifndef __DC_MODEM_MODEM_H
20 #define __DC_MODEM_MODEM_H
21 
22 #include "mconst.h"
23 
24 /** \defgroup modem_modes Modes of operation of the Dreamcast modem.
25 
26  This group defines the modes that the Dreamcast modem can be in at any given
27  point in time.
28 
29  @{
30 */
31 /** \brief Connect to a remote modem. */
32 #define MODEM_MODE_REMOTE 0
33 
34 /** \brief Answer a call when a ring is detected. */
35 #define MODEM_MODE_ANSWER 1
36 
37 /** \brief Modem not in use. Do not attempt to set this mode yourself! */
38 #define MODEM_MODE_NULL 255
39 /** @} */
40 
41 /** \defgroup modem_v22bis Modem V.22bis modes
42  @{
43 */
44 /** \brief 1200bps, V.22bis */
45 #define MODEM_SPEED_V22BIS_1200 MODEM_MAKE_SPEED(MODEM_PROTOCOL_V22BIS, MODEM_SPEED_1200)
46 
47 /** \brief 2400bps, V.22bis */
48 #define MODEM_SPEED_V22BIS_2400 MODEM_MAKE_SPEED(MODEM_PROTOCOL_V22BIS, MODEM_SPEED_2400)
49 /** @} */
50 
51 /** \defgroup modem_v22 Modem V.22 modes
52  @{
53 */
54 /** \brief 1200bps, V.22 */
55 #define MODEM_SPEED_V22_1200 MODEM_MAKE_SPEED(MODEM_PROTOCOL_V22, MODEM_SPEED_1200)
56 /** @} */
57 
58 /** \defgroup modem_v32 Modem V.32 modes
59  @{
60 */
61 /** \brief 4800bps, V.32 */
62 #define MODEM_SPEED_V32_4800 MODEM_MAKE_SPEED(MODEM_PROTOCOL_V32, MODEM_SPEED_4800)
63 
64 /** \brief 9600bps, V.32 */
65 #define MODEM_SPEED_V32_9600 MODEM_MAKE_SPEED(MODEM_PROTOCOL_V32, MODEM_SPEED_9600)
66 /** @} */
67 
68 /** \defgroup modem_v32bis Modem V.32 bis modes
69  @{
70 */
71 /** \brief 7200bps, V.32bis */
72 #define MODEM_SPEED_V32BIS_7200 MODEM_MAKE_SPEED(MODEM_PROTOCOL_V32BIS, MODEM_SPEED_7200)
73 
74 /** \brief 12000bps, V.32bis */
75 #define MODEM_SPEED_V32BIS_12000 MODEM_MAKE_SPEED(MODEM_PROTOCOL_V32BIS, MODEM_SPEED_12000)
76 
77 /** \brief 14400bps, V.32bis */
78 #define MODEM_SPEED_V32BIS_14400 MODEM_MAKE_SPEED(MODEM_PROTOCOL_V32BIS, MODEM_SPEED_14400)
79 /** @} */
80 
81 /** \defgroup modem_v8 Modem V.8 modes
82  @{
83 */
84 /** \brief 2400bps, V.8 */
85 #define MODEM_SPEED_V8_2400 MODEM_MAKE_SPEED(MODEM_PROTOCOL_V8, MODEM_SPEED_2400)
86 
87 /** \brief 4800bps, V.8 */
88 #define MODEM_SPEED_V8_4800 MODEM_MAKE_SPEED(MODEM_PROTOCOL_V8, MODEM_SPEED_4800)
89 
90 /** \brief 7200bps, V.8 */
91 #define MODEM_SPEED_V8_7200 MODEM_MAKE_SPEED(MODEM_PROTOCOL_V8, MODEM_SPEED_7200)
92 
93 /** \brief 9600bps, V.8 */
94 #define MODEM_SPEED_V8_9600 MODEM_MAKE_SPEED(MODEM_PROTOCOL_V8, MODEM_SPEED_9600)
95 
96 /** \brief 12000bps, V.8 */
97 #define MODEM_SPEED_V8_12000 MODEM_MAKE_SPEED(MODEM_PROTOCOL_V8, MODEM_SPEED_12000)
98 
99 /** \brief 14400bps, V.8 */
100 #define MODEM_SPEED_V8_14400 MODEM_MAKE_SPEED(MODEM_PROTOCOL_V8, MODEM_SPEED_14400)
101 
102 /** \brief 16800bps, V.8 */
103 #define MODEM_SPEED_V8_16800 MODEM_MAKE_SPEED(MODEM_PROTOCOL_V8, MODEM_SPEED_16800)
104 
105 /** \brief 19200bps, V.8 */
106 #define MODEM_SPEED_V8_19200 MODEM_MAKE_SPEED(MODEM_PROTOCOL_V8, MODEM_SPEED_19200)
107 
108 /** \brief 21600bps, V.8 */
109 #define MODEM_SPEED_V8_21600 MODEM_MAKE_SPEED(MODEM_PROTOCOL_V8, MODEM_SPEED_21600)
110 
111 /** \brief 24000bps, V.8 */
112 #define MODEM_SPEED_V8_24000 MODEM_MAKE_SPEED(MODEM_PROTOCOL_V8, MODEM_SPEED_24000)
113 
114 /** \brief 26400bps, V.8 */
115 #define MODEM_SPEED_V8_26400 MODEM_MAKE_SPEED(MODEM_PROTOCOL_V8, MODEM_SPEED_26400)
116 
117 /** \brief 28000bps, V.8 */
118 #define MODEM_SPEED_V8_28000 MODEM_MAKE_SPEED(MODEM_PROTOCOL_V8, MODEM_SPEED_28000)
119 
120 /** \brief 31200bps, V.8 */
121 #define MODEM_SPEED_V8_31200 MODEM_MAKE_SPEED(MODEM_PROTOCOL_V8, MODEM_SPEED_31200)
122 
123 /** \brief 33600bps, V.8 */
124 #define MODEM_SPEED_V8_33600 MODEM_MAKE_SPEED(MODEM_PROTOCOL_V8, MODEM_SPEED_33600)
125 
126 /** \brief Automatically set speed, V.8 */
127 #define MODEM_SPEED_V8_AUTO MODEM_MAKE_SPEED(MODEM_PROTOCOL_V8, MODEM_SPEED_1200)
128 /** @} */
129 
130 /** \brief Modem event types.
131 
132  These are teh events that a modem event handler should be expected to
133  receive at any given point in time.
134 */
135 typedef enum {
136  /** \brief The modem tried to establish a connection, but failed.*/
138 
139  /** \brief A connection has been established. */
141 
142  /** \brief The remote modem dropped the connection. */
144 
145  /** \brief New data has entered the previously empty receive buffer. */
147 
148  /** \brief The receive buffer overflowed and was cleared. */
150 
151  /** \brief The transmit buffer has been emptied. */
153 } modemEvent_t;
154 
155 /** \brief Type of a modem event handling function. */
156 typedef void (*MODEMEVENTHANDLERPROC)(modemEvent_t event);
157 
158 /* From modem.c */
159 /** \brief Initialize the modem.
160 
161  This function initializes the modem for use.
162 
163  \retval 0 On failure.
164  \retval 1 On success.
165 */
166 int modem_init(void);
167 
168 /** \brief Shut down the modem.
169 
170  This function shuts down the modem after it has been initialized, resetting
171  all of the registers to their defaults.
172 */
173 void modem_shutdown(void);
174 
175 /** \brief Set the modem up for the specified mode.
176 
177  This function sets up the modem's registers for the specified mode and speed
178  combination.
179 
180  \param mode The mode to use.
181  \param speed The speed to use.
182  \see modem_modes
183  \see modem_v22bis
184  \see modem_v22
185  \see modem_v32
186  \see modem_v32bis
187  \see modem_v8
188 */
189 int modem_set_mode(int mode, modem_speed_t speed);
190 
191 /** \brief Wait for the modem to detect a dialtone.
192 
193  This function waits for a dialtone to be detected on the modem.
194 
195  \param ms_timeout The number of milliseconds to wait, in multiples of 100.
196  \retval 0 If a dialtone is detected before timeout.
197  \retval -1 If no dialtone is detected.
198 */
199 int modem_wait_dialtone(int ms_timeout);
200 
201 /** \brief Dial the specified number on the modem.
202  \param digits The number to dial, as a string.
203  \retval 0 On failure.
204  \retval 1 On success.
205 */
206 int modem_dial(const char *digits);
207 
208 /** \brief Set the event handler for the modem.
209 
210  This function sets up an event handler for when things happen on the modem.
211 
212  \param eventHandler The function to call when an event occurs.
213 */
215 
216 /** \brief Disconnect the modem.
217 
218  This function instructs the modem to disconnect from the remote modem.
219 */
220 void modem_disconnect(void);
221 
222 /** \brief Check if the modem is connecting.
223  \return 0 if the modem is not currently connecting, non-zero
224  otherwise.
225 */
226 int modem_is_connecting(void);
227 
228 /** \brief Check if the modem is connected.
229  \return 0 if the modem is not currently connected, non-zero
230  otherwise.
231 */
232 int modem_is_connected(void);
233 
234 /** \brief Get the connection rate that the modem is connected at.
235  \return The connection rate in bits per second.
236 */
237 unsigned long modem_get_connection_rate(void);
238 
239 /* From mdata.c */
240 /** \brief Read data from the modem buffers.
241  \param data The buffer to read into.
242  \param size The maximum number of bytes to read.
243  \return The actual number of bytes read.
244 */
245 int modem_read_data(unsigned char *data, int size);
246 
247 /** \brief Write data to the modem buffers.
248  \param data The buffer to write from.
249  \param size The maximum number of bytes to write.
250  \return The actual number of bytes written.
251 */
252 int modem_write_data(unsigned char *data, int size);
253 
254 /** \brief Check if the modem has data waiting to be read.
255  \return 0 if no data available, non-zero otherwise.
256 */
257 int modem_has_data(void);
258 
259 #endif
int modem_dial(const char *digits)
Dial the specified number on the modem.
The remote modem dropped the connection.
Definition: modem.h:143
void modem_set_event_handler(MODEMEVENTHANDLERPROC eventHandler)
Set the event handler for the modem.
int modem_is_connecting(void)
Check if the modem is connecting.
The transmit buffer has been emptied.
Definition: modem.h:152
int modem_has_data(void)
Check if the modem has data waiting to be read.
int modem_set_mode(int mode, modem_speed_t speed)
Set the modem up for the specified mode.
int modem_wait_dialtone(int ms_timeout)
Wait for the modem to detect a dialtone.
int modem_write_data(unsigned char *data, int size)
Write data to the modem buffers.
unsigned long modem_get_connection_rate(void)
Get the connection rate that the modem is connected at.
void(* MODEMEVENTHANDLERPROC)(modemEvent_t event)
Type of a modem event handling function.
Definition: modem.h:156
The receive buffer overflowed and was cleared.
Definition: modem.h:149
int modem_is_connected(void)
Check if the modem is connected.
A connection has been established.
Definition: modem.h:140
modemEvent_t
Modem event types.
Definition: modem.h:135
int modem_init(void)
Initialize the modem.
New data has entered the previously empty receive buffer.
Definition: modem.h:146
Constants used in the modem driver.
void modem_disconnect(void)
Disconnect the modem.
void modem_shutdown(void)
Shut down the modem.
int modem_read_data(unsigned char *data, int size)
Read data from the modem buffers.
The modem tried to establish a connection, but failed.
Definition: modem.h:137
unsigned char modem_speed_t
Modem speed/protocol value type.
Definition: mconst.h:110