spandsp 0.0.6

async.h
Go to the documentation of this file.
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
26/*! \file */
27
28/*! \page async_page Asynchronous bit stream processing
29\section async_page_sec_1 What does it do?
30 The asynchronous serial bit stream processing module provides
31 generation and decoding facilities for most asynchronous data
32 formats. It supports:
33 - 1 or 2 stop bits.
34 - Odd, even or no parity.
35 - 5, 6, 7, or 8 bit characters.
36 - V.14 rate adaption.
37 The input to this module is a bit stream. This means any symbol synchronisation
38 and decoding must occur before data is fed to this module.
39
40\section async_page_sec_2 The transmitter
41???.
42
43\section async_page_sec_3 The receiver
44???.
45*/
46
47#if !defined(_SPANDSP_ASYNC_H_)
48#define _SPANDSP_ASYNC_H_
49
50/*! Special "bit" values for the bitstream put and get functions, and the signal status functions. */
51 enum
52{
53 /*! \brief The carrier signal has dropped. */
54 SIG_STATUS_CARRIER_DOWN = -1,
55 /*! \brief The carrier signal is up. This merely indicates that carrier
56 energy has been seen. It is not an indication that the carrier is either
57 valid, or of the expected type. */
58 SIG_STATUS_CARRIER_UP = -2,
59 /*! \brief The modem is training. This is an early indication that the
60 signal seems to be of the right type. This may be needed in time critical
61 applications, like T.38, to forward an early indication of what is happening
62 on the wire. */
63 SIG_STATUS_TRAINING_IN_PROGRESS = -3,
64 /*! \brief The modem has trained, and is ready for data exchange. */
65 SIG_STATUS_TRAINING_SUCCEEDED = -4,
66 /*! \brief The modem has failed to train. */
67 SIG_STATUS_TRAINING_FAILED = -5,
68 /*! \brief Packet framing (e.g. HDLC framing) is OK. */
69 SIG_STATUS_FRAMING_OK = -6,
70 /*! \brief The data stream has ended. */
71 SIG_STATUS_END_OF_DATA = -7,
72 /*! \brief An abort signal (e.g. an HDLC abort) has been received. */
73 SIG_STATUS_ABORT = -8,
74 /*! \brief A break signal (e.g. an async break) has been received. */
75 SIG_STATUS_BREAK = -9,
76 /*! \brief A modem has completed its task, and shut down. */
77 SIG_STATUS_SHUTDOWN_COMPLETE = -10,
78 /*! \brief Regular octet report for things like HDLC to the MTP standards. */
79 SIG_STATUS_OCTET_REPORT = -11,
80 /*! \brief Notification that a modem has detected signal quality degradation. */
81 SIG_STATUS_POOR_SIGNAL_QUALITY = -12,
82 /*! \brief Notification that a modem retrain has occurred. */
83 SIG_STATUS_MODEM_RETRAIN_OCCURRED = -13,
84 /*! \brief The link protocol (e.g. V.42) has connected. */
85 SIG_STATUS_LINK_CONNECTED = -14,
86 /*! \brief The link protocol (e.g. V.42) has disconnected. */
87 SIG_STATUS_LINK_DISCONNECTED = -15,
88 /*! \brief An error has occurred in the link protocol (e.g. V.42). */
89 SIG_STATUS_LINK_ERROR = -16
90};
91
92/*! Message put function for data pumps */
93 typedef void (*put_msg_func_t)(void *user_data, const uint8_t *msg, int len);
94
95/*! Message get function for data pumps */
96 typedef int (*get_msg_func_t)(void *user_data, uint8_t *msg, int max_len);
97
98/*! Byte put function for data pumps */
99 typedef void (*put_byte_func_t)(void *user_data, int byte);
100
101/*! Byte get function for data pumps */
102 typedef int (*get_byte_func_t)(void *user_data);
103
104/*! Bit put function for data pumps */
105 typedef void (*put_bit_func_t)(void *user_data, int bit);
106
107/*! Bit get function for data pumps */
108 typedef int (*get_bit_func_t)(void *user_data);
109
110#define modem_rx_status_func_t modem_status_func_t
111#define modem_tx_status_func_t modem_status_func_t
112
113/*! Status change callback function for data pumps */
114 typedef void (*modem_status_func_t)(void *user_data, int status);
115
116/*!
117 Asynchronous data transmit descriptor. This defines the state of a single
118 working instance of a byte to asynchronous serial converter, for use
119 in FSK modems.
120*/
121 typedef struct async_tx_state_s async_tx_state_t;
122
123/*!
124 Asynchronous data receive descriptor. This defines the state of a single
125 working instance of an asynchronous serial to byte converter, for use
126 in FSK modems.
127*/
128 typedef struct async_rx_state_s async_rx_state_t;
129
130 enum
131{
132 /*! No parity bit should be used */
133 ASYNC_PARITY_NONE = 0,
134 /*! An even parity bit will exist, after the data bits */
135 ASYNC_PARITY_EVEN,
136 /*! An odd parity bit will exist, after the data bits */
137 ASYNC_PARITY_ODD
138};
139
140#if defined(__cplusplus)
141 extern "C"
142{
143#endif
144
145/*! Convert a signal status to a short text description.
146 \brief Convert a signal status to a short text description.
147 \param status The modem signal status.
148 \return A pointer to the description. */
149SPAN_DECLARE(const char *) signal_status_to_str(int status);
150
151/*! Initialise an asynchronous data transmit context.
152 \brief Initialise an asynchronous data transmit context.
153 \param s The transmitter context.
154 \param data_bits The number of data bit.
155 \param parity_bits The type of parity.
156 \param stop_bits The number of stop bits.
157 \param use_v14 TRUE if V.14 rate adaption processing should be used.
158 \param get_byte The callback routine used to get the data to be transmitted.
159 \param user_data An opaque pointer.
160 \return A pointer to the initialised context, or NULL if there was a problem. */
161SPAN_DECLARE(async_tx_state_t *) async_tx_init(async_tx_state_t *s,
162 int data_bits,
163 int parity_bits,
164 int stop_bits,
165 int use_v14,
166 get_byte_func_t get_byte,
167 void *user_data);
168
169SPAN_DECLARE(int) async_tx_release(async_tx_state_t *s);
170
171SPAN_DECLARE(int) async_tx_free(async_tx_state_t *s);
172
173/*! Get the next bit of a transmitted serial bit stream.
174 \brief Get the next bit of a transmitted serial bit stream.
175 \param user_data An opaque point which must point to a transmitter context.
176 \return the next bit, or PUTBIT_END_OF_DATA to indicate the data stream has ended. */
177 SPAN_DECLARE_NONSTD(int) async_tx_get_bit(void *user_data);
178
179/*! Initialise an asynchronous data receiver context.
180 \brief Initialise an asynchronous data receiver context.
181 \param s The receiver context.
182 \param data_bits The number of data bits.
183 \param parity_bits The type of parity.
184 \param stop_bits The number of stop bits.
185 \param use_v14 TRUE if V.14 rate adaption processing should be used.
186 \param put_byte The callback routine used to put the received data.
187 \param user_data An opaque pointer.
188 \return A pointer to the initialised context, or NULL if there was a problem. */
189SPAN_DECLARE(async_rx_state_t *) async_rx_init(async_rx_state_t *s,
190 int data_bits,
191 int parity_bits,
192 int stop_bits,
193 int use_v14,
194 put_byte_func_t put_byte,
195 void *user_data);
196
197SPAN_DECLARE(int) async_rx_release(async_rx_state_t *s);
198
199SPAN_DECLARE(int) async_rx_free(async_rx_state_t *s);
200
201/*! Accept a bit from a received serial bit stream
202 \brief Accept a bit from a received serial bit stream
203 \param user_data An opaque point which must point to a receiver context.
204 \param bit The new bit. Some special values are supported for this field.
205 - SIG_STATUS_CARRIER_UP
206 - SIG_STATUS_CARRIER_DOWN
207 - SIG_STATUS_TRAINING_SUCCEEDED
208 - SIG_STATUS_TRAINING_FAILED
209 - SIG_STATUS_END_OF_DATA */
210 SPAN_DECLARE_NONSTD(void) async_rx_put_bit(void *user_data, int bit);
211
212#if defined(__cplusplus)
213}
214#endif
215
216#endif
217/*- End of file ------------------------------------------------------------*/
get_msg_func_t
int(* get_msg_func_t)(void *user_data, uint8_t *msg, int max_len)
Definition async.h:96
SIG_STATUS_LINK_CONNECTED
@ SIG_STATUS_LINK_CONNECTED
The link protocol (e.g. V.42) has connected.
Definition async.h:85
SIG_STATUS_BREAK
@ SIG_STATUS_BREAK
A break signal (e.g. an async break) has been received.
Definition async.h:75
SIG_STATUS_TRAINING_FAILED
@ SIG_STATUS_TRAINING_FAILED
The modem has failed to train.
Definition async.h:67
SIG_STATUS_LINK_ERROR
@ SIG_STATUS_LINK_ERROR
An error has occurred in the link protocol (e.g. V.42).
Definition async.h:89
SIG_STATUS_ABORT
@ SIG_STATUS_ABORT
An abort signal (e.g. an HDLC abort) has been received.
Definition async.h:73
SIG_STATUS_MODEM_RETRAIN_OCCURRED
@ SIG_STATUS_MODEM_RETRAIN_OCCURRED
Notification that a modem retrain has occurred.
Definition async.h:83
SIG_STATUS_TRAINING_SUCCEEDED
@ SIG_STATUS_TRAINING_SUCCEEDED
The modem has trained, and is ready for data exchange.
Definition async.h:65
SIG_STATUS_CARRIER_UP
@ SIG_STATUS_CARRIER_UP
The carrier signal is up. This merely indicates that carrier energy has been seen....
Definition async.h:58
SIG_STATUS_CARRIER_DOWN
@ SIG_STATUS_CARRIER_DOWN
The carrier signal has dropped.
Definition async.h:54
SIG_STATUS_END_OF_DATA
@ SIG_STATUS_END_OF_DATA
The data stream has ended.
Definition async.h:71
SIG_STATUS_FRAMING_OK
@ SIG_STATUS_FRAMING_OK
Packet framing (e.g. HDLC framing) is OK.
Definition async.h:69
SIG_STATUS_TRAINING_IN_PROGRESS
@ SIG_STATUS_TRAINING_IN_PROGRESS
The modem is training. This is an early indication that the signal seems to be of the right type....
Definition async.h:63
SIG_STATUS_OCTET_REPORT
@ SIG_STATUS_OCTET_REPORT
Regular octet report for things like HDLC to the MTP standards.
Definition async.h:79
SIG_STATUS_SHUTDOWN_COMPLETE
@ SIG_STATUS_SHUTDOWN_COMPLETE
A modem has completed its task, and shut down.
Definition async.h:77
SIG_STATUS_POOR_SIGNAL_QUALITY
@ SIG_STATUS_POOR_SIGNAL_QUALITY
Notification that a modem has detected signal quality degradation.
Definition async.h:81
SIG_STATUS_LINK_DISCONNECTED
@ SIG_STATUS_LINK_DISCONNECTED
The link protocol (e.g. V.42) has disconnected.
Definition async.h:87
modem_status_func_t
void(* modem_status_func_t)(void *user_data, int status)
Definition async.h:114
signal_status_to_str
const char * signal_status_to_str(int status)
Convert a signal status to a short text description.
Definition async.c:42
async_tx_init
async_tx_state_t * async_tx_init(async_tx_state_t *s, int data_bits, int parity_bits, int stop_bits, int use_v14, get_byte_func_t get_byte, void *user_data)
Initialise an asynchronous data transmit context.
Definition async.c:208
put_bit_func_t
void(* put_bit_func_t)(void *user_data, int bit)
Definition async.h:105
SPAN_DECLARE_NONSTD
SPAN_DECLARE_NONSTD(void) async_rx_put_bit(void *user_data
Accept a bit from a received serial bit stream.
get_byte_func_t
int(* get_byte_func_t)(void *user_data)
Definition async.h:102
ASYNC_PARITY_NONE
@ ASYNC_PARITY_NONE
Definition async.h:133
ASYNC_PARITY_ODD
@ ASYNC_PARITY_ODD
Definition async.h:137
ASYNC_PARITY_EVEN
@ ASYNC_PARITY_EVEN
Definition async.h:135
async_rx_state_t
struct async_rx_state_s async_rx_state_t
Definition async.h:128
put_byte_func_t
void(* put_byte_func_t)(void *user_data, int byte)
Definition async.h:99
put_msg_func_t
void(* put_msg_func_t)(void *user_data, const uint8_t *msg, int len)
Definition async.h:93
async_tx_state_t
struct async_tx_state_s async_tx_state_t
Definition async.h:121
get_bit_func_t
int(* get_bit_func_t)(void *user_data)
Definition async.h:108
async_rx_init
async_rx_state_t * async_rx_init(async_rx_state_t *s, int data_bits, int parity_bits, int stop_bits, int use_v14, put_byte_func_t put_byte, void *user_data)
Initialise an asynchronous data receiver context.
Definition async.c:83
async_rx_state_s
Definition private/async.h:61
async_rx_state_s::data_bits
int data_bits
The number of data bits per character.
Definition private/async.h:63
async_rx_state_s::stop_bits
int stop_bits
The number of stop bits per character.
Definition private/async.h:67
async_rx_state_s::use_v14
int use_v14
TRUE if V.14 rate adaption processing should be performed.
Definition private/async.h:69
async_rx_state_s::put_byte
put_byte_func_t put_byte
A pointer to the callback routine used to handle received characters.
Definition private/async.h:71
async_rx_state_s::user_data
void * user_data
An opaque pointer passed when calling put_byte.
Definition private/async.h:73
async_tx_state_s
Definition private/async.h:35