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

Subversion Repositories scalable_arbiter

[/] [scalable_arbiter/] [trunk/] [rtl/] [verilog/] [demo_top.v] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 kendallc
/*
2
 * Copyright (c) 2009, Kendall Correll
3
 *
4
 * Permission to use, copy, modify, and distribute this software for any
5
 * purpose with or without fee is hereby granted, provided that the above
6
 * copyright notice and this permission notice appear in all copies.
7
 *
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
 */
16
 
17
`timescale 1ns / 1ps
18
 
19
`define MHZ 100
20
`define WIDTH 8
21
`define SELECT_WIDTH 3
22
`define DEBOUNCE_MSEC 250
23
`define STRETCH_MSEC 250
24
 
25
module demo_top (
26
        input [1:0] buttons,
27
        output [`SELECT_WIDTH:0] indicators,
28
 
29
        input refclock
30
);
31
 
32
wire reset;
33
wire clock;
34
wire locked;
35
wire usec_tick;
36
wire msec_tick;
37
wire next_test;
38
wire next_step;
39
wire [`SELECT_WIDTH-1:0] select;
40
wire valid;
41
 
42
reg [1:0] buttons_reg;
43
 
44
// replace the clock generator with the appropriate module for your part
45
assign reset = ~locked;
46
 
47
/*clockgen clockgen (
48
        .inclk0(refclock),
49
        .c0(clock),
50
        .locked(locked)
51
);*/
52
clockgen clockgen (
53
        .CLKIN_IN(refclock),
54
        .CLKFX_OUT(clock),
55
        .CLKIN_IBUFG_OUT(),
56
        .LOCKED_OUT(locked)
57
);
58
 
59
// register inputs
60
always @(posedge clock)
61
begin
62
        buttons_reg <= buttons;
63
end
64
 
65
// this counter is always enabled, so subtract 1 from the count to account for
66
// the extra clock that it takes to reload the counter
67
pulser #(
68
        .count(`MHZ-1)
69
) usec_pulser (
70
        .enable(1'b1),
71
        .out(usec_tick),
72
 
73
        .clock(clock),
74
        .reset(1'b0)
75
);
76
 
77
// this counter is only enabled every few clocks, so use the full count because
78
// the clock that it takes to reload the counter will happen between enables
79
pulser #(
80
        .count(1000)
81
) msec_pulser (
82
        .enable(usec_tick),
83
        .out(msec_tick),
84
 
85
        .clock(clock),
86
        .reset(1'b0)
87
);
88
 
89
// this assumes that the buttons are normally low, it fires a pulse on the
90
// rising edge of a button event, and only accepts one event per DEBOUNCE_MSEC
91
debouncer #(
92
        .low_count(`DEBOUNCE_MSEC)
93
) next_test_debouncer (
94
        .enable(msec_tick),
95
        .in(buttons_reg[1]),
96
        .out(),
97
        .rising_pulse(next_test),
98
        .falling_pulse(),
99
        .valid(),
100
 
101
        .clock(clock),
102
        .reset(1'b0)
103
);
104
 
105
debouncer #(
106
        .low_count(`DEBOUNCE_MSEC)
107
) next_step_debouncer (
108
        .enable(msec_tick),
109
        .in(buttons_reg[0]),
110
        .out(),
111
        .rising_pulse(next_step),
112
        .falling_pulse(),
113
        .valid(),
114
 
115
        .clock(clock),
116
        .reset(1'b0)
117
);
118
 
119
// the arbiter demo module
120
demo #(
121
        .width(`WIDTH),
122
        .select_width(`SELECT_WIDTH)
123
) demo (
124
        .next_test(next_test),
125
        .next_step(next_step),
126
        .select(select),
127
        .valid(valid),
128
 
129
        .clock(clock),
130
        .reset(reset)
131
);
132
 
133
// this stretches brief changes long enough to be visible, specifically, to see
134
// select blip when the arbiter wraps around (a wrap around is the transition
135
// from granting a higher number req to a lower number, and while select blips,
136
// all grants are deasserted)
137
stretcher #(
138
        .count(`STRETCH_MSEC),
139
        .width(`SELECT_WIDTH)
140
) select_stretcher (
141
        .enable(msec_tick),
142
        .in(select),
143
        .out(indicators[`SELECT_WIDTH:1]),
144
        .valid(),
145
 
146
        .clock(clock),
147
        .reset(1'b0)
148
);
149
 
150
stretcher #(
151
        .count(`STRETCH_MSEC)
152
) valid_stretcher (
153
        .enable(msec_tick),
154
        .in(valid),
155
        .out(indicators[0]),
156
        .valid(),
157
 
158
        .clock(clock),
159
        .reset(1'b0)
160
);
161
 
162
endmodule

powered by: WebSVN 2.1.0

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