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

Subversion Repositories pit

[/] [pit/] [trunk/] [rtl/] [verilog/] [pit_wb_bus.v] - Blame information for rev 12

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

Line No. Rev Author Line
1 2 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) 2009, 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 <organization> 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
module pit_wb_bus #(parameter ARST_LVL = 1'b0,    // asynchronous reset level
40 10 rehayes
                    parameter DWIDTH = 16,
41
                    parameter SINGLE_CYCLE = 1'b0)
42 2 rehayes
  (
43
  // Wishbone Signals
44 12 rehayes
  output      [DWIDTH-1:0] wb_dat_o,     // databus output
45 10 rehayes
  output                   wb_ack_o,     // bus cycle acknowledge output
46 2 rehayes
  input                    wb_clk_i,     // master clock input
47
  input                    wb_rst_i,     // synchronous active high reset
48
  input                    arst_i,       // asynchronous reset
49
  input             [ 2:0] wb_adr_i,     // lower address bits
50
  input       [DWIDTH-1:0] wb_dat_i,     // databus input
51
  input                    wb_we_i,      // write enable input
52
  input                    wb_stb_i,     // stobe/core select signal
53
  input                    wb_cyc_i,     // valid bus cycle input
54
  input              [1:0] wb_sel_i,     // Select byte in word bus transaction
55
  // PIT Control Signals
56
  output reg        [ 3:0] write_regs,   // Decode write control register
57
  output                   async_rst_b,  //
58
  output                   sync_reset,   //
59
  input                    irq_source,   //
60
  input             [47:0] read_regs     // status register bits
61
  );
62
 
63
 
64
  // registers
65 12 rehayes
  reg                bus_wait_state;  // Holdoff wb_ack_o for one clock to add wait state
66
  reg  [DWIDTH-1:0]  rd_data_mux;     // Pseudo Register, WISHBONE Read Data Mux
67
  reg  [DWIDTH-1:0]  rd_data_reg;     // Latch for WISHBONE Read Data
68 2 rehayes
 
69
  // Wires
70
  wire   eight_bit_bus;
71 12 rehayes
  wire   module_sel;      // This module is selected for bus transaction
72 10 rehayes
  wire   wb_wacc;         // WISHBONE Write Strobe
73 12 rehayes
  wire   wb_racc;         // WISHBONE Read Access (Clock gating signal)
74 2 rehayes
 
75
  //
76
  // module body
77
  //
78
 
79
  // generate internal resets
80
  assign eight_bit_bus = (DWIDTH == 8);
81
 
82
  assign async_rst_b = arst_i ^ ARST_LVL;
83
  assign sync_reset = wb_rst_i;
84
 
85
  // generate wishbone signals
86 12 rehayes
  assign module_sel = wb_cyc_i && wb_stb_i;
87
  assign wb_wacc    = module_sel && wb_we_i && (wb_ack_o || SINGLE_CYCLE);
88
  assign wb_racc    = module_sel && !wb_we_i;
89
  assign wb_ack_o   = SINGLE_CYCLE ? module_sel : bus_wait_state;
90
  assign wb_dat_o   = SINGLE_CYCLE ? rd_data_mux : rd_data_reg;
91 2 rehayes
 
92 10 rehayes
  // generate acknowledge output signal, By using register all accesses takes two cycles.
93
  //  Accesses in back to back clock cycles are not possable.
94
  always @(posedge wb_clk_i or negedge async_rst_b)
95
    if (!async_rst_b)
96
      bus_wait_state <=  1'b0;
97
    else if (sync_reset)
98
      bus_wait_state <=  1'b0;
99
    else
100 12 rehayes
      bus_wait_state <=  module_sel && !bus_wait_state;
101 2 rehayes
 
102
  // assign data read bus -- DAT_O
103
  always @(posedge wb_clk_i)
104 12 rehayes
    if ( wb_racc )                     // Clock gate for power saving
105
      rd_data_reg <= rd_data_mux;
106
 
107
  // WISHBONE Read Data Mux
108
  always @*
109
      case ({eight_bit_bus, wb_adr_i}) // synopsys parallel_case
110 2 rehayes
      // 8 bit Bus, 8 bit Granularity
111 12 rehayes
      4'b1_000: rd_data_mux <= read_regs[ 7: 0];  // 8 bit read address 0
112
      4'b1_001: rd_data_mux <= read_regs[15: 8];  // 8 bit read address 1
113
      4'b1_010: rd_data_mux <= read_regs[23:16];  // 8 bit read address 2
114
      4'b1_011: rd_data_mux <= read_regs[31:24];  // 8 bit read address 3
115
      4'b1_100: rd_data_mux <= read_regs[39:32];  // 8 bit read address 4
116
      4'b1_101: rd_data_mux <= read_regs[47:40];  // 8 bit read address 5
117 2 rehayes
      // 16 bit Bus, 16 bit Granularity
118 12 rehayes
      4'b0_000: rd_data_mux <= read_regs[15: 0];  // 16 bit read access address 0
119
      4'b0_001: rd_data_mux <= read_regs[31:16];
120
      4'b0_010: rd_data_mux <= read_regs[47:32];
121 2 rehayes
    endcase
122
 
123
  // generate wishbone write register strobes -- one hot if 8 bit bus
124
  always @*
125
    begin
126
      write_regs = 0;
127
      if (wb_wacc)
128
        case ({eight_bit_bus, wb_adr_i}) // synopsys parallel_case
129
           // 8 bit Bus, 8 bit Granularity
130
           4'b1_000 : write_regs = 4'b0001;
131
           4'b1_001 : write_regs = 4'b0010;
132
           4'b1_010 : write_regs = 4'b0100;
133
           4'b1_011 : write_regs = 4'b1000;
134
           // 16 bit Bus, 16 bit Granularity
135
           4'b0_000 : write_regs = 4'b0011;
136
           4'b0_001 : write_regs = 4'b1100;
137
           default: ;
138
        endcase
139
    end
140
 
141
 
142
endmodule  // pit_wb_bus

powered by: WebSVN 2.1.0

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