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

Subversion Repositories wb_size_bridge

[/] [wb_size_bridge/] [trunk/] [tb/] [models/] [wb_slave_model.v] - Blame information for rev 4

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

Line No. Rev Author Line
1 4 qaztronic
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
4
////                                                              ////
5
//// This source file may be used and distributed without         ////
6
//// restriction provided that this copyright statement is not    ////
7
//// removed from the file and that any derivative work contains  ////
8
//// the original copyright notice and the associated disclaimer. ////
9
////                                                              ////
10
//// This source file is free software; you can redistribute it   ////
11
//// and/or modify it under the terms of the GNU Lesser General   ////
12
//// Public License as published by the Free Software Foundation; ////
13
//// either version 2.1 of the License, or (at your option) any   ////
14
//// later version.                                               ////
15
////                                                              ////
16
//// This source is distributed in the hope that it will be       ////
17
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
18
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
19
//// PURPOSE.  See the GNU Lesser General Public License for more ////
20
//// details.                                                     ////
21
////                                                              ////
22
//// You should have received a copy of the GNU Lesser General    ////
23
//// Public License along with this source; if not, download it   ////
24
//// from http://www.opencores.org/lgpl.shtml                     ////
25
////                                                              ////
26
//////////////////////////////////////////////////////////////////////
27
 
28
`timescale 1ns/10ps
29
 
30
 
31
module wb_slave_model(  clk_i, rst_i, dat_o, dat_i, adr_i,
32
                        cyc_i, stb_i, we_i, sel_i,
33
                        ack_o, err_o, rty_o );
34
 
35
  parameter DWIDTH    = 8;
36
  parameter AWIDTH    = 8;
37
  parameter ACK_DELAY = 2;
38
  parameter SLAVE_RAM_INIT = "wb_slave_model.txt";
39
 
40
  input                         clk_i;
41
  input                         rst_i;
42
  output [DWIDTH-1:0]           dat_o;
43
  input  [DWIDTH-1:0]           dat_i;
44
  input  [AWIDTH-1:0]           adr_i;
45
  input                         cyc_i;
46
  input                         stb_i;
47
  input                         we_i;
48
  input  [( (DWIDTH/8) - 1 ):0] sel_i;
49
  output                        ack_o;
50
  output                        err_o;
51
  output                        rty_o;
52
 
53
 
54
 
55
 
56
 
57
  // --------------------------------------------------------------------
58
  //  slave ram
59
  reg [7:0] ram[2**AWIDTH-1:0];
60
 
61
  initial
62
    $readmemh( SLAVE_RAM_INIT, ram );
63
 
64
  // --------------------------------------------------------------------
65
  //  
66
  generate
67
    case( DWIDTH )
68
      8:        begin
69
                  initial
70
                    $display( "###- wb_slave_model(): WISHBONE 8 BIT SLAVE MODEL INSTANTIATED " );
71
 
72
                  always @ (posedge clk_i)
73
                    if (we_i & cyc_i & stb_i & sel_i[0])
74
                      ram[adr_i] <= dat_i[7:0];
75
 
76
                  assign dat_o = ram[adr_i];
77
 
78
                end
79
 
80
      16:       begin
81
                  initial
82
                    $display( "###- wb_slave_model(): WISHBONE 16 BIT SLAVE MODEL INSTANTIATED " );
83
 
84
                  always @ (posedge clk_i)
85
                    if (we_i & cyc_i & stb_i & sel_i[0])
86
                      ram[{adr_i[AWIDTH-1:1], 1'b0}] <= dat_i[7:0];
87
 
88
                  always @ (posedge clk_i)
89
                    if (we_i & cyc_i & stb_i & sel_i[1])
90
                      ram[{adr_i[AWIDTH-1:1], 1'b1}] <= dat_i[15:8];
91
 
92
                  assign dat_o = { ram[{adr_i[AWIDTH-1:1], 1'b1}], ram[{adr_i[AWIDTH-1:1], 1'b0}] };
93
 
94
                end
95
 
96
      32:       begin
97
                  initial
98
                    begin
99
                      $display( "###- wb_slave_model(): WISHBONE 32 BIT SLAVE MODEL INSTANTIATED " );
100
                      $display( "###- wb_slave_model(): Not yet supported " );
101
                      $stop();
102
                    end
103
                end
104
 
105
      default:  begin
106
                  localparam SLAVE_SIZE = -1;
107
                  initial
108
                    begin
109
                      $display( "!!!- wb_slave_model(): invalad DWIDTH parameter" );
110
                      $stop();
111
                    end
112
                end
113
    endcase
114
  endgenerate
115
 
116
 
117
  // --------------------------------------------------------------------
118
  //  ack delay
119
  reg ack_delayed;
120
 
121
  initial
122
    ack_delayed = 1'b0;
123
 
124
  always @(posedge clk_i or cyc_i or stb_i)
125
    begin
126
      if(cyc_i & stb_i)
127
        begin
128
          ack_delayed = 1'b0;
129
          repeat(ACK_DELAY) @(posedge clk_i);
130
          if(cyc_i & stb_i)
131
            ack_delayed = 1'b1;
132
          else
133
            ack_delayed = 1'b0;
134
        end
135
      else
136
        ack_delayed = 1'b0;
137
    end
138
 
139
  // --------------------------------------------------------------------
140
  //  assign outputs  
141
  assign ack_o = ack_delayed;
142
  assign err_o = 1'b0;
143
  assign rty_o = 1'b0;
144
 
145
 
146 2 qaztronic
endmodule

powered by: WebSVN 2.1.0

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