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

Subversion Repositories rf6809

[/] [rf6809/] [trunk/] [rtl/] [noc/] [memory/] [semamem.sv] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2018-2022  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch@finitron.ca
6
//       ||
7
//
8
//      semamem.sv
9
//
10
// BSD 3-Clause License
11
// Redistribution and use in source and binary forms, with or without
12
// modification, are permitted provided that the following conditions are met:
13
//
14
// 1. Redistributions of source code must retain the above copyright notice, this
15
//    list of conditions and the following disclaimer.
16
//
17
// 2. Redistributions in binary form must reproduce the above copyright notice,
18
//    this list of conditions and the following disclaimer in the documentation
19
//    and/or other materials provided with the distribution.
20
//
21
// 3. Neither the name of the copyright holder nor the names of its
22
//    contributors may be used to endorse or promote products derived from
23
//    this software without specific prior written permission.
24
//
25
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
//
36
// Address
37
// 0b0nnnnnnaaaa                read: decrement by aaaaaa, write increment by aaaaaa
38
// 0b1nnnnnn----          read: peek value, write absolute data
39
// ============================================================================
40
 
41
module semamem(rst_i, clk_i, cs_i, cyc_i, stb_i, ack_o, we_i, adr_i, dat_i, dat_o);
42
input rst_i;
43
input clk_i;
44
input cs_i;
45
input cyc_i;
46
input stb_i;
47
output ack_o;
48
input we_i;
49
input [12:0] adr_i;
50
input [11:0] dat_i;
51
output reg [11:0] dat_o;
52
 
53
wire cs = cs_i & cyc_i & stb_i;
54
reg ack;
55
always_ff @(posedge clk_i)
56
  ack <= cs;
57
assign ack_o = ack & cs;
58
 
59
reg [11:0] mem [0:255];
60
reg [11:0] memi;
61
reg [11:0] memo;
62
reg [12:0] memopi,memomi;
63
always_comb
64
        memo <= mem[adr_i[11:4]];
65
always_comb
66
        memopi <= memo + adr_i[3:0];
67
always_comb
68
        memomi <= memo - adr_i[3:0];
69
assign o = memo;
70
 
71
wire pe_cs, ne_cs;
72
edge_det ued1 (.rst(rst_i), .clk(clk_i), .ce(1'b1), .i(cs), .pe(pe_cs), .ne(ne_cs), .ee());
73
 
74
always_ff @(posedge clk_i)
75
if (pe_cs)
76
        mem[adr_i[11:4]] <= memi;
77
 
78
always_comb
79
begin
80
        casez({adr_i[12],we_i})
81
        2'b00:  memi <= memomi[12] ? 12'h000 : memomi[11:0];
82
        2'b01:  memi <= memopi[12] ? 12'hFFF : memopi[11:0];
83
        2'b10:  memi <= memo;
84
        2'b11:  memi <= dat_i;
85
        endcase
86
end
87
 
88
always_ff @(posedge clk_i)
89
if (cs) begin
90
  if (pe_cs)
91
    dat_o <= mem[adr_i[11:4]];
92
end
93
else
94
        dat_o <= 12'h00;
95
 
96
endmodule

powered by: WebSVN 2.1.0

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