inp000.c 2.12 KB
/*
 *  vi_lerp000.c - generate test vectors for max module
 * 
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

/*
 *  G l o b a l s
 */

int frac, rgb_a, rgb_b, sync_b;
char *prog_name;

static void
  print_vectors()
{
  static int first_time = 1;
  if(first_time)
  {
    first_time = 0;
    printf("#\n");
    printf("#   created by %s.c\n", prog_name);
    printf("#\n");
    printf("vclk                @C 1(8) 0(8)\n");
    printf("frac[4:0]           @I @E 0\n");
    printf("rgb_a[7:0]          @I @E 0\n");
    printf("rgb_b[7:0]          @I @E 0\n");
    printf("sync_b              @I @E 0\n");
    printf("\n"); /* required newline */
  }

  /*
   *  print input signals
   */

  printf("0x%.2x 0x%.2x 0x%.2x %d\n", frac, rgb_a, rgb_b, sync_b);
}

void usage(void)
{
    fprintf(stderr, "Try again \n");
    exit(1);
}

void initialize(void)
{
    frac   = 0;
    rgb_a  = 0;
    rgb_b  = 0;
    sync_b = 0;
}

void setwires(int fracval, int rgb_aval, int rgb_bval, int sync_bval)
{
    frac   = fracval;
    rgb_a  = rgb_aval;
    rgb_b  = rgb_bval;
    sync_b = sync_bval;

    print_vectors();
}

void HandTests(void)
{
    int i;

    for (i=0; i<32; i++)
	{
	    setwires(i, 0,     0, 0);
	    setwires(i, 0,     0, 1);
	    setwires(i, 0,   255, 0);
	    setwires(i, 0,   255, 1);
	    setwires(i, 255,   0, 0);
	    setwires(i, 255,   0, 1);
	    setwires(i, 255, 255, 0);
	    setwires(i, 255, 255, 1);
	}
}

void DoRandomTests(void)
{
    int i;

    /* need to use a constant seed so that we can
       diff tab files against a golden set stored away
       to see if anything has broken later */

    srandom(100);

    for (i=0; i<20000; i++)
	{
	    setwires(random() & 0x1f,
		     random() & 0xff, 
		     random() & 0xff,
		     random() & 0x01);
	}
}

int
  main(int argc, char **argv)
{
    int c;
    extern char *optarg;
    extern int optind;
    char *ofile = NULL;
    int i;

    prog_name = argv[0];

    /* Print Headers */
    print_vectors();

    initialize();

    HandTests();
    DoRandomTests();

    /* Flush pipe */

    setwires(0, 0, 0, 0);
    for (i=0; i<3; i++)
	print_vectors();
}