📄 ogrt_proc.c
字号:
/* ************************************************************************ * * * OpenGPS Receiver * * * * -------------------------------------------------------------------- * * * * Module: ogrt_proc.c * * * * Version: 0.1 * * * * Date: 09.12.03 * * * * Author: C. Kelley, G. Beyerle * * * * -------------------------------------------------------------------- * * * * Copyright (C) 2001-2003 C. Kelley, G. Beyerle, S. Esterhuizen * * * * 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/ioport.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_prototypes.h"#define OGRTMAIN# include "ogrt_globals.h"#undef OGRTMAINMODULE_LICENSE( "GPL");/* ------------------------------ local variables ------------------------- */RT_TASK thread;/* ------------------------------ prototypes ------------------------------ *//* ------------------------------ procedures ------------------------------ *///------------------------------------------------------------------------------// registerGPS// // Registers GPS board with Linux (nobody else can use our memory space)//// Author: S. Esterhuizen//// Source: OpenGPS/src/rtproc.c//static int registerGPS(void) { int result;#ifdef ISABOARD// see whether somebody is already using our ISA space result = check_region( ISABASE, ISA_NR_PORTS); if ( result) { rt_printk( KERN_INFO "ogr: can't get ISA I/O port \ address 0x%hx\n", ISABASE); return result; } request_region( ISABASE, ISA_NR_PORTS, ISA_BOARDNAME); rt_printk( KERN_INFO "ogr: obtained ISA port 0x%hx\n", ISABASE);#endif#ifdef PCIBOARD// see whether somebody is already using our ISA space result = check_region( PCIBASE, PCI_NR_PORTS); if ( result) { rt_printk( KERN_INFO "ogr: can't get PCI I/O port \ address 0x%hx\n", PCIBASE); return result; } request_region( PCIBASE, PCI_NR_PORTS, PCI_BOARDNAME); rt_printk( KERN_INFO "ogr: obtained PCI port 0x%hx\n", PCIBASE);#endif return TRUE;}/* ------------------------------------------------------------------------- *FUNCTION void watchdog( void)RETURNS nonePARAMETERS nonePURPOSE check whether GP2021 still alive* ------------------------------------------------------------------------- */void watchdog( void){ UINT16 oldval = 1, newval; if ( oldval != 1) { newval = data_retent_r(); if ( newval != oldval) { rt_printk( KERN_INFO "ogr: watchdog says we've lost contact to GP2021 (%d != %d)!\n", oldval, newval); RT_Ctrl->rt_polling = 0; return; } oldval += 0x100; } else oldval = 0; data_retent_w( oldval); return;}/* * monosat mode: shift correlators? */static void slew_slave_code_delay( void){ INT16 ch; // user might have pressed '-' or '+' in navigation mode ... if ( RT_Ctrl->leadch < 0) return; if ( RT_Ctrl->monosat_slew > 0) {// it is save to change monosat_cod_ofs[leadch] as well// since it is ignored anyway for ( ch=0; ch<NOFCHN; ch++) monosat_cod_ofs[ch] += MONOSAT_COD_OFS_STEP; } else if ( monosat_cod_ofs[RT_Ctrl->leadch] > 0) {// at this point we don't allow to slew to negative offsets!// (slave channels are not allowed to preceed master channel.) for ( ch=0; ch<NOFCHN; ch++) monosat_cod_ofs[ch] -= MONOSAT_COD_OFS_STEP; } RT_Ctrl->monosat_slew = 0; // done return;}/* *********************************************************************FUNCTION handle_DUMP_event()RETURNS None.PARAMETERS None.PURPOSE Handle DUMP event********************************************************************* */inline static void handle_DUMP_event( INT16 accum_new, INT16 accum_missed){ INT16 ch; UINT16 adr; for ( ch=0; ch<NOFCHN; ch++) { if ( (accum_new >> ch) & 0x1) {/* * DUMP event occurred, ms_count = 0,...,5999; one subframe. * in 'acquisition' and 'pull-in' mode 'ms_count' is not yet * aligned to subframes! */ Chan[ch].ms_count = (Chan[ch].ms_count + 1) % 6000; if ( Chan[ch].ms_count == 0) {// ch_epoch_count_load( ch, 0);// tow read from HOW refers to start of _next_ subframe! Chan[ch].tow = Chan[ch].tow_HOW; } adr = CHx_ACCUM_BASE + (ch<<2); Chan[ch].i_dith = from_gps( adr); // inphase dither adr++; Chan[ch].q_dith = from_gps( adr); // quadrature dither adr++; Chan[ch].i_prompt = from_gps( adr); // inphase prompt adr++; Chan[ch].q_prompt = from_gps( adr); // quadrature prompt/* * reading Q_PROMPT clears CHx_NEW_ACCUM_DATA bit */ /* ch_accum_reset( ch); */ } if ( (accum_missed >> ch) & 0x1) { Chan[ch].missed++; ch_accum_reset( ch);/* * if miss happened in 'track'ing mode we lost nav bit synchronization; re-align */ if ( Chan[ch].state == track) Chan[ch].state = align; } } return;}/* *********************************************************************FUNCTION handle_TIC_event()RETURNS None.PARAMETERS None.PURPOSE Handle TIC event********************************************************************* */inline static void handle_TIC_event( INT16 accum_new, INT16 accum_missed){ INT16 ch; UINT16 adr;/* * and read code and carrier phase data sampled at TIC */ for ( ch=0; ch<NOFCHN; ch++) { adr = CODE_SLEW + (ch<<3); Chan[ch].code_slew = from_gps( adr); adr++; Chan[ch].code_phase = from_gps( adr); adr++; Chan[ch].carr_cycle_lo = from_gps( adr); adr++; Chan[ch].carr_dco_phase = from_gps( adr); adr++; Chan[ch].epoch = from_gps( adr); adr++; Chan[ch].code_dco_phase = from_gps( adr); adr++; Chan[ch].carr_cycle_hi = from_gps( adr);// code_phase, // code phase: 0,...,2046 halfchips// code_dco_phase, // code fract. phase: 0,...,1023, 1024 = halfchip// carr_dco_phase, // carr fract. phase: 0,...,1023/* * tell if non-sensical values appear */ if ( Chan[ch].code_phase > 2047) rt_printk( KERN_INFO "ogr: value exceeds valid range; Chan[%d].code_phase = %d \n", ch, Chan[ch].code_phase); if ( Chan[ch].code_dco_phase > 1023) rt_printk( KERN_INFO "ogr: value exceeds valid range; Chan[%d].code_dco_phase = %d \n", ch, Chan[ch].code_dco_phase); if ( Chan[ch].carr_dco_phase > 1023) rt_printk( KERN_INFO "ogr: value exceeds valid range; Chan[%d].carr_dco_phase = %d \n", ch, Chan[ch].carr_dco_phase); } return;}/* *********************************************************************FUNCTION call_ch_funs()RETURNS None.PARAMETERS ACCUM_NEWPURPOSE Call ch_*() functions********************************************************************* */inline static void call_ch_funs( INT16 accum_new, INT16 accum_missed){ INT16 ch;/* * process according to state of channel if DUMP event * for this channel occurred */ for ( ch=0; ch<NOFCHN; ch++) { if ( (accum_new >> ch) & 0x1) { switch( Chan[ch].state) { case initialize: ch_initialize( ch); break; case acquisition: ch_acquisition( ch); break; case confirm: ch_confirm( ch); break; case pull_in: ch_pull_in( ch); break; case align: ch_align( ch); break; case track: ch_track( ch); break; case track_monosat: ch_track_monosat( ch, accum_missed); break; case follow_monosat: ch_follow_monosat_DUMP( ch);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -