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