| 1 |
2 |
dgisselq |
///////////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
//
|
| 3 |
|
|
// Filename: zipcounter.v
|
| 4 |
|
|
//
|
| 5 |
|
|
// Project: Zip CPU -- a small, lightweight, RISC CPU soft core
|
| 6 |
|
|
//
|
| 7 |
|
|
// Purpose:
|
| 8 |
|
|
// A very, _very_ simple counter. It's purpose doesn't really
|
| 9 |
|
|
// include rollover, but it will interrupt on rollover. It can be set,
|
| 10 |
|
|
// although my design concept is that it can be reset. It cannot be
|
| 11 |
|
|
// halted. It will always produce interrupts--whether or not they are
|
| 12 |
|
|
// handled interrupts is another question--that's up to the interrupt
|
| 13 |
|
|
// controller.
|
| 14 |
|
|
//
|
| 15 |
|
|
// My intention is to use this counter for process accounting: I should
|
| 16 |
|
|
// be able to use this to count clock ticks of processor time assigned to
|
| 17 |
|
|
// each task by resetting the counter at the beginning of every task
|
| 18 |
|
|
// interval, and reading the result at the end of the interval. As long
|
| 19 |
|
|
// as the interval is less than 2^32 clocks, there should be no problem.
|
| 20 |
|
|
// Similarly, this can be used to measure CPU wishbone bus stalls,
|
| 21 |
|
|
// prefetch stalls, or other CPU stalls (i.e. stalling as part of a JMP
|
| 22 |
|
|
// instruction, or a read from the condition codes following a write).
|
| 23 |
|
|
//
|
| 24 |
|
|
//
|
| 25 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
| 26 |
|
|
// Gisselquist Tecnology, LLC
|
| 27 |
|
|
//
|
| 28 |
|
|
///////////////////////////////////////////////////////////////////////////
|
| 29 |
|
|
//
|
| 30 |
|
|
// Copyright (C) 2015, Gisselquist Technology, LLC
|
| 31 |
|
|
//
|
| 32 |
|
|
// This program is free software (firmware): you can redistribute it and/or
|
| 33 |
|
|
// modify it under the terms of the GNU General Public License as published
|
| 34 |
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
| 35 |
|
|
// your option) any later version.
|
| 36 |
|
|
//
|
| 37 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
| 38 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
| 39 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
| 40 |
|
|
// for more details.
|
| 41 |
|
|
//
|
| 42 |
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
| 43 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
| 44 |
|
|
//
|
| 45 |
|
|
//
|
| 46 |
|
|
///////////////////////////////////////////////////////////////////////////
|
| 47 |
|
|
//
|
| 48 |
|
|
module zipcounter(i_clk, i_ce,
|
| 49 |
|
|
i_wb_cyc, i_wb_stb, i_wb_we, i_wb_data,
|
| 50 |
|
|
o_wb_ack, o_wb_stall, o_wb_data,
|
| 51 |
|
|
o_int);
|
| 52 |
|
|
parameter BW = 32;
|
| 53 |
|
|
input i_clk, i_ce;
|
| 54 |
|
|
// Wishbone inputs
|
| 55 |
|
|
input i_wb_cyc, i_wb_stb, i_wb_we;
|
| 56 |
|
|
input [(BW-1):0] i_wb_data;
|
| 57 |
|
|
// Wishbone outputs
|
| 58 |
|
|
output reg o_wb_ack;
|
| 59 |
|
|
output wire o_wb_stall;
|
| 60 |
|
|
output reg [(BW-1):0] o_wb_data;
|
| 61 |
|
|
// Interrupt line
|
| 62 |
|
|
output reg o_int;
|
| 63 |
|
|
|
| 64 |
|
|
initial o_wb_data = 32'h00;
|
| 65 |
|
|
always @(posedge i_clk)
|
| 66 |
|
|
if ((i_wb_cyc)&&(i_wb_stb)&&(i_wb_we))
|
| 67 |
|
|
o_wb_data <= i_wb_data;
|
| 68 |
|
|
else if (i_ce)
|
| 69 |
|
|
o_wb_data <= o_wb_data + 1;
|
| 70 |
|
|
|
| 71 |
|
|
initial o_int = 0;
|
| 72 |
|
|
always @(posedge i_clk)
|
| 73 |
|
|
if (i_ce)
|
| 74 |
|
|
o_int <= &o_wb_data;
|
| 75 |
|
|
else
|
| 76 |
|
|
o_int <= 1'b0;
|
| 77 |
|
|
|
| 78 |
|
|
initial o_wb_ack = 1'b0;
|
| 79 |
|
|
always @(posedge i_clk)
|
| 80 |
|
|
o_wb_ack <= (i_wb_cyc)&&(i_wb_stb);
|
| 81 |
|
|
assign o_wb_stall = 1'b0;
|
| 82 |
|
|
endmodule
|