00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * private/v22bis.h - ITU V.22bis modem 00005 * 00006 * Written by Steve Underwood <steveu@coppice.org> 00007 * 00008 * Copyright (C) 2004 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 * $Id: v22bis.h,v 1.10 2009/04/29 12:37:45 steveu Exp $ 00026 */ 00027 00028 #if !defined(_SPANDSP_PRIVATE_V22BIS_H_) 00029 #define _SPANDSP_PRIVATE_V22BIS_H_ 00030 00031 /*! Segments of the training sequence on the receive side */ 00032 enum 00033 { 00034 V22BIS_RX_TRAINING_STAGE_NORMAL_OPERATION, 00035 V22BIS_RX_TRAINING_STAGE_SYMBOL_ACQUISITION, 00036 V22BIS_RX_TRAINING_STAGE_LOG_PHASE, 00037 V22BIS_RX_TRAINING_STAGE_UNSCRAMBLED_ONES, 00038 V22BIS_RX_TRAINING_STAGE_UNSCRAMBLED_ONES_SUSTAINING, 00039 V22BIS_RX_TRAINING_STAGE_SCRAMBLED_ONES_AT_1200, 00040 V22BIS_RX_TRAINING_STAGE_SCRAMBLED_ONES_AT_1200_SUSTAINING, 00041 V22BIS_RX_TRAINING_STAGE_WAIT_FOR_SCRAMBLED_ONES_AT_2400, 00042 V22BIS_RX_TRAINING_STAGE_PARKED 00043 }; 00044 00045 /*! Segments of the training sequence on the transmit side */ 00046 enum 00047 { 00048 V22BIS_TX_TRAINING_STAGE_NORMAL_OPERATION = 0, 00049 V22BIS_TX_TRAINING_STAGE_INITIAL_TIMED_SILENCE, 00050 V22BIS_TX_TRAINING_STAGE_INITIAL_SILENCE, 00051 V22BIS_TX_TRAINING_STAGE_U11, 00052 V22BIS_TX_TRAINING_STAGE_U0011, 00053 V22BIS_TX_TRAINING_STAGE_S11, 00054 V22BIS_TX_TRAINING_STAGE_TIMED_S11, 00055 V22BIS_TX_TRAINING_STAGE_S1111, 00056 V22BIS_TX_TRAINING_STAGE_PARKED 00057 }; 00058 00059 /*! 00060 V.22bis modem descriptor. This defines the working state for a single instance 00061 of a V.22bis modem. 00062 */ 00063 struct v22bis_state_s 00064 { 00065 /*! \brief The maximum permitted bit rate of the modem. Valid values are 1200 and 2400. */ 00066 int bit_rate; 00067 /*! \brief TRUE is this is the calling side modem. */ 00068 int caller; 00069 /*! \brief The callback function used to get the next bit to be transmitted. */ 00070 get_bit_func_t get_bit; 00071 /*! \brief A user specified opaque pointer passed to the get_bit callback routine. */ 00072 void *get_bit_user_data; 00073 /*! \brief The callback function used to put each bit received. */ 00074 put_bit_func_t put_bit; 00075 /*! \brief A user specified opaque pointer passed to the put_bit callback routine. */ 00076 void *put_bit_user_data; 00077 /*! \brief The callback function used to report modem status changes. */ 00078 modem_rx_status_func_t status_handler; 00079 /*! \brief A user specified opaque pointer passed to the status function. */ 00080 void *status_user_data; 00081 00082 int negotiated_bit_rate; 00083 00084 /* Receive section */ 00085 struct 00086 { 00087 /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */ 00088 float rrc_filter[2*V22BIS_RX_FILTER_STEPS]; 00089 /*! \brief Current offset into the RRC pulse shaping filter buffer. */ 00090 int rrc_filter_step; 00091 00092 /*! \brief The register for the data scrambler. */ 00093 unsigned int scramble_reg; 00094 /*! \brief A counter for the number of consecutive bits of repeating pattern through 00095 the scrambler. */ 00096 int scrambler_pattern_count; 00097 00098 /*! \brief 0 if receiving user data. A training stage value during training */ 00099 int training; 00100 /*! \brief A count of how far through the current training step we are. */ 00101 int training_count; 00102 00103 /*! \brief >0 if a signal above the minimum is present. It may or may not be a V.22bis signal. */ 00104 int signal_present; 00105 00106 /*! \brief A measure of how much mismatch there is between the real constellation, 00107 and the decoded symbol positions. */ 00108 float training_error; 00109 00110 /*! \brief The current phase of the carrier (i.e. the DDS parameter). */ 00111 uint32_t carrier_phase; 00112 /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */ 00113 int32_t carrier_phase_rate; 00114 /*! \brief The proportional part of the carrier tracking filter. */ 00115 float carrier_track_p; 00116 /*! \brief The integral part of the carrier tracking filter. */ 00117 float carrier_track_i; 00118 00119 /*! \brief A callback function which may be enabled to report every symbol's 00120 constellation position. */ 00121 qam_report_handler_t qam_report; 00122 /*! \brief A user specified opaque pointer passed to the qam_report callback 00123 routine. */ 00124 void *qam_user_data; 00125 00126 /*! \brief A power meter, to measure the HPF'ed signal power in the channel. */ 00127 power_meter_t rx_power; 00128 /*! \brief The power meter level at which carrier on is declared. */ 00129 int32_t carrier_on_power; 00130 /*! \brief The power meter level at which carrier off is declared. */ 00131 int32_t carrier_off_power; 00132 /*! \brief The scaling factor accessed by the AGC algorithm. */ 00133 float agc_scaling; 00134 00135 int constellation_state; 00136 00137 /*! \brief The current delta factor for updating the equalizer coefficients. */ 00138 float eq_delta; 00139 #if defined(SPANDSP_USE_FIXED_POINTx) 00140 /*! \brief The adaptive equalizer coefficients. */ 00141 complexi_t eq_coeff[2*V22BIS_EQUALIZER_LEN + 1]; 00142 /*! \brief The equalizer signal buffer. */ 00143 complexi_t eq_buf[V22BIS_EQUALIZER_MASK + 1]; 00144 #else 00145 complexf_t eq_coeff[2*V22BIS_EQUALIZER_LEN + 1]; 00146 complexf_t eq_buf[V22BIS_EQUALIZER_MASK + 1]; 00147 #endif 00148 /*! \brief Current offset into the equalizer buffer. */ 00149 int eq_step; 00150 /*! \brief Current write offset into the equalizer buffer. */ 00151 int eq_put_step; 00152 00153 /*! \brief Integration variable for damping the Gardner algorithm tests. */ 00154 int gardner_integrate; 00155 /*! \brief Current step size of Gardner algorithm integration. */ 00156 int gardner_step; 00157 /*! \brief The total symbol timing correction since the carrier came up. 00158 This is only for performance analysis purposes. */ 00159 int total_baud_timing_correction; 00160 /*! \brief The current fractional phase of the baud timing. */ 00161 int baud_phase; 00162 00163 int sixteen_way_decisions; 00164 00165 int pattern_repeats; 00166 int last_raw_bits; 00167 } rx; 00168 00169 /* Transmit section */ 00170 struct 00171 { 00172 /*! \brief The gain factor needed to achieve the specified output power. */ 00173 float gain; 00174 00175 /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */ 00176 complexf_t rrc_filter[2*V22BIS_TX_FILTER_STEPS]; 00177 /*! \brief Current offset into the RRC pulse shaping filter buffer. */ 00178 int rrc_filter_step; 00179 00180 /*! \brief The register for the data scrambler. */ 00181 unsigned int scramble_reg; 00182 /*! \brief A counter for the number of consecutive bits of repeating pattern through 00183 the scrambler. */ 00184 int scrambler_pattern_count; 00185 00186 /*! \brief 0 if transmitting user data. A training stage value during training */ 00187 int training; 00188 /*! \brief A counter used to track progress through sending the training sequence. */ 00189 int training_count; 00190 /*! \brief The current phase of the carrier (i.e. the DDS parameter). */ 00191 uint32_t carrier_phase; 00192 /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */ 00193 int32_t carrier_phase_rate; 00194 /*! \brief The current phase of the guard tone (i.e. the DDS parameter). */ 00195 uint32_t guard_phase; 00196 /*! \brief The update rate for the phase of the guard tone (i.e. the DDS increment). */ 00197 int32_t guard_phase_rate; 00198 float guard_level; 00199 /*! \brief The current fractional phase of the baud timing. */ 00200 int baud_phase; 00201 /*! \brief The code number for the current position in the constellation. */ 00202 int constellation_state; 00203 /*! \brief An indicator to mark that we are tidying up to stop transmission. */ 00204 int shutdown; 00205 /*! \brief The get_bit function in use at any instant. */ 00206 get_bit_func_t current_get_bit; 00207 } tx; 00208 00209 /*! \brief Error and flow logging control */ 00210 logging_state_t logging; 00211 }; 00212 00213 #if defined(__cplusplus) 00214 extern "C" 00215 { 00216 #endif 00217 00218 /*! Reinitialise an existing V.22bis modem receive context. 00219 \brief Reinitialise an existing V.22bis modem receive context. 00220 \param s The modem context. 00221 \return 0 for OK, -1 for bad parameter */ 00222 int v22bis_rx_restart(v22bis_state_t *s); 00223 00224 void v22bis_report_status_change(v22bis_state_t *s, int status); 00225 00226 void v22bis_equalizer_coefficient_reset(v22bis_state_t *s); 00227 00228 #if defined(__cplusplus) 00229 } 00230 #endif 00231 00232 #endif 00233 /*- End of file ------------------------------------------------------------*/