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

Subversion Repositories tv80

[/] [tv80/] [trunk/] [sc_env/] [app_localcfg/] [app_env_top.cpp] - Blame information for rev 111

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

Line No. Rev Author Line
1 104 ghutchis
#include "systemc.h"
2
#include "systemperl.h"
3
//#include "env_memory.h"
4
 
5
//#include "SpTraceVcd.h"
6
#include "verilated_vcd_sc.h"
7
#include <unistd.h>
8
#include "it_cfg_driver.h"
9
#include "it_cfg_monitor.h"
10
#include "Vlcfg.h"
11
#include "load_ihex.h"
12 108 ghutchis
#include <assert.h>
13 104 ghutchis
 
14
extern char *optarg;
15
extern int optind, opterr, optopt;
16
 
17
#define FILENAME_SZ 80
18 106 ghutchis
#define MAX_MEM_SIZE 32768
19 104 ghutchis
 
20
int sc_main(int argc, char *argv[])
21
{
22
  bool dumping = false;
23
  bool memfile = false;
24
  int index;
25
  char dumpfile_name[FILENAME_SZ];
26
  char mem_src_name[FILENAME_SZ];
27
  uint8_t memory[MAX_MEM_SIZE];
28
  VerilatedVcdSc *tfp;
29 108 ghutchis
  int run_time = 5; // in microseconds
30 104 ghutchis
  //z80_decoder dec0 ("dec0");
31
 
32
  sc_clock clk("clk125", 8, SC_NS, 0.5);
33
 
34
  sc_signal<bool> reset_n;
35
  sc_signal<bool>  lcfg_init;
36
  sc_signal<bool>  lcfg_proc_reset;
37
 
38
  sc_signal<bool>      cfgi_irdy;
39
  sc_signal<bool>      cfgi_trdy;
40
  sc_signal<uint32_t>  cfgi_addr;
41
  sc_signal<bool>      cfgi_write;
42
  sc_signal<uint32_t>  cfgi_wr_data;
43
  sc_signal<uint32_t>  cfgi_rd_data;
44
 
45
  // outgoing config interface to system
46
  // configuration bus
47
  sc_signal<bool>      cfgo_irdy;
48
  sc_signal<bool>      cfgo_trdy;
49
  sc_signal<uint32_t>  cfgo_addr;
50
  sc_signal<bool>      cfgo_write;
51
  sc_signal<uint32_t>  cfgo_wr_data;
52
  sc_signal<uint32_t>  cfgo_rd_data;
53
 
54
  // clear program memory
55
  for (int i=0; i<MAX_MEM_SIZE; i++) memory[i] = 0;
56
 
57 108 ghutchis
  while ( (index = getopt(argc, argv, "d:i:t:")) != -1) {
58 104 ghutchis
    printf ("DEBUG: getopt optind=%d index=%d char=%c\n", optind, index, (char) index);
59
    if  (index == 'd') {
60
      strncpy (dumpfile_name, optarg, FILENAME_SZ);
61
      dumping = true;
62
      printf ("VCD dump enabled to %s\n", dumpfile_name);
63
    } else if (index == 'i') {
64
      strncpy (mem_src_name, optarg, FILENAME_SZ);
65
      memfile = true;
66 108 ghutchis
    } else if (index == 't') {
67
      run_time = atoi (optarg);
68
      assert (run_time > 0);
69
      printf ("Running for %d microseconds\n", run_time);
70
    } else {
71
      printf ("Unknown index %c\n", (char) index);
72 104 ghutchis
    }
73
  }
74
 
75
  Vlcfg lcfg ("lcfg");
76
  lcfg.clk (clk);
77
  lcfg.reset_n(reset_n);
78
  lcfg.lcfg_init (lcfg_init);
79
  lcfg.lcfg_proc_reset (lcfg_proc_reset);
80
 
81
  lcfg.cfgi_irdy(cfgi_irdy);
82
  lcfg.cfgi_trdy(cfgi_trdy);
83
  lcfg.cfgi_addr(cfgi_addr);
84
  lcfg.cfgi_write(cfgi_write);
85
  lcfg.cfgi_rd_data(cfgi_rd_data);
86
  lcfg.cfgi_wr_data(cfgi_wr_data);
87
 
88
  lcfg.cfgo_irdy(cfgo_irdy);
89
  lcfg.cfgo_trdy(cfgo_trdy);
90
  lcfg.cfgo_addr(cfgo_addr);
91
  lcfg.cfgo_write(cfgo_write);
92
  lcfg.cfgo_rd_data(cfgo_rd_data);
93
  lcfg.cfgo_wr_data(cfgo_wr_data);
94
 
95
  it_cfg_driver driver ("driver");
96
  driver.clk (clk);
97
  driver.reset_n(reset_n);
98
 
99
  driver.cfgi_irdy(cfgi_irdy);
100
  driver.cfgi_trdy(cfgi_trdy);
101
  driver.cfgi_addr(cfgi_addr);
102
  driver.cfgi_write(cfgi_write);
103
  driver.cfgi_rd_data(cfgi_rd_data);
104
  driver.cfgi_wr_data(cfgi_wr_data);
105
 
106
  it_cfg_monitor monitor ("monitor");
107
  monitor.clk (clk);
108
  monitor.reset_n(reset_n);
109
 
110
  monitor.cfgo_irdy(cfgo_irdy);
111
  monitor.cfgo_trdy(cfgo_trdy);
112
  monitor.cfgo_addr(cfgo_addr);
113
  monitor.cfgo_write(cfgo_write);
114
  monitor.cfgo_rd_data(cfgo_rd_data);
115
  monitor.cfgo_wr_data(cfgo_wr_data);
116
 
117
 
118
  //env_memory env_memory0("env_memory0");
119
 
120
  // Start Verilator traces
121
  if (dumping) {
122
    Verilated::traceEverOn(true);
123
    tfp = new VerilatedVcdSc;
124
    lcfg.trace (tfp, 99);
125
    tfp->open (dumpfile_name);
126
  }
127
 
128
  // check for command line argument
129
  if (memfile) {
130
    int max, bused = 0;
131
    uint32_t cword;
132
    max = load_ihex (mem_src_name, memory, MAX_MEM_SIZE);
133
    printf ("Loading IHEX file %s, max addr=%d\n", mem_src_name, max);
134
    while (bused <= max) {
135
      cword = 0;
136
      for (int i=0; i<4; i++) cword |= (memory[bused++] << (i*8));
137 108 ghutchis
      //printf ("Queueing %x\n", cword);
138 104 ghutchis
      driver.add_queue (cword);
139
    }
140
  }
141
 
142
  // set reset to 0 before sim start
143
  reset_n.write (0);
144
  lcfg_proc_reset.write(1);
145
 
146
  //sc_time *runtime = new sc_time(100, SC_NS);
147
  sc_time time100(100, SC_NS);
148
  sc_start(time100);
149
 
150
  reset_n.write (1);
151
 
152
  //delete runtime; runtime = new sc_time (1000, SC_NS);
153
  sc_start (sc_time(2500,SC_NS));
154
  lcfg_proc_reset.write(0);
155
 
156 108 ghutchis
  sc_start (sc_time(run_time, SC_US));
157 104 ghutchis
 
158
  /*
159
  sc_close_vcd_trace_file (trace_file);
160
  */
161
  if (dumping)
162
    tfp->close();
163
 
164
  return 0;
165
}

powered by: WebSVN 2.1.0

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