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

Subversion Repositories pit

[/] [pit/] [trunk/] [rtl/] [sys_verilog/] [pit_wb_bus.sv] - Blame information for rev 24

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 21 rehayes
////////////////////////////////////////////////////////////////////////////////
2
//
3
//  WISHBONE revB.2 compliant Programable Interrupt Timer - Bus interface
4
//
5
//  Author: Bob Hayes
6
//          rehayes@opencores.org
7
//
8
//  Downloaded from: http://www.opencores.org/projects/pit.....
9
//
10
////////////////////////////////////////////////////////////////////////////////
11
// Copyright (c) 2011, Robert Hayes
12
//
13
// All rights reserved.
14
//
15
// Redistribution and use in source and binary forms, with or without
16
// modification, are permitted provided that the following conditions are met:
17
//     * Redistributions of source code must retain the above copyright
18
//       notice, this list of conditions and the following disclaimer.
19
//     * Redistributions in binary form must reproduce the above copyright
20
//       notice, this list of conditions and the following disclaimer in the
21
//       documentation and/or other materials provided with the distribution.
22
//     * Neither the name of the  nor the
23
//       names of its contributors may be used to endorse or promote products
24
//       derived from this software without specific prior written permission.
25
//
26
// THIS SOFTWARE IS PROVIDED BY Robert Hayes ''AS IS'' AND ANY
27
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29
// DISCLAIMED. IN NO EVENT SHALL Robert Hayes BE LIABLE FOR ANY
30
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
33
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
////////////////////////////////////////////////////////////////////////////////
37
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
38
 
39 24 rehayes
interface wishbone_if #(parameter D_WIDTH = 16,
40
                        parameter A_WIDTH = 3)
41
 
42
  // These signals maintain their direction without regard to master or slave
43
  //  Some signals may not be connected in every instance of the interface usage
44
  (logic [D_WIDTH-1:0] wb_dat_i,  // databus input
45
   logic               wb_clk,    // master clock input
46
 
47
   // These signals will change direction based on interface usage
48
   logic               arst,        // asynchronous reset
49
   logic               wb_rst,      // synchronous active high reset
50
   logic [A_WIDTH-1:0] wb_adr,      // lower address bits
51
   logic               wb_we,       // write enable input
52
   logic               wb_cyc,      // valid bus cycle input
53
   logic [2:0]         wb_sel       // Select bytes in word bus transaction
54
  );
55
 
56
  // Define the signal directions when the interface is used as a slave
57
  modport slave (input   wb_clk,
58
                         arst,
59
                         wb_rst,
60
                         wb_adr,
61
                         wb_dat_i,
62
                         wb_we,
63
                         wb_cyc,
64
                         wb_sel);
65
 
66
  // define the signal directions when the interface is used as a master
67
  modport master (output wb_adr,
68
                         wb_we,
69
                         wb_cyc,
70
                         wb_sel,
71
                  input  wb_clk,
72
                         wb_dat_i,
73
                         arst,
74
                         wb_rst);
75
 
76
endinterface  // wishbone_if
77
 
78
module pit_wb_bus #(parameter D_WIDTH = 16,
79
                    parameter S_WIDTH = 2,
80
                    parameter A_WIDTH = 3,
81
                    parameter ARST_LVL = 1'b0,      // asynchronous reset level
82
                    parameter SINGLE_CYCLE = 1'b0)  // Add a wait state to bus transcation
83 21 rehayes
  (
84
  // Wishbone Signals
85 24 rehayes
  wishbone_if.slave          wb,          // Define the interface instance name
86
  output logic [D_WIDTH-1:0] wb_dat_o,    // databus output - Pseudo Register
87
  output logic               wb_ack,      // bus cycle acknowledge output
88
  input  logic               wb_stb,      // stobe/core select signal
89 21 rehayes
  // PIT Control Signals
90 24 rehayes
  output logic       [ 3:0] write_regs,  // Decode write control register
91
  output                    async_rst_b, //
92
  output                    sync_reset,  //
93
  input                     irq_source,  //
94
  input              [47:0] read_regs    // status register bits
95 21 rehayes
  );
96
 
97
 
98
  // registers
99 24 rehayes
  logic       bus_wait_state;  // Holdoff wb_ack for one clock to add wait state
100 21 rehayes
  logic [2:0] addr_latch;      // Capture WISHBONE Address
101
 
102
  // Wires
103
  logic       eight_bit_bus;
104
  logic       module_sel;      // This module is selected for bus transaction
105
  logic       wb_wacc;         // WISHBONE Write Strobe
106
  logic       wb_racc;         // WISHBONE Read Access (Clock gating signal)
107
  logic [2:0] address;         // Select either direct or latched address
108
 
109
  //
110
  // module body
111
  //
112
 
113
  // generate internal resets
114 24 rehayes
  assign eight_bit_bus = (D_WIDTH == 8);
115 21 rehayes
 
116 24 rehayes
  assign async_rst_b = wb.arst ^ ARST_LVL;
117
  assign sync_reset  = wb.wb_rst;
118 21 rehayes
 
119
  // generate wishbone signals
120 24 rehayes
  assign module_sel = wb.wb_cyc && wb_stb;
121
  assign wb_wacc    = module_sel && wb.wb_we && (wb_ack || SINGLE_CYCLE);
122
  assign wb_racc    = module_sel && !wb.wb_we;
123
  assign wb_ack     = SINGLE_CYCLE ? module_sel : (bus_wait_state && module_sel);
124
  assign address    = SINGLE_CYCLE ? wb.wb_adr : addr_latch;
125 21 rehayes
 
126
  // generate acknowledge output signal, By using register all accesses takes two cycles.
127
  //  Accesses in back to back clock cycles are not possable.
128 24 rehayes
  always_ff @(posedge wb.wb_clk or negedge async_rst_b)
129 21 rehayes
    if (!async_rst_b)
130
      bus_wait_state <=  1'b0;
131
    else if (sync_reset)
132
      bus_wait_state <=  1'b0;
133
    else
134
      bus_wait_state <=  module_sel && !bus_wait_state;
135
 
136
  // Capture address in first cycle of WISHBONE Bus tranaction
137
  //  Only used when Wait states are enabled
138 24 rehayes
  //  Synthesis tool should be enabled to remove these registers in SINGLE_CYCLE mode
139
  always_ff @(posedge wb.wb_clk)
140 21 rehayes
    if ( module_sel )                  // Clock gate for power saving
141 24 rehayes
      addr_latch <= wb.wb_adr;
142 21 rehayes
 
143
  // WISHBONE Read Data Mux
144 22 rehayes
  always_comb
145 21 rehayes
      case ({eight_bit_bus, address}) // synopsys parallel_case
146
      // 8 bit Bus, 8 bit Granularity
147
      4'b1_000: wb_dat_o = read_regs[ 7: 0];  // 8 bit read address 0
148
      4'b1_001: wb_dat_o = read_regs[15: 8];  // 8 bit read address 1
149
      4'b1_010: wb_dat_o = read_regs[23:16];  // 8 bit read address 2
150
      4'b1_011: wb_dat_o = read_regs[31:24];  // 8 bit read address 3
151
      4'b1_100: wb_dat_o = read_regs[39:32];  // 8 bit read address 4
152
      4'b1_101: wb_dat_o = read_regs[47:40];  // 8 bit read address 5
153
      // 16 bit Bus, 16 bit Granularity
154
      4'b0_000: wb_dat_o = read_regs[15: 0];  // 16 bit read access address 0
155
      4'b0_001: wb_dat_o = read_regs[31:16];
156
      4'b0_010: wb_dat_o = read_regs[47:32];
157 24 rehayes
      default:  wb_dat_o = '0;
158 21 rehayes
    endcase
159
 
160
  // generate wishbone write register strobes -- one hot if 8 bit bus
161 22 rehayes
  always_comb
162 21 rehayes
    begin
163
      write_regs = 0;
164
      if (wb_wacc)
165
        case ({eight_bit_bus, address}) // synopsys parallel_case
166
           // 8 bit Bus, 8 bit Granularity
167
           4'b1_000 : write_regs = 4'b0001;
168
           4'b1_001 : write_regs = 4'b0010;
169
           4'b1_010 : write_regs = 4'b0100;
170
           4'b1_011 : write_regs = 4'b1000;
171
           // 16 bit Bus, 16 bit Granularity
172
           4'b0_000 : write_regs = 4'b0011;
173
           4'b0_001 : write_regs = 4'b1100;
174
           default: ;
175
        endcase
176
    end
177
 
178
 
179
endmodule  // pit_wb_bus

powered by: WebSVN 2.1.0

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