⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gp2021.cpp

📁 此程序为GPS软件接收机的源码
💻 CPP
字号:
/***********************************************************************
  GPS RECEIVER (GPSRCVR) Ver. 1.06
  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  <stdio.h>
#include  <stdlib.h>
#include  <conio.h>
#include  <math.h>
#include  <string.h>
#include  <io.h>
#include  <Dos.h>


int port(int);
void self_test(void);
void to_gps(int, int);
int  from_gps(int);
// Setting up the library of GP1020 GPS correlator functions
int  meas_status(void);
int  accum_status_a(char);
int  accum_status_b(char);
int  accum_status_c(void);
void ch_accum_reset(char);
void all_accum_reset(void);
long  ch_carrier_cycle(char);
int  ch_carrier_dco_phase(char);
void all_carr_incr_hi(int);
void all_carr_incr_lo(int);
void ch_code_incr_hi(char,int);
void ch_code_incr_lo(char,int);
void all_code_incr_hi(int);
void all_code_incr_lo(int);
void ch_off(char);
void ch_on(char);
void ch_cntl(char,int);
void all_cntl(int);
void ch_code_slew(char,int);
void all_code_slew(int);
unsigned int  ch_epoch(char);
void  ch_epoch_load(char,unsigned int);
unsigned int  ch_epoch_chk(char);
int  ch_i_track(char);
int  ch_i_prompt(char);
int  ch_q_track(char);
int  ch_q_prompt(char);
int  ch_code_phase(char);
int  ch_code_DCO_phase(char);
void ch_preset_phase(char,int);
void all_preset_phase(int);
void data_bus_test_w(int);
void data_retent_w(int);
int  data_bus_test_r(void);
int  data_retent_r(void);
void program_TIC(long);
void reset_cntl(int);
int  rtc_delay(void);
void stat_chk_sel(int);
int  stat_chk_sign(void);
int  stat_chk_mag(void);
void status_latch(void);
void test_control(int);
void system_setup(int);
void multi_control(int);
void multi_channel_select(int);
void x_dco_incr_high(int);
void prog_accum_int(int);
void timemark_control(int);
void io_config(int);

void interface_status(void);
int ready(void);
int bit_pat[12]={0x2,0x4,0x8,0x10,0x20,0x40,0x80,0x100,0x200,0x400,0x800,0x1000};
int last_hi_carr[12],last_hi_code[12],ch_status;
char last_address;

inline void to_gps(int add,int data)
{
 outpw(0x304,add);
 outpw(0x308,data);
}

inline int from_gps(int add)
{
  outpw(0x304,add);
  return(inpw(0x308));
}

inline int accum_status(void)
{
  return(from_gps(0x82));
}

void all_accum_reset(void)
{
}

void data_tst(int data)
{
  to_gps(0xf2,data);
}

unsigned int  ch_epoch(char ch)
{
  return(from_gps((ch<<3)+4));
}

unsigned int  ch_epoch_chk(char ch)
{
  return(from_gps((ch<<3)+7));
}

long   ch_carrier_cycle(char ch)
{
  long result;
  result=from_gps((ch<<3)+6);
  result=result<<16;
  result=result+from_gps((ch<<3)+2);
  return(result);
}

int  ch_code_DCO_phase(char ch)
{
  return(from_gps((ch<<3)+5));
}

void ch_code_incr_hi(char ch,int data)
{
  to_gps((ch<<3)+0x5,data);
}

void ch_code_incr_lo(char ch,int data)
{
  to_gps((ch<<3)+0x6,data);
}

int ch_code_phase(char ch)
{
 return(from_gps((ch<<3)+0x1));
}

int ch_carrier_DCO_phase(char ch)
{
  return(from_gps((ch<<3)+0x3));
}

void carr_incr_hi(char ch,int data)
{
  to_gps((ch<<3)+0x3,data);
}

void carr_incr_lo(char ch,int data)
{
  to_gps((ch<<3)+0x4,data);
}

void ch_cntl(char ch,int data)
{
//  printf("ch=%d  port=%x\n",ch,port(ch<<3));
  to_gps(ch<<3,data);
}


void all_cntl(int data)
{
  to_gps(0x70,data);

}
void multi_cntl(int data)
{
  to_gps(0x60,data);

}

int ch_i_track(char ch)
{
  return(from_gps((ch<<2)+0x84));
}

int ch_q_track(char ch)
{
  return(from_gps((ch<<2)+0x85));
}

int ch_i_prompt(char ch)
{
  return(from_gps((ch<<2)+0x86));
}

int ch_q_prompt(char ch)
{
  return(from_gps((ch<<2)+0x87));
}

void ch_accum_reset(char ch)
{
  to_gps((ch<<2)+0x85,0);
}

void ch_code_slew(char ch,int data)
{
  to_gps((ch<<2)+0x84,data);
}

void all_code_slew(int data)
{
  to_gps(0x70,data);
}

void data_retent_w(int data)
{
  to_gps(0xe4,data);
}

int data_retent_r(void)
{
  return(from_gps(0xe4));
}

void data_bus_test_w(int data)
{
  to_gps(0xf2,data);
}

int data_bus_test_r(void)
{
  return(from_gps(0xf2));
}


inline int meas_status(void)
{
  return(from_gps(0x81));
}

void program_TIC(long data)
{
  unsigned int high,low;
  high=int(data>>16);
  low =int(data & 0xffff);
  to_gps(0x6d,high);
  to_gps(0x6f,low);
}

void reset_cntl(int data)
{
  to_gps(0x7f,data);
//  fprintf(out,"reset data=%x\n",data);
}

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)+3;
  outpw(0x304,add);
  outpw(0x308,freq_hi);
//  carr_incr_hi(ch,freq_hi);
  add++;
  outpw(0x304,add);
  outpw(0x308,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)+5;
  outpw(0x304,add);
  outpw(0x308,freq_hi);
//  ch_code_incr_hi(ch,freq_hi);
  add++;
  outpw(0x304,add);
  outpw(0x308,freq_lo);
//  ch_code_incr_lo(ch,freq_lo);
}

void ch_epoch_load(char ch,unsigned int data)
{
  to_gps((ch<<3)+7,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(0x7e,data);
}

void test_control(int data)
{
  to_gps(0x7c,data);
}

void status_latch(void)
{
  to_gps(0x80,0);
}
void io_config(int data)
{
  to_gps(0xf0,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);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -