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

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [bench/] [rtl/] [memdev.v] - Blame information for rev 209

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 209 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    memdev.v
4
//
5
// Project:     Zip CPU -- a small, lightweight, RISC CPU soft core
6
//
7
// Purpose:     This file is really simple: it creates an on-chip memory,
8
//              accessible via the wishbone bus, that can be used in this
9
//      project.  The memory has single cycle pipeline access, although the
10
//      memory pipeline here still costs a cycle and there may be other cycles
11
//      lost between the ZipCPU (or whatever is the master of the bus) and this,
12
//      thus costing more cycles in access.  Either way, operations can be
13
//      pipelined for single cycle access on subsequent transactions.
14
//
15
//
16
// Creator:     Dan Gisselquist, Ph.D.
17
//              Gisselquist Technology, LLC
18
//
19
////////////////////////////////////////////////////////////////////////////////
20
//
21
// Copyright (C) 2015-2019, Gisselquist Technology, LLC
22
//
23
// This program is free software (firmware): you can redistribute it and/or
24
// modify it under the terms of  the GNU General Public License as published
25
// by the Free Software Foundation, either version 3 of the License, or (at
26
// your option) any later version.
27
//
28
// This program is distributed in the hope that it will be useful, but WITHOUT
29
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
30
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
31
// for more details.
32
//
33
// You should have received a copy of the GNU General Public License along
34
// with this program.  (It's in the $(ROOT)/doc directory.  Run make with no
35
// target there if the PDF file isn't present.)  If not, see
36
// <http://www.gnu.org/licenses/> for a copy.
37
//
38
// License:     GPL, v3, as defined and found on www.gnu.org,
39
//              http://www.gnu.org/licenses/gpl.html
40
//
41
//
42
////////////////////////////////////////////////////////////////////////////////
43
//
44
//
45
module  memdev(i_clk, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data, i_wb_sel,
46
                o_wb_ack, o_wb_stall, o_wb_data);
47
        parameter       LGMEMSZ=15, DW=32, EXTRACLOCK= 0;
48
        localparam      AW = LGMEMSZ - 2;
49
        input   wire                    i_clk, i_wb_cyc, i_wb_stb, i_wb_we;
50
        input   wire    [(AW-1):0]       i_wb_addr;
51
        input   wire    [(DW-1):0]       i_wb_data;
52
        input   wire    [(DW/8-1):0]     i_wb_sel;
53
        output  reg                     o_wb_ack;
54
        output  wire                    o_wb_stall;
55
        output  reg     [(DW-1):0]       o_wb_data;
56
 
57
        wire                    w_wstb, w_stb;
58
        wire    [(DW-1):0]       w_data;
59
        wire    [(AW-1):0]       w_addr;
60
        wire    [(DW/8-1):0]     w_sel;
61
 
62
        generate
63
        if (EXTRACLOCK == 0)
64
        begin
65
 
66
                assign  w_wstb = (i_wb_stb)&&(i_wb_we);
67
                assign  w_stb  = i_wb_stb;
68
                assign  w_addr = i_wb_addr;
69
                assign  w_data = i_wb_data;
70
                assign  w_sel  = i_wb_sel;
71
 
72
        end else begin
73
 
74
                reg             last_wstb, last_stb;
75
                always @(posedge i_clk)
76
                        last_wstb <= (i_wb_stb)&&(i_wb_we);
77
                always @(posedge i_clk)
78
                        last_stb <= (i_wb_stb);
79
 
80
                reg     [(AW-1):0]       last_addr;
81
                reg     [(DW-1):0]       last_data;
82
                reg     [(DW/8-1):0]     last_sel;
83
                always @(posedge i_clk)
84
                        last_data <= i_wb_data;
85
                always @(posedge i_clk)
86
                        last_addr <= i_wb_addr;
87
                always @(posedge i_clk)
88
                        last_sel <= i_wb_sel;
89
 
90
                assign  w_wstb = last_wstb;
91
                assign  w_stb  = last_stb;
92
                assign  w_addr = last_addr;
93
                assign  w_data = last_data;
94
                assign  w_sel  = last_sel;
95
        end endgenerate
96
 
97
        reg     [(DW-1):0]       mem     [0:((1<<AW)-1)];
98
 
99
        always @(posedge i_clk)
100
                o_wb_data <= mem[w_addr];
101
        always @(posedge i_clk)
102
        begin
103
                if ((w_wstb)&&(w_sel[3]))
104
                        mem[w_addr][31:24] <= w_data[31:24];
105
                if ((w_wstb)&&(w_sel[2]))
106
                        mem[w_addr][23:16] <= w_data[23:16];
107
                if ((w_wstb)&&(w_sel[1]))
108
                        mem[w_addr][15: 8] <= w_data[15:8];
109
                if ((w_wstb)&&(w_sel[0]))
110
                        mem[w_addr][ 7: 0] <= w_data[7:0];
111
        end
112
 
113
        always @(posedge i_clk)
114
                o_wb_ack <= (w_stb);
115
        assign  o_wb_stall = 1'b0;
116
 
117
        // verilator lint_off UNUSED
118
        wire    unused;
119
        assign unused = i_wb_cyc;
120
        // verilator lint_on UNUSED
121
endmodule

powered by: WebSVN 2.1.0

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