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

Subversion Repositories openrisc

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

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

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

powered by: WebSVN 2.1.0

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