📄 regtest.c
字号:
/* ************************************************************************
* *
* OpenGPS Receiver *
* *
* -------------------------------------------------------------------- *
* *
* Module: regtest.c *
* *
* Author: C. Kelley *
* *
* -------------------------------------------------------------------- *
* *
* Copyright (C) 2003-2004 C. Kelley *
* *
* 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. *
* *
* -------------------------------------------------------------------- *
* *
* Test GP2021 registers *
* *
************************************************************************ */
/*
* Changes:
*
* 11.01.04 - ported to Linux /GB
*/
/* ------------------------------ includes -------------------------------- */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#ifndef __linux__
# include <conio.h>
# include <io.h>
# include <Dos.h>
#else
# include <termios.h>
# include <term.h>
# include <curses.h>
# include <unistd.h>
# include <sys/io.h>
#endif
/* ------------------------------- defines -------------------------------- */
#ifdef __linux__
# define inpb(p) inb(p)
# define inpw(p) inw(p)
# define outpb(p,v) outb(v,p)
# define outpw(p,v) outw(v,p)
# define max(a,b) ((a)>(b)?a:b)
# define min(a,b) ((a)<(b)?a:b)
#endif
// it's either ISA or PCI!
#if 0
# define PCIBOARD
#else
# define ISABOARD
#endif
#ifdef PCIBOARD
//# define PCIBASE 0xb800 // kg96 : cat /proc/pci
# define PCIBASE 0xe000 // champ73 : cat /proc/pci
# define IO_COMMAND (PCIBASE+0x0)
# define IO_DATA (PCIBASE+0x4)
#endif
#ifdef ISABOARD
# define ISABASE 0x300
# define IO_COMMAND (ISABASE+0x4)
# define IO_DATA (ISABASE+0x8)
#endif
/* ------------------------------ globals --------------------------------- */
static short int max_i_prompt[12], min_i_prompt[12],
max_q_prompt[12], min_q_prompt[12],
max_i_track[12], min_i_track[12],
max_q_track[12], min_q_track[12];
/* ----------------------------- procedures ------------------------------- */
void to_gps( int add, int data)
{
outpw( IO_COMMAND, add);
outpw( IO_DATA, data);
}
short int from_gps( int add)
{
outpw( IO_COMMAND, add);
return( inpw( IO_DATA));
}
#ifdef __linux__
/*
* clear screen
*/
void clrscr( void)
{
printf( "\x1B[2J\x1B[0d\x1B[0G");
return;
}
/*
* move cursor to col x and row y
*/
void gotoxy( int x, int y)
{
printf( "\x1B[%dd \x1B[%dG", y, x);
return;
}
/* ---------------------------------------------------------------------- */
/*
* from kbhit.c, WROX book "Beginning LINUX Programming" (www.wrox.com)
*/
static struct termios initial_settings,
new_settings;
static int peek_character = -1;
void init_keyboard( void)
{
tcgetattr( 0, &initial_settings);
new_settings = initial_settings;
new_settings.c_lflag &= ~ICANON;
new_settings.c_lflag &= ~ECHO;
new_settings.c_lflag &= ~ISIG;
new_settings.c_cc[VMIN] = 1;
new_settings.c_cc[VTIME] = 0;
tcsetattr( 0, TCSANOW, &new_settings);
return;
}
void close_keyboard( void)
{
tcsetattr(0, TCSANOW, &initial_settings);
return;
}
int kbhit( void)
{
char ch;
int nread;
if ( peek_character != -1)
return 1;
new_settings.c_cc[VMIN]=0;
tcsetattr( 0, TCSANOW, &new_settings);
nread = read(0,&ch,1);
new_settings.c_cc[VMIN]=1;
tcsetattr( 0, TCSANOW, &new_settings);
if ( nread == 1)
{
peek_character = ch;
return (1);
}
return (0);
}
int readch( void)
{
char ch;
if ( peek_character != -1)
{
ch = peek_character;
peek_character = -1;
return ch;
}
read( 0, &ch, 1);
return ch;
}
#endif
int main( void)
{
unsigned char addlo, addhi, address;
int key, i, ch;
short int result;
unsigned int cycle;
FILE *error_file;
unsigned short int data[256] =
{ 0xa3f6,0x0000,0x0000,0x01f7,0xb1b9,0x016e,0xa4a8,0x0000, //0 cntl 0
0xa3ec,0x0000,0x0000,0x01f7,0xb1b9,0x016e,0xa4a8,0x0000, //0 cntl 1
0xa3d8,0x0000,0x0000,0x01f7,0xb1b9,0x016e,0xa4a8,0x0000, //1 cntl 2
0xa3b0,0x0000,0x0000,0x01f7,0xb1b9,0x016e,0xa4a8,0x0000, //1 cntl 3
0xa04b,0x0000,0x0000,0x01f7,0xb1b9,0x016e,0xa4a8,0x0000, //2 cntl 4
0xa096,0x0000,0x0000,0x01f7,0xb1b9,0x016e,0xa4a8,0x0000, //2 cntl 5
0xa2cb,0x0000,0x0000,0x01f7,0xb1b9,0x016e,0xa4a8,0x0000, //3 cntl 6
0xa196,0x0000,0x0000,0x01f7,0xb1b9,0x016e,0xa4a8,0x0000, //3 cntl 7
0xa32c,0x0000,0x0000,0x01f7,0xb1b9,0x016e,0xa4a8,0x0000, //4 cntl 8
0xa3ba,0x0000,0x0000,0x01f7,0xb1b9,0x016e,0xa4a8,0x0000, //4 cntl 9
0xa374,0x0000,0x0000,0x01f7,0xb1b9,0x016e,0xa4a8,0x0000, //5 cntl 10
0xa1d0,0x0000,0x0000,0x01f7,0xb1b9,0x016e,0xa4a8,0x0000, //5 cntl 11
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, //6 cntl Multi
0x0000,0x0000,0x0000,0x0000,0x0000,0x0008,0x0000,0xb823, //6 TIC
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, //7 cntl All
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x1fff, //7 reset
0x0000,0x0000,0x0000,0x0000, //8 Status
0x0000,0x0000,0x0000,0x0000, //8 accum 0
0x0000,0x0000,0x0000,0x0000, //8 accum 1
0x0000,0x0000,0x0000,0x0000, //8 accum 2
0x0000,0x0000,0x0000,0x0000, //9 accum 3
0x0000,0x0000,0x0000,0x0000, //9 accum 4
0x0000,0x0000,0x0000,0x0000, //9 accum 5
0x0000,0x0000,0x0000,0x0000, //9 accum 6
0x0000,0x0000,0x0000,0x0000, //a accum 7
0x0000,0x0000,0x0000,0x0000, //a accum 8
0x0000,0x0000,0x0000,0x0000, //a accum 9
0x0000,0x0000,0x0000,0x0000, //a accum 10
0x0000,0x0000,0x0000,0x0000, //b accum 11
0x0000,0x0000,0x0000,0x0000, //b accum Multi
0x0000,0x0000,0x0000,0x0000, //b accum ALL
0x0000,0x0000,0x0000,0x0000, //b
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, //c RTC
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, //c RTC
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, //d DUART
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, //d DUART
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, //e System cntl
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, //e
0x0301,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, //f General cntl
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000};//f
error_file = fopen( "reg_err.dat", "w+");
if ( !error_file)
{
printf( "error opening error file\n");
exit(-1);
}
clrscr();
#ifdef __linux__
init_keyboard();
iopl(3);
#endif
to_gps( 0x7f, 0); // reset control
#ifndef __linux__
delay( 100);
#endif
to_gps( 0x7f, 0x1fff); // reset control
to_gps( 0xf0, 0x0301); // io config
to_gps( 0x7c, 0); // test control
to_gps( 0x7e, 0x200); // system setup
cycle = 1;
// fill GP2021 registers
for (i=0; i<256; i++)
{
if (i<0x70 || i>0x77)
to_gps( i, data[i]);
}
do
{
if (kbhit())
#ifdef __linux__
key = readch();
#else
key = getch();
#endif
else
key = '\0';
gotoxy( 1, 1);
printf( "cycle %d\n\n", cycle);
to_gps( 0x80, 0); // latch status bits
for ( addhi=0; addhi<16; addhi++)
{
for ( addlo=0; addlo<16; addlo++)
{
address = addhi*16 + addlo;
#ifdef __linux__
if ( addlo == 0)
printf( "%02x: ", address);
#endif
result = from_gps( address);
#ifdef __linux__
printf( "%4x ", (result & 0xffff));
#endif
// read ACCUM regeisters
if ( address >= 0x84 && address < 0xb4)
{
ch = (address - 0x84) >> 2;
switch( address & 0x3)
{
case 0:
max_i_track[ch] = max( max_i_track[ch], result);
min_i_track[ch] = min( min_i_track[ch], result);
break;
case 1:
max_q_track[ch] = max( max_q_track[ch], result);
min_q_track[ch] = min( min_q_track[ch], result);
break;
case 2:
max_i_prompt[ch] = max( max_i_prompt[ch], result);
min_i_prompt[ch] = min( min_i_prompt[ch], result);
break;
case 3:
max_q_prompt[ch] = max( max_q_prompt[ch], result);
min_q_prompt[ch] = min( min_q_prompt[ch], result);
break;
}
}
}
#ifdef __linux__
printf( "\n");
#endif
}
data[0xf2]++;
to_gps( 0xf2, data[0xf2]); // data bus test
data[0xe4]++;
to_gps( 0xe4, data[0xe4]); // data retent
result = from_gps( 0xf2);
if ( result != data[0xf2])
{
printf( "data bus problem w=%4x r=%4x\n", data[0xf2], result);
fprintf( error_file, "data bus problem w=%4x r=%4x\n", data[0xf2], result);
}
if (data[0xf2] == 0xffff)
{
fprintf( error_file, "completed cycle %d\n", cycle);
cycle++;
}
printf( "\nch min(I_P) min(I_T) min(Q_P) min(Q_T) max(I_P) max(I_T) max(Q_P) max(Q_T)\n");
for (i=0; i<12; i++)
{
printf( "%2d: %8d %8d %8d %8d %8d %8d %8d %8d\n",
i, min_i_prompt[i], min_i_track[i], min_q_prompt[i], min_q_track[i],
max_i_prompt[i], max_i_track[i], max_q_prompt[i], max_q_track[i]);
}
} while (key != 'x' && key != 'X' && key != 'q' && key != 'Q'); /*Stay in loop until 'X' or 'Q' key is pressed.*/
#ifdef __linux__
close_keyboard();
#endif
return (0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -