00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * async.h - Asynchronous serial bit stream encoding and decoding 00005 * 00006 * Written by Steve Underwood <steveu@coppice.org> 00007 * 00008 * Copyright (C) 2003 Steve Underwood 00009 * 00010 * All rights reserved. 00011 * 00012 * This program is free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU Lesser General Public License version 2.1, 00014 * as published by the Free Software Foundation. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with this program; if not, write to the Free Software 00023 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00024 */ 00025 00026 /*! \file */ 00027 00028 /*! \page async_page Asynchronous bit stream processing 00029 \section async_page_sec_1 What does it do? 00030 The asynchronous serial bit stream processing module provides 00031 generation and decoding facilities for most asynchronous data 00032 formats. It supports: 00033 - 1 or 2 stop bits. 00034 - Odd, even or no parity. 00035 - 5, 6, 7, or 8 bit characters. 00036 - V.14 rate adaption. 00037 The input to this module is a bit stream. This means any symbol synchronisation 00038 and decoding must occur before data is fed to this module. 00039 00040 \section async_page_sec_2 The transmitter 00041 ???. 00042 00043 \section async_page_sec_3 The receiver 00044 ???. 00045 */ 00046 00047 #if !defined(_SPANDSP_ASYNC_H_) 00048 #define _SPANDSP_ASYNC_H_ 00049 00050 /*! Special "bit" values for the bitstream put and get functions, and the signal status functions. */ 00051 enum 00052 { 00053 /*! \brief The carrier signal has dropped. */ 00054 SIG_STATUS_CARRIER_DOWN = -1, 00055 /*! \brief The carrier signal is up. This merely indicates that carrier 00056 energy has been seen. It is not an indication that the carrier is either 00057 valid, or of the expected type. */ 00058 SIG_STATUS_CARRIER_UP = -2, 00059 /*! \brief The modem is training. This is an early indication that the 00060 signal seems to be of the right type. This may be needed in time critical 00061 applications, like T.38, to forward an early indication of what is happening 00062 on the wire. */ 00063 SIG_STATUS_TRAINING_IN_PROGRESS = -3, 00064 /*! \brief The modem has trained, and is ready for data exchange. */ 00065 SIG_STATUS_TRAINING_SUCCEEDED = -4, 00066 /*! \brief The modem has failed to train. */ 00067 SIG_STATUS_TRAINING_FAILED = -5, 00068 /*! \brief Packet framing (e.g. HDLC framing) is OK. */ 00069 SIG_STATUS_FRAMING_OK = -6, 00070 /*! \brief The data stream has ended. */ 00071 SIG_STATUS_END_OF_DATA = -7, 00072 /*! \brief An abort signal (e.g. an HDLC abort) has been received. */ 00073 SIG_STATUS_ABORT = -8, 00074 /*! \brief A break signal (e.g. an async break) has been received. */ 00075 SIG_STATUS_BREAK = -9, 00076 /*! \brief A modem has completed its task, and shut down. */ 00077 SIG_STATUS_SHUTDOWN_COMPLETE = -10, 00078 /*! \brief Regular octet report for things like HDLC to the MTP standards. */ 00079 SIG_STATUS_OCTET_REPORT = -11, 00080 /*! \brief Notification that a modem has detected signal quality degradation. */ 00081 SIG_STATUS_POOR_SIGNAL_QUALITY = -12, 00082 /*! \brief Notification that a modem retrain has occurred. */ 00083 SIG_STATUS_MODEM_RETRAIN_OCCURRED = -13, 00084 /*! \brief The link protocol (e.g. V.42) has connected. */ 00085 SIG_STATUS_LINK_CONNECTED = -14, 00086 /*! \brief The link protocol (e.g. V.42) has disconnected. */ 00087 SIG_STATUS_LINK_DISCONNECTED = -15, 00088 /*! \brief An error has occurred in the link protocol (e.g. V.42). */ 00089 SIG_STATUS_LINK_ERROR = -16 00090 }; 00091 00092 /*! Message put function for data pumps */ 00093 typedef void (*put_msg_func_t)(void *user_data, const uint8_t *msg, int len); 00094 00095 /*! Message get function for data pumps */ 00096 typedef int (*get_msg_func_t)(void *user_data, uint8_t *msg, int max_len); 00097 00098 /*! Byte put function for data pumps */ 00099 typedef void (*put_byte_func_t)(void *user_data, int byte); 00100 00101 /*! Byte get function for data pumps */ 00102 typedef int (*get_byte_func_t)(void *user_data); 00103 00104 /*! Bit put function for data pumps */ 00105 typedef void (*put_bit_func_t)(void *user_data, int bit); 00106 00107 /*! Bit get function for data pumps */ 00108 typedef int (*get_bit_func_t)(void *user_data); 00109 00110 /*! Status change callback function for data pumps */ 00111 typedef void (*modem_status_func_t)(void *user_data, int status); 00112 00113 /*! 00114 Asynchronous data transmit descriptor. This defines the state of a single 00115 working instance of a byte to asynchronous serial converter, for use 00116 in FSK modems. 00117 */ 00118 typedef struct async_tx_state_s async_tx_state_t; 00119 00120 /*! 00121 Asynchronous data receive descriptor. This defines the state of a single 00122 working instance of an asynchronous serial to byte converter, for use 00123 in FSK modems. 00124 */ 00125 typedef struct async_rx_state_s async_rx_state_t; 00126 00127 enum 00128 { 00129 /*! No parity bit should be used */ 00130 ASYNC_PARITY_NONE = 0, 00131 /*! An even parity bit will exist, after the data bits */ 00132 ASYNC_PARITY_EVEN, 00133 /*! An odd parity bit will exist, after the data bits */ 00134 ASYNC_PARITY_ODD 00135 }; 00136 00137 #if defined(__cplusplus) 00138 extern "C" 00139 { 00140 #endif 00141 00142 /*! Convert a signal status to a short text description. 00143 \brief Convert a signal status to a short text description. 00144 \param status The modem signal status. 00145 \return A pointer to the description. */ 00146 SPAN_DECLARE(const char *) signal_status_to_str(int status); 00147 00148 /*! Initialise an asynchronous data transmit context. 00149 \brief Initialise an asynchronous data transmit context. 00150 \param s The transmitter context. 00151 \param data_bits The number of data bit. 00152 \param parity_bits The type of parity. 00153 \param stop_bits The number of stop bits. 00154 \param use_v14 TRUE if V.14 rate adaption processing should be used. 00155 \param get_byte The callback routine used to get the data to be transmitted. 00156 \param user_data An opaque pointer. 00157 \return A pointer to the initialised context, or NULL if there was a problem. */ 00158 SPAN_DECLARE(async_tx_state_t *) async_tx_init(async_tx_state_t *s, 00159 int data_bits, 00160 int parity_bits, 00161 int stop_bits, 00162 int use_v14, 00163 get_byte_func_t get_byte, 00164 void *user_data); 00165 00166 SPAN_DECLARE(int) async_tx_release(async_tx_state_t *s); 00167 00168 SPAN_DECLARE(int) async_tx_free(async_tx_state_t *s); 00169 00170 /*! Get the next bit of a transmitted serial bit stream. 00171 \brief Get the next bit of a transmitted serial bit stream. 00172 \param user_data An opaque point which must point to a transmitter context. 00173 \return the next bit, or PUTBIT_END_OF_DATA to indicate the data stream has ended. */ 00174 SPAN_DECLARE_NONSTD(int) async_tx_get_bit(void *user_data); 00175 00176 /*! Initialise an asynchronous data receiver context. 00177 \brief Initialise an asynchronous data receiver context. 00178 \param s The receiver context. 00179 \param data_bits The number of data bits. 00180 \param parity_bits The type of parity. 00181 \param stop_bits The number of stop bits. 00182 \param use_v14 TRUE if V.14 rate adaption processing should be used. 00183 \param put_byte The callback routine used to put the received data. 00184 \param user_data An opaque pointer. 00185 \return A pointer to the initialised context, or NULL if there was a problem. */ 00186 SPAN_DECLARE(async_rx_state_t *) async_rx_init(async_rx_state_t *s, 00187 int data_bits, 00188 int parity_bits, 00189 int stop_bits, 00190 int use_v14, 00191 put_byte_func_t put_byte, 00192 void *user_data); 00193 00194 SPAN_DECLARE(int) async_rx_release(async_rx_state_t *s); 00195 00196 SPAN_DECLARE(int) async_rx_free(async_rx_state_t *s); 00197 00198 /*! Accept a bit from a received serial bit stream 00199 \brief Accept a bit from a received serial bit stream 00200 \param user_data An opaque point which must point to a receiver context. 00201 \param bit The new bit. Some special values are supported for this field. 00202 - SIG_STATUS_CARRIER_UP 00203 - SIG_STATUS_CARRIER_DOWN 00204 - SIG_STATUS_TRAINING_SUCCEEDED 00205 - SIG_STATUS_TRAINING_FAILED 00206 - SIG_STATUS_END_OF_DATA */ 00207 SPAN_DECLARE_NONSTD(void) async_rx_put_bit(void *user_data, int bit); 00208 00209 #if defined(__cplusplus) 00210 } 00211 #endif 00212 00213 #endif 00214 /*- End of file ------------------------------------------------------------*/
1.6.1