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

Subversion Repositories pit

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

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
  output reg  [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 10 rehayes
  reg    bus_wait_state;  // Holdoff wb_ack_o for one clock to add wait state
66 2 rehayes
 
67
  // Wires
68
  wire   eight_bit_bus;
69 10 rehayes
  wire   wb_wacc;         // WISHBONE Write Strobe
70 2 rehayes
 
71
  //
72
  // module body
73
  //
74
 
75
  // generate internal resets
76
  assign eight_bit_bus = (DWIDTH == 8);
77
 
78
  assign async_rst_b = arst_i ^ ARST_LVL;
79
  assign sync_reset = wb_rst_i;
80
 
81
  // generate wishbone signals
82 10 rehayes
  assign wb_wacc = wb_cyc_i && wb_stb_i && wb_we_i && (wb_ack_o || SINGLE_CYCLE);
83
  assign wb_ack_o = SINGLE_CYCLE ? wb_cyc_i && wb_stb_i : bus_wait_state;
84 2 rehayes
 
85 10 rehayes
  // generate acknowledge output signal, By using register all accesses takes two cycles.
86
  //  Accesses in back to back clock cycles are not possable.
87
  always @(posedge wb_clk_i or negedge async_rst_b)
88
    if (!async_rst_b)
89
      bus_wait_state <=  1'b0;
90
    else if (sync_reset)
91
      bus_wait_state <=  1'b0;
92
    else
93
      bus_wait_state <=  wb_cyc_i && wb_stb_i && !bus_wait_state;
94 2 rehayes
 
95
  // assign data read bus -- DAT_O
96
  always @(posedge wb_clk_i)
97
    case ({eight_bit_bus, wb_adr_i}) // synopsys parallel_case
98
      // 8 bit Bus, 8 bit Granularity
99
      4'b1_000: wb_dat_o <= read_regs[ 7: 0];  // 8 bit read address 0
100
      4'b1_001: wb_dat_o <= read_regs[15: 8];  // 8 bit read address 1
101
      4'b1_010: wb_dat_o <= read_regs[23:16];  // 8 bit read address 2
102
      4'b1_011: wb_dat_o <= read_regs[31:24];  // 8 bit read address 3
103
      4'b1_100: wb_dat_o <= read_regs[39:32];  // 8 bit read address 4
104
      4'b1_101: wb_dat_o <= read_regs[47:40];  // 8 bit read address 5
105
      // 16 bit Bus, 16 bit Granularity
106
      4'b0_000: wb_dat_o <= read_regs[15: 0];  // 16 bit read access address 0
107
      4'b0_001: wb_dat_o <= read_regs[31:16];
108
      4'b0_010: wb_dat_o <= read_regs[47:32];
109
    endcase
110
 
111
  // generate wishbone write register strobes -- one hot if 8 bit bus
112
  always @*
113
    begin
114
      write_regs = 0;
115
      if (wb_wacc)
116
        case ({eight_bit_bus, wb_adr_i}) // synopsys parallel_case
117
           // 8 bit Bus, 8 bit Granularity
118
           4'b1_000 : write_regs = 4'b0001;
119
           4'b1_001 : write_regs = 4'b0010;
120
           4'b1_010 : write_regs = 4'b0100;
121
           4'b1_011 : write_regs = 4'b1000;
122
           // 16 bit Bus, 16 bit Granularity
123
           4'b0_000 : write_regs = 4'b0011;
124
           4'b0_001 : write_regs = 4'b1100;
125
           default: ;
126
        endcase
127
    end
128
 
129
 
130
endmodule  // pit_wb_bus

powered by: WebSVN 2.1.0

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