////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
//
|
//
|
// WISHBONE revB.2 compliant Programable Interrupt Timer - Top-level
|
// WISHBONE revB.2 compliant Programable Interrupt Timer - Top-level
|
//
|
//
|
// Author: Bob Hayes
|
// Author: Bob Hayes
|
// rehayes@opencores.org
|
// rehayes@opencores.org
|
//
|
//
|
// Downloaded from: http://www.opencores.org/projects/pit.....
|
// Downloaded from: http://www.opencores.org/projects/pit.....
|
//
|
//
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
// Copyright (c) 2009, Robert Hayes
|
// Copyright (c) 2009, Robert Hayes
|
//
|
//
|
// All rights reserved.
|
// All rights reserved.
|
//
|
//
|
// Redistribution and use in source and binary forms, with or without
|
// Redistribution and use in source and binary forms, with or without
|
// modification, are permitted provided that the following conditions are met:
|
// modification, are permitted provided that the following conditions are met:
|
// * Redistributions of source code must retain the above copyright
|
// * Redistributions of source code must retain the above copyright
|
// notice, this list of conditions and the following disclaimer.
|
// notice, this list of conditions and the following disclaimer.
|
// * Redistributions in binary form must reproduce the above copyright
|
// * Redistributions in binary form must reproduce the above copyright
|
// notice, this list of conditions and the following disclaimer in the
|
// notice, this list of conditions and the following disclaimer in the
|
// documentation and/or other materials provided with the distribution.
|
// documentation and/or other materials provided with the distribution.
|
// * Neither the name of the <organization> nor the
|
// * Neither the name of the <organization> nor the
|
// names of its contributors may be used to endorse or promote products
|
// names of its contributors may be used to endorse or promote products
|
// derived from this software without specific prior written permission.
|
// derived from this software without specific prior written permission.
|
//
|
//
|
// THIS SOFTWARE IS PROVIDED BY Robert Hayes ''AS IS'' AND ANY
|
// THIS SOFTWARE IS PROVIDED BY Robert Hayes ''AS IS'' AND ANY
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
// DISCLAIMED. IN NO EVENT SHALL Robert Hayes BE LIABLE FOR ANY
|
// DISCLAIMED. IN NO EVENT SHALL Robert Hayes BE LIABLE FOR ANY
|
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
|
|
module pit_top #(parameter ARST_LVL = 1'b0, // asynchronous reset level
|
module pit_top #(parameter ARST_LVL = 1'b0, // asynchronous reset level
|
parameter PRE_COUNT_SIZE = 15, // Prescale Counter size
|
parameter PRE_COUNT_SIZE = 15, // Prescale Counter size
|
parameter COUNT_SIZE = 16, // Main counter size
|
parameter COUNT_SIZE = 16, // Main counter size
|
parameter DECADE_CNTR = 1'b1, // Prescale rollover decode
|
parameter DECADE_CNTR = 1'b1, // Prescale rollover decode
|
parameter NO_PRESCALE = 1'b0, // Remove prescale function
|
parameter NO_PRESCALE = 1'b0, // Remove prescale function
|
|
parameter SINGLE_CYCLE = 1'b0, // No bus wait state added
|
parameter DWIDTH = 16) // Data bus width
|
parameter DWIDTH = 16) // Data bus width
|
(
|
(
|
// Wishbone Signals
|
// Wishbone Signals
|
output [DWIDTH-1:0] wb_dat_o, // databus output
|
output [DWIDTH-1:0] wb_dat_o, // databus output
|
output wb_ack_o, // bus cycle acknowledge output
|
output wb_ack_o, // bus cycle acknowledge output
|
input wb_clk_i, // master clock input
|
input wb_clk_i, // master clock input
|
input wb_rst_i, // synchronous active high reset
|
input wb_rst_i, // synchronous active high reset
|
input arst_i, // asynchronous reset
|
input arst_i, // asynchronous reset
|
input [2:0] wb_adr_i, // lower address bits
|
input [2:0] wb_adr_i, // lower address bits
|
input [DWIDTH-1:0] wb_dat_i, // databus input
|
input [DWIDTH-1:0] wb_dat_i, // databus input
|
input wb_we_i, // write enable input
|
input wb_we_i, // write enable input
|
input wb_stb_i, // stobe/core select signal
|
input wb_stb_i, // stobe/core select signal
|
input wb_cyc_i, // valid bus cycle input
|
input wb_cyc_i, // valid bus cycle input
|
input [1:0] wb_sel_i, // Select byte in word bus transaction
|
input [1:0] wb_sel_i, // Select byte in word bus transaction
|
// PIT IO Signals
|
// PIT IO Signals
|
output pit_o, // PIT output pulse
|
output pit_o, // PIT output pulse
|
output pit_irq_o, // PIT interrupt request signal output
|
output pit_irq_o, // PIT interrupt request signal output
|
output cnt_flag_o, // PIT Flag Out
|
output cnt_flag_o, // PIT Flag Out
|
output cnt_sync_o, // PIT Master Enable for Slave PIT's
|
output cnt_sync_o, // PIT Master Enable for Slave PIT's
|
input ext_sync_i // Counter enable from Master PIT
|
input ext_sync_i // Counter enable from Master PIT
|
);
|
);
|
|
|
wire [COUNT_SIZE-1:0] mod_value; // Main Counter Modulo
|
wire [COUNT_SIZE-1:0] mod_value; // Main Counter Modulo
|
wire [COUNT_SIZE-1:0] cnt_n; // PIT Counter Value
|
wire [COUNT_SIZE-1:0] cnt_n; // PIT Counter Value
|
wire async_rst_b; // Asyncronous reset
|
wire async_rst_b; // Asyncronous reset
|
wire sync_reset; // Syncronous reset
|
wire sync_reset; // Syncronous reset
|
wire [ 3:0] write_regs; // Control register write strobes
|
wire [ 3:0] write_regs; // Control register write strobes
|
wire prescale_out; //
|
wire prescale_out; //
|
wire pit_flg_clr; // Clear PIT Rollover Status Bit
|
wire pit_flg_clr; // Clear PIT Rollover Status Bit
|
wire pit_slave; // PIT in Slave Mode, ext_sync_i selected
|
wire pit_slave; // PIT in Slave Mode, ext_sync_i selected
|
wire [ 3:0] pit_pre_scl; // Prescaler modulo
|
wire [ 3:0] pit_pre_scl; // Prescaler modulo
|
wire counter_sync; //
|
wire counter_sync; //
|
|
|
// Wishbone Bus interface
|
// Wishbone Bus interface
|
pit_wb_bus #(.ARST_LVL(ARST_LVL),
|
pit_wb_bus #(.ARST_LVL(ARST_LVL),
|
|
.SINGLE_CYCLE(SINGLE_CYCLE),
|
.DWIDTH(DWIDTH))
|
.DWIDTH(DWIDTH))
|
wishbone(
|
wishbone(
|
.wb_dat_o ( wb_dat_o ),
|
.wb_dat_o ( wb_dat_o ),
|
.wb_ack_o ( wb_ack_o ),
|
.wb_ack_o ( wb_ack_o ),
|
.wb_clk_i ( wb_clk_i ),
|
.wb_clk_i ( wb_clk_i ),
|
.wb_rst_i ( wb_rst_i ),
|
.wb_rst_i ( wb_rst_i ),
|
.arst_i ( arst_i ),
|
.arst_i ( arst_i ),
|
.wb_adr_i ( wb_adr_i ),
|
.wb_adr_i ( wb_adr_i ),
|
.wb_dat_i ( wb_dat_i ),
|
.wb_dat_i ( wb_dat_i ),
|
.wb_we_i ( wb_we_i ),
|
.wb_we_i ( wb_we_i ),
|
.wb_stb_i ( wb_stb_i ),
|
.wb_stb_i ( wb_stb_i ),
|
.wb_cyc_i ( wb_cyc_i ),
|
.wb_cyc_i ( wb_cyc_i ),
|
.wb_sel_i ( wb_sel_i ),
|
.wb_sel_i ( wb_sel_i ),
|
|
|
// outputs
|
// outputs
|
.write_regs ( write_regs ),
|
.write_regs ( write_regs ),
|
.sync_reset ( sync_reset ),
|
.sync_reset ( sync_reset ),
|
// inputs
|
// inputs
|
.async_rst_b ( async_rst_b ),
|
.async_rst_b ( async_rst_b ),
|
.irq_source ( cnt_flag_o ),
|
.irq_source ( cnt_flag_o ),
|
.read_regs ( // in -- status register bits
|
.read_regs ( // in -- status register bits
|
{ cnt_n,
|
{ cnt_n,
|
mod_value,
|
mod_value,
|
{pit_slave, DECADE_CNTR, NO_PRESCALE, 1'b0, pit_pre_scl,
|
{pit_slave, DECADE_CNTR, NO_PRESCALE, 1'b0, pit_pre_scl,
|
5'b0, cnt_flag_o, pit_ien, cnt_sync_o}
|
5'b0, cnt_flag_o, pit_ien, cnt_sync_o}
|
}
|
}
|
)
|
)
|
);
|
);
|
|
|
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
pit_regs #(.ARST_LVL(ARST_LVL),
|
pit_regs #(.ARST_LVL(ARST_LVL),
|
.COUNT_SIZE(COUNT_SIZE),
|
.COUNT_SIZE(COUNT_SIZE),
|
.NO_PRESCALE(NO_PRESCALE),
|
.NO_PRESCALE(NO_PRESCALE),
|
.DWIDTH(DWIDTH))
|
.DWIDTH(DWIDTH))
|
regs(
|
regs(
|
// outputs
|
// outputs
|
.mod_value ( mod_value ),
|
.mod_value ( mod_value ),
|
.pit_pre_scl ( pit_pre_scl ),
|
.pit_pre_scl ( pit_pre_scl ),
|
.pit_slave ( pit_slave ),
|
.pit_slave ( pit_slave ),
|
.pit_flg_clr ( pit_flg_clr ),
|
.pit_flg_clr ( pit_flg_clr ),
|
.pit_ien ( pit_ien ),
|
.pit_ien ( pit_ien ),
|
.cnt_sync_o ( cnt_sync_o ),
|
.cnt_sync_o ( cnt_sync_o ),
|
.pit_irq_o ( pit_irq_o ),
|
.pit_irq_o ( pit_irq_o ),
|
// inputs
|
// inputs
|
.async_rst_b ( async_rst_b ),
|
.async_rst_b ( async_rst_b ),
|
.sync_reset ( sync_reset ),
|
.sync_reset ( sync_reset ),
|
.bus_clk ( wb_clk_i ),
|
.bus_clk ( wb_clk_i ),
|
.write_bus ( wb_dat_i ),
|
.write_bus ( wb_dat_i ),
|
.write_regs ( write_regs ),
|
.write_regs ( write_regs ),
|
.cnt_flag_o ( cnt_flag_o )
|
.cnt_flag_o ( cnt_flag_o )
|
);
|
);
|
|
|
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
pit_prescale #(.COUNT_SIZE(PRE_COUNT_SIZE),
|
pit_prescale #(.COUNT_SIZE(PRE_COUNT_SIZE),
|
.DECADE_CNTR(DECADE_CNTR),
|
.DECADE_CNTR(DECADE_CNTR),
|
.NO_PRESCALE(NO_PRESCALE))
|
.NO_PRESCALE(NO_PRESCALE))
|
prescale(
|
prescale(
|
// outputs
|
// outputs
|
.prescale_out ( prescale_out ),
|
.prescale_out ( prescale_out ),
|
.counter_sync ( counter_sync ),
|
.counter_sync ( counter_sync ),
|
// inputs
|
// inputs
|
.async_rst_b ( async_rst_b ),
|
.async_rst_b ( async_rst_b ),
|
.sync_reset ( sync_reset ),
|
.sync_reset ( sync_reset ),
|
.bus_clk ( wb_clk_i ),
|
.bus_clk ( wb_clk_i ),
|
.cnt_sync_o ( cnt_sync_o ),
|
.cnt_sync_o ( cnt_sync_o ),
|
.ext_sync_i ( ext_sync_i ),
|
.ext_sync_i ( ext_sync_i ),
|
.pit_slave ( pit_slave ),
|
.pit_slave ( pit_slave ),
|
.divisor ( pit_pre_scl )
|
.divisor ( pit_pre_scl )
|
);
|
);
|
|
|
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
pit_count #(.COUNT_SIZE(COUNT_SIZE))
|
pit_count #(.COUNT_SIZE(COUNT_SIZE))
|
counter(
|
counter(
|
// outputs
|
// outputs
|
.cnt_n ( cnt_n ),
|
.cnt_n ( cnt_n ),
|
.cnt_flag_o ( cnt_flag_o ),
|
.cnt_flag_o ( cnt_flag_o ),
|
.pit_o ( pit_o ),
|
.pit_o ( pit_o ),
|
// inputs
|
// inputs
|
.async_rst_b ( async_rst_b ),
|
.async_rst_b ( async_rst_b ),
|
.sync_reset ( sync_reset ),
|
.sync_reset ( sync_reset ),
|
.bus_clk ( wb_clk_i ),
|
.bus_clk ( wb_clk_i ),
|
.counter_sync ( counter_sync ),
|
.counter_sync ( counter_sync ),
|
.prescale_out ( prescale_out ),
|
.prescale_out ( prescale_out ),
|
.pit_flg_clr ( pit_flg_clr ),
|
.pit_flg_clr ( pit_flg_clr ),
|
.mod_value ( mod_value )
|
.mod_value ( mod_value )
|
);
|
);
|
|
|
endmodule // pit_top
|
endmodule // pit_top
|
|
|