OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

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

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

Rev 362 Rev 363
Line 40... Line 40...
////                                                              ////
////                                                              ////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
 
 
#include "OrpsocMain.h"
#include "OrpsocMain.h"
 
 
#include "JtagSC_includes.h"
// TODO - copy orpsoc-defines.h and or1200-defines.h somewhere this can see
 
//        them and include/exclude RSP stuff. For now is defined
 
//#define JTAG_DEBUG
 
 
#include "Vorpsoc_top.h"
#include "Vorpsoc_top.h"
#include "OrpsocAccess.h"
#include "OrpsocAccess.h"
#include "MemoryLoad.h"
#include "MemoryLoad.h"
 
 
#include <verilated_vcd_c.h>
#include <verilated_vcd_c.h>
 
 
#include "ResetSC.h"
#include "ResetSC.h"
#include "Or1200MonitorSC.h"
#include "Or1200MonitorSC.h"
 
 
 
#ifdef JTAG_DEBUG
#include "GdbServerSC.h"
#include "GdbServerSC.h"
 
# include "JtagSC_includes.h"
 
#endif
 
 
#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;
 
 
 
#ifdef JTAG_DEBUG
 
  sc_time   jtagPeriod (JTAG_CLK_HALFPERIOD * 2.0, TIMESCALE_UNIT);
 
  sc_clock  jtag_tck ("jtag-clk", jtagPeriod, 0.5, SC_ZERO_TIME, false);
 
 
  sc_signal<bool>      jtag_tdi;                // JTAG interface
  sc_signal<bool>      jtag_tdi;                // JTAG interface
  sc_signal<bool>      jtag_tdo;
  sc_signal<bool>      jtag_tdo;
  sc_signal<bool>      jtag_tms;
  sc_signal<bool>      jtag_tms;
  sc_signal<bool>      jtag_trst;
  sc_signal<bool>      jtag_trst;
 
#endif
 
 
  sc_signal<bool>      uart_rx;         // External UART
  sc_signal<bool>      uart_rx;         // External UART
  sc_signal<bool>      uart_tx;
  sc_signal<bool>      uart_tx;
 
 
  SIM_RUNNING = 0;
  SIM_RUNNING = 0;
Line 88... Line 97...
  // VCD dump controling vars
  // VCD dump controling vars
  bool dump_start_delay_set = false, dump_stop_set = false;
  bool dump_start_delay_set = false, dump_stop_set = false;
  bool dumping_now = false;
  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;
  bool finish_time_set = false; // By default we will let the simulation finish naturally
  bool finish_time_set = false; // By default we will let the simulation 
 
                                // finish naturally
  VerilatedVcdC *verilatorVCDFile;
  VerilatedVcdC *verilatorVCDFile;
 
 
  /*int*/double time_val;
  /*int*/double time_val;
  bool vcd_file_name_given = false;
  bool vcd_file_name_given = false;
 
 
 
#ifdef JTAG_DEBUG
  bool rsp_server_enabled = false;
  bool rsp_server_enabled = false;
  int rsp_server_port = DEFAULT_RSP_PORT;
  int rsp_server_port = DEFAULT_RSP_PORT;
 
#endif
 
 
  // 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
 
 
  // Verilator accessor
  // Verilator accessor
  OrpsocAccess    *accessor;
  OrpsocAccess    *accessor;
 
 
Line 110... Line 123...
  Vorpsoc_top *orpsoc;          // Verilated ORPSoC
  Vorpsoc_top *orpsoc;          // Verilated ORPSoC
 
 
  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
 
 
 
#ifdef JTAG_DEBUG
  JtagSC           *jtag;               // Generate JTAG signals
  JtagSC           *jtag;               // Generate JTAG signals
  GdbServerSC      *gdbServer;          // Map RSP requests to debug unit
  GdbServerSC      *gdbServer;          // Map RSP requests to debug unit
 
#endif
 
 
  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");
 
 
Line 128... Line 146...
                                    argc, argv);
                                    argc, argv);
 
 
  // Instantiate the SystemC modules
  // Instantiate the SystemC modules
  reset         = new ResetSC ("reset", BENCH_RESET_TIME);
  reset         = new ResetSC ("reset", BENCH_RESET_TIME);
 
 
 
#ifdef JTAG_DEBUG  
  jtag          = new JtagSC ("jtag");
  jtag          = new JtagSC ("jtag");
 
#endif
 
 
  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
 
 
  // 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++)
Line 151... Line 172...
              finish_time_set = true;
              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) ||
          else if ((strcmp(argv[i], "-d")==0) ||
                   (strcmp(argv[i], "--vcdfile")==0) ||
                   (strcmp(argv[i], "--vcdfile")==0) ||
                   (strcmp(argv[i], "-v")==0) ||
                   (strcmp(argv[i], "-v")==0) ||
Line 190... Line 212...
              time_val = strtod(argv[i+1],NULL);
              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 = true;
              dump_stop_set = true;
            }
            }
 
#ifdef JTAG_DEBUG
          else if ( (strcmp(argv[i], "-r")==0) ||
          else if ( (strcmp(argv[i], "-r")==0) ||
                    (strcmp(argv[i], "--rsp")==0) )
                    (strcmp(argv[i], "--rsp")==0) )
            {
            {
              rsp_server_enabled = true;
              rsp_server_enabled = true;
              if (i+1 < argc) if(argv[i+1][0] != '-')
              if (i+1 < argc) if(argv[i+1][0] != '-')
                                {
                                {
                                  rsp_server_port = atoi(argv[i+1]);
                                  rsp_server_port = atoi(argv[i+1]);
                                  i++;
                                  i++;
                                }
                                }
            }
            }
 
#endif
          /*
          /*
             Depth setting of VCD doesn't appear to work, I think it's only
             Depth setting of VCD doesn't appear to work, I think it's only
             configurable during at compile time .
             configurable during at compile time .
          */
          */
          /*      else if ( (strcmp(argv[i], "-p")==0) ||
          /*      else if ( (strcmp(argv[i], "-p")==0) ||
Line 227... Line 251...
              printf("  -v, --vcdon\t\tEnable VCD generation\n");
              printf("  -v, --vcdon\t\tEnable VCD generation\n");
              printf("  -d, --vcdfile <file>\tEnable and save VCD to <file>\n");
              printf("  -d, --vcdfile <file>\tEnable and save VCD to <file>\n");
 
 
              printf("  -s, --vcdstart <val>\tEnable and delay VCD generation until <val> ns\n");
              printf("  -s, --vcdstart <val>\tEnable and delay VCD generation until <val> ns\n");
              printf("  -t, --vcdstop <val> \tEnable and terminate VCD generation at <val> ns\n");
              printf("  -t, --vcdstop <val> \tEnable and terminate VCD generation at <val> ns\n");
 
#ifdef JTAG_DEBUG
              printf("\nRemote debugging:\n");
              printf("\nRemote debugging:\n");
              printf("  -r, --rsp [<port>]\tEnable RSP debugging server, opt. specify <port>\n");
              printf("  -r, --rsp [<port>]\tEnable RSP debugging server, opt. specify <port>\n");
 
#endif
              monitor->printUsage();
              monitor->printUsage();
              printf("\n");
              printf("\n");
              return 0;
              return 0;
            }
            }
 
 
Line 250... Line 276...
        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;
    }
    }
 
#ifdef JTAG_DEBUG  
  if (rsp_server_enabled)
  if (rsp_server_enabled)
    gdbServer     = new GdbServerSC ("gdb-server", FLASH_START, FLASH_END,
    gdbServer     = new GdbServerSC ("gdb-server", FLASH_START, FLASH_END,
                                       rsp_server_port, jtag->tapActionQueue);
                                       rsp_server_port, jtag->tapActionQueue);
  else
  else
      gdbServer = NULL;
      gdbServer = NULL;
 
#endif
 
 
  // Connect up ORPSoC
  // Connect up ORPSoC
  orpsoc->clk_pad_i (clk);
  orpsoc->clk_pad_i (clk);
  orpsoc->rst_n_pad_i (rstn);
  orpsoc->rst_n_pad_i (rstn);
 
 
 
#ifdef JTAG_DEBUG
  orpsoc->tck_pad_i  (jtag_tck);                // JTAG interface
  orpsoc->tck_pad_i  (jtag_tck);                // JTAG interface
  orpsoc->tdi_pad_i  (jtag_tdi);
  orpsoc->tdi_pad_i  (jtag_tdi);
  orpsoc->tms_pad_i  (jtag_tms);
  orpsoc->tms_pad_i  (jtag_tms);
  orpsoc->tdo_pad_o  (jtag_tdo);
  orpsoc->tdo_pad_o  (jtag_tdo);
 
#endif
 
 
  orpsoc->uart0_srx_pad_i (uart_rx);            // External UART
  orpsoc->uart0_srx_pad_i (uart_rx);            // External UART
  orpsoc->uart0_stx_pad_o (uart_tx);
  orpsoc->uart0_stx_pad_o (uart_tx);
 
 
  // Connect up the SystemC  modules
  // Connect up the SystemC  modules
Line 276... Line 305...
  reset->rst (rst);
  reset->rst (rst);
  reset->rstn (rstn);
  reset->rstn (rstn);
 
 
  monitor->clk (clk);                   // Monitor
  monitor->clk (clk);                   // Monitor
 
 
 
#ifdef JTAG_DEBUG
  jtag->sysReset (rst);                 // JTAG
  jtag->sysReset (rst);                 // JTAG
  jtag->tck (jtag_tck);
  jtag->tck (jtag_tck);
  jtag->tdi (jtag_tdi);
  jtag->tdi (jtag_tdi);
  jtag->tdo (jtag_tdo);
  jtag->tdo (jtag_tdo);
  jtag->tms (jtag_tms);
  jtag->tms (jtag_tms);
  jtag->trst (jtag_trst);
  jtag->trst (jtag_trst);
 
#endif
 
 
  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
 
#ifdef JTAG_DEBUG
  jtag_tdi      = 1;                    // Tie off the JTAG inputs
  jtag_tdi      = 1;                    // Tie off the JTAG inputs
  jtag_tms      = 1;
  jtag_tms      = 1;
 
#endif
 
 
  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());
 
 
      // Establish a new trace with its correct time resolution, and trace to
      // Establish a new trace with its correct time resolution, and trace to
      // great depth.
      // great depth.
      verilatorVCDFile = new VerilatedVcdC ();
      verilatorVCDFile = new VerilatedVcdC ();
      //verilatorVCDFile->verilated()->set_time_resolution (sc_get_time_resolution());
 
      //setSpTimeResolution (sc_get_time_resolution ());
 
      //traceTarget->trace (verilatorVCDFile, 99);
 
      orpsoc->trace (verilatorVCDFile, dump_depth);
      orpsoc->trace (verilatorVCDFile, dump_depth);
 
 
      if (dumping_now)
      if (dumping_now)
        {
        {
          verilatorVCDFile->open (vcdDumpFile.c_str());
          verilatorVCDFile->open (vcdDumpFile.c_str());
Line 321... Line 352...
  if (do_program_file_load) // Did the user specify a file to load?
  if (do_program_file_load) // Did the user specify a file to load?
    {
    {
      cout << "* Loading program from " << program_file << endl;
      cout << "* Loading program from " << program_file << endl;
      if (memoryload->loadcode(program_file,0,0) < 0)
      if (memoryload->loadcode(program_file,0,0) < 0)
        {
        {
          cout << "* Error: executable file " << program_file << " not loaded" << endl;
          cout << "* Error: executable file " << program_file <<
 
            " not loaded" << endl;
        }
        }
    }
    }
  else // Load SRAM from VMEM file
  else // Load SRAM from VMEM file
    {
    {
      accessor->do_ram_readmemh();
      accessor->do_ram_readmemh();
Line 421... Line 453...
        }
        }
    }
    }
  else
  else
    {
    {
      // Simple run case
      // Simple run case
      // Ideally a "l.nop 1" will terminate the simulation gracefully
      // Ideally a "l.nop 1" will terminate the simulation gracefully.
      // Need to step at clock period / 4, otherwise model appears to skip the monitor and logging functions sometimes (?!?)
      // Need to step at clock period / 4, otherwise model appears to skip the 
 
      // monitor and logging functions sometimes (?!?)
      while (SIM_RUNNING)
      while (SIM_RUNNING)
        sc_start(BENCH_CLK_HALFPERIOD / 2, TIMESCALE_UNIT);
        sc_start(BENCH_CLK_HALFPERIOD / 2, TIMESCALE_UNIT);
      //sc_start();
      //sc_start();
    }
    }
 
 
 
 
  // Free memory
  // Free memory
 
#ifdef JTAG_DEBUG
  if (rsp_server_enabled)
  if (rsp_server_enabled)
    delete gdbServer;
    delete gdbServer;
 
 
  delete jtag;
  delete jtag;
 
#endif
 
 
  delete monitor;
  delete monitor;
 
 
  delete reset;
  delete reset;
 
 
  delete accessor;
  delete accessor;
 
 
  //delete trace;
  //delete trace;
 
 
  delete orpsoc;
  delete orpsoc;
 
 
  return 0;
  return 0;
 
 
}       /* sc_main() */
}       /* sc_main() */

powered by: WebSVN 2.1.0

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