📄 ogrt_riseset.c
字号:
/* ************************************************************************ * * * OpenGPS Receiver * * * * -------------------------------------------------------------------- * * * * Module: ogrt_riseset.c * * * * Version: 0.1 * * * * Date: 09.12.02 * * * * Author: C. Kelley, G. Beyerle * * * * -------------------------------------------------------------------- * * * * Copyright (C) 2001-2003 C. Kelley, G. Beyerle * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * * * -------------------------------------------------------------------- * * * * OpenGPS is based on Clifford Kelley's OpenSourceGPS distribution. * * The OpenSourceGPS distribution can be obtained from * * http://www.home.earthlink.net/~cwkelley * * * * -------------------------------------------------------------------- * * * * Real-time process * * * ************************************************************************ *//* ******************************* changes ******************************** 26.01.03 - replace 'trackch' by 'RT_Ctrl->leadch' use fields RT_Ctrl->accum_missed & ->accum_new 18.07.03 - Chan[].ms_count wraps at 6000 (instead of 30000) 18.07.03 - move Ms_Count to struct Chan[] 31.07.03 - fixed bug in find/read_preamble() 03.08.03 - copy carrier-aided code tracking from OpenSourceGPS ************************************************************************ *//*********************************************************************** GPS RECEIVER (GPSRCVR) Ver. 1.02 12 Channel All-in-View GPS Receiver Program based on Mitel GP2021 chipset Clifford Kelley cwkelley@earthlink.net Copyright (c) 1996-2002 Clifford Kelley. All Rights Reserved. This LICENSE must be included with the OGR code.***********************************************************************//*Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions aremet: CONDITIONS1. Redistributions of GPSRCVR source code must retain the above copyrightnotice, this list of conditions, and the following disclaimer.2. Redistributions in binary form must contain the above copyrightnotice, this list of conditions and the following disclaimer in thedocumentation and/or other materials provided with the distribution.3. All modifications to the source code must be clearly marked assuch. Binary redistributions based on modified source code must beclearly marked as modified versions in the documentation and/or othermaterials provided with the distribution.4. Notice must be given of the location of the availability of theunmodified current source code, e.g., http://www.Kelley.com/or ftp://ftp.Kelley.comin the documentation and/or other materials provided with thedistribution.5. All advertising and published materials mentioning features or useof this software must display the following acknowledgment: "Thisproduct includes software developed by Clifford Kelley and othercontributors."6. The name of Clifford Kelley may not be used to endorse or promoteproducts derived from this software without specific prior writtenpermission. DISCLAIMERThis software is provided by Clifford Kelley and contributors "as is" andany expressed or implied warranties, including, but not limited to, theimplied warranties of merchantability and fitness for a particularpurpose are disclaimed. In no event shall Clifford Kelley orcontributors be liable for any direct, indirect, incidental, special,exemplary, or consequential damages (including, but not limited to,procurement of substitute goods or services; loss of use, data, orprofits; or business interruption) however caused and on any theory ofliability, whether in contract, strict liability, or tort (includingnegligence or otherwise) arising in any way out of the use of thissoftware, even if advised of the possibility of such damage.*//* ------------------------------- includes ------------------------------- */#include <linux/kernel.h>#include <linux/module.h>#include <linux/slab.h>#include <rtai.h>#include <rtai_sched.h>#include <rtai_fifos.h>#include <rtai_shm.h>#include "port.h"#include "ogr_defines.h"#include "ogr_structs.h"#include "ogrt_defines.h"#include "ogrt_globals.h"#include "ogrt_prototypes.h"MODULE_LICENSE( "GPL");/* ------------------------------- defines -------------------------------- *//* ------------------------------ globals --------------------------------- *///static long delta_carrier[NOFCHN], delta_code[NOFCHN];/* ------------------------------ prototypes ------------------------------ *//* ------------------------------ procedures ------------------------------ *//* ------------------------------------------------------------------------- *FUNCTION init_risesetriseset()RETURNS None.PARAMETERS ch channel number (0-11)PURPOSE init 'riseset' and 'riseset' modes: all 12 channels track the same PRN tracked by channel no. 'RT_Ctrl->leadch'* ------------------------------------------------------------------------- *//* ------------------------------------------------------------------------- *FUNCTION ch_track_riseset()RETURNS None.PARAMETERS ch : channel numberPURPOSE track signal in code and doppler space write inphase / quad data to user prg via FIFOWRITTEN BY Clifford Kelley* ------------------------------------------------------------------------- */void ch_track_riseset( INT16 ch, INT16 accum_missed){ INT16 bit; long i_sum, q_sum, dfrq, car_phs_res, cod_phs_res, prompt_mag, dith_mag; if ( ch != RT_Ctrl->leadch) return;// GP2021 has two tracking arms only: prompt & dither i_sum = Chan[ch].i_prompt + Chan[ch].i_dith; q_sum = Chan[ch].q_prompt + Chan[ch].q_dith;/* * phase discriminator: atan( Q, I), we can't use atan2() here, since data bits * are still modulated on the signal causing sign flips. */ car_phs_res = fix_atan( q_sum, i_sum);/* --- 2nd order PLL --- */ dfrq = trk_car_c3 * car_phs_res - trk_car_c1 * car_phs_res_prv[ch];/* --- save residual phase for next iteration --- */ car_phs_res_prv[ch] = car_phs_res;/* --- fix point arithmetics (2^14 <-> 1.0) --- */ Chan[ch].car_frq += dfrq >> 14;/* * update carrier frq (all channels simultaneously!) */ all_carrier( Chan[ch].car_frq);// ch_carrier( ch, Chan[ch].car_frq);#if 0// adjust carrier frqs of trailing channels every TIC event only rt_printk( "ch_track_riseset: delta_carrier[%d] = %ld\n", ch, delta_carrier[ch]); if ( accum_missed & 0x2000) { int i; for ( i=0; i<NOFCHN; i++) { rt_printk( "ch_track_riseset: (2) delta_carrier[i] = %ld\n", delta_carrier[i]); if ( i != ch) ch_carrier( i, Chan[ch].car_frq - delta_carrier[i]); } }#endif/* * average over 20ms */ Chan[ch].q_dith_20ms += Chan[ch].q_dith; Chan[ch].q_prompt_20ms += Chan[ch].q_prompt; Chan[ch].i_dith_20ms += Chan[ch].i_dith; Chan[ch].i_prompt_20ms += Chan[ch].i_prompt;/* * we've added 20 samples */ if ( ( Chan[ch].ms_count % 20) == 0) { prompt_mag = rss( Chan[ch].i_prompt_20ms, Chan[ch].q_prompt_20ms); dith_mag = rss( Chan[ch].i_dith_20ms, Chan[ch].q_dith_20ms); cod_phs_res = RT_Ctrl->earlylate * ( prompt_mag - 2 * dith_mag);/* --- 2nd order PLL --- */ dfrq = trk_cod_c3 * cod_phs_res - trk_cod_c1 * cod_phs_res_prv[ch];/* --- save for next iteration --- */ cod_phs_res_prv[ch] = cod_phs_res;/* --- fix point arithmetics (2^14 <-> 1.0) --- */ Chan[ch].cod_frq += dfrq >> 14;// update code frq all_code( Chan[ch].cod_frq);#if 0// shift slave channels at TIC rate (0.1 s) only if ( accum_missed & 0x2000) { int i; for ( i=0; i<NOFCHN; i++) { if ( i != ch) ch_code( i, Chan[ch].cod_frq - delta_code[i]); } }#endif// Chan[ch].sum += Chan[ch].prompt_mag + Chan[ch].dith_mag;//// if ( Chan[ch].ms_count % 100 == 0)// {// Chan[ch].avg_20ms = Chan[ch].sum / 5;// Chan[ch].sum = 0;// }// nav bit bit = BSIGN( Chan[ch].i_prompt_20ms + Chan[ch].i_dith_20ms);/* * Find preamble if not yet found. If already found, just read it. */ if ( !Chan[ch].tow_sync) find_preamble( ch, bit); else read_preamble( ch, bit);/* * Variable 'Preamble_Found[]' is set in find_preamble() */ if ( Preamble_Found[ch]) writefifo_navbit( ch, bit); writefifo_corrdata( ch, ch); // in riseset mode, ch == RT_Ctrl->leadch! Chan[ch].q_dith_20ms = 0; Chan[ch].q_prompt_20ms = 0; Chan[ch].i_dith_20ms = 0; Chan[ch].i_prompt_20ms = 0; } // --- if ( msec_count[ch] ... ) ---// we count bits & frames only in tracking mode if ( Chan[ch].ms_count % 20 == 0) Chan[ch].bit_count = (Chan[ch].bit_count + 1) % 1500; if ( Chan[ch].ms_count == 0 && Chan[ch].sfid == 5) Chan[ch].frame_count += 1; return;}/* ------------------------------------------------------------------------- *FUNCTION ch_follow_riseset_DUMP()RETURNS nonePARAMETERS ch : channel number idx : index in channel_list + 1 (1,...,11)PURPOSE in 'riseset' mode 11 'slave' channels follow 1 'master' channel, add amplitudes at DUMP event* ------------------------------------------------------------------------- */void ch_follow_riseset_DUMP( INT16 ch){ INT16 leadch; /* * don't touch the master channel! */ if ( ch == RT_Ctrl->leadch) return; leadch = RT_Ctrl->leadch;// code_phase : 0,...,2045; halfchips// code_DCO_phase : 0,...,1023; 1/1024 halfchip// Ofs = (Chan[ch].code_phase - Chan[RT_Ctrl->leadch].code_phase)*1024 + // (Chan[ch].code_DCO_phase - Chan[RT_Ctrl->leadch].code_DCO_phase);// keep track of I/Q Chan[ch].q_dith_20ms += Chan[ch].q_dith; Chan[ch].q_prompt_20ms += Chan[ch].q_prompt; Chan[ch].i_dith_20ms += Chan[ch].i_dith; Chan[ch].i_prompt_20ms += Chan[ch].i_prompt; if ( ( Chan[leadch].ms_count % 20) == 0) { writefifo_corrdata( ch, leadch); Chan[ch].q_dith_20ms = 0; Chan[ch].q_prompt_20ms = 0; Chan[ch].i_dith_20ms = 0; Chan[ch].i_prompt_20ms = 0; } return; }/* ------------------------------------------------------------------------- *FUNCTION ch_follow_riseset_TIC()RETURNS nonePARAMETERS ch : channel number idx : index in channel_list + 1 (1,...,11)PURPOSE in 'riseset' mode 11 'slave' channels follow 1 'master' channel, keep synchronization Correct code/carrier DCO frequencies at TICs only.* ------------------------------------------------------------------------- */void ch_follow_riseset_TIC( INT16 leadch){ INT16 ch; long delta; for ( ch=0; ch<NOFCHN; ch++) {// don't touch the master channel if ( ch == leadch) continue; // first align in carrier space ... if ( Chan[ch].carr_dco_phase <= 1023 && Chan[leadch].carr_dco_phase <= 1023) { delta = Chan[ch].carr_dco_phase - Chan[leadch].carr_dco_phase; /* * delta : -1023,...,1-,0,1,...,1023 * map to interval -512,...,512 */ delta = ((delta + 1024 + 512) % 1024) - 512; /* * positive phase difference -> run slower * negative phase difference -> run faster */ /* * deviate somewhat from master's frequency to re-sync */ ch_carrier( ch, Chan[leadch].car_frq - 10 * delta); } /* * ... then align in code space * Chan[ch].code_phase = 0,...,2045 [halfchips] * Chan[ch].code_dco_phase = 0,...,1023 [1/1024 halfchips] */ /* * ignore outlier values */ if ( Chan[ch].code_phase <= 2047 && Chan[ch].code_dco_phase <= 1023 && Chan[leadch].code_phase <= 2047 && Chan[leadch].code_dco_phase <= 1023) { delta = (Chan[ch].code_phase * 1024L + Chan[ch].code_dco_phase) - (Chan[leadch].code_phase * 1024L + Chan[leadch].code_dco_phase); // delta : -2046*1024,...,1-,0,1,...,2046*1024 // delta = ( delta > 1023L * 1024L) ? delta - 2046L * 1024L : delta; // delta = ( delta < -1023L * 1024L) ? delta + 2046L * 1024L : delta; delta = ((delta + 2046L * 1024L + 1023L * 1024L) % (2046L * 1024L)) - 1023L * 1024L; // add offsets to spread slave channels in code space// delta += riseset_cod_ofs[ch]; delta = 0; /* * update code and carrier NCOs to keep them in sync */ ch_code( ch, Chan[leadch].cod_frq - delta); } } // --- for ( ch=0; ch<NOFCHN; ch++) --- return;}/* ------------------------------- end of file ---------------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -