OpenCores
URL https://opencores.org/ocsvn/gecko3/gecko3/trunk

Subversion Repositories gecko3

[/] [gecko3/] [trunk/] [GECKO3COM/] [gecko3com-ip/] [core/] [GECKO3COM_simple_prng_tb.c] - Diff between revs 29 and 31

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 29 Rev 31
/* GECKO3COM
/* GECKO3COM
 *
 *
 * Copyright (C) 2010 by
 * Copyright (C) 2010 by
 *   ___    ____  _   _
 *   ___    ____  _   _
 *  (  _`\ (  __)( ) ( )
 *  (  _`\ (  __)( ) ( )
 *  | (_) )| (_  | |_| |   Bern University of Applied Sciences
 *  | (_) )| (_  | |_| |   Bern University of Applied Sciences
 *  |  _ <'|  _) |  _  |   School of Engineering and
 *  |  _ <'|  _) |  _  |   School of Engineering and
 *  | (_) )| |   | | | |   Information Technology
 *  | (_) )| |   | | | |   Information Technology
 *  (____/'(_)   (_) (_)
 *  (____/'(_)   (_) (_)
 *
 *
 *
 *
 * This program is free software: you can redistribute it and/or modify
 * 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
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * (at your option) any later version.
 *
 *
 * This program is distributed in the hope that it will be useful,
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 */
 
 
/*********************************************************************/
/*********************************************************************/
/** \file     GECKO3COM_simple_prng_tb.c
/** \file     GECKO3COM_simple_prng_tb.c
 *********************************************************************
 *********************************************************************
 * \brief     simple programm to fill a file with a desired length value
 * \brief     simple programm to fill a file with a desired length value
 *
 *
 *  to change the length of the value simply change the type of the value
 *  to change the length of the value simply change the type of the value
 *  variable.
 *  variable.
 *
 *
 
 *  compile with:
 
 *  "gcc -o GECKO3COM_simple_prng_tb GECKO3COM_simple_prng_tb.c"
 
 *
 * \author    Christoph Zimmermann bfh.ch
 * \author    Christoph Zimmermann bfh.ch
 * \date      26. February 2010
 * \date      26. February 2010
 *
 *
 */
 */
 
 
#include <stdio.h>
#include <stdio.h>
#include <stdint.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdbool.h>
#include <math.h>
#include <math.h>
 
 
int main (void)
int main (void)
{
{
  /*--------------------------------------------------------------------------*/
  /*--------------------------------------------------------------------------*/
  /* start of user configuration values */
  /* start of user configuration values */
 
 
  /* variable type of the desired value */
  /* variable type of the desired value */
  uint32_t prng_data = 0x55555555;
  uint32_t prng_data = 0x55555555;
 
 
  /* desired filename */
  /* desired filename */
  const char* FILENAME = "GECKO3COM_simple_prng_tb.hex";
  const char* FILENAME = "GECKO3COM_simple_prng_tb.hex";
 
 
  /* how many times should the datablock repeated in the file */
  /* how many times should the datablock repeated in the file */
  int16_t loop = 4096;
  int16_t loop = 4096;
 
 
  /* end of configuration values */
  /* end of configuration values */
  /*--------------------------------------------------------------------------*/
  /*--------------------------------------------------------------------------*/
 
 
  FILE *output;
  FILE *output;
  uint64_t i,j;
  uint64_t i,j;
 
 
  uint32_t prng_feedback;
  uint32_t prng_feedback;
 
 
  printf("Hello, this programm will write values with a bit length of %d to the file %s\n", sizeof(prng_data)*8, FILENAME);
  printf("Hello, this programm will write values with a bit length of %d to the file %s\n", sizeof(prng_data)*8, FILENAME);
 
 
  output = fopen(FILENAME, "w+b");
  output = fopen(FILENAME, "w+b");
 
 
  /* create the desired number of data blocks */
  /* create the desired number of data blocks */
  for(j=0; j<loop;j++) {
  for(j=0; j<loop;j++) {
 
 
    if(!fwrite(&prng_data, sizeof(prng_data), 1, output)) {
    if(!fwrite(&prng_data, sizeof(prng_data), 1, output)) {
      printf("ERROR writing to the file\n");
      printf("ERROR writing to the file\n");
      return 0;
      return 0;
    }
    }
 
 
    prng_feedback = prng_data >> 10;
    prng_feedback = prng_data >> 10;
    prng_feedback ^= prng_data >> 12;
    prng_feedback ^= prng_data >> 12;
    prng_feedback ^= prng_data >> 13;
    prng_feedback ^= prng_data >> 13;
    prng_feedback ^= prng_data >> 15;
    prng_feedback ^= prng_data >> 15;
 
 
    prng_feedback &= 0x00000001;
    prng_feedback &= 0x00000001;
 
 
    prng_data = prng_data << 1;
    prng_data = prng_data << 1;
    prng_data |= prng_feedback;
    prng_data |= prng_feedback;
  }
  }
 
 
  fclose(output);
  fclose(output);
  return 1;
  return 1;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.