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

Subversion Repositories s1_core

[/] [s1_core/] [trunk/] [hdl/] [behav/] [testbench/] [mem_harness.v] - Blame information for rev 114

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 fafa1971
/*
2
 * Memory Harness with Wishbone Slave interface
3
 *
4 114 albert.wat
 * (C) Copyleft 2007 Fabrizio Fazzino
5 4 fafa1971
 *
6
 * LICENSE:
7
 * This is a Free Hardware Design; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * version 2 as published by the Free Software Foundation.
10
 * The above named program is distributed in the hope that it will
11
 * be useful, but WITHOUT ANY WARRANTY; without even the implied
12
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 * See the GNU General Public License for more details.
14
 *
15
 * DESCRIPTION:
16
 * Filename is a parameter, and the corresponding file content
17
 * must follow the rules stated in Verilog standard for the
18
 * $readmemh() system task.
19
 * For instance if you don't change the default name you just
20
 * have to put a text file named "memory.hex" in your simulation
21
 * directory with the following content inside:
22
 *
23
 *   // We start from address zero by default:
24
 *   1234567812345678
25
 *   FEDCBA9876543210
26
 *   // Now we jump to doubleword number 10 (i.e. address 80):
27
 *   @ 10
28
 *   02468ACE13579BDF
29
 *
30
 * This memory harness was originally based upon a Wishbone Slave
31
 * model written by Rudolf Usselmann <rudi@asics.ws> but now I've
32
 * written it again entirely from scratch.
33
 */
34
 
35
module mem_harness (
36
    sys_clock_i, sys_reset_i,
37
    wbs_addr_i, wbs_data_i, wbs_data_o, wbs_cycle_i, wbs_strobe_i,
38
    wbs_sel_i, wbs_we_i, wbs_ack_o
39
  );
40
 
41
  // System inputs
42
  input         sys_clock_i;     // System Clock
43
  input         sys_reset_i;     // System Reset
44
 
45
  // Wishbone Slave interface inputs
46
  input         wbs_cycle_i;     // Wishbone Cycle
47
  input         wbs_strobe_i;    // Wishbone Strobe
48
  input[63:0]   wbs_addr_i;      // Wishbone Address
49
  input[63:0]   wbs_data_i;      // Wishbone Data Input
50
  input         wbs_we_i;        // Wishbone Write Enable
51
  input[7:0]    wbs_sel_i;       // Wishbone Byte Select
52
 
53
  // Wishbone Slave interface registered outputs
54
  output        wbs_ack_o;       // Wishbone Ack
55
  reg           wbs_ack_o;       // Wishbone Ack
56
  output[63:0]  wbs_data_o;      // Wishbone Data Output
57
  reg[63:0]     wbs_data_o;      // Wishbone Data Output
58
 
59
  // Parameters
60
  parameter     addr_bits = 20;
61
  parameter     addr_max = (1<<addr_bits)-1;
62
  parameter     memfilename = "memory.hex";
63
  parameter     memdefaultcontent = 64'h0000000000000000;
64
 
65
  // Wires
66
  reg[63:0]     mem[addr_max:0];       // This is the memory!
67
  wire[63:0]    tmp_rd;                // Temporary read data
68
  wire[63:0]    tmp_wd;                // Temporary write data
69
  integer       i;                     // Index
70
 
71
  // Initialization
72 113 albert.wat
`ifdef SIMPLY_RISC_DEBUG
73 4 fafa1971
  initial begin
74
    $display("INFO: MEMH %m: Memory Harness with Wishbone Slave interface starting...");
75
    $display("INFO: MEMH %m: %0d Address Bits / %0d Doublewords / %0d Bytes Total Memory", addr_bits, addr_max+1, (addr_max+1)*8);
76
    for(i=0; i<=addr_max; i=i+1) mem[i] = memdefaultcontent;
77
    $readmemh(memfilename, mem);
78
    $display("INFO: MEMH %m: Memory initialization completed");
79
  end
80 57 fafa1971
`endif
81 4 fafa1971
 
82
  // Assignments
83
  assign tmp_rd = mem[wbs_addr_i[addr_bits+2:3]];
84
  assign tmp_wd[63:56] = !wbs_sel_i[7] ? tmp_rd[63:56] : wbs_data_i[63:56];
85
  assign tmp_wd[55:48] = !wbs_sel_i[6] ? tmp_rd[55:48] : wbs_data_i[55:48];
86
  assign tmp_wd[47:40] = !wbs_sel_i[5] ? tmp_rd[47:40] : wbs_data_i[47:40];
87
  assign tmp_wd[39:32] = !wbs_sel_i[4] ? tmp_rd[39:32] : wbs_data_i[39:32];
88
  assign tmp_wd[31:24] = !wbs_sel_i[3] ? tmp_rd[31:24] : wbs_data_i[31:24];
89
  assign tmp_wd[23:16] = !wbs_sel_i[2] ? tmp_rd[23:16] : wbs_data_i[23:16];
90
  assign tmp_wd[15:08] = !wbs_sel_i[1] ? tmp_rd[15:08] : wbs_data_i[15:08];
91
  assign tmp_wd[07:00] = !wbs_sel_i[0] ? tmp_rd[07:00] : wbs_data_i[07:00];
92
 
93
  // Process the requests
94
  always @(posedge sys_clock_i) begin
95
 
96
    // Read cycle
97
    if(wbs_cycle_i & wbs_strobe_i & !wbs_we_i) begin
98
 
99
      // Return the ack
100
      wbs_ack_o = 1;
101
 
102
      // Return the data (ignore the byte select for reads)
103
      wbs_data_o = tmp_rd;
104
 
105
      // Write a comment
106 113 albert.wat
`ifdef SIMPLY_RISC_DEBUG
107 4 fafa1971
      if(wbs_sel_i) $display("INFO: MEMH %m: R @ %t ns, AD=%X SEL=%X DAT=%X", $time, wbs_addr_i, wbs_sel_i, wbs_data_o);
108 57 fafa1971
`endif
109 4 fafa1971
 
110
    // Write cycle
111
    end else if(wbs_cycle_i & wbs_strobe_i & wbs_we_i) begin
112
 
113
      // Return the ack
114
      wbs_ack_o = 1;
115
 
116
      // Clear the output data
117
      wbs_data_o = 64'hZZZZZZZZZZZZZZZZ;
118
 
119
      // Store the data
120
      mem[wbs_addr_i[addr_bits+2:3]] = tmp_wd;
121
 
122
      // Write a comment
123 113 albert.wat
`ifdef SIMPLY_RISC_DEBUG
124 4 fafa1971
      if(wbs_sel_i) $display("INFO: MEMH %m: W @ %t ns, AD=%X SEL=%X DAT=%X", $time, wbs_addr_i, wbs_sel_i, tmp_wd);
125 57 fafa1971
`endif
126 4 fafa1971
 
127
    // No read/write cycle
128
    end else begin
129
 
130
      // Clear the ack
131
      wbs_ack_o = 0;
132
 
133
      // Clear the output data
134
      wbs_data_o = 64'hZZZZZZZZZZZZZZZZ;
135
 
136
    end
137
  end
138
 
139
endmodule
140
 

powered by: WebSVN 2.1.0

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