comparison spandsp-0.0.6pre17/src/spandsp/async.h @ 4:26cd8f1ef0b1

import spandsp-0.0.6pre17
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Fri, 25 Jun 2010 15:50:58 +0200
parents
children
comparison
equal deleted inserted replaced
3:c6c5a16ce2f2 4:26cd8f1ef0b1
1 /*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * async.h - Asynchronous serial bit stream encoding and decoding
5 *
6 * Written by Steve Underwood <steveu@coppice.org>
7 *
8 * Copyright (C) 2003 Steve Underwood
9 *
10 * All rights reserved.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 2.1,
14 * as published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 * $Id: async.h,v 1.25 2009/04/23 14:12:34 steveu Exp $
26 */
27
28 /*! \file */
29
30 /*! \page async_page Asynchronous bit stream processing
31 \section async_page_sec_1 What does it do?
32 The asynchronous serial bit stream processing module provides
33 generation and decoding facilities for most asynchronous data
34 formats. It supports:
35 - 1 or 2 stop bits.
36 - Odd, even or no parity.
37 - 5, 6, 7, or 8 bit characters.
38 - V.14 rate adaption.
39 The input to this module is a bit stream. This means any symbol synchronisation
40 and decoding must occur before data is fed to this module.
41
42 \section async_page_sec_2 The transmitter
43 ???.
44
45 \section async_page_sec_3 The receiver
46 ???.
47 */
48
49 #if !defined(_SPANDSP_ASYNC_H_)
50 #define _SPANDSP_ASYNC_H_
51
52 /*! Special "bit" values for the bitstream put and get functions, and the signal status functions. */
53 enum
54 {
55 /*! \brief The carrier signal has dropped. */
56 SIG_STATUS_CARRIER_DOWN = -1,
57 /*! \brief The carrier signal is up. This merely indicates that carrier
58 energy has been seen. It is not an indication that the carrier is either
59 valid, or of the expected type. */
60 SIG_STATUS_CARRIER_UP = -2,
61 /*! \brief The modem is training. This is an early indication that the
62 signal seems to be of the right type. This may be needed in time critical
63 applications, like T.38, to forward an early indication of what is happening
64 on the wire. */
65 SIG_STATUS_TRAINING_IN_PROGRESS = -3,
66 /*! \brief The modem has trained, and is ready for data exchange. */
67 SIG_STATUS_TRAINING_SUCCEEDED = -4,
68 /*! \brief The modem has failed to train. */
69 SIG_STATUS_TRAINING_FAILED = -5,
70 /*! \brief Packet framing (e.g. HDLC framing) is OK. */
71 SIG_STATUS_FRAMING_OK = -6,
72 /*! \brief The data stream has ended. */
73 SIG_STATUS_END_OF_DATA = -7,
74 /*! \brief An abort signal (e.g. an HDLC abort) has been received. */
75 SIG_STATUS_ABORT = -8,
76 /*! \brief A break signal (e.g. an async break) has been received. */
77 SIG_STATUS_BREAK = -9,
78 /*! \brief A modem has completed its task, and shut down. */
79 SIG_STATUS_SHUTDOWN_COMPLETE = -10,
80 /*! \brief Regular octet report for things like HDLC to the MTP standards. */
81 SIG_STATUS_OCTET_REPORT = -11,
82 /*! \brief Notification that a modem has detected signal quality degradation. */
83 SIG_STATUS_POOR_SIGNAL_QUALITY = -12,
84 /*! \brief Notification that a modem retrain has occurred. */
85 SIG_STATUS_MODEM_RETRAIN_OCCURRED = -13
86 };
87
88 /*! Message put function for data pumps */
89 typedef void (*put_msg_func_t)(void *user_data, const uint8_t *msg, int len);
90
91 /*! Message get function for data pumps */
92 typedef int (*get_msg_func_t)(void *user_data, uint8_t *msg, int max_len);
93
94 /*! Byte put function for data pumps */
95 typedef void (*put_byte_func_t)(void *user_data, int byte);
96
97 /*! Byte get function for data pumps */
98 typedef int (*get_byte_func_t)(void *user_data);
99
100 /*! Bit put function for data pumps */
101 typedef void (*put_bit_func_t)(void *user_data, int bit);
102
103 /*! Bit get function for data pumps */
104 typedef int (*get_bit_func_t)(void *user_data);
105
106 /*! Completion callback function for tx data pumps */
107 typedef void (*modem_tx_status_func_t)(void *user_data, int status);
108
109 /*! Completion callback function for rx data pumps */
110 typedef void (*modem_rx_status_func_t)(void *user_data, int status);
111
112 enum
113 {
114 /*! No parity bit should be used */
115 ASYNC_PARITY_NONE = 0,
116 /*! An even parity bit will exist, after the data bits */
117 ASYNC_PARITY_EVEN,
118 /*! An odd parity bit will exist, after the data bits */
119 ASYNC_PARITY_ODD
120 };
121
122 /*!
123 Asynchronous data transmit descriptor. This defines the state of a single
124 working instance of a byte to asynchronous serial converter, for use
125 in FSK modems.
126 */
127 typedef struct async_tx_state_s async_tx_state_t;
128
129 /*!
130 Asynchronous data receive descriptor. This defines the state of a single
131 working instance of an asynchronous serial to byte converter, for use
132 in FSK modems.
133 */
134 typedef struct async_rx_state_s async_rx_state_t;
135
136 #if defined(__cplusplus)
137 extern "C"
138 {
139 #endif
140
141 /*! Convert a signal status to a short text description.
142 \brief Convert a signal status to a short text description.
143 \param status The modem signal status.
144 \return A pointer to the description. */
145 SPAN_DECLARE(const char *) signal_status_to_str(int status);
146
147 /*! Initialise an asynchronous data transmit context.
148 \brief Initialise an asynchronous data transmit context.
149 \param s The transmitter context.
150 \param data_bits The number of data bit.
151 \param parity_bits The type of parity.
152 \param stop_bits The number of stop bits.
153 \param use_v14 TRUE if V.14 rate adaption processing should be used.
154 \param get_byte The callback routine used to get the data to be transmitted.
155 \param user_data An opaque pointer.
156 \return A pointer to the initialised context, or NULL if there was a problem. */
157 SPAN_DECLARE(async_tx_state_t *) async_tx_init(async_tx_state_t *s,
158 int data_bits,
159 int parity_bits,
160 int stop_bits,
161 int use_v14,
162 get_byte_func_t get_byte,
163 void *user_data);
164
165 SPAN_DECLARE(int) async_tx_release(async_tx_state_t *s);
166
167 SPAN_DECLARE(int) async_tx_free(async_tx_state_t *s);
168
169 /*! Get the next bit of a transmitted serial bit stream.
170 \brief Get the next bit of a transmitted serial bit stream.
171 \param user_data An opaque point which must point to a transmitter context.
172 \return the next bit, or PUTBIT_END_OF_DATA to indicate the data stream has ended. */
173 SPAN_DECLARE_NONSTD(int) async_tx_get_bit(void *user_data);
174
175 /*! Initialise an asynchronous data receiver context.
176 \brief Initialise an asynchronous data receiver context.
177 \param s The receiver context.
178 \param data_bits The number of data bits.
179 \param parity_bits The type of parity.
180 \param stop_bits The number of stop bits.
181 \param use_v14 TRUE if V.14 rate adaption processing should be used.
182 \param put_byte The callback routine used to put the received data.
183 \param user_data An opaque pointer.
184 \return A pointer to the initialised context, or NULL if there was a problem. */
185 SPAN_DECLARE(async_rx_state_t *) async_rx_init(async_rx_state_t *s,
186 int data_bits,
187 int parity_bits,
188 int stop_bits,
189 int use_v14,
190 put_byte_func_t put_byte,
191 void *user_data);
192
193 SPAN_DECLARE(int) async_rx_release(async_rx_state_t *s);
194
195 SPAN_DECLARE(int) async_rx_free(async_rx_state_t *s);
196
197 /*! Accept a bit from a received serial bit stream
198 \brief Accept a bit from a received serial bit stream
199 \param user_data An opaque point which must point to a receiver context.
200 \param bit The new bit. Some special values are supported for this field.
201 - SIG_STATUS_CARRIER_UP
202 - SIG_STATUS_CARRIER_DOWN
203 - SIG_STATUS_TRAINING_SUCCEEDED
204 - SIG_STATUS_TRAINING_FAILED
205 - SIG_STATUS_END_OF_DATA */
206 SPAN_DECLARE_NONSTD(void) async_rx_put_bit(void *user_data, int bit);
207
208 #if defined(__cplusplus)
209 }
210 #endif
211
212 #endif
213 /*- End of file ------------------------------------------------------------*/

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.