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

Subversion Repositories wb4pb

[/] [wb4pb/] [trunk/] [rtl/] [wbm_picoblaze.v] - Blame information for rev 31

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ste.fis
////////////////////////////////////////////////////////////////////////////////
2
// This sourcecode is released under BSD license.
3
// Please see http://www.opensource.org/licenses/bsd-license.php for details!
4
////////////////////////////////////////////////////////////////////////////////
5
//
6
// Copyright (c) 2010, Stefan Fischer <Ste.Fis@OpenCores.org>
7
// All rights reserved.
8
//
9
// Redistribution and use in source and binary forms, with or without 
10
// modification, are permitted provided that the following conditions are met:
11
//
12
//  * Redistributions of source code must retain the above copyright notice, 
13
//    this list of conditions and the following disclaimer.
14
//  * Redistributions in binary form must reproduce the above copyright notice,
15
//    this list of conditions and the following disclaimer in the documentation
16 31 ste.fis
//    and/or other materials provided with the distribution.
17 2 ste.fis
//
18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
19
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
20
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
21
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 
22
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
23
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
24
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
25
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
26
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
27
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
28
// POSSIBILITY OF SUCH DAMAGE.
29
//
30
////////////////////////////////////////////////////////////////////////////////
31
// filename: wbm_picoblaze.v
32
// description: synthesizable wishbone master adapter for PicoBlaze (TM),
33
//              working together with "wb_wr" and "wb_rd" assembler subroutines
34
// todo4user: module should not be changed!
35
// version: 0.0.0
36
// changelog: - 0.0.0, initial release
37
//            - ...
38
////////////////////////////////////////////////////////////////////////////////
39
 
40
 
41
module wbm_picoblaze (
42
  rst,
43
  clk,
44
 
45
  wbm_cyc_o,
46
  wbm_stb_o,
47
  wbm_we_o,
48
  wbm_adr_o,
49
  wbm_dat_m2s_o,
50
  wbm_dat_s2m_i,
51
  wbm_ack_i,
52
 
53
  pb_port_id_i,
54
  pb_write_strobe_i,
55
  pb_out_port_i,
56
  pb_read_strobe_i,
57
  pb_in_port_o
58
);
59
 
60
  input rst;
61
  wire  rst;
62
  input clk;
63
  wire  clk;
64
 
65
  output wbm_cyc_o;
66 10 ste.fis
  wire   wbm_cyc_o;
67 2 ste.fis
  output wbm_stb_o;
68
  reg    wbm_stb_o;
69
  output wbm_we_o;
70
  reg    wbm_we_o;
71
  output[7:0] wbm_adr_o;
72
  reg   [7:0] wbm_adr_o;
73
  output[7:0] wbm_dat_m2s_o;
74
  reg   [7:0] wbm_dat_m2s_o;
75
  input[7:0] wbm_dat_s2m_i;
76
  wire [7:0] wbm_dat_s2m_i;
77
  input wbm_ack_i;
78
  wire  wbm_ack_i;
79
 
80
  input[7:0] pb_port_id_i;
81
  wire [7:0] pb_port_id_i;
82
  input pb_write_strobe_i;
83
  wire  pb_write_strobe_i;
84
  input[7:0] pb_out_port_i;
85
  wire [7:0] pb_out_port_i;
86
  input pb_read_strobe_i;
87
  wire  pb_read_strobe_i;
88
  output[7:0] pb_in_port_o;
89
  reg   [7:0] pb_in_port_o;
90
 
91
  reg[7:0] wb_buffer;
92
 
93
  parameter[7:0] WB_ACK_FLAG = 8'h01;
94
 
95
  parameter[1:0]
96
    S_IDLE = 2'b00,
97
    S_WAIT_ON_WB_ACK = 2'b01,
98
    S_SOFTWARE_HANDSHAKE = 2'b10,
99
    S_SOFTWARE_READ = 2'b11
100
  ;
101
  reg[1:0] state;
102
 
103 10 ste.fis
  assign wbm_cyc_o = wbm_stb_o;
104 2 ste.fis
 
105
  always@(posedge clk) begin
106
 
107
    case(state)
108
      S_IDLE:
109
        // setting up wishbone address, data and control signals from 
110
        // PicoBlaze (TM) signals
111
        if (pb_write_strobe_i) begin
112
          wbm_stb_o <= 1'b1;
113
          wbm_we_o <= 1'b1;
114
          wbm_adr_o <= pb_port_id_i;
115
          wbm_dat_m2s_o <= pb_out_port_i;
116
          state <= S_WAIT_ON_WB_ACK;
117
        end else if (pb_read_strobe_i) begin
118
          wbm_stb_o <= 1'b1;
119
          wbm_we_o <= 1'b0;
120
          wbm_adr_o <= pb_port_id_i;
121
          state <= S_WAIT_ON_WB_ACK;
122
        end
123
      S_WAIT_ON_WB_ACK:
124
        // waiting on slave peripheral to complete wishbone transfer cycle
125
        if (wbm_ack_i) begin
126
          wbm_stb_o <= 1'b0;
127
          wb_buffer <= wbm_dat_s2m_i;
128
          pb_in_port_o <= WB_ACK_FLAG;
129
          state <= S_SOFTWARE_HANDSHAKE;
130
        end
131
      S_SOFTWARE_HANDSHAKE:
132
        // software recognition of wishbone handshake
133 10 ste.fis
        if (pb_read_strobe_i)
134 2 ste.fis
          // transfer complete for a write access
135
          if (wbm_we_o) begin
136
            pb_in_port_o <= 8'h00;
137
            state <= S_IDLE;
138
          // presenting valid wishbone data to PicoBlaze (TM) port in read 
139
          // access
140
          end else begin
141
            pb_in_port_o <= wb_buffer;
142
            state <= S_SOFTWARE_READ;
143
          end
144
      S_SOFTWARE_READ:
145
        // transfer complete for a read access after software recognition of
146
        // wishbone data
147
        if (pb_read_strobe_i) begin
148
          pb_in_port_o <= 8'h00;
149
          state <= S_IDLE;
150
        end
151
      default: ;
152
    endcase
153
 
154
    if (rst) begin
155
      wbm_stb_o <= 1'b0;
156
      pb_in_port_o <= 8'h00;
157
      state <= S_IDLE;
158
    end
159
 
160
  end
161
 
162
endmodule

powered by: WebSVN 2.1.0

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