inp002.c 4.15 KB
/*
 *  inp002.c: Random test case
 */

#define NUM_RUNS	(1000)

#define MAX_DX	(5.0)
#define BIAS_L	(MAX_DX+2)
#define BIAS_R	(BIAS_L+2)

#include <stdio.h>
#include "sigs.h"

int  gen_test_case( void );
void send_params( void );
void send_pixels( int );
void dump_test( void );

int time( int );
int srandom( int );
int random( void );

/*
 *   Generate test vectors 
 */
main(int argc, char **argv)
{
  int i;
  int n;
  int rseed = 0x12345678;

  if( argc > 1 )
      rseed = time( 0 );

  x_major = 0x00;
  cycle_type = 0;
  left = 1;

  print_input_header();
 
  printf("# Seed = %d\n", rseed );
  printf("# reset 6 clocks\n"); 
  reset = 0;
  for(i = 0; i < 6; i++)
    print_input_sigs();

  reset = 1;

  for(i=0; i<NUM_RUNS; i++) {
      n = gen_test_case();

      send_params();

      send_pixels( n );
  };
}

/*

    Generate Random Spans
*/
double xleft[4],
       xright[4];

int xval;
int xmin,
    xmax;

void gen_xs( double *, double, double );

int
gen_test_case( void )
{
    int i;

    gen_xs( xleft,  MAX_DX, BIAS_L );
    gen_xs( xright, MAX_DX, BIAS_R );

    xval = 0;
    xmin = xleft[0];
    xmax = xright[0];
    for(i=0; i<4; i++) {

	if(xleft[i] < xright[i])
	    xval |= (1<<i);
	
	if( xleft[i] < xmin )
	    xmin = xleft[i];
    
	if( xright[i] < xmin )
	    xmin = xright[i];
    
	if( xleft[i] > xmax )
	    xmax = xleft[i];
    
	if( xright[i] > xmax )
	    xmax = xright[i];
    };
    
    return( BIAS_R+MAX_DX+1 );
}

double frand( void );
#include <values.h>

void
gen_xs( double *xlist, double dx, double bias )
{
    int iy;
    double cx, cy;
    double dxt, dxb;
    double x,y;

    cx = frand();
    cy = frand();

    dxt = (2*dx*frand()) - dx;
    dxb = (2*dx*frand()) - dx;

    for(iy=0; iy<4; iy++) {
	y = iy * 0.25;

	if( y < cy )	/* Top */
	    x = (y-cy)*dxt;
	else
	    x = (y-cy)*dxb;
	
	xlist[iy] = x + cx + bias;
    };
}

double
frand( void )
{
    return( random()/(MAXINT * 1.0) );
}

/*

    Send Span Parameters
*/

#define XM(x)	(xright[i]*8)
#define XH(x)	(xleft[i]*8)

void
send_params( void )
{
  int i;

  dump_test();

  for(i=0; i<4; i++) {
      printf("# xh%d (%lg)\n", i, xright[i]); 
      ew_cv_data = XH(i);
      print_input_sigs();

      printf("# xm%d (%lg)\n", i, xleft[i]); 
      ew_cv_data = XM(i);
      print_input_sigs();
  };

  printf("# xval, latch xm's, xh's\n"); 
  ew_cv_data = xval;
  ew_cv_newspan = 1; 
  x_major = xmin-1;
  print_input_sigs();

  dv = 1; /* one clock after new span, data should be valid */
  ew_cv_newspan = 0; 
}

void 
send_pixels( int n )
{
    int i;

    printf("# Range xmin = %d, xmax = %d\n", xmin, xmax );
    for(i=xmin-1; i<=xmax+1; i++) {
	printf("#pixel x = %d\n", i );
	x_major = i;
	print_input_sigs();
    }
}
/*

	General Support Routines
*/

/*
 *  Prints header info for input signals, same for all dumps
 */
static void
  print_input_header( void )
{
  printf("gclk @C 1(8) 0(8)\n");
  printf("ew_cv_data[12:0] @I @E 0\n");
  printf("x_major[11:0] @I @E 0\n");
  printf("cycle_type @I @E 0\n");
  printf("ew_cv_newspan @I @E 0\n");
  printf("left @I @E 0\n");
  printf("reset @I @E 0\n");
  printf("dv @I @E 0\n");
  printf("\n");
}


/*
 *  Prints signal values info for input signals, same for all dumps
 */
static void
  print_input_sigs( void )
{
  printf("0x%.4x 0x%0.3x %d %d %d %d %d\n",
    ew_cv_data,
    x_major,
    cycle_type,
    ew_cv_newspan,
    left,
    reset,
    dv);
}

char *top    = "   %2d   ";

char *row[5] = { "+ - - - ",
		 "| . . . ",
		 "| . . . ",
		 "| . . . ",
		 "+ - - - "
		};

char *lastc = "+|||+";

double floor (double x);

void
dump_test( void )
{
    int i;
    int x,y;
    char tmp[9];

    printf("# ");
    for(x=xmin; x<=xmax; x++) {
	printf(top,x);
    };
    printf("\n");

    for(y=0; y<4; y++) {
	printf("# ");
	for(x=xmin; x<=xmax; x++) {
	    strcpy( tmp, row[y] );

	    i = floor( 8*(xleft[y] - x) );
	    if( (i>=0) && (i<8) )
		tmp[i] = 'L';

	    i = floor( 8*(xright[y] - x) );
	    if( (i>=0) && (i<8) ) {
		if( tmp[i] == 'L' )
		    tmp[i] = 'X';
		else
		    tmp[i] = 'R';
	    };
	    printf(tmp);
	};
	printf("%c\n", lastc[y] );
    };

    printf("# ");
    for(x=xmin; x<=xmax; x++) {
	printf(row[4]);
    };
    printf("%c\n", lastc[4]);
}