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

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [rtl/] [memdev.v] - Blame information for rev 46

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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