1 |
2 |
rehayes |
////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
//
|
3 |
|
|
// WISHBONE revB.2 compliant Programable Interrupt Timer - Top-level
|
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_top #(parameter ARST_LVL = 1'b0, // asynchronous reset level
|
40 |
|
|
parameter PRE_COUNT_SIZE = 15, // Prescale Counter size
|
41 |
|
|
parameter COUNT_SIZE = 16, // Main counter size
|
42 |
|
|
parameter DECADE_CNTR = 1'b1, // Prescale rollover decode
|
43 |
|
|
parameter NO_PRESCALE = 1'b0, // Remove prescale function
|
44 |
10 |
rehayes |
parameter SINGLE_CYCLE = 1'b0, // No bus wait state added
|
45 |
2 |
rehayes |
parameter DWIDTH = 16) // Data bus width
|
46 |
|
|
(
|
47 |
|
|
// Wishbone Signals
|
48 |
|
|
output [DWIDTH-1:0] wb_dat_o, // databus output
|
49 |
|
|
output wb_ack_o, // bus cycle acknowledge output
|
50 |
|
|
input wb_clk_i, // master clock input
|
51 |
|
|
input wb_rst_i, // synchronous active high reset
|
52 |
|
|
input arst_i, // asynchronous reset
|
53 |
|
|
input [2:0] wb_adr_i, // lower address bits
|
54 |
|
|
input [DWIDTH-1:0] wb_dat_i, // databus input
|
55 |
|
|
input wb_we_i, // write enable input
|
56 |
|
|
input wb_stb_i, // stobe/core select signal
|
57 |
|
|
input wb_cyc_i, // valid bus cycle input
|
58 |
|
|
input [1:0] wb_sel_i, // Select byte in word bus transaction
|
59 |
|
|
// PIT IO Signals
|
60 |
|
|
output pit_o, // PIT output pulse
|
61 |
|
|
output pit_irq_o, // PIT interrupt request signal output
|
62 |
|
|
output cnt_flag_o, // PIT Flag Out
|
63 |
|
|
output cnt_sync_o, // PIT Master Enable for Slave PIT's
|
64 |
|
|
input ext_sync_i // Counter enable from Master PIT
|
65 |
|
|
);
|
66 |
|
|
|
67 |
|
|
wire [COUNT_SIZE-1:0] mod_value; // Main Counter Modulo
|
68 |
|
|
wire [COUNT_SIZE-1:0] cnt_n; // PIT Counter Value
|
69 |
|
|
wire async_rst_b; // Asyncronous reset
|
70 |
|
|
wire sync_reset; // Syncronous reset
|
71 |
|
|
wire [ 3:0] write_regs; // Control register write strobes
|
72 |
|
|
wire prescale_out; //
|
73 |
|
|
wire pit_flg_clr; // Clear PIT Rollover Status Bit
|
74 |
|
|
wire pit_slave; // PIT in Slave Mode, ext_sync_i selected
|
75 |
|
|
wire [ 3:0] pit_pre_scl; // Prescaler modulo
|
76 |
|
|
wire counter_sync; //
|
77 |
|
|
|
78 |
|
|
// Wishbone Bus interface
|
79 |
|
|
pit_wb_bus #(.ARST_LVL(ARST_LVL),
|
80 |
10 |
rehayes |
.SINGLE_CYCLE(SINGLE_CYCLE),
|
81 |
2 |
rehayes |
.DWIDTH(DWIDTH))
|
82 |
|
|
wishbone(
|
83 |
|
|
.wb_dat_o ( wb_dat_o ),
|
84 |
|
|
.wb_ack_o ( wb_ack_o ),
|
85 |
|
|
.wb_clk_i ( wb_clk_i ),
|
86 |
|
|
.wb_rst_i ( wb_rst_i ),
|
87 |
|
|
.arst_i ( arst_i ),
|
88 |
|
|
.wb_adr_i ( wb_adr_i ),
|
89 |
|
|
.wb_dat_i ( wb_dat_i ),
|
90 |
|
|
.wb_we_i ( wb_we_i ),
|
91 |
|
|
.wb_stb_i ( wb_stb_i ),
|
92 |
|
|
.wb_cyc_i ( wb_cyc_i ),
|
93 |
|
|
.wb_sel_i ( wb_sel_i ),
|
94 |
|
|
|
95 |
|
|
// outputs
|
96 |
|
|
.write_regs ( write_regs ),
|
97 |
|
|
.sync_reset ( sync_reset ),
|
98 |
|
|
// inputs
|
99 |
|
|
.async_rst_b ( async_rst_b ),
|
100 |
|
|
.irq_source ( cnt_flag_o ),
|
101 |
|
|
.read_regs ( // in -- status register bits
|
102 |
|
|
{ cnt_n,
|
103 |
|
|
mod_value,
|
104 |
|
|
{pit_slave, DECADE_CNTR, NO_PRESCALE, 1'b0, pit_pre_scl,
|
105 |
|
|
5'b0, cnt_flag_o, pit_ien, cnt_sync_o}
|
106 |
|
|
}
|
107 |
|
|
)
|
108 |
|
|
);
|
109 |
|
|
|
110 |
|
|
// -----------------------------------------------------------------------------
|
111 |
|
|
pit_regs #(.ARST_LVL(ARST_LVL),
|
112 |
|
|
.COUNT_SIZE(COUNT_SIZE),
|
113 |
|
|
.NO_PRESCALE(NO_PRESCALE),
|
114 |
|
|
.DWIDTH(DWIDTH))
|
115 |
|
|
regs(
|
116 |
|
|
// outputs
|
117 |
|
|
.mod_value ( mod_value ),
|
118 |
|
|
.pit_pre_scl ( pit_pre_scl ),
|
119 |
|
|
.pit_slave ( pit_slave ),
|
120 |
|
|
.pit_flg_clr ( pit_flg_clr ),
|
121 |
|
|
.pit_ien ( pit_ien ),
|
122 |
|
|
.cnt_sync_o ( cnt_sync_o ),
|
123 |
|
|
.pit_irq_o ( pit_irq_o ),
|
124 |
|
|
// inputs
|
125 |
|
|
.async_rst_b ( async_rst_b ),
|
126 |
|
|
.sync_reset ( sync_reset ),
|
127 |
|
|
.bus_clk ( wb_clk_i ),
|
128 |
|
|
.write_bus ( wb_dat_i ),
|
129 |
|
|
.write_regs ( write_regs ),
|
130 |
|
|
.cnt_flag_o ( cnt_flag_o )
|
131 |
|
|
);
|
132 |
|
|
|
133 |
|
|
// -----------------------------------------------------------------------------
|
134 |
|
|
pit_prescale #(.COUNT_SIZE(PRE_COUNT_SIZE),
|
135 |
|
|
.DECADE_CNTR(DECADE_CNTR),
|
136 |
|
|
.NO_PRESCALE(NO_PRESCALE))
|
137 |
|
|
prescale(
|
138 |
|
|
// outputs
|
139 |
|
|
.prescale_out ( prescale_out ),
|
140 |
|
|
.counter_sync ( counter_sync ),
|
141 |
|
|
// inputs
|
142 |
|
|
.async_rst_b ( async_rst_b ),
|
143 |
|
|
.sync_reset ( sync_reset ),
|
144 |
|
|
.bus_clk ( wb_clk_i ),
|
145 |
|
|
.cnt_sync_o ( cnt_sync_o ),
|
146 |
|
|
.ext_sync_i ( ext_sync_i ),
|
147 |
|
|
.pit_slave ( pit_slave ),
|
148 |
|
|
.divisor ( pit_pre_scl )
|
149 |
|
|
);
|
150 |
|
|
|
151 |
|
|
// -----------------------------------------------------------------------------
|
152 |
|
|
pit_count #(.COUNT_SIZE(COUNT_SIZE))
|
153 |
|
|
counter(
|
154 |
|
|
// outputs
|
155 |
|
|
.cnt_n ( cnt_n ),
|
156 |
|
|
.cnt_flag_o ( cnt_flag_o ),
|
157 |
|
|
.pit_o ( pit_o ),
|
158 |
|
|
// inputs
|
159 |
|
|
.async_rst_b ( async_rst_b ),
|
160 |
|
|
.sync_reset ( sync_reset ),
|
161 |
|
|
.bus_clk ( wb_clk_i ),
|
162 |
|
|
.counter_sync ( counter_sync ),
|
163 |
|
|
.prescale_out ( prescale_out ),
|
164 |
|
|
.pit_flg_clr ( pit_flg_clr ),
|
165 |
|
|
.mod_value ( mod_value )
|
166 |
|
|
);
|
167 |
|
|
|
168 |
|
|
endmodule // pit_top
|