| 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 |
|
|
#include "TraceSC.h"
|
| 49 |
|
|
#include "ResetSC.h"
|
| 50 |
|
|
#include "Or1200MonitorSC.h"
|
| 51 |
|
|
#include "UartSC.h"
|
| 52 |
|
|
|
| 53 |
|
|
|
| 54 |
|
|
int sc_main (int argc,
|
| 55 |
|
|
char *argv[] )
|
| 56 |
|
|
{
|
| 57 |
|
|
|
| 58 |
|
|
// CPU clock (also used as JTAG TCK) and reset (both active high and low)
|
| 59 |
|
|
sc_time clkPeriod (BENCH_CLK_HALFPERIOD * 2.0, TIMESCALE_UNIT);
|
| 60 |
|
|
|
| 61 |
|
|
sc_clock clk ("clk", clkPeriod);
|
| 62 |
|
|
sc_signal<bool> rst;
|
| 63 |
|
|
sc_signal<bool> rstn;
|
| 64 |
|
|
sc_signal<bool> rst_o;
|
| 65 |
|
|
|
| 66 |
|
|
sc_signal<bool> jtag_tdi; // JTAG interface
|
| 67 |
|
|
sc_signal<bool> jtag_tdo;
|
| 68 |
|
|
sc_signal<bool> jtag_tms;
|
| 69 |
|
|
sc_signal<bool> jtag_trst;
|
| 70 |
|
|
|
| 71 |
|
|
sc_signal<bool> uart_rx; // External UART
|
| 72 |
|
|
sc_signal<bool> uart_tx;
|
| 73 |
|
|
|
| 74 |
|
|
sc_signal<bool> spi_sd_sclk; // SD Card Memory SPI
|
| 75 |
|
|
sc_signal<bool> spi_sd_ss;
|
| 76 |
|
|
sc_signal<bool> spi_sd_miso;
|
| 77 |
|
|
sc_signal<bool> spi_sd_mosi;
|
| 78 |
|
|
|
| 79 |
|
|
sc_signal<uint32_t> gpio_a; // GPIO bus - output only in verilator sims
|
| 80 |
|
|
|
| 81 |
|
|
sc_signal<bool> spi1_mosi;
|
| 82 |
|
|
sc_signal<bool> spi1_miso;
|
| 83 |
|
|
sc_signal<bool> spi1_ss;
|
| 84 |
|
|
sc_signal<bool> spi1_sclk;
|
| 85 |
|
|
|
| 86 |
|
|
|
| 87 |
|
|
// Verilator accessor
|
| 88 |
|
|
OrpsocAccess *accessor;
|
| 89 |
|
|
|
| 90 |
|
|
// Modules
|
| 91 |
|
|
Vorpsoc_top *orpsoc; // Verilated ORPSoC
|
| 92 |
|
|
TraceSC *trace; // Drive VCD
|
| 93 |
|
|
|
| 94 |
|
|
ResetSC *reset; // Generate a RESET signal
|
| 95 |
|
|
Or1200MonitorSC *monitor; // Handle l.nop x instructions
|
| 96 |
|
|
UartSC *uart; // Handle UART signals
|
| 97 |
|
|
|
| 98 |
|
|
// Instantiate the Verilator model, VCD trace handler and accessor
|
| 99 |
|
|
orpsoc = new Vorpsoc_top ("orpsoc");
|
| 100 |
|
|
trace = new TraceSC ("trace", orpsoc, argc, argv);
|
| 101 |
|
|
accessor = new OrpsocAccess (orpsoc);
|
| 102 |
|
|
|
| 103 |
|
|
// Instantiate the SystemC modules
|
| 104 |
|
|
reset = new ResetSC ("reset", BENCH_RESET_TIME);
|
| 105 |
|
|
monitor = new Or1200MonitorSC ("monitor", accessor);
|
| 106 |
|
|
uart = new UartSC("uart"); // TODO: Probalby some sort of param
|
| 107 |
|
|
|
| 108 |
|
|
// Connect up ORPSoC
|
| 109 |
|
|
orpsoc->clk_pad_i (clk);
|
| 110 |
|
|
orpsoc->rst_pad_i (rstn);
|
| 111 |
|
|
orpsoc->rst_pad_o (rst_o);
|
| 112 |
|
|
|
| 113 |
|
|
orpsoc->dbg_tck_pad_i (clk); // JTAG interface
|
| 114 |
|
|
orpsoc->dbg_tdi_pad_i (jtag_tdi);
|
| 115 |
|
|
orpsoc->dbg_tms_pad_i (jtag_tms);
|
| 116 |
|
|
orpsoc->dbg_tdo_pad_o (jtag_tdo);
|
| 117 |
|
|
|
| 118 |
|
|
orpsoc->uart0_srx_pad_i (uart_rx); // External UART
|
| 119 |
|
|
orpsoc->uart0_stx_pad_o (uart_tx);
|
| 120 |
|
|
|
| 121 |
|
|
orpsoc->spi_sd_sclk_pad_o (spi_sd_sclk); // SD Card Memory SPI
|
| 122 |
|
|
orpsoc->spi_sd_ss_pad_o (spi_sd_ss);
|
| 123 |
|
|
orpsoc->spi_sd_miso_pad_i (spi_sd_miso);
|
| 124 |
|
|
orpsoc->spi_sd_mosi_pad_o (spi_sd_mosi);
|
| 125 |
|
|
|
| 126 |
|
|
orpsoc->spi1_mosi_pad_o (spi1_mosi);
|
| 127 |
|
|
orpsoc->spi1_miso_pad_i (spi1_miso);
|
| 128 |
|
|
orpsoc->spi1_ss_pad_o (spi1_ss);
|
| 129 |
|
|
orpsoc->spi1_sclk_pad_o (spi1_sclk);
|
| 130 |
|
|
|
| 131 |
|
|
|
| 132 |
|
|
orpsoc->gpio_a_pad_io (gpio_a); // GPIO bus - output only in
|
| 133 |
|
|
// verilator sims
|
| 134 |
|
|
|
| 135 |
|
|
|
| 136 |
|
|
// Connect up the VCD trace handler
|
| 137 |
|
|
trace->clk (clk); // Trace
|
| 138 |
|
|
|
| 139 |
|
|
// Connect up the SystemC modules
|
| 140 |
|
|
reset->clk (clk); // Reset
|
| 141 |
|
|
reset->rst (rst);
|
| 142 |
|
|
reset->rstn (rstn);
|
| 143 |
|
|
|
| 144 |
|
|
monitor->clk (clk); // Monitor
|
| 145 |
|
|
|
| 146 |
|
|
uart->clk (clk); // Uart
|
| 147 |
|
|
uart->uartrx (uart_rx); // orpsoc's receive line
|
| 148 |
|
|
uart->uarttx (uart_tx); // orpsoc's transmit line
|
| 149 |
|
|
|
| 150 |
|
|
// Tie off signals
|
| 151 |
|
|
jtag_tdi = 1; // Tie off the JTAG inputs
|
| 152 |
|
|
jtag_tms = 1;
|
| 153 |
|
|
|
| 154 |
|
|
spi_sd_miso = 0; // Tie off master-in/slave-out of SD SPI bus
|
| 155 |
|
|
|
| 156 |
|
|
spi1_miso = 0;
|
| 157 |
|
|
|
| 158 |
|
|
printf("Beginning test\n");
|
| 159 |
|
|
|
| 160 |
|
|
// Init the UART function
|
| 161 |
|
|
uart->initUart(25000000, 115200);
|
| 162 |
|
|
|
| 163 |
|
|
// Execute until we stop
|
| 164 |
|
|
sc_start ();
|
| 165 |
|
|
|
| 166 |
|
|
// Free memory
|
| 167 |
|
|
delete monitor;
|
| 168 |
|
|
delete reset;
|
| 169 |
|
|
|
| 170 |
|
|
delete accessor;
|
| 171 |
|
|
|
| 172 |
|
|
delete trace;
|
| 173 |
|
|
delete orpsoc;
|
| 174 |
|
|
|
| 175 |
|
|
return 0;
|
| 176 |
|
|
|
| 177 |
|
|
} /* sc_main() */
|