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

Subversion Repositories sxp

[/] [sxp/] [trunk/] [dpmem/] [src/] [dpmem.v] - Blame information for rev 59

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 10 samg
/* Behavioral memory verilog module
2
   SXP Processor
3
   Sam Gladstone
4
 
5
   This can not be synthesized!
6
   The purpose is to emmulate standard dual port memories.
7
*/
8
 
9
 
10
module dpmem (  clk,
11
                reset_b,
12
                addra,          // address a port
13
                addrb,          // address b port
14
                wea,            // write enable a
15
                web,            // write enable b
16
                oea,            // output enable a
17
                oeb,            // output enable b
18
                da,             // data input a
19
                db,             // data input b
20
 
21
                qa,             // data output a
22
                qb);            // data output b
23
 
24
parameter ADDR_WIDTH = 32;
25
parameter MEM_SIZE = 1024;
26
 
27
input clk;
28
input reset_b;
29
input [ADDR_WIDTH-1:0] addra;
30
input [ADDR_WIDTH-1:0] addrb;
31
input wea;
32
input web;
33
input oea;
34
input oeb;
35
input [31:0] da;
36
input [31:0] db;
37
 
38
 
39
output [31:0] qa;
40
output [31:0] qb;
41
 
42 21 samg
reg [31:0] mem [0:MEM_SIZE-1];
43 10 samg
 
44
wire [31:0] data_a;
45
wire [31:0] data_b;
46
 
47
reg [31:0] mem_data_a;
48
reg [31:0] mem_data_b;
49
 
50
integer i;
51
 
52
wire [31:0] mem_limit;
53
 
54 21 samg
assign mem_limit = MEM_SIZE-1;
55 10 samg
 
56
assign qa = (oea) ? data_a : {32{1'b z}};
57
assign qb = (oeb) ? data_b : {32{1'b z}};
58
 
59
assign data_a = (wea) ? {32{1'b x}} : mem_data_a;
60
assign data_b = (web) ? {32{1'b x}} : mem_data_b;
61
 
62
// Checking address a
63
always @(addra)
64
  begin
65 21 samg
    if ((addra > (MEM_SIZE-1)) && wea)
66 10 samg
      $display ("address a = %d, out of range of memory limit (%d)",addra,mem_limit);
67
  end
68
 
69
// Checking address b
70
always @(addrb)
71
  begin
72 21 samg
    if ((addrb > (MEM_SIZE-1)) && web)
73 10 samg
      $display ("address b = %d, out of range of memory limit (%d)",addrb,mem_limit);
74
  end
75
 
76
// Reading data from memory port a
77
always @(posedge clk or negedge reset_b)
78
  begin
79
    if (!reset_b)
80
      mem_data_a <= {32{1'b x}};
81
    else
82
      if ((addra==addrb)&&(web==1'b1))          // You cannot write b and read a from the same address
83
        mem_data_a <= #3 {32{1'bx}};
84
      else
85 21 samg
        mem_data_a <= #3 mem[addra];
86 10 samg
  end
87
 
88
// Reading data from memory port b
89
always @(posedge clk or negedge reset_b)
90
  begin
91
    if (!reset_b)
92
      mem_data_b <= {32{1'b x}};
93
    else
94
      if ((addra==addrb)&&(wea==1'b1))          // You cannot write a and read b from the same address
95
        mem_data_b <= #3 {32{1'bx}};
96
      else
97 21 samg
        mem_data_b <= #3 mem[addrb];
98 10 samg
  end
99
 
100
// Writing data to memory
101 48 samg
always @(posedge clk or negedge reset_b)
102 10 samg
  begin
103
    if (!reset_b)
104 21 samg
      for (i=0;i<MEM_SIZE;i=i+1)
105 10 samg
        mem[i] <= {32{1'bx}};
106
    else
107
      begin
108
        if (wea === 1'b 1)
109 21 samg
          if (addra<MEM_SIZE)
110
            mem[addra] <= da;
111 10 samg
        if (web === 1'b 1)
112 21 samg
          if (addrb<MEM_SIZE)
113
            mem[addrb] <= db;
114 10 samg
      end
115
  end
116
 
117
task mem_display;
118
integer rnum;
119
  begin
120 21 samg
    for (rnum=0;rnum<MEM_SIZE;rnum=rnum+1)
121
      $display("Location %d = %h",rnum,mem[rnum]);
122 10 samg
  end
123
endtask
124
endmodule
125
 
126
/*
127 48 samg
 *  $Id: dpmem.v,v 1.3 2001-12-05 05:46:00 samg Exp $
128 10 samg
 *  Module : dpmem
129
 *  Author : Sam Gladstone
130
 *  Function : Simple behavioral module for dual port memories
131
 *  $Log: not supported by cvs2svn $
132 48 samg
 *  Revision 1.2  2001/10/28 03:18:17  samg
133
 *  array range fix
134
 *
135 21 samg
 *  Revision 1.1  2001/10/26 21:49:59  samg
136
 *  behavioral dual port memory
137
 *
138 10 samg
 */

powered by: WebSVN 2.1.0

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