📄 ogrt_preamble.c
字号:
/* ************************************************************************ * * * OpenGPS Receiver * * * * -------------------------------------------------------------------- * * * * Module: ogrt_preamble.c * * * * Version: 0.1 * * * * Date: 13.10.03 * * * * 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 -------------------------------- *//* ------------------------------ local variables ------------------------- */// 'TLMFifo' holds first word (TLM), 'HOWFifo' holds second word (HOW).// 'TLMFifo' is fed from 'HOWFifo', 'HOWFifo' from variable 'bit'.// Shift bits to TLMFifo/1 until TLMFifo contains TLM word and // HOWFifo HOW word.unsigned long TLMFifo[NOFCHN], HOWFifo[NOFCHN];/* ------------------------------ prototypes ------------------------------ *//* ------------------------------ procedures ------------------------------ *//* ------------------------------------------------------------------------- *FUNCTION find_preamble()RETURNS None.PARAMETERS ch channel number (0-11) bit the latest bit from the satellitePURPOSE This function finds the preamble in the navigation message. The preamble 0x8b is found in the first 8 bits of the TLM word (first word of each subframe).WRITTEN BY Clifford Kelley* ------------------------------------------------------------------------- */void find_preamble( INT16 ch, INT16 bit){ int d29, d30; INT16 parity0, parity1; unsigned long TLM, HOW, pattern;/* * 'TLMFifo' holds first word (TLM), 'HOWFifo' holds second word (HOW). * 'TLMFifo' is fed from 'HOWFifo', 'HOWFifo' from variable 'bit'. * Shift bits to TLMFifo/1 until TLMFifo contains TLM word and * HOWFifo HOW word. */ TLMFifo[ch] = (TLMFifo[ch]<<1) + (( HOWFifo[ch]>>29) & 0x1); HOWFifo[ch] = (HOWFifo[ch]<<1) + bit; pattern = (( TLMFifo[ch] ^ PREAMBLE) & 0x3fc00000L); if ( pattern == 0) Preamble_Found[ch] = 1; else if ( pattern == 0x3fc00000L) Preamble_Found[ch] = -1; else Preamble_Found[ch] = 0; if ( Preamble_Found[ch]) { TLM = TLMFifo[ch]; HOW = HOWFifo[ch];// found inverted preamble pattern? if ( Preamble_Found[ch] < 0) { TLM = ~TLM; HOW = ~HOW; } parity0 = (xors( TLM & PARBIT1)<<5)+(xors( TLM & PARBIT2)<<4)+ (xors( TLM & PARBIT3)<<3)+(xors( TLM & PARBIT4)<<2)+ (xors( TLM & PARBIT5)<<1)+(xors( TLM & PARBIT6)); if ( parity0 == (TLM & 0x3f)) // is parity of TLM ok? { d30 = (HOW >> 30) & 0x1; d29 = (HOW >> 31) & 0x1; parity1 = ((d29^xors( HOW & PARBIT1)) << 5) + ((d30^xors( HOW & PARBIT2)) << 4) + ((d29^xors( HOW & PARBIT3)) << 3) + ((d30^xors( HOW & PARBIT4)) << 2) + ((0 ^xors( HOW & PARBIT5)) << 1) + ((d29^d30^xors( HOW & PARBIT6))); if ( parity1 == (HOW & 0x3f)) // is parity of HOW ok? {// we at start of 3rd word, i.e. 1.2 sec after start of subframe // (therefore, Chx_20MS_EPOCH = 10, Chx_1MS_EPOCH = 0) ch_epoch_count_load( ch, 0xa00);// ch_epoch_count_load( ch, (0x1f & ch_epoch_check(ch)) | 0xa00); // D1-D24 = D30 ^ d1-d24. (Note: for TLM d30 is 0 by construction!) if ( d30) HOW = HOW ^ 0x3fffffc0L;// compute the subframe id number Chan[ch].sfid = (HOW & 0x700) >> 8;// was: Chan[ch].TLM = (TLM >> 2) & 0x3fff; Chan[ch].TLM = (TLM >> 6) & 0xffff; if ( Chan[ch].sfid >= 1 && Chan[ch].sfid <= 5) { /* * tow in HOW word is given in units of 6 seconds (4*1.5 seconds), * tow refers to the start of _next_ subframe; * field 'tow_HOW' uses units of seconds! */ Chan[ch].tow_HOW = ((HOW & 0x3fffffffL) >> 13) * 6;// rt_printk( "Chan[%d].tow_HOW = %ld\n", ch, ((HOW & 0x3fffffffL) >> 13)); Chan[ch].tow_sync = 1;// ms_count = 0,...,5999; start of 3rd word (30 bits per word, 20 ms per bit) Chan[ch].ms_count = 1200; } else Chan[ch].tow_sync = 0; } // --- if ( parity1 == (HOW & 0x3f)) --- } } // --- if (((pream^TLM) & 0x3fc00000L) == 0) --- return;}/* ------------------------------------------------------------------------- *FUNCTION read_preamble()RETURNS None.PARAMETERS ch channel number (0-11) bit the latest bit from the satellitePURPOSE Read preamble of the navigation message. It is assumed that we already know the preample's startWRITTEN BY Clifford Kelley* ------------------------------------------------------------------------- */void read_preamble( INT16 ch, INT16 bit){ int d29, d30; INT16 parity0, parity1; unsigned long TLM, HOW; TLMFifo[ch] = (TLMFifo[ch]<<1) + (( HOWFifo[ch]>>29) & 0x1); HOWFifo[ch] = (HOWFifo[ch]<<1) + bit;// we expect preamble for ms_count == 1200 if ( Chan[ch].ms_count == 1200) { TLM = TLMFifo[ch]; HOW = HOWFifo[ch];// found inverted preamble pattern? if ( Preamble_Found[ch] < 0) { TLM = ~TLM; HOW = ~HOW; } parity0 = (xors( TLM & PARBIT1)<<5)+(xors( TLM & PARBIT2)<<4)+ (xors( TLM & PARBIT3)<<3)+(xors( TLM & PARBIT4)<<2)+ (xors( TLM & PARBIT5)<<1)+(xors( TLM & PARBIT6)); d30 = (HOW >> 30) & 0x1; d29 = (HOW >> 31) & 0x1; parity1 = ((d29^xors( HOW & PARBIT1)) << 5) + ((d30^xors( HOW & PARBIT2)) << 4) + ((d29^xors( HOW & PARBIT3)) << 3) + ((d30^xors( HOW & PARBIT4)) << 2) + ((0 ^xors( HOW & PARBIT5)) << 1) + ((d29^d30^xors( HOW & PARBIT6))); if ( parity0 == (TLM & 0x3f) && parity1 == (HOW & 0x3f)) { if ( d30) HOW = HOW ^ 0x3fffffc0L; Chan[ch].TLM = (TLM >> 6) & 0xffff;// extract subframe id number Chan[ch].sfid = (HOW & 0x700) >> 8;// extract HOW Chan[ch].tow_HOW = ((HOW & 0x3fffffffL) >> 13) * 6;// rt_printk( " Chan[%d].tow_HOW = %ld\n", ch, ((HOW & 0x3fffffffL) >> 13)); } else Chan[ch].tow_sync = 0; } return;}/* ------------------------------- end of file ---------------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -