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

Subversion Repositories openrisc_me

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

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 49 julius
 
49
//#if VM_TRACE
50
//#include <systemc.h>
51
#include <SpTraceVcdC.h>
52
//#endif
53
 
54
//#include "TraceSC.h"
55 6 julius
#include "ResetSC.h"
56
#include "Or1200MonitorSC.h"
57
#include "UartSC.h"
58
 
59 49 julius
int SIM_RUNNING;
60 6 julius
int sc_main (int   argc,
61
             char *argv[] )
62
{
63 49 julius
  sc_set_time_resolution( 1, TIMESCALE_UNIT);
64 6 julius
  // CPU clock (also used as JTAG TCK) and reset (both active high and low)
65
  sc_time  clkPeriod (BENCH_CLK_HALFPERIOD * 2.0, TIMESCALE_UNIT);
66
 
67
  sc_clock             clk ("clk", clkPeriod);
68
  sc_signal<bool>      rst;
69
  sc_signal<bool>      rstn;
70
  sc_signal<bool>      rst_o;
71
 
72
  sc_signal<bool>      jtag_tdi;                // JTAG interface
73
  sc_signal<bool>      jtag_tdo;
74
  sc_signal<bool>      jtag_tms;
75
  sc_signal<bool>      jtag_trst;
76
 
77
  sc_signal<bool>      uart_rx;         // External UART
78
  sc_signal<bool>      uart_tx;
79
 
80
  sc_signal<bool> spi_sd_sclk; // SD Card Memory SPI
81
  sc_signal<bool> spi_sd_ss;
82
  sc_signal<bool> spi_sd_miso;
83
  sc_signal<bool> spi_sd_mosi;
84
 
85
  sc_signal<uint32_t> gpio_a; // GPIO bus - output only in verilator sims
86
 
87
  sc_signal<bool> spi1_mosi;
88
  sc_signal<bool> spi1_miso;
89
  sc_signal<bool> spi1_ss;
90
  sc_signal<bool> spi1_sclk;
91
 
92 49 julius
  SIM_RUNNING = 0;
93 6 julius
 
94 49 julius
  // Setup the name of the VCD dump file
95
  int VCD_enabled = 0;
96
  string dumpNameDefault("vlt-dump.vcd");
97
  string testNameString;
98
  string vcdDumpFile;
99
  // VCD dump controling vars
100
  int dump_start_delay, dump_stop_set;
101
  int dumping_now;
102
  int dump_depth = 99; // Default dump depth
103
  sc_time dump_start,dump_stop, finish_time;
104
  int finish_time_set = 0; // By default we will let the simulation finish naturally
105
  SpTraceVcdCFile *spTraceFile;
106
 
107
  int time_val;
108
  int cmdline_name_found=0;
109
 
110 6 julius
  // Verilator accessor
111
  OrpsocAccess    *accessor;
112
 
113
  // Modules
114
  Vorpsoc_top *orpsoc;          // Verilated ORPSoC
115 49 julius
  //TraceSC          *trace;            // Drive VCD
116 6 julius
 
117
  ResetSC          *reset;              // Generate a RESET signal
118
  Or1200MonitorSC  *monitor;            // Handle l.nop x instructions
119
  UartSC          *uart;                // Handle UART signals
120
 
121
  // Instantiate the Verilator model, VCD trace handler and accessor
122
  orpsoc     = new Vorpsoc_top ("orpsoc");
123 49 julius
  //trace      = new TraceSC ("trace", orpsoc, argc, argv);
124 6 julius
  accessor   = new OrpsocAccess (orpsoc);
125
 
126
  // Instantiate the SystemC modules
127
  reset         = new ResetSC ("reset", BENCH_RESET_TIME);
128 49 julius
  monitor       = new Or1200MonitorSC ("monitor", accessor, argc, argv);
129 6 julius
  uart          = new UartSC("uart"); // TODO: Probalby some sort of param
130
 
131 49 julius
 
132
  // Parse command line options
133
  // Default is for VCD generation OFF, only turned on if specified on command line
134
  dump_start_delay = 0;
135
  dump_stop_set = 0;
136
  dumping_now = 0;
137
 
138
 
139
  // Search through the command line parameters for  options
140
 
141
  if (argc > 1)
142
    {
143
      for(int i=1; i<argc; i++)
144
        {
145
          if ((strcmp(argv[i], "-d")==0) ||
146
              (strcmp(argv[i], "--vcdfile")==0))
147
            {
148
              testNameString = (argv[i+1]);
149
              vcdDumpFile = testNameString;
150
              cmdline_name_found=1;
151
            }
152
          else if ((strcmp(argv[i], "-v")==0) ||
153
                   (strcmp(argv[i], "--vcdon")==0))
154
            {
155
              dumping_now = 1;
156
            }
157
          else if ( (strcmp(argv[i], "-e")==0) ||
158
                    (strcmp(argv[i], "--endtime")==0) )
159
            {
160
              time_val = atoi(argv[i+1]);
161
              sc_time opt_end_time(time_val,TIMESCALE_UNIT);
162
              finish_time = opt_end_time;
163
              //if (DEBUG_TRACESC) cout << "* Commmand line opt: Sim. will end at " << finish_time.to_string() << endl;
164
              finish_time_set = 1;
165
            }
166
          //#if VM_TRACE  
167
          else if ( (strcmp(argv[i], "-s")==0) ||
168
                    (strcmp(argv[i], "--vcdstart")==0) )
169
            {
170
              time_val = atoi(argv[i+1]);
171
              sc_time dump_start_time(time_val,TIMESCALE_UNIT);
172
              dump_start = dump_start_time;
173
              //if (DEBUG_TRACESC) cout << "* Commmand line opt: Dump start time set at " << dump_start.to_string() << endl;
174
              dump_start_delay = 1;
175
              dumping_now = 0;
176
            }
177
          else if ( (strcmp(argv[i], "-t")==0) ||
178
                    (strcmp(argv[i], "--vcdstop")==0) )
179
            {
180
              time_val = atoi(argv[i+1]);
181
              sc_time dump_stop_time(time_val,TIMESCALE_UNIT);
182
              dump_stop = dump_stop_time;
183
              //if (DEBUG_TRACESC) cout << "* Commmand line opt: Dump stop time set at " << dump_stop.to_string() << endl;
184
              dump_stop_set = 1;
185
            }
186
          /* Depth setting of VCD doesn't appear to work, I think it's set during verilator script compile time */
187
          /*      else if ( (strcmp(argv[i], "-p")==0) ||
188
                    (strcmp(argv[i], "--vcddepth")==0) )
189
            {
190
              dump_depth = atoi(argv[i+1]);
191
              //if (DEBUG_TRACESC) cout << "* Commmand line opt: Dump depth set to " << dump_depth << endl;
192
              }*/
193
          else if ( (strcmp(argv[i], "-h")==0) ||
194
                    (strcmp(argv[i], "--help")==0) )
195
            {
196
              printf("\n  ORPSoC Cycle Accurate model usage:\n");
197
              printf("  %s [-vh] [-d <file>] [-e <time>] [-s <time>] [-t <time>]",argv[0]);
198
              monitor->printSwitches();
199
              printf("\n\n");
200
              printf("  -h, --help\t\tPrint this help message\n");
201
              printf("  -e, --endtime\t\tStop the sim at this time (ns)\n");
202
              printf("  -v, --vcdon\t\tEnable VCD generation\n");
203
              printf("  -d, --vcdfile\t\tEnable and specify target VCD file name\n");
204
 
205
              printf("  -s, --vcdstart\tEnable and delay VCD generation until this time (ns)\n");
206
              printf("  -t, --vcdstop\t\tEnable and terminate VCD generation at this time (ns)\n");
207
              monitor->printUsage();
208
              printf("\n");
209
              return 0;
210
            }
211
 
212
        }
213
    }
214
 
215
  if(cmdline_name_found==0) // otherwise use our default VCD dump file name
216
    vcdDumpFile = dumpNameDefault;
217
 
218
  // Determine if we're going to setup a VCD dump:
219
  // Pretty much setting any option will enable VCD dumping.
220
  if ((cmdline_name_found) || (dumping_now) || (dump_start_delay) || (dump_stop_set))
221
    {
222
      VCD_enabled = 1;
223
 
224
      cout << "* Enabling VCD trace";
225
 
226
      if (dump_start_delay)
227
        cout << ", on at time " << dump_start.to_string();
228
      if (dump_stop_set)
229
    cout << ", off at time " << dump_stop.to_string();
230
      cout << endl;
231
    }
232
 
233
 
234 6 julius
  // Connect up ORPSoC
235
  orpsoc->clk_pad_i (clk);
236
  orpsoc->rst_pad_i (rstn);
237
  orpsoc->rst_pad_o (rst_o);
238
 
239
  orpsoc->dbg_tck_pad_i  (clk);         // JTAG interface
240
  orpsoc->dbg_tdi_pad_i  (jtag_tdi);
241
  orpsoc->dbg_tms_pad_i  (jtag_tms);
242
  orpsoc->dbg_tdo_pad_o  (jtag_tdo);
243
 
244
  orpsoc->uart0_srx_pad_i (uart_rx);            // External UART
245
  orpsoc->uart0_stx_pad_o (uart_tx);
246
 
247
  orpsoc->spi_sd_sclk_pad_o (spi_sd_sclk); // SD Card Memory SPI
248
  orpsoc->spi_sd_ss_pad_o (spi_sd_ss);
249
  orpsoc->spi_sd_miso_pad_i (spi_sd_miso);
250
  orpsoc->spi_sd_mosi_pad_o (spi_sd_mosi);
251
 
252
  orpsoc->spi1_mosi_pad_o (spi1_mosi);
253
  orpsoc->spi1_miso_pad_i (spi1_miso);
254
  orpsoc->spi1_ss_pad_o  (spi1_ss);
255
  orpsoc->spi1_sclk_pad_o (spi1_sclk);
256
 
257
 
258
  orpsoc->gpio_a_pad_io (gpio_a); // GPIO bus - output only in 
259
                                  // verilator sims
260
 
261
  // Connect up the VCD trace handler
262 49 julius
  //trace->clk (clk);                   // Trace
263
 
264 6 julius
  // Connect up the SystemC  modules
265
  reset->clk (clk);                     // Reset
266
  reset->rst (rst);
267
  reset->rstn (rstn);
268
 
269
  monitor->clk (clk);                   // Monitor
270
 
271
  uart->clk (clk); // Uart
272
  uart->uartrx (uart_rx); // orpsoc's receive line
273
  uart->uarttx (uart_tx); // orpsoc's transmit line
274
 
275
   // Tie off signals
276
   jtag_tdi      = 1;                   // Tie off the JTAG inputs
277
   jtag_tms      = 1;
278
 
279
   spi_sd_miso = 0; // Tie off master-in/slave-out of SD SPI bus
280
 
281
  spi1_miso = 0;
282 49 julius
 
283
  //#if VM_TRACE  
284
  if (VCD_enabled)
285
    {
286
      Verilated::traceEverOn (true);
287
 
288
      printf("* VCD dumpfile: %s\n", vcdDumpFile.c_str());
289
 
290
      // Establish a new trace with its correct time resolution, and trace to
291
      // great depth.
292
      spTraceFile = new SpTraceVcdCFile ();
293
      //spTraceFile->spTrace()->set_time_resolution (sc_get_time_resolution());
294
      //setSpTimeResolution (sc_get_time_resolution ());
295
      //traceTarget->trace (spTraceFile, 99);
296
      orpsoc->trace (spTraceFile, dump_depth);
297
 
298
      if (dumping_now)
299
        {
300
          spTraceFile->open (vcdDumpFile.c_str());
301
        }
302
      //#endif
303
    }
304 6 julius
 
305 49 julius
  printf("* Beginning test\n");
306 6 julius
 
307
  // Init the UART function
308
  uart->initUart(25000000, 115200);
309
 
310 49 julius
  SIM_RUNNING = 1;
311 44 julius
 
312 49 julius
  // First check how we should run the sim.
313
  if (VCD_enabled || finish_time_set)
314
    { // We'll run sim with step
315
 
316
      if (!VCD_enabled && finish_time_set)
317
        {
318
          // We just run the sim until the set finish time
319
          sc_start((double)(finish_time.to_double()), TIMESCALE_UNIT);
320
          SIM_RUNNING=0;
321
          sc_stop();
322
          // Print performance summary
323
          monitor->perfSummary();
324
        }
325
      else
326
        {
327
          if (dump_start_delay)
328
            {
329
              // Run the sim until we want to dump
330
              sc_start((double)(dump_start.to_double()),TIMESCALE_UNIT);
331
              // Open the trace file
332
              spTraceFile->open (vcdDumpFile.c_str());
333
              dumping_now = 1;
334
            }
335 6 julius
 
336 49 julius
          if (dumping_now)
337
            {
338
              // Step the sim and generate the trace
339
                  // Execute until we stop
340
              while(!Verilated::gotFinish())
341
                {
342
                  if (SIM_RUNNING) // Changed by Or1200MonitorSC when finish NOP
343
                    sc_start (1,TIMESCALE_UNIT); // Step the sim
344
                  else
345
                    {
346
                      spTraceFile->close();
347
                      break;
348
                    }
349
 
350
                  spTraceFile->dump (sc_time_stamp().to_double());
351
 
352
                  if (dump_stop_set)
353
                    {
354
                      if (sc_time_stamp() >=  dump_stop)
355
                        {
356
                          // Close dump file
357
                          spTraceFile->close();
358
                          // Now continue on again until the end
359
                          if (!finish_time_set)
360
                            sc_start();
361
                          else
362
                            {
363
                              // Determine how long we should run for
364
                              sc_time sim_time_remaining =
365
                                finish_time - sc_time_stamp();
366
                              sc_start((double)(sim_time_remaining.to_double()),
367
                                       TIMESCALE_UNIT);
368
                              // Officially stop the sim
369
                              sc_stop();
370
                              // Print performance summary
371
                              monitor->perfSummary();
372
                            }
373
                          break;
374
                        }
375
                    }
376
                  if (finish_time_set)
377
                    {
378
                      if (sc_time_stamp() >=  finish_time)
379
                        {
380
                          // Officially stop the sim
381
                          sc_stop();
382
                          // Close dump file
383
                          spTraceFile->close();
384
                          // Print performance summary
385
                          monitor->perfSummary();
386
                          break;
387
                        }
388
                    }
389
                }
390
            }
391
        }
392
    }
393
  else
394
    {
395
      // Simple run case
396
      sc_start();
397
    }
398
 
399
 
400 6 julius
  // Free memory
401
  delete monitor;
402
  delete reset;
403
 
404
  delete accessor;
405
 
406 49 julius
  //delete trace;
407 6 julius
  delete orpsoc;
408
 
409
  return 0;
410
 
411
}       /* sc_main() */

powered by: WebSVN 2.1.0

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