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

Subversion Repositories pit

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

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 18 rehayes
  output reg  [DWIDTH-1:0] wb_dat_o,     // databus output - Pseudo Register
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 18 rehayes
  reg        bus_wait_state;  // Holdoff wb_ack_o for one clock to add wait state
66
  reg  [2:0] addr_latch;      // Capture WISHBONE Address 
67 2 rehayes
 
68
  // Wires
69 18 rehayes
  wire       eight_bit_bus;
70
  wire       module_sel;      // This module is selected for bus transaction
71
  wire       wb_wacc;         // WISHBONE Write Strobe
72
  wire       wb_racc;         // WISHBONE Read Access (Clock gating signal)
73
  wire [2:0] address;         // Select either direct or latched address
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 17 rehayes
  assign wb_ack_o   = SINGLE_CYCLE ? module_sel : (bus_wait_state && module_sel);
90 18 rehayes
  assign address    = SINGLE_CYCLE ? wb_adr_i : addr_latch;
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 18 rehayes
  // Capture address in first cycle of WISHBONE Bus tranaction
103
  //  Only used when Wait states are enabled
104 2 rehayes
  always @(posedge wb_clk_i)
105 18 rehayes
    if ( module_sel )                  // Clock gate for power saving
106
      addr_latch <= wb_adr_i;
107 12 rehayes
 
108
  // WISHBONE Read Data Mux
109
  always @*
110 18 rehayes
      case ({eight_bit_bus, address}) // synopsys parallel_case
111 2 rehayes
      // 8 bit Bus, 8 bit Granularity
112 18 rehayes
      4'b1_000: wb_dat_o = read_regs[ 7: 0];  // 8 bit read address 0
113
      4'b1_001: wb_dat_o = read_regs[15: 8];  // 8 bit read address 1
114
      4'b1_010: wb_dat_o = read_regs[23:16];  // 8 bit read address 2
115
      4'b1_011: wb_dat_o = read_regs[31:24];  // 8 bit read address 3
116
      4'b1_100: wb_dat_o = read_regs[39:32];  // 8 bit read address 4
117
      4'b1_101: wb_dat_o = read_regs[47:40];  // 8 bit read address 5
118 2 rehayes
      // 16 bit Bus, 16 bit Granularity
119 18 rehayes
      4'b0_000: wb_dat_o = read_regs[15: 0];  // 16 bit read access address 0
120
      4'b0_001: wb_dat_o = read_regs[31:16];
121
      4'b0_010: wb_dat_o = read_regs[47:32];
122 2 rehayes
    endcase
123
 
124
  // generate wishbone write register strobes -- one hot if 8 bit bus
125
  always @*
126
    begin
127
      write_regs = 0;
128
      if (wb_wacc)
129 18 rehayes
        case ({eight_bit_bus, address}) // synopsys parallel_case
130 2 rehayes
           // 8 bit Bus, 8 bit Granularity
131
           4'b1_000 : write_regs = 4'b0001;
132
           4'b1_001 : write_regs = 4'b0010;
133
           4'b1_010 : write_regs = 4'b0100;
134
           4'b1_011 : write_regs = 4'b1000;
135
           // 16 bit Bus, 16 bit Granularity
136
           4'b0_000 : write_regs = 4'b0011;
137
           4'b0_001 : write_regs = 4'b1100;
138
           default: ;
139
        endcase
140
    end
141
 
142
 
143
endmodule  // pit_wb_bus

powered by: WebSVN 2.1.0

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