📄 ogrt_inout.c
字号:
/* ************************************************************************ * * * OpenGPS Receiver * * * * -------------------------------------------------------------------- * * * * Module: ogrt_inout.c * * * * Version: 0.1 * * * * Date: 01.12.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 - input/output functions * * * ************************************************************************ *//* ******************************* changes ******************************** 01.12.03 - separate input/output function from ogrt_proc.c ************************************************************************ *//*********************************************************************** 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_prototypes.h"#include "ogrt_globals.h"MODULE_LICENSE( "GPL");/* ------------------------------ local variables ------------------------- *//* ------------------------------ prototypes ------------------------------ *//* ------------------------------ procedures ------------------------------ *//* ------------------------------------------------------------------------- *FUNCTION writefifo_navdata()RETURNS nonePARAMETERS ch : channel numberPURPOSE tell user land of nav bit* ------------------------------------------------------------------------- */inline void writefifo_navbit( INT16 ch, INT16 bit){ signed char chr, buf[MSG_MAX_LEN]; unsigned char len;// write to FIFO: channel number / nav bit chr = MSG_NAVBIT; memcpy( buf, &chr, sizeof( char)); len = MSG_NAVBIT_LEN; memcpy( buf+1, &len, sizeof( char)); chr = (char) ch; memcpy( buf+2, &chr, sizeof( char)); chr = (char)((Preamble_Found[ch] > 0) ? bit : ~bit & 0x1);// bit 1 of chr indicates start of TLM (bit 1 ends at 20 ms offset) if ( Chan[ch].ms_count == 20) chr = ( 0x2 | chr); memcpy( buf+3, &chr, sizeof( char)); rtf_put( FIFO_NAVBIT, buf, len+2); return;}/* ------------------------------------------------------------------------- *FUNCTION writefifo_navdata()RETURNS nonePARAMETERSPURPOSE communicate to user land* ------------------------------------------------------------------------- */inline void writefifo_navdata( void){ UINT16 ch; char chr, len, buf[MSG_MAX_LEN]; unsigned long tow_1s; for ( ch=0; ch<NOFCHN; ch++) {/** field 'epoch' provides elapsed time up to 1 sec* take full seconds from 'tow' and millisecond counter 'ms_count'*/// alternative: tow_1s = Chan[ch].tow_HOW + ((Chan[ch].ms_count + 4800) % 6000 + 1200) / 1000; tow_1s = Chan[ch].tow + Chan[ch].ms_count / 1000;// assemble message and send to user proc chr = MSG_PSIRANGE; memcpy( buf, &chr, sizeof( char)); len = MSG_PSIRANGE_LEN; // length of message not counting header memcpy( buf+1, &len, sizeof( char)); memcpy( buf+2, &ch, sizeof( INT16)); memcpy( buf+4, &Chan[ch].epoch, sizeof( INT16)); memcpy( buf+6, &Chan[ch].code_phase, sizeof( INT16)); memcpy( buf+8, &Chan[ch].code_dco_phase, sizeof( INT16)); memcpy( buf+10, &Chan[ch].carr_dco_phase, sizeof( INT16)); memcpy( buf+12, &Chan[ch].carr_cycle_lo, sizeof( INT16)); memcpy( buf+14, &Chan[ch].carr_cycle_hi, sizeof( INT16)); memcpy( buf+16, &RT_Ctrl->tow_tic_count, sizeof( long)); memcpy( buf+20, &tow_1s, sizeof( long)); rtf_put( FIFO_NAVBIT, buf, len+2);// rt_printk( "OGRT_PROC: wrote %d bytes to fifo.\n", len+2); } // --- for ( ch=0; ch<NOFCHN; ch++) --- return;}/* ------------------------------------------------------------------------- *FUNCTION writefifo_corrdata()RETURNS nonePARAMETERS ch : channel numberPURPOSE save correlator data to file* ------------------------------------------------------------------------- */inline void writefifo_corrdata( INT16 ch, INT16 leadch){ char buf[64];// #include <rtai_sched.h>// RTIME rt;// rt = rt_get_time_ns();// rt = rt_get_cpu_time_ns();//// rtf_put( 1, &rt, sizeof( long long)); memcpy( buf, &RT_Ctrl->tow_tic_count, sizeof( long)); memcpy( buf+ 4, &Chan[ch].i_prompt_20ms, sizeof( long)); memcpy( buf+ 8, &Chan[ch].i_dith_20ms, sizeof( long)); memcpy( buf+12, &Chan[ch].q_prompt_20ms, sizeof( long)); memcpy( buf+16, &Chan[ch].q_dith_20ms, sizeof( long)); memcpy( buf+20, &ch, sizeof( INT16)); memcpy( buf+22, &Chan[ch].carr_cycle_lo, sizeof( INT16)); memcpy( buf+24, &Chan[ch].carr_cycle_hi, sizeof( INT16)); memcpy( buf+26, &Chan[ch].carr_dco_phase, sizeof( INT16)); memcpy( buf+28, &Chan[ch].code_phase, sizeof( INT16)); memcpy( buf+30, &Chan[ch].code_dco_phase, sizeof( INT16)); rtf_put( FIFO_IQDUMP, buf, 32); return;}/* ------------------------------------------------------------------------- *FUNCTION fill_channelinfo_ringbuffer()RETURNS nonePARAMETERSPURPOSE save amplitude and phase data to ring buffer -> gpsplot* ------------------------------------------------------------------------- */void fill_channelinfo_ringbuffer( void){ INT16 idx, ch; CHN_INFO Chn_Info; if ( !Chn_RBuf) return;/* next element is written to 'Chn_RBuf->ch_head' */ idx = Chn_RBuf->ch_head;// rt_printk( "OGRT_INOUT: (1) Chn_RBuf->ch_head = %d\n", Chn_RBuf->ch_head); if ( idx < 0) idx = 0;// i_prompt_20ms, // I prompt avg'ed over 20 ms// q_prompt_20ms, // Q prompt avg'ed over 20 ms// i_dith_20ms, // I dither avg'ed over 20 ms// q_dith_20ms, // Q dither avg'ed over 20 ms for ( ch=0; ch<NOFCHN; ch++) { Chn_Info.ch = ch; Chn_Info.car_frq = Chan[ch].car_frq; Chn_Info.cod_frq = Chan[ch].cod_frq; Chn_Info.missed = Chan[ch].missed; Chn_Info.code_phase = Chan[ch].code_phase; // code phase: 0,...,2046 halfchips Chn_Info.code_dco_phase = Chan[ch].code_dco_phase; // code frc. phs: 0,...,1023, 1024 = halfchip Chn_Info.i_prompt = Chan[ch].i_prompt; Chn_Info.q_prompt = Chan[ch].q_prompt; Chn_Info.i_dith = Chan[ch].i_dith; Chn_Info.q_dith = Chan[ch].q_dith; Chn_Info.prn = Chan[ch].prn; Chn_Info.i_prompt_20ms = Chan[ch].i_prompt_20ms; Chn_Info.q_prompt_20ms = Chan[ch].q_prompt_20ms; Chn_Info.i_dith_20ms = Chan[ch].i_dith_20ms; Chn_Info.q_dith_20ms = Chan[ch].q_dith_20ms; Chn_Info.sourceSel = 0; Chn_RBuf->chan[idx] = Chn_Info; idx = (idx + 1) % CHN_RBUF_LEN; } Chn_RBuf->ch_head = idx; Chn_RBuf->leadch = RT_Ctrl->leadch; Chn_RBuf->watchdog += 1; // rt_printk( "OGRT_INOUT: (2) Chn_RBuf->ch_head = %d\n", Chn_RBuf->ch_head); return;}/* ------------------------------- end of file ---------------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -