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

Subversion Repositories i2c_to_wb

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

powered by: WebSVN 2.1.0

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