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

Subversion Repositories wb_async_mem_bridge

[/] [wb_async_mem_bridge/] [trunk/] [sim/] [models/] [wb_slave_model.v] - Blame information for rev 6

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

Line No. Rev Author Line
1 6 qaztronic
// --------------------------------------------------------------------
2
//
3
// --------------------------------------------------------------------
4
 
5
`timescale 1ns/10ps
6
 
7
 
8
module wb_slave_model(  clk_i, rst_i, dat_o, dat_i, adr_i,
9
                        cyc_i, stb_i, we_i, sel_i,
10
                        ack_o, err_o, rty_o );
11
 
12
  parameter DWIDTH    = 8;
13
  parameter AWIDTH    = 8;
14
  parameter ACK_DELAY = 2;
15
  parameter SLAVE_RAM_INIT = "wb_slave_model.txt";
16
 
17
  input                         clk_i;
18
  input                         rst_i;
19
  output [DWIDTH-1:0]           dat_o;
20
  input  [DWIDTH-1:0]           dat_i;
21
  input  [AWIDTH-1:0]           adr_i;
22
  input                         cyc_i;
23
  input                         stb_i;
24
  input                         we_i;
25
  input  [( (DWIDTH/8) - 1 ):0] sel_i;
26
  output                        ack_o;
27
  output                        err_o;
28
  output                        rty_o;
29
 
30
 
31
 
32
 
33
 
34
  // --------------------------------------------------------------------
35
  //  slave ram
36
  reg [7:0] ram[2**AWIDTH-1:0];
37
 
38
  initial
39
    $readmemh( SLAVE_RAM_INIT, ram );
40
 
41
  // --------------------------------------------------------------------
42
  //  
43
  generate
44
    case( DWIDTH )
45
      8:        begin
46
                  initial
47
                    $display( "###- wb_slave_model(): WISHBONE 8 BIT SLAVE MODEL INSTANTIATED " );
48
 
49
                  always @ (posedge clk_i)
50
                    if (we_i & cyc_i & stb_i & sel_i[0])
51
                      ram[adr_i] <= dat_i[7:0];
52
 
53
                  assign dat_o = ram[adr_i];
54
 
55
                end
56
 
57
      16:       begin
58
                  initial
59
                    $display( "###- wb_slave_model(): WISHBONE 16 BIT SLAVE MODEL INSTANTIATED " );
60
 
61
                  always @ (posedge clk_i)
62
                    if (we_i & cyc_i & stb_i & sel_i[0])
63
                      ram[{adr_i[AWIDTH-1:1], 1'b0}] <= dat_i[7:0];
64
 
65
                  always @ (posedge clk_i)
66
                    if (we_i & cyc_i & stb_i & sel_i[1])
67
                      ram[{adr_i[AWIDTH-1:1], 1'b1}] <= dat_i[15:8];
68
 
69
                  assign dat_o = { ram[{adr_i[AWIDTH-1:1], 1'b1}], ram[{adr_i[AWIDTH-1:1], 1'b0}] };
70
 
71
                end
72
 
73
      32:       begin
74
                  initial
75
                    $display( "###- wb_slave_model(): WISHBONE 32 BIT SLAVE MODEL INSTANTIATED " );
76
 
77
                  always @ (posedge clk_i)
78
                    if (we_i & cyc_i & stb_i & sel_i[0])
79
                      ram[{adr_i[AWIDTH-1:2], 2'b00}] <= dat_i[7:0];
80
 
81
                  always @ (posedge clk_i)
82
                    if (we_i & cyc_i & stb_i & sel_i[1])
83
                      ram[{adr_i[AWIDTH-1:2], 2'b01}] <= dat_i[15:8];
84
 
85
                  always @ (posedge clk_i)
86
                    if (we_i & cyc_i & stb_i & sel_i[2])
87
                      ram[{adr_i[AWIDTH-1:2], 2'b10}] <= dat_i[23:16];
88
 
89
                  always @ (posedge clk_i)
90
                    if (we_i & cyc_i & stb_i & sel_i[3])
91
                      ram[{adr_i[AWIDTH-1:2], 2'b11}] <= dat_i[31:24];
92
 
93
                  assign dat_o = { ram[{adr_i[AWIDTH-1:2], 2'b11}], ram[{adr_i[AWIDTH-1:2], 2'b10}], ram[{adr_i[AWIDTH-1:2], 2'b01}], ram[{adr_i[AWIDTH-1:2], 2'b00}] };
94
 
95
                end
96
 
97
      default:  begin
98
                  localparam SLAVE_SIZE = -1;
99
                  initial
100
                    begin
101
                      $display( "!!!- wb_slave_model(): invalad DWIDTH parameter" );
102
                      $stop();
103
                    end
104
                end
105
    endcase
106
  endgenerate
107
 
108
 
109
  // --------------------------------------------------------------------
110
  //  ack delay
111
  reg ack_delayed;
112
 
113
  initial
114
    ack_delayed = 1'b0;
115
 
116
  always @(posedge clk_i or cyc_i or stb_i)
117
    begin
118
      if(cyc_i & stb_i)
119
        begin
120
          ack_delayed = 1'b0;
121
          repeat(ACK_DELAY) @(posedge clk_i);
122
          if(cyc_i & stb_i)
123
            ack_delayed = 1'b1;
124
          else
125
            ack_delayed = 1'b0;
126
        end
127
      else
128
        ack_delayed = 1'b0;
129
    end
130
 
131
  // --------------------------------------------------------------------
132
  //  assign outputs  
133
  assign ack_o = ack_delayed;
134
  assign err_o = 1'b0;
135
  assign rty_o = 1'b0;
136
 
137
 
138 2 qaztronic
endmodule

powered by: WebSVN 2.1.0

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