www.pudn.com > opengpssim.zip > gp2021.c


/* ************************************************************************ 
   *                                                                      *
   *                          GPS Simulation                              *
   *                                                                      *
   * -------------------------------------------------------------------- *
   *                                                                      *
   *    Module:   gp2021.c                                                *
   *                                                                      *
   *   Version:   0.1                                                     *
   *                                                                      *
   *      Date:   17.02.02                                                *
   *                                                                      *
   *    Author:   G. Beyerle                                              *
   *                                                                      *
   * -------------------------------------------------------------------- *
   *                                                                      *
   * Copyright (c) 1996-2001 Clifford Kelley.  All Rights Reserved.       *
   * Copyright (C) 2002-2006 Georg 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.            *
   *                                                                      *
   * -------------------------------------------------------------------- *
   *                                                                      *
   * The files 'gpsfuncs.cpp', 'gpsrcvr.cpp' and 'gp2021.cpp' are modi-   *
   * fied versions of the files with the same name from Clifford Kelley's * 
   * OpenSourceGPS distribution. The unmodified files can be obtained     *
   * from http://www.home.earthlink.net/~cwkelley                         *
   *                                                                      *
   * -------------------------------------------------------------------- *
   *                                                                      *
   *                             Correlator                               *
   *                                                                      *
   ************************************************************************ */

/* ******************************* changes ********************************

   dd.mm.yy -

   ************************************************************************ */

/*********************************************************************** 
  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-2001 Clifford Kelley.  All Rights Reserved. 
  This LICENSE must be included with the GPSRCVR code. 
***********************************************************************/ 
/* 
Redistribution and use in source and binary forms, with or without 
modification, are permitted provided that the following conditions are 
met: 
 
      CONDITIONS 
 
1. Redistributions of GPSRCVR source code must retain the above copyright 
notice, this list of conditions, and the following disclaimer. 
 
2. Redistributions in binary form must contain the above copyright 
notice, this list of conditions and the following disclaimer in the 
documentation and/or other materials provided with the distribution. 
 
3. All modifications to the source code must be clearly marked as 
such.  Binary redistributions based on modified source code must be 
clearly marked as modified versions in the documentation and/or other 
materials provided with the distribution. 
 
4. Notice must be given of the location of the availability of the 
unmodified current source code, e.g., 
  http://www.Kelley.com/ 
or 
  ftp://ftp.Kelley.com 
in the documentation and/or other materials provided with the 
distribution. 
 
5. All advertising and published materials mentioning features or use 
of this software must display the following acknowledgment:  "This 
product includes software developed by Clifford Kelley and other 
contributors." 
 
6. The name of Clifford Kelley may not be used to endorse or promote 
products derived from this software without specific prior written 
permission. 
 
      DISCLAIMER 
 
This software is provided by Clifford Kelley and contributors "as is" and 
any expressed or implied warranties, including, but not limited to, the 
implied warranties of merchantability and fitness for a particular 
purpose are disclaimed.  In no event shall Clifford Kelley or 
contributors 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, or 
profits; or business interruption) however caused and on any theory of 
liability, whether in contract, strict liability, or tort (including 
negligence or otherwise) arising in any way out of the use of this 
software, even if advised of the possibility of such damage. 
*/ 
 
#include   
#include   
#ifdef __TURBOC__ 
# include   
# include   
#endif 
#include   
#include   
#ifndef linux 
# include   
#endif 
#include   
 
#include "ogsdefine.h" 
#include "ogsstructs.h" 
#include "ogsextern.h" 
#include "ogsprototypes.h" 
 
 
inline int accum_status( void) 
{ 
  return( from_gps( ACCUM_STATUS_A)); 
} 
 
void all_accum_reset( void) 
{ 
  return; 
} 
 
void data_tst( int data) 
{ 
  to_gps( DATABUSTEST, data); 
} 
 
unsigned int  ch_epoch(char ch) 
{ 
  return( from_gps( (ch<<3)+EPOCH)); 
} 
 
unsigned int  ch_epoch_chk(char ch) 
{ 
  return( from_gps( (ch<<3)+EPOCH_CHECK)); 
} 
 
long   ch_carrier_cycle(char ch) 
{ 
  long result; 
 
  result = from_gps( (ch<<3)+CARRIER_CYCLE_HIGH); 
  result = result<<16; 
  result = result + from_gps( (ch<<3)+CARRIER_CYCLE_LOW); 
 
  return result; 
} 
 
int  ch_code_DCO_phase( char ch) 
{ 
  return (from_gps( (ch<<3)+CODE_DCO_PHASE)); 
} 
 
void ch_code_incr_hi(char ch,int data) 
{ 
  to_gps( (ch<<3)+CODE_DCO_INCR_HIGH, data); 
} 
 
void ch_code_incr_lo(char ch,int data) 
{ 
  to_gps( (ch<<3)+CODE_DCO_INCR_LOW, data); 
} 
 
int ch_code_phase(char ch) 
{ 
 return (from_gps( (ch<<3)+CODE_PHASE)); 
} 
 
int ch_carrier_DCO_phase(char ch) 
{ 
  return (from_gps( (ch<<3)+CARRIER_DCO_PHASE)); 
} 
 
void carr_incr_hi(char ch,int data) 
{ 
  to_gps( (ch<<3)+CARRIER_DCO_INCR_HIGH, data); 
} 
 
void carr_incr_lo(char ch,int data) 
{ 
  to_gps( (ch<<3)+CARRIER_DCO_INCR_LOW, data); 
} 
 
void ch_cntl( char ch, int data) 
{ 
//  printf("ch=%d  port=%x\n",ch,port(ch<<3)); 
  to_gps( ch<<3+SATCNTL, data); 
} 
 
 
void all_cntl(int data) 
{ 
  to_gps(ALLCONTROL,data); 
 
} 
void multi_cntl(int data) 
{ 
  to_gps(MULTICONTROL,data); 
 
} 
 
int ch_i_track(char ch) 
{ 
  return (from_gps((ch<<2)+I_TRACK)); 
} 
 
int ch_q_track(char ch) 
{ 
  return (from_gps((ch<<2)+Q_TRACK)); 
} 
 
int ch_i_prompt(char ch) 
{ 
  return (from_gps((ch<<2)+I_PROMPT)); 
} 
 
int ch_q_prompt(char ch) 
{ 
  return (from_gps((ch<<2)+Q_PROMPT)); 
} 
 
void ch_accum_reset(char ch) 
{ 
  to_gps ((ch<<2)+ACCUM_RESET,0); 
} 
 
void ch_code_slew(char ch, int data) 
{ 
  to_gps( (ch<<2)+CODE_SLEW_COUNTER, data); 
} 
 
void all_code_slew(int data) 
{ 
  to_gps( ALLCONTROL, data); 
} 
 
void data_retent_w(int data) 
{ 
  to_gps( DATA_RETENT, data); 
} 
 
int data_retent_r(void) 
{ 
  return (from_gps( DATA_RETENT)); 
} 
 
void data_bus_test_w(int data) 
{ 
  to_gps( DATABUSTEST, data); 
} 
 
int data_bus_test_r(void) 
{ 
  return (from_gps( DATABUSTEST)); 
} 
 
 
inline int meas_status(void) 
{ 
  return (from_gps( MEAS_STATUS_A)); 
} 
 
void program_TIC(long data) 
{ 
  unsigned int high,low; 
 
  high = (int)(data>>16); 
  low  = (int)(data & 0xffff); 
 
  to_gps( PROC_TIC_HIGH, high); 
  to_gps( PROC_TIC_LOW, low); 
} 
 
void reset_cntl(int data) 
{ 
  to_gps(RESET_CONTROL,data); 
//  fprintf(out,"reset data=%x\n",data); 
} 
 
#if 0 
void ch_carrier( char ch, long freq) 
{ 
  int freq_hi, freq_lo; 
  unsigned int add; 
 
  freq_hi = (int)( freq >> 16); 
  freq_lo = (int)( freq & 0xffff); 
 
  add = (ch<<3) + CARRIER_DCO_INCR_HIGH; 
  outpw( IO_ADDRESS, add); 
  outpw( IO_DATA, freq_hi); 
//  carr_incr_hi(ch,freq_hi); 
  add++; 
  outpw( IO_ADDRESS, add); 
  outpw( IO_DATA, freq_lo); 
//  carr_incr_lo(ch,freq_lo); 
} 
 
void ch_code( char ch, long freq) 
{ 
  int freq_hi, freq_lo; 
  unsigned int add; 
 
  freq_hi = (int)( freq >> 16); 
  freq_lo = (int)( freq & 0xffff); 
 
  add = (ch<<3)+CODE_DCO_INCR_HIGH; 
 
  outpw( IO_ADDRESS, add); 
  outpw( IO_DATA, freq_hi); 
//  ch_code_incr_hi(ch,freq_hi); 
 
  add++; 
 
  outpw( IO_ADDRESS, add); 
  outpw( IO_DATA, freq_lo); 
//  ch_code_incr_lo(ch,freq_lo); 
} 
#endif 
 
void ch_epoch_load( char ch, unsigned int data) 
{ 
  to_gps( (ch<<3)+EPOCH_COUNT_LOAD, data); 
} 
 
void ch_on( char ch) 
{ 
  ch_status = ch_status | bit_pat[ch]; 
  reset_cntl( ch_status); 
} 
 
void ch_off( char ch) 
{ 
  ch_status = ch_status & !bit_pat[ch]; 
  reset_cntl( ch_status); 
} 
 
void system_setup( int data) 
{ 
  to_gps( SYSTEM_SETUP, data); 
} 
 
void test_control( int data) 
{ 
  to_gps( TEST_CONTROL, data); 
} 
 
void status_latch(void) 
{ 
  to_gps( STATUS, 0); 
} 
 
void io_config(int data) 
{ 
  to_gps( IO_CONFIG, data); 
} 
 
void self_test( void) 
{ 
  unsigned int indataaax, indata55x, indataaay, indata55y,error; 
 
  error=0; 
 
  data_retent_w( 0x5500); 
  data_bus_test_w( 0xaa55); 
  indata55x = data_retent_r(); 
  indataaax = data_bus_test_r(); 
  data_retent_w( 0xaa00); 
  data_bus_test_w( 0x55aa); 
  indataaay = data_retent_r(); 
  indata55y = data_bus_test_r(); 
  if ((indata55x != 0x5500) || (indataaax != 0xaa55) ||  
      (indataaay != 0xaa00) || (indata55y != 0x55aa)) 
  { 
   error = 1; 
   printf( "data line error\n"); 
   printf( "indata55x=%x , indataaax=%x\n", indata55x, indataaax); 
   printf( "indataaay=%x , indata55y=%x\n", indataaay, indata55y); 
  } 
  if ( error==1)  
    exit( 0); 
} 
 
/* ========================= End of File ========================= */