async.h

Go to the documentation of this file.
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 General Public License version 2, as
00014  * 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 General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00024  *
00025  * $Id: async.h,v 1.12 2007/12/13 11:31:32 steveu Exp $
00026  */
00027 
00028 /*! \file */
00029 
00030 /*! \page async_page Asynchronous bit stream processing
00031 \section async_page_sec_1 What does it do?
00032 The asynchronous serial bit stream processing module provides
00033 generation and decoding facilities for most asynchronous data
00034 formats. It supports:
00035  - 1 or 2 stop bits.
00036  - Odd, even or no parity.
00037  - 5, 6, 7, or 8 bit characters.
00038  - V.14 rate adaption.
00039 The input to this module is a bit stream. This means any symbol synchronisation
00040 and decoding must occur before data is fed to this module.
00041 
00042 \section async_page_sec_2 The transmitter
00043 ???.
00044 
00045 \section async_page_sec_3 The receiver
00046 ???.
00047 */
00048 
00049 #if !defined(_SPANDSP_ASYNC_H_)
00050 #define _SPANDSP_ASYNC_H_
00051 
00052 /*! Special "bit" values for the put and get bit functions */
00053 enum
00054 {
00055     /*! \brief The carrier signal has dropped. */
00056     PUTBIT_CARRIER_DOWN = -1,
00057     /*! \brief The carrier signal is up. This merely indicates that carrier
00058          energy has been seen. It is not an indication that the carrier is either
00059          valid, or of the expected type. */
00060     PUTBIT_CARRIER_UP = -2,
00061     /*! \brief The modem is training. This is an early indication that the
00062         signal seems to be of the right type. This may be needed in time critical
00063         applications, like T.38, to forward an early indication of what is happening
00064         on the wire. */
00065     PUTBIT_TRAINING_IN_PROGRESS = -3,
00066     /*! \brief The modem has trained, and is ready for data exchange. */
00067     PUTBIT_TRAINING_SUCCEEDED = -4,
00068     /*! \brief The modem has failed to train. */
00069     PUTBIT_TRAINING_FAILED = -5,
00070     /*! \brief Packet framing (e.g. HDLC framing) is OK. */
00071     PUTBIT_FRAMING_OK = -6,
00072     /*! \brief The data stream has ended. */
00073     PUTBIT_END_OF_DATA = -7,
00074     /*! \brief An abort signal (e.g. an HDLC abort) has been received. */
00075     PUTBIT_ABORT = -8,
00076     /*! \brief A break signal (e.g. an async break) has been received. */
00077     PUTBIT_BREAK = -9,
00078     /*! \brief Regular octet report for things like HDLC to the MTP standards. */
00079     PUTBIT_OCTET_REPORT = -10
00080 };
00081 
00082 /*! Message put function for data pumps */
00083 typedef void (*put_msg_func_t)(void *user_data, const uint8_t *msg, int len);
00084 
00085 /*! Message get function for data pumps */
00086 typedef int (*get_msg_func_t)(void *user_data, uint8_t *msg, int max_len);
00087 
00088 /*! Byte put function for data pumps */
00089 typedef void (*put_byte_func_t)(void *user_data, int byte);
00090 
00091 /*! Byte get function for data pumps */
00092 typedef int (*get_byte_func_t)(void *user_data);
00093 
00094 /*! Bit put function for data pumps */
00095 typedef void (*put_bit_func_t)(void *user_data, int bit);
00096 
00097 /*! Bit get function for data pumps */
00098 typedef int (*get_bit_func_t)(void *user_data);
00099 
00100 enum
00101 {
00102     /*! No parity bit should be used */
00103     ASYNC_PARITY_NONE = 0,
00104     /*! An even parity bit will exist, after the data bits */
00105     ASYNC_PARITY_EVEN,
00106     /*! An odd parity bit will exist, after the data bits */
00107     ASYNC_PARITY_ODD
00108 };
00109 
00110 /*!
00111     Asynchronous data transmit descriptor. This defines the state of a single
00112     working instance of a byte to asynchronous serial converter, for use
00113     in FSK modems.
00114 */
00115 typedef struct
00116 {
00117     /*! \brief The number of data bits per character. */
00118     int data_bits;
00119     /*! \brief The type of parity. */
00120     int parity;
00121     /*! \brief The number of stop bits per character. */
00122     int stop_bits;
00123     /*! \brief A pointer to the callback routine used to get characters to be transmitted. */
00124     get_byte_func_t get_byte;
00125     /*! \brief An opaque pointer passed when calling get_byte. */
00126     void *user_data;
00127 
00128     /*! \brief A current, partially transmitted, character. */
00129     int byte_in_progress;
00130     /*! \brief The current bit position within a partially transmitted character. */
00131     int bitpos;
00132     /*! \brief Parity bit. */
00133     int parity_bit;
00134 } async_tx_state_t;
00135 
00136 /*!
00137     Asynchronous data receive descriptor. This defines the state of a single
00138     working instance of an asynchronous serial to byte converter, for use
00139     in FSK modems.
00140 */
00141 typedef struct
00142 {
00143     /*! \brief The number of data bits per character. */
00144     int data_bits;
00145     /*! \brief The type of parity. */
00146     int parity;
00147     /*! \brief The number of stop bits per character. */
00148     int stop_bits;
00149     /*! \brief TRUE if V.14 rate adaption processing should be performed. */
00150     int use_v14;
00151     /*! \brief A pointer to the callback routine used to handle received characters. */
00152     put_byte_func_t put_byte;
00153     /*! \brief An opaque pointer passed when calling put_byte. */
00154     void *user_data;
00155 
00156     /*! \brief A current, partially complete, character. */
00157     int byte_in_progress;
00158     /*! \brief The current bit position within a partially complete character. */
00159     int bitpos;
00160     /*! \brief Parity bit. */
00161     int parity_bit;
00162 
00163     /*! A count of the number of parity errors seen. */
00164     int parity_errors;
00165     /*! A count of the number of character framing errors seen. */
00166     int framing_errors;
00167 } async_rx_state_t;
00168 
00169 #if defined(__cplusplus)
00170 extern "C"
00171 {
00172 #endif
00173 
00174 /*! Initialise an asynchronous data transmit context.
00175     \brief Initialise an asynchronous data transmit context.
00176     \param s The transmitter context.
00177     \param data_bits The number of data bit.
00178     \param parity_bits The type of parity.
00179     \param stop_bits The number of stop bits.
00180     \param use_v14 TRUE if V.14 rate adaption processing should be used.
00181     \param get_byte The callback routine used to get the data to be transmitted.
00182     \param user_data An opaque pointer.
00183     \return A pointer to the initialised context, or NULL if there was a problem. */
00184 async_tx_state_t *async_tx_init(async_tx_state_t *s,
00185                                 int data_bits,
00186                                 int parity_bits,
00187                                 int stop_bits,
00188                                 int use_v14,
00189                                 get_byte_func_t get_byte,
00190                                 void *user_data);
00191 
00192 /*! Get the next bit of a transmitted serial bit stream.
00193     \brief Get the next bit of a transmitted serial bit stream.
00194     \param user_data An opaque point which must point to a transmitter context.
00195     \return the next bit, or PUTBIT_END_OF_DATA to indicate the data stream has ended. */
00196 int async_tx_get_bit(void *user_data);
00197 
00198 /*! Initialise an asynchronous data receiver context.
00199     \brief Initialise an asynchronous data receiver context.
00200     \param s The receiver context.
00201     \param data_bits The number of data bits.
00202     \param parity_bits The type of parity.
00203     \param stop_bits The number of stop bits.
00204     \param use_v14 TRUE if V.14 rate adaption processing should be used.
00205     \param put_byte The callback routine used to put the received data.
00206     \param user_data An opaque pointer.
00207     \return A pointer to the initialised context, or NULL if there was a problem. */
00208 async_rx_state_t *async_rx_init(async_rx_state_t *s,
00209                                 int data_bits,
00210                                 int parity_bits,
00211                                 int stop_bits,
00212                                 int use_v14,
00213                                 put_byte_func_t put_byte,
00214                                 void *user_data);
00215 
00216 /*! Accept a bit from a received serial bit stream
00217     \brief Accept a bit from a received serial bit stream
00218     \param user_data An opaque point which must point to a receiver context.
00219     \param bit The new bit. Some special values are supported for this field.
00220         - PUTBIT_CARRIER_UP
00221         - PUTBIT_CARRIER_DOWN
00222         - PUTBIT_TRAINING_SUCCEEDED
00223         - PUTBIT_TRAINING_FAILED
00224         - PUTBIT_END_OF_DATA */
00225 void async_rx_put_bit(void *user_data, int bit);
00226 
00227 #if defined(__cplusplus)
00228 }
00229 #endif
00230 
00231 #endif
00232 /*- End of file ------------------------------------------------------------*/

Generated on Thu Mar 20 17:20:08 2008 for libspandsp by  doxygen 1.5.5