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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [bench/] [sysc/] [src/] [OrpsocMain.cpp] - Diff between revs 52 and 63

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 52 Rev 63
Line 1... Line 1...
//////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
////                                                              ////
////                                                              ////
////  ORPSoC SystemC Testbench                                    ////
////  ORPSoC SystemC Testbench                                    ////
////                                                              ////
////                                                              ////
////  Description                                                 ////
////  Description                                                 ////
////  ORPSoC Testbench file                                       ////
////  ORPSoC Testbench file                                       ////
////                                                              ////
////                                                              ////
////  To Do:                                                      ////
////  To Do:                                                      ////
////        Somehow allow tracing to begin later in the sim       ////
 
////                                                              ////
////                                                              ////
////                                                              ////
////                                                              ////
////  Author(s):                                                  ////
////  Author(s):                                                  ////
////      - Jeremy Bennett jeremy.bennett@embecosm.com            ////
////      - Jeremy Bennett jeremy.bennett@embecosm.com            ////
////      - Julius Baxter jb@orsoc.se                             ////
////      - Julius Baxter jb@orsoc.se                             ////
Line 41... Line 40...
////                                                              ////
////                                                              ////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
 
 
#include "OrpsocMain.h"
#include "OrpsocMain.h"
 
 
 
#include "jtagsc.h"
 
 
#include "Vorpsoc_top.h"
#include "Vorpsoc_top.h"
#include "OrpsocAccess.h"
#include "OrpsocAccess.h"
#include "MemoryLoad.h"
#include "MemoryLoad.h"
 
 
#include <SpTraceVcdC.h>
#include <SpTraceVcdC.h>
 
 
//#include "TraceSC.h"
 
#include "ResetSC.h"
#include "ResetSC.h"
#include "Or1200MonitorSC.h"
#include "Or1200MonitorSC.h"
 
#include "GdbServerSC.h"
#include "UartSC.h"
#include "UartSC.h"
 
 
int SIM_RUNNING;
int SIM_RUNNING;
int sc_main (int   argc,
int sc_main (int   argc,
             char *argv[] )
             char *argv[] )
{
{
  sc_set_time_resolution( 1, TIMESCALE_UNIT);
  sc_set_time_resolution( 1, TIMESCALE_UNIT);
  // CPU clock (also used as JTAG TCK) and reset (both active high and low)
  // CPU clock (also used as JTAG TCK) and reset (both active high and low)
  sc_time  clkPeriod (BENCH_CLK_HALFPERIOD * 2.0, TIMESCALE_UNIT);
  sc_time  clkPeriod (BENCH_CLK_HALFPERIOD * 2.0, TIMESCALE_UNIT);
 
  sc_time   jtagPeriod (JTAG_CLK_HALFPERIOD * 2.0, TIMESCALE_UNIT);
 
 
  sc_clock             clk ("clk", clkPeriod);
  sc_clock             clk ("clk", clkPeriod);
 
  sc_clock  jtag_tck ("jtag-clk", jtagPeriod, 0.5, SC_ZERO_TIME, false);
 
 
  sc_signal<bool>      rst;
  sc_signal<bool>      rst;
  sc_signal<bool>      rstn;
  sc_signal<bool>      rstn;
  sc_signal<bool>      rst_o;
  sc_signal<bool>      rst_o;
 
 
  sc_signal<bool>      jtag_tdi;                // JTAG interface
  sc_signal<bool>      jtag_tdi;                // JTAG interface
Line 88... Line 92...
  sc_signal<bool> spi1_sclk;
  sc_signal<bool> spi1_sclk;
 
 
  SIM_RUNNING = 0;
  SIM_RUNNING = 0;
 
 
  // Setup the name of the VCD dump file
  // Setup the name of the VCD dump file
  int VCD_enabled = 0;
  bool VCD_enabled = false;
  string dumpNameDefault("vlt-dump.vcd");
  string dumpNameDefault("vlt-dump.vcd");
  string testNameString;
  string testNameString;
  string vcdDumpFile;
  string vcdDumpFile;
  // VCD dump controling vars
  // VCD dump controling vars
  int dump_start_delay, dump_stop_set;
  bool dump_start_delay_set = false, dump_stop_set = false;
  int dumping_now;
  bool dumping_now = false;
  int dump_depth = 99; // Default dump depth
  int dump_depth = 99; // Default dump depth
  sc_time dump_start,dump_stop, finish_time;
  sc_time dump_start,dump_stop, finish_time;
  int finish_time_set = 0; // By default we will let the simulation finish naturally
  bool finish_time_set = false; // By default we will let the simulation finish naturally
  SpTraceVcdCFile *spTraceFile;
  SpTraceVcdCFile *spTraceFile;
 
 
  int time_val;
  /*int*/double time_val;
  int cmdline_name_found=0;
  bool vcd_file_name_given = false;
 
 
 
  bool rsp_server_enabled = false;
 
  int rsp_server_port = DEFAULT_RSP_PORT;
 
 
  // Executable app load variables
  // Executable app load variables
  int do_program_file_load = 0; // Default: we don't require a file, we use the VMEM
  int do_program_file_load = 0; // Default: we don't require a file, we use the VMEM
  char* program_file; // Old char* style for program name
  char* program_file; // Old char* style for program name
 
 
Line 117... Line 124...
 
 
  MemoryLoad *memoryload;       // Memory loader
  MemoryLoad *memoryload;       // Memory loader
 
 
  ResetSC          *reset;              // Generate a RESET signal
  ResetSC          *reset;              // Generate a RESET signal
  Or1200MonitorSC  *monitor;            // Handle l.nop x instructions
  Or1200MonitorSC  *monitor;            // Handle l.nop x instructions
 
  JtagSC           *jtag;               // Generate JTAG signals
 
  GdbServerSC      *gdbServer;          // Map RSP requests to debug unit
  UartSC          *uart;                // Handle UART signals
  UartSC          *uart;                // Handle UART signals
 
 
  // Instantiate the Verilator model, VCD trace handler and accessor
  // Instantiate the Verilator model, VCD trace handler and accessor
  orpsoc     = new Vorpsoc_top ("orpsoc");
  orpsoc     = new Vorpsoc_top ("orpsoc");
 
 
  accessor   = new OrpsocAccess (orpsoc);
  accessor   = new OrpsocAccess (orpsoc);
 
 
  memoryload = new MemoryLoad (accessor);
  memoryload = new MemoryLoad (accessor);
 
 
 
  monitor    = new Or1200MonitorSC ("monitor", accessor, memoryload,
 
                                    argc, argv);
 
 
  // Instantiate the SystemC modules
  // Instantiate the SystemC modules
  reset         = new ResetSC ("reset", BENCH_RESET_TIME);
  reset         = new ResetSC ("reset", BENCH_RESET_TIME);
  monitor       = new Or1200MonitorSC ("monitor", accessor, memoryload, argc, argv);
 
 
  jtag          = new JtagSC ("jtag");
 
 
  uart          = new UartSC("uart"); // TODO: Probalby some sort of param
  uart          = new UartSC("uart"); // TODO: Probalby some sort of param
 
 
  // Parse command line options
  // Parse command line options
  // Default is for VCD generation OFF, only turned on if specified on command line
  // Default is for VCD generation OFF, only turned on if specified on command line
  dump_start_delay = 0;
 
  dump_stop_set = 0;
 
  dumping_now = 0;
 
 
 
  // Search through the command line parameters for options  
  // Search through the command line parameters for options  
  if (argc > 1)
  if (argc > 1)
    {
    {
      for(int i=1; i<argc; i++)
      for(int i=1; i<argc; i++)
        {
        {
          if ((strcmp(argv[i], "-d")==0) ||
          if ( (strcmp(argv[i], "-e")==0) ||
              (strcmp(argv[i], "--vcdfile")==0))
 
            {
 
              testNameString = (argv[i+1]);
 
              vcdDumpFile = testNameString;
 
              cmdline_name_found=1;
 
            }
 
          else if ((strcmp(argv[i], "-v")==0) ||
 
                   (strcmp(argv[i], "--vcdon")==0))
 
            {
 
              dumping_now = 1;
 
            }
 
          else if ( (strcmp(argv[i], "-e")==0) ||
 
                    (strcmp(argv[i], "--endtime")==0) )
                    (strcmp(argv[i], "--endtime")==0) )
            {
            {
              time_val = atoi(argv[i+1]);
              time_val = strtod(argv[i+1], NULL);
              sc_time opt_end_time(time_val,TIMESCALE_UNIT);
              sc_time opt_end_time(time_val,TIMESCALE_UNIT);
              finish_time = opt_end_time;
              finish_time = opt_end_time;
              finish_time_set = 1;
              finish_time_set = true;
            }
            }
          else if ( (strcmp(argv[i], "-f")==0) ||
          else if ( (strcmp(argv[i], "-f")==0) ||
                    (strcmp(argv[i], "--program")==0) )
                    (strcmp(argv[i], "--program")==0) )
            {
            {
              do_program_file_load = 1; // Enable program loading - will be done after sim init
              do_program_file_load = 1; // Enable program loading - will be done after sim init
              program_file = argv[i+1]; // Old char* style for program name
              program_file = argv[i+1]; // Old char* style for program name
            }
            }
 
          else if ((strcmp(argv[i], "-d")==0) ||
 
                   (strcmp(argv[i], "--vcdfile")==0) ||
 
                   (strcmp(argv[i], "-v")==0) ||
 
                   (strcmp(argv[i], "--vcdon")==0)
 
                   )
 
            {
 
              VCD_enabled = true;
 
              dumping_now = true;
 
              vcdDumpFile = dumpNameDefault;
 
              if (i+1 < argc)
 
                if(argv[i+1][0] != '-')
 
                  {
 
                    testNameString = argv[i+1];
 
                    vcdDumpFile = testNameString;
 
                    i++;
 
                  }
 
            }
          else if ( (strcmp(argv[i], "-s")==0) ||
          else if ( (strcmp(argv[i], "-s")==0) ||
                    (strcmp(argv[i], "--vcdstart")==0) )
                    (strcmp(argv[i], "--vcdstart")==0) )
            {
            {
              time_val = atoi(argv[i+1]);
              VCD_enabled = true;
 
              time_val = strtod(argv[i+1], NULL);
              sc_time dump_start_time(time_val,TIMESCALE_UNIT);
              sc_time dump_start_time(time_val,TIMESCALE_UNIT);
              dump_start = dump_start_time;
              dump_start = dump_start_time;
              dump_start_delay = 1;
              dump_start_delay_set = true;
              dumping_now = 0;
              dumping_now = false;
            }
            }
          else if ( (strcmp(argv[i], "-t")==0) ||
          else if ( (strcmp(argv[i], "-t")==0) ||
                    (strcmp(argv[i], "--vcdstop")==0) )
                    (strcmp(argv[i], "--vcdstop")==0) )
            {
            {
              time_val = atoi(argv[i+1]);
              VCD_enabled = true;
 
              time_val = strtod(argv[i+1],NULL);
              sc_time dump_stop_time(time_val,TIMESCALE_UNIT);
              sc_time dump_stop_time(time_val,TIMESCALE_UNIT);
              dump_stop = dump_stop_time;
              dump_stop = dump_stop_time;
              dump_stop_set = 1;
              dump_stop_set = true;
 
            }
 
          else if ( (strcmp(argv[i], "-r")==0) ||
 
                    (strcmp(argv[i], "--rsp")==0) )
 
            {
 
              rsp_server_enabled = true;
 
              if (i+1 < argc) if(argv[i+1][0] != '-')
 
                                {
 
                                  rsp_server_port = atoi(argv[i+1]);
 
                                  i++;
            }
            }
          /* Depth setting of VCD doesn't appear to work,
            }
             I think it's set during verilator script
          /*
             compile time */
             Depth setting of VCD doesn't appear to work, I think it's only
 
             configurable during at compile time .
 
          */
          /*      else if ( (strcmp(argv[i], "-p")==0) ||
          /*      else if ( (strcmp(argv[i], "-p")==0) ||
                  (strcmp(argv[i], "--vcddepth")==0) )
                  (strcmp(argv[i], "--vcddepth")==0) )
                  {
                  {
                  dump_depth = atoi(argv[i+1]);
                  dump_depth = atoi(argv[i+1]);
                  }*/
                  }*/
          else if ( (strcmp(argv[i], "-h")==0) ||
          else if ( (strcmp(argv[i], "-h")==0) ||
                    (strcmp(argv[i], "--help")==0) )
                    (strcmp(argv[i], "--help")==0) )
            {
            {
              printf("\n  ORPSoC Cycle Accurate model usage:\n");
              printf("Usage: %s [options]\n",argv[0]);
              printf("  %s [-vh] [-f <file] [-d <file>] [-e <time>] [-s <time>] [-t <time>]",argv[0]);
              printf("\n  ORPSoCv2 cycle accurate model\n");
              monitor->printSwitches();
              printf("  For details visit http://opencores.org/openrisc,orpsocv2\n");
              printf("\n\n");
              printf("\n");
 
              printf("Options:\n");
              printf("  -h, --help\t\tPrint this help message\n");
              printf("  -h, --help\t\tPrint this help message\n");
              printf("  -e, --endtime\t\tStop the sim at this time (ns)\n");
              printf("\nSimulation control:\n");
              printf("  -f, --program\t\tLoad program from an OR32 ELF\n");
              printf("  -f, --program <file> \tLoad program from OR32 ELF <file>\n");
 
              printf("  -e, --endtime <val> \tStop the sim at <val> ns\n");
 
              printf("\nVCD generation:\n");
              printf("  -v, --vcdon\t\tEnable VCD generation\n");
              printf("  -v, --vcdon\t\tEnable VCD generation\n");
              printf("  -d, --vcdfile\t\tEnable and specify target VCD file name\n");
              printf("  -d, --vcdfile <file>\tEnable and save VCD to <file>\n");
 
 
              printf("  -s, --vcdstart\tEnable and delay VCD generation until this time (ns)\n");
              printf("  -s, --vcdstart <val>\tEnable and delay VCD generation until <val> ns\n");
              printf("  -t, --vcdstop\t\tEnable and terminate VCD generation at this time (ns)\n");
              printf("  -t, --vcdstop <val> \tEnable and terminate VCD generation at <val> ns\n");
 
              printf("\nRemote debugging:\n");
 
              printf("  -r, --rsp [<port>]\tEnable RSP debugging server, opt. specify <port>\n");
              monitor->printUsage();
              monitor->printUsage();
              printf("\n");
              printf("\n");
              return 0;
              return 0;
            }
            }
 
 
        }
        }
    }
    }
 
 
  if(cmdline_name_found==0) // otherwise use our default VCD dump file name
 
    vcdDumpFile = dumpNameDefault;
 
 
 
  // Determine if we're going to setup a VCD dump:
  // Determine if we're going to setup a VCD dump:
  // Pretty much setting any option will enable VCD dumping.
  // Pretty much setting any related option will enable VCD dumping.
  if ((cmdline_name_found) || (dumping_now) || (dump_start_delay) || (dump_stop_set))
  if (VCD_enabled)
    {
    {
      VCD_enabled = 1;
 
 
 
      cout << "* Enabling VCD trace";
      cout << "* Enabling VCD trace";
 
 
      if (dump_start_delay)
      if (dump_start_delay_set)
        cout << ", on at time " << dump_start.to_string();
        cout << ", on at time " << dump_start.to_string();
      if (dump_stop_set)
      if (dump_stop_set)
    cout << ", off at time " << dump_stop.to_string();
    cout << ", off at time " << dump_stop.to_string();
      cout << endl;
      cout << endl;
    }
    }
 
 
 
  if (rsp_server_enabled)
 
    gdbServer     = new GdbServerSC ("gdb-server", FLASH_START, FLASH_END,
 
                                       rsp_server_port, jtag->tapActionQueue);
 
  else
 
      gdbServer = NULL;
 
 
  // Connect up ORPSoC
  // Connect up ORPSoC
  orpsoc->clk_pad_i (clk);
  orpsoc->clk_pad_i (clk);
  orpsoc->rst_pad_i (rstn);
  orpsoc->rst_pad_i (rstn);
  orpsoc->rst_pad_o (rst_o);
  orpsoc->rst_pad_o (rst_o);
 
 
  orpsoc->dbg_tck_pad_i  (clk);         // JTAG interface
  orpsoc->dbg_tck_pad_i  (jtag_tck);            // JTAG interface
  orpsoc->dbg_tdi_pad_i  (jtag_tdi);
  orpsoc->dbg_tdi_pad_i  (jtag_tdi);
  orpsoc->dbg_tms_pad_i  (jtag_tms);
  orpsoc->dbg_tms_pad_i  (jtag_tms);
  orpsoc->dbg_tdo_pad_o  (jtag_tdo);
  orpsoc->dbg_tdo_pad_o  (jtag_tdo);
 
 
  orpsoc->uart0_srx_pad_i (uart_rx);            // External UART
  orpsoc->uart0_srx_pad_i (uart_rx);            // External UART
Line 262... Line 297...
 
 
 
 
  orpsoc->gpio_a_pad_io (gpio_a); // GPIO bus - output only in 
  orpsoc->gpio_a_pad_io (gpio_a); // GPIO bus - output only in 
                                  // verilator sims
                                  // verilator sims
 
 
  // Connect up the VCD trace handler
 
  //trace->clk (clk);                   // Trace
 
 
 
  // Connect up the SystemC  modules
  // Connect up the SystemC  modules
  reset->clk (clk);                     // Reset
  reset->clk (clk);                     // Reset
  reset->rst (rst);
  reset->rst (rst);
  reset->rstn (rstn);
  reset->rstn (rstn);
 
 
  monitor->clk (clk);                   // Monitor
  monitor->clk (clk);                   // Monitor
 
 
 
  jtag->sysReset (rst);                 // JTAG
 
  jtag->tck (jtag_tck);
 
  jtag->tdi (jtag_tdi);
 
  jtag->tdo (jtag_tdo);
 
  jtag->tms (jtag_tms);
 
  jtag->trst (jtag_trst);
 
 
  uart->clk (clk); // Uart
  uart->clk (clk); // Uart
  uart->uartrx (uart_rx); // orpsoc's receive line
  uart->uartrx (uart_rx); // orpsoc's receive line
  uart->uarttx (uart_tx); // orpsoc's transmit line
  uart->uarttx (uart_tx); // orpsoc's transmit line
 
 
   // Tie off signals
   // Tie off signals
Line 284... Line 323...
 
 
   spi_sd_miso = 0; // Tie off master-in/slave-out of SD SPI bus
   spi_sd_miso = 0; // Tie off master-in/slave-out of SD SPI bus
 
 
  spi1_miso = 0;
  spi1_miso = 0;
 
 
  //#if VM_TRACE  
 
  if (VCD_enabled)
  if (VCD_enabled)
    {
    {
      Verilated::traceEverOn (true);
      Verilated::traceEverOn (true);
 
 
      printf("* VCD dumpfile: %s\n", vcdDumpFile.c_str());
      printf("* VCD dumpfile: %s\n", vcdDumpFile.c_str());
Line 303... Line 342...
 
 
      if (dumping_now)
      if (dumping_now)
        {
        {
          spTraceFile->open (vcdDumpFile.c_str());
          spTraceFile->open (vcdDumpFile.c_str());
        }
        }
      //#endif
 
    }
    }
 
 
  //printf("* Beginning test\n");
  //printf("* Beginning test\n");
 
 
  // Init the UART function
  // Init the UART function
Line 343... Line 381...
          // Do memdump if enabled
          // Do memdump if enabled
          monitor->memdump();
          monitor->memdump();
        }
        }
      else
      else
        {
        {
          if (dump_start_delay)
          if (dump_start_delay_set)
            {
            {
              // Run the sim until we want to dump
              // Run the sim until we want to dump
              sc_start((double)(dump_start.to_double()),TIMESCALE_UNIT);
              sc_start((double)(dump_start.to_double()),TIMESCALE_UNIT);
              // Open the trace file
              // Open the trace file
              spTraceFile->open (vcdDumpFile.c_str());
              spTraceFile->open (vcdDumpFile.c_str());
Line 422... Line 460...
      sc_start();
      sc_start();
    }
    }
 
 
 
 
  // Free memory
  // Free memory
 
  if (rsp_server_enabled)
 
    delete gdbServer;
 
  delete jtag;
  delete monitor;
  delete monitor;
  delete reset;
  delete reset;
 
 
  delete accessor;
  delete accessor;
 
 

powered by: WebSVN 2.1.0

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