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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [bench/] [sysc/] [src/] [OrpsocMain.cpp] - Blame information for rev 363

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 63 julius
/////////////////////////////////////////////////////////////////////
2 6 julius
////                                                              ////
3
////  ORPSoC SystemC Testbench                                    ////
4
////                                                              ////
5
////  Description                                                 ////
6
////  ORPSoC Testbench file                                       ////
7
////                                                              ////
8
////  To Do:                                                      ////
9
////                                                              ////
10
////                                                              ////
11
////  Author(s):                                                  ////
12
////      - Jeremy Bennett jeremy.bennett@embecosm.com            ////
13
////      - Julius Baxter jb@orsoc.se                             ////
14
////                                                              ////
15
////                                                              ////
16
//////////////////////////////////////////////////////////////////////
17
////                                                              ////
18
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
19
////                                                              ////
20
//// This source file may be used and distributed without         ////
21
//// restriction provided that this copyright statement is not    ////
22
//// removed from the file and that any derivative work contains  ////
23
//// the original copyright notice and the associated disclaimer. ////
24
////                                                              ////
25
//// This source file is free software; you can redistribute it   ////
26
//// and/or modify it under the terms of the GNU Lesser General   ////
27
//// Public License as published by the Free Software Foundation; ////
28
//// either version 2.1 of the License, or (at your option) any   ////
29
//// later version.                                               ////
30
////                                                              ////
31
//// This source is distributed in the hope that it will be       ////
32
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
33
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
34
//// PURPOSE.  See the GNU Lesser General Public License for more ////
35
//// details.                                                     ////
36
////                                                              ////
37
//// You should have received a copy of the GNU Lesser General    ////
38
//// Public License along with this source; if not, download it   ////
39
//// from http://www.opencores.org/lgpl.shtml                     ////
40
////                                                              ////
41
//////////////////////////////////////////////////////////////////////
42
 
43
#include "OrpsocMain.h"
44
 
45 363 julius
// TODO - copy orpsoc-defines.h and or1200-defines.h somewhere this can see
46
//        them and include/exclude RSP stuff. For now is defined
47
//#define JTAG_DEBUG
48 63 julius
 
49 6 julius
#include "Vorpsoc_top.h"
50
#include "OrpsocAccess.h"
51 51 julius
#include "MemoryLoad.h"
52 49 julius
 
53 70 julius
#include <verilated_vcd_c.h>
54 49 julius
 
55 6 julius
#include "ResetSC.h"
56
#include "Or1200MonitorSC.h"
57 363 julius
 
58
#ifdef JTAG_DEBUG
59
# include "GdbServerSC.h"
60
# include "JtagSC_includes.h"
61
#endif
62
 
63 6 julius
#include "UartSC.h"
64
 
65 49 julius
int SIM_RUNNING;
66 6 julius
int sc_main (int   argc,
67
             char *argv[] )
68
{
69 49 julius
  sc_set_time_resolution( 1, TIMESCALE_UNIT);
70 6 julius
  // CPU clock (also used as JTAG TCK) and reset (both active high and low)
71
  sc_time  clkPeriod (BENCH_CLK_HALFPERIOD * 2.0, TIMESCALE_UNIT);
72 363 julius
  sc_clock             clk ("clk", clkPeriod);
73 6 julius
 
74
  sc_signal<bool>      rst;
75
  sc_signal<bool>      rstn;
76
 
77 363 julius
#ifdef JTAG_DEBUG
78
  sc_time   jtagPeriod (JTAG_CLK_HALFPERIOD * 2.0, TIMESCALE_UNIT);
79
  sc_clock  jtag_tck ("jtag-clk", jtagPeriod, 0.5, SC_ZERO_TIME, false);
80
 
81 6 julius
  sc_signal<bool>      jtag_tdi;                // JTAG interface
82
  sc_signal<bool>      jtag_tdo;
83
  sc_signal<bool>      jtag_tms;
84
  sc_signal<bool>      jtag_trst;
85 363 julius
#endif
86 6 julius
 
87
  sc_signal<bool>      uart_rx;         // External UART
88
  sc_signal<bool>      uart_tx;
89
 
90 49 julius
  SIM_RUNNING = 0;
91 6 julius
 
92 49 julius
  // Setup the name of the VCD dump file
93 63 julius
  bool VCD_enabled = false;
94 49 julius
  string dumpNameDefault("vlt-dump.vcd");
95
  string testNameString;
96
  string vcdDumpFile;
97
  // VCD dump controling vars
98 63 julius
  bool dump_start_delay_set = false, dump_stop_set = false;
99
  bool dumping_now = false;
100 49 julius
  int dump_depth = 99; // Default dump depth
101
  sc_time dump_start,dump_stop, finish_time;
102 363 julius
  bool finish_time_set = false; // By default we will let the simulation 
103
                                // finish naturally
104 70 julius
  VerilatedVcdC *verilatorVCDFile;
105 49 julius
 
106 63 julius
  /*int*/double time_val;
107
  bool vcd_file_name_given = false;
108 49 julius
 
109 363 julius
#ifdef JTAG_DEBUG
110 63 julius
  bool rsp_server_enabled = false;
111
  int rsp_server_port = DEFAULT_RSP_PORT;
112 363 julius
#endif
113 63 julius
 
114 51 julius
  // Executable app load variables
115 363 julius
  int do_program_file_load = 0; // Default: we don't require a file, we use the
116
                                // VMEM
117 51 julius
  char* program_file; // Old char* style for program name
118
 
119 6 julius
  // Verilator accessor
120
  OrpsocAccess    *accessor;
121
 
122
  // Modules
123
  Vorpsoc_top *orpsoc;          // Verilated ORPSoC
124
 
125 51 julius
  MemoryLoad *memoryload;       // Memory loader
126
 
127 6 julius
  ResetSC          *reset;              // Generate a RESET signal
128 363 julius
 
129 6 julius
  Or1200MonitorSC  *monitor;            // Handle l.nop x instructions
130 363 julius
 
131
#ifdef JTAG_DEBUG
132 63 julius
  JtagSC           *jtag;               // Generate JTAG signals
133
  GdbServerSC      *gdbServer;          // Map RSP requests to debug unit
134 363 julius
#endif
135
 
136 6 julius
  UartSC          *uart;                // Handle UART signals
137
 
138
  // Instantiate the Verilator model, VCD trace handler and accessor
139
  orpsoc     = new Vorpsoc_top ("orpsoc");
140 51 julius
 
141 6 julius
  accessor   = new OrpsocAccess (orpsoc);
142
 
143 51 julius
  memoryload = new MemoryLoad (accessor);
144
 
145 63 julius
  monitor    = new Or1200MonitorSC ("monitor", accessor, memoryload,
146
                                    argc, argv);
147
 
148 6 julius
  // Instantiate the SystemC modules
149
  reset         = new ResetSC ("reset", BENCH_RESET_TIME);
150 363 julius
 
151
#ifdef JTAG_DEBUG  
152 63 julius
  jtag          = new JtagSC ("jtag");
153 363 julius
#endif
154 63 julius
 
155 6 julius
  uart          = new UartSC("uart"); // TODO: Probalby some sort of param
156
 
157 49 julius
  // Parse command line options
158 363 julius
  // Default is for VCD generation OFF, only turned on if specified on command 
159
  // line
160 49 julius
 
161 51 julius
  // Search through the command line parameters for options  
162 49 julius
  if (argc > 1)
163
    {
164
      for(int i=1; i<argc; i++)
165
        {
166 63 julius
          if ( (strcmp(argv[i], "-e")==0) ||
167
               (strcmp(argv[i], "--endtime")==0) )
168 49 julius
            {
169 63 julius
              time_val = strtod(argv[i+1], NULL);
170 49 julius
              sc_time opt_end_time(time_val,TIMESCALE_UNIT);
171
              finish_time = opt_end_time;
172 63 julius
              finish_time_set = true;
173 49 julius
            }
174 51 julius
          else if ( (strcmp(argv[i], "-f")==0) ||
175
                    (strcmp(argv[i], "--program")==0) )
176
            {
177 363 julius
              do_program_file_load = 1; // Enable program loading - will be 
178
                                        // done after sim init.
179 51 julius
              program_file = argv[i+1]; // Old char* style for program name
180
            }
181 63 julius
          else if ((strcmp(argv[i], "-d")==0) ||
182
                   (strcmp(argv[i], "--vcdfile")==0) ||
183
                   (strcmp(argv[i], "-v")==0) ||
184
                   (strcmp(argv[i], "--vcdon")==0)
185
                   )
186
            {
187
              VCD_enabled = true;
188
              dumping_now = true;
189
              vcdDumpFile = dumpNameDefault;
190
              if (i+1 < argc)
191
                if(argv[i+1][0] != '-')
192
                  {
193
                    testNameString = argv[i+1];
194
                    vcdDumpFile = testNameString;
195
                    i++;
196
                  }
197
            }
198
          else if ( (strcmp(argv[i], "-s")==0) ||
199 49 julius
                    (strcmp(argv[i], "--vcdstart")==0) )
200
            {
201 63 julius
              VCD_enabled = true;
202
              time_val = strtod(argv[i+1], NULL);
203 49 julius
              sc_time dump_start_time(time_val,TIMESCALE_UNIT);
204
              dump_start = dump_start_time;
205 63 julius
              dump_start_delay_set = true;
206
              dumping_now = false;
207 49 julius
            }
208
          else if ( (strcmp(argv[i], "-t")==0) ||
209
                    (strcmp(argv[i], "--vcdstop")==0) )
210
            {
211 63 julius
              VCD_enabled = true;
212
              time_val = strtod(argv[i+1],NULL);
213 49 julius
              sc_time dump_stop_time(time_val,TIMESCALE_UNIT);
214
              dump_stop = dump_stop_time;
215 63 julius
              dump_stop_set = true;
216 49 julius
            }
217 363 julius
#ifdef JTAG_DEBUG
218 63 julius
          else if ( (strcmp(argv[i], "-r")==0) ||
219
                    (strcmp(argv[i], "--rsp")==0) )
220
            {
221
              rsp_server_enabled = true;
222
              if (i+1 < argc) if(argv[i+1][0] != '-')
223
                                {
224
                                  rsp_server_port = atoi(argv[i+1]);
225
                                  i++;
226
                                }
227
            }
228 363 julius
#endif
229 63 julius
          /*
230
             Depth setting of VCD doesn't appear to work, I think it's only
231
             configurable during at compile time .
232
          */
233 49 julius
          /*      else if ( (strcmp(argv[i], "-p")==0) ||
234 51 julius
                  (strcmp(argv[i], "--vcddepth")==0) )
235
                  {
236
                  dump_depth = atoi(argv[i+1]);
237
                  }*/
238 49 julius
          else if ( (strcmp(argv[i], "-h")==0) ||
239
                    (strcmp(argv[i], "--help")==0) )
240
            {
241 63 julius
              printf("Usage: %s [options]\n",argv[0]);
242
              printf("\n  ORPSoCv2 cycle accurate model\n");
243
              printf("  For details visit http://opencores.org/openrisc,orpsocv2\n");
244
              printf("\n");
245
              printf("Options:\n");
246 49 julius
              printf("  -h, --help\t\tPrint this help message\n");
247 63 julius
              printf("\nSimulation control:\n");
248
              printf("  -f, --program <file> \tLoad program from OR32 ELF <file>\n");
249
              printf("  -e, --endtime <val> \tStop the sim at <val> ns\n");
250
              printf("\nVCD generation:\n");
251 49 julius
              printf("  -v, --vcdon\t\tEnable VCD generation\n");
252 63 julius
              printf("  -d, --vcdfile <file>\tEnable and save VCD to <file>\n");
253 49 julius
 
254 63 julius
              printf("  -s, --vcdstart <val>\tEnable and delay VCD generation until <val> ns\n");
255
              printf("  -t, --vcdstop <val> \tEnable and terminate VCD generation at <val> ns\n");
256 363 julius
#ifdef JTAG_DEBUG
257 63 julius
              printf("\nRemote debugging:\n");
258
              printf("  -r, --rsp [<port>]\tEnable RSP debugging server, opt. specify <port>\n");
259 363 julius
#endif
260 49 julius
              monitor->printUsage();
261
              printf("\n");
262
              return 0;
263
            }
264
 
265
        }
266
    }
267 63 julius
 
268 49 julius
  // Determine if we're going to setup a VCD dump:
269 63 julius
  // Pretty much setting any related option will enable VCD dumping.
270
  if (VCD_enabled)
271 49 julius
    {
272
 
273
      cout << "* Enabling VCD trace";
274
 
275 63 julius
      if (dump_start_delay_set)
276 49 julius
        cout << ", on at time " << dump_start.to_string();
277
      if (dump_stop_set)
278 63 julius
        cout << ", off at time " << dump_stop.to_string();
279 49 julius
      cout << endl;
280
    }
281 363 julius
#ifdef JTAG_DEBUG  
282 63 julius
  if (rsp_server_enabled)
283
    gdbServer     = new GdbServerSC ("gdb-server", FLASH_START, FLASH_END,
284
                                       rsp_server_port, jtag->tapActionQueue);
285
  else
286
      gdbServer = NULL;
287 363 julius
#endif
288 63 julius
 
289 6 julius
  // Connect up ORPSoC
290
  orpsoc->clk_pad_i (clk);
291 362 julius
  orpsoc->rst_n_pad_i (rstn);
292 6 julius
 
293 363 julius
#ifdef JTAG_DEBUG
294 362 julius
  orpsoc->tck_pad_i  (jtag_tck);                // JTAG interface
295
  orpsoc->tdi_pad_i  (jtag_tdi);
296
  orpsoc->tms_pad_i  (jtag_tms);
297
  orpsoc->tdo_pad_o  (jtag_tdo);
298 363 julius
#endif
299 6 julius
 
300
  orpsoc->uart0_srx_pad_i (uart_rx);            // External UART
301
  orpsoc->uart0_stx_pad_o (uart_tx);
302
 
303
  // Connect up the SystemC  modules
304
  reset->clk (clk);                     // Reset
305
  reset->rst (rst);
306
  reset->rstn (rstn);
307
 
308
  monitor->clk (clk);                   // Monitor
309
 
310 363 julius
#ifdef JTAG_DEBUG
311 63 julius
  jtag->sysReset (rst);                 // JTAG
312
  jtag->tck (jtag_tck);
313
  jtag->tdi (jtag_tdi);
314
  jtag->tdo (jtag_tdo);
315
  jtag->tms (jtag_tms);
316
  jtag->trst (jtag_trst);
317 363 julius
#endif
318 63 julius
 
319 6 julius
  uart->clk (clk); // Uart
320
  uart->uartrx (uart_rx); // orpsoc's receive line
321
  uart->uarttx (uart_tx); // orpsoc's transmit line
322
 
323 63 julius
  // Tie off signals
324 363 julius
#ifdef JTAG_DEBUG
325 63 julius
  jtag_tdi      = 1;                    // Tie off the JTAG inputs
326
  jtag_tms      = 1;
327 363 julius
#endif
328 63 julius
 
329 49 julius
  if (VCD_enabled)
330
    {
331
      Verilated::traceEverOn (true);
332
 
333
      printf("* VCD dumpfile: %s\n", vcdDumpFile.c_str());
334
 
335
      // Establish a new trace with its correct time resolution, and trace to
336
      // great depth.
337 70 julius
      verilatorVCDFile = new VerilatedVcdC ();
338 363 julius
 
339 70 julius
      orpsoc->trace (verilatorVCDFile, dump_depth);
340 49 julius
 
341
      if (dumping_now)
342
        {
343 70 julius
          verilatorVCDFile->open (vcdDumpFile.c_str());
344 49 julius
        }
345
    }
346 362 julius
 
347 52 julius
  //printf("* Beginning test\n");
348 6 julius
 
349
  // Init the UART function
350 354 julius
  uart->initUart(50000000, 115200);
351 6 julius
 
352 51 julius
  if (do_program_file_load) // Did the user specify a file to load?
353
    {
354
      cout << "* Loading program from " << program_file << endl;
355
      if (memoryload->loadcode(program_file,0,0) < 0)
356
        {
357 363 julius
          cout << "* Error: executable file " << program_file <<
358
            " not loaded" << endl;
359 51 julius
        }
360
    }
361
  else // Load SRAM from VMEM file
362
    {
363
      accessor->do_ram_readmemh();
364
    }
365 44 julius
 
366 51 julius
  SIM_RUNNING = 1;
367
 
368 49 julius
  // First check how we should run the sim.
369
  if (VCD_enabled || finish_time_set)
370
    { // We'll run sim with step
371
 
372
      if (!VCD_enabled && finish_time_set)
373
        {
374
          // We just run the sim until the set finish time
375
          sc_start((double)(finish_time.to_double()), TIMESCALE_UNIT);
376
          SIM_RUNNING=0;
377
          sc_stop();
378
          // Print performance summary
379 52 julius
          monitor->perfSummary();
380
          // Do memdump if enabled
381
          monitor->memdump();
382 49 julius
        }
383
      else
384
        {
385 63 julius
          if (dump_start_delay_set)
386 49 julius
            {
387
              // Run the sim until we want to dump
388
              sc_start((double)(dump_start.to_double()),TIMESCALE_UNIT);
389
              // Open the trace file
390 70 julius
              verilatorVCDFile->open (vcdDumpFile.c_str());
391 49 julius
              dumping_now = 1;
392
            }
393 6 julius
 
394 49 julius
          if (dumping_now)
395
            {
396
              // Step the sim and generate the trace
397
                  // Execute until we stop
398
              while(!Verilated::gotFinish())
399
                {
400
                  if (SIM_RUNNING) // Changed by Or1200MonitorSC when finish NOP
401
                    sc_start (1,TIMESCALE_UNIT); // Step the sim
402
                  else
403
                    {
404 70 julius
                      verilatorVCDFile->close();
405 49 julius
                      break;
406
                    }
407
 
408 70 julius
                  verilatorVCDFile->dump (sc_time_stamp().to_double());
409 49 julius
 
410
                  if (dump_stop_set)
411
                    {
412
                      if (sc_time_stamp() >=  dump_stop)
413
                        {
414
                          // Close dump file
415 70 julius
                          verilatorVCDFile->close();
416 49 julius
                          // Now continue on again until the end
417
                          if (!finish_time_set)
418
                            sc_start();
419
                          else
420
                            {
421
                              // Determine how long we should run for
422
                              sc_time sim_time_remaining =
423
                                finish_time - sc_time_stamp();
424
                              sc_start((double)(sim_time_remaining.to_double()),
425
                                       TIMESCALE_UNIT);
426
                              // Officially stop the sim
427
                              sc_stop();
428
                              // Print performance summary
429
                              monitor->perfSummary();
430 52 julius
                              // Do memdump if enabled
431
                              monitor->memdump();
432 49 julius
                            }
433
                          break;
434
                        }
435
                    }
436
                  if (finish_time_set)
437
                    {
438
                      if (sc_time_stamp() >=  finish_time)
439
                        {
440
                          // Officially stop the sim
441
                          sc_stop();
442
                          // Close dump file
443 70 julius
                          verilatorVCDFile->close();
444 52 julius
                          // Do memdump if enabled
445
                          monitor->memdump();
446 49 julius
                          // Print performance summary
447
                          monitor->perfSummary();
448
                          break;
449
                        }
450
                    }
451
                }
452
            }
453
        }
454
    }
455
  else
456
    {
457
      // Simple run case
458 363 julius
      // Ideally a "l.nop 1" will terminate the simulation gracefully.
459
      // Need to step at clock period / 4, otherwise model appears to skip the 
460
      // monitor and logging functions sometimes (?!?)
461 64 julius
      while (SIM_RUNNING)
462
        sc_start(BENCH_CLK_HALFPERIOD / 2, TIMESCALE_UNIT);
463
      //sc_start();
464 49 julius
    }
465
 
466
 
467 6 julius
  // Free memory
468 363 julius
#ifdef JTAG_DEBUG
469 63 julius
  if (rsp_server_enabled)
470
    delete gdbServer;
471 363 julius
 
472 63 julius
  delete jtag;
473 363 julius
#endif
474
 
475 6 julius
  delete monitor;
476 363 julius
 
477 6 julius
  delete reset;
478
 
479
  delete accessor;
480
 
481 49 julius
  //delete trace;
482 363 julius
 
483 6 julius
  delete orpsoc;
484
 
485
  return 0;
486
 
487
}       /* sc_main() */

powered by: WebSVN 2.1.0

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