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 113

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

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

powered by: WebSVN 2.1.0

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