inp000.c 3.11 KB
/*
 *  vi_gamma000.c - generate test vectors for gamma module
 * 
 */

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

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

int gamma_enable, gamma_dither_enable, rgb, vrand, sync;
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("gamma_enable        @I @E 0\n");
    printf("gamma_dither_enable @I @E 0\n");
    printf("rgb[7:0]            @I @E 0\n");
    printf("rand[5:0]           @I @E 0\n");
    printf("sync                @I @E 0\n");

    printf("\n"); /* required newline */
  }

  /*
   *  print input signals
   */

  printf("%d %d 0x%.2x 0x%.2x %d \n", gamma_enable, gamma_dither_enable, rgb, vrand, sync);
}

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

void initialize(void)
{
    gamma_enable        = 0;
    gamma_dither_enable = 0;
    rgb                 = 0;
    vrand               = 0;
    sync                = 0;
}

void setwires(int gamma_enableval, int gamma_dither_enableval,  
	      int rgb_val, int rand_val, int sync_val)
{
    gamma_enable        = gamma_enableval        & 0x01;
    gamma_dither_enable = gamma_dither_enableval & 0x01;
    rgb                 = rgb_val                & 0xff;
    vrand               = rand_val               & 0x3f;
    sync                = sync_val               & 0x01;

    print_vectors();
}

void FullGammaTest(void)
{
    int i;

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

void FooTests(void)
{
    setwires(0, 0, 100, 0, 0);
    setwires(0, 1, 100, 0, 0);
    setwires(0, 1, 144, 0, 0);
    setwires(0, 0, 100, 0, 0);
    setwires(0, 0, 144, 0, 0);

    setwires(1, 1, 100, 0, 0);
    setwires(1, 1, 144, 0, 0);
    setwires(1, 0, 100, 0, 0);
    setwires(1, 0, 144, 0, 0); 

    setwires(0, 0, 101, 0, 0);
    setwires(0, 1, 101, 0, 0);
    setwires(0, 1, 101, 32, 0);


    setwires(0, 0, 255, 255, 0);
    setwires(0, 0, 255, 255, 1);
    setwires(0, 1, 255, 255, 0);
    setwires(0, 1, 255, 255, 1);
    setwires(1, 0, 255, 255, 0);
    setwires(1, 0, 255, 255, 1);
    setwires(1, 1, 255, 255, 0);
    setwires(1, 1, 255, 255, 1);    
}

void PrimePipe(void)
{
    setwires(0, 0, 0, 0, 1);
}

void HandTests(void)
{    
    PrimePipe();
    FullGammaTest();
    FooTests();
}

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<5000; i++)
	{
	    setwires(random() & 0x01,
		     random() & 0x01,
		     random() & 0xff,
		     random() & 0x3f,
		     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, 0);
    for (i=0; i<2; i++)
	print_vectors();
}