-
Notifications
You must be signed in to change notification settings - Fork 0
/
toplevel.sv
211 lines (175 loc) · 5.21 KB
/
toplevel.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
module toplevel (
input logic [3:0] KEY, // 3 = continue, 2 = start
input logic CLOCK_50,
input logic PS2_KBCLK, PS2_KBDAT,
output logic [7:0] VGA_R, VGA_G, VGA_B,
output logic VGA_CLK, VGA_SYNC_N, VGA_BLANK_N, VGA_VS, VGA_HS,
output logic [6:0] HEX0, HEX1, HEX2, HEX3, HEX4, HEX5, HEX6, HEX7,
output logic [9:0] LEDG,
// audio IO
output logic AUD_DACDAT, I2C_SCLK, AUD_XCK,
inout I2C_SDAT,
input AUD_DACLRCK, AUD_ADCLRCK, AUD_BCLK, AUD_ADCDAT,
output logic [31:0] ADCDATA,
// SRAM io
input logic [15:0] SRAM_DQ,
output logic SRAM_CE_N, SRAM_UB_N, SRAM_LB_N, SRAM_OE_N, SRAM_WE_N,
output logic [19:0] SRAM_ADDR
);
logic start, cont; // continue
assign start = ~KEY[2];
assign cont = ~KEY[3];
// audio logics
logic [15:0] audio_data;
logic [15:0] sram_data_out;
logic sram_data_load;
// clock and reset
logic Clk, reset;
assign Clk = CLOCK_50;
always_ff @ (posedge Clk) begin
reset <= ~(KEY[0]);
end
// vga clk reset
always_ff @ (posedge Clk) begin
if(reset)
VGA_CLK <= 1'b0;
else
VGA_CLK <= ~VGA_CLK;
end
// end clock and reset
logic [7:0] keycode;
logic keypress;
assign LEDG[8] = keypress;
assign LEDG[7:0] = keycode;
// for keycode
// HexDriver hex_driver_0 ( .In0 (SRAM_ADDR[3:0]), .Out0(HEX0) );
// HexDriver hex_driver_1 ( .In0 (SRAM_ADDR[7:4]), .Out0(HEX1) );
// HexDriver hex_driver_2 ( .In0 (SRAM_ADDR[11:8]), .Out0(HEX2) );
// HexDriver hex_driver_3 ( .In0 (SRAM_ADDR[15:12]), .Out0(HEX3) );
// HexDriver hex_driver_4 ( .In0 (sram_data_out[3:0]), .Out0(HEX4) );
// HexDriver hex_driver_5 ( .In0 (sram_data_out[7:4]), .Out0(HEX5) );
// HexDriver hex_driver_6 ( .In0 (sram_data_out[11:8]), .Out0(HEX6) );
// HexDriver hex_driver_7 ( .In0 (sram_data_out[15:12]), .Out0(HEX7) );
HexDriver hex_driver_0 ( .In0 (sram_data_out[3:0]), .Out0(HEX0) );
HexDriver hex_driver_1 ( .In0 (sram_data_out[7:4]), .Out0(HEX1) );
HexDriver hex_driver_2 ( .In0 (sram_data_out[11:8]), .Out0(HEX2) );
HexDriver hex_driver_3 ( .In0 (sram_data_out[15:12]), .Out0(HEX3) );
HexDriver hex_driver_4 ( .In0 (SRAM_ADDR[3:0]), .Out0(HEX4) );
HexDriver hex_driver_5 ( .In0 (SRAM_ADDR[7:4]), .Out0(HEX5) );
HexDriver hex_driver_6 ( .In0 (SRAM_ADDR[11:8]), .Out0(HEX6) );
HexDriver hex_driver_7 ( .In0 (SRAM_ADDR[15:12]), .Out0(HEX7) );
keyboard keyboard_inst(
.Clk (Clk),
.psClk (PS2_KBCLK), .psData(PS2_KBDAT),
.reset (reset),
.keyCode(keycode),
.press (keypress)
);
// audio //////////////////////////////////////////////////////////////////////
assign AUD_XCK = CLOCK_50;
// synchronizers for ram writes
logic clk_div, xck_divider;
// uw
logic [23:0] dac_left, dac_right;
audio_driver audio_driver_inst(
.CLOCK_50, .reset,
.dac_left( $signed(sram_data_out) ), .dac_right( $signed(sram_data_out) ),
// .adc_left, .adc_right, // don't care so we don't need to hook them up
// .advance, // don't care: output to signal that there's been input
.FPGA_I2C_SCLK(I2C_SCLK), .FPGA_I2C_SDAT(I2C_SDAT), .AUD_DACLRCK, //.AUD_XCK,
.AUD_ADCLRCK, .AUD_BCLK, .AUD_ADCDAT, .AUD_DACDAT
);
logic sq_wv;
square_wave sq_inst (
.clk(Clk),
.rst(reset),
.dac_out(sq_wv)
);
sram_reading_fsm sram_reading_fsm_inst(
.Clk, .reset,
.SRAM_CE_N, .SRAM_UB_N, .SRAM_LB_N, .SRAM_OE_N, .SRAM_WE_N,
.SRAM_ADDR,
.sram_data_load,
.start, .cont(clk_div)
);
// register to hold current sample
reg_16 sram_data(
.clk(Clk), .reset,
.load (sram_data_load), .din(SRAM_DQ), .dout (sram_data_out)
);
ClkDivider clk_divider_inst(
.clk(Clk), .rst(reset),
.clk_div
);
aud_xck_divider aud_xck_divider_inst(
.clk (Clk), .rst (reset),
.clk_div(xck_divider)
);
// end audio //////////////////////////////////////////////////////////////////
// begin display
logic [9:0] DrawX, DrawY;
// signals to tell color mapper to draw on screen
logic ball, background, receptor_background;
logic [3:0] receptor, display_arrow;
//
logic [3:0] display_signal;
//timer
logic [3:0] arrows;
timer counter(.Clk(Clk), .Reset(reset), .arrows(arrows));
// mostly from VGA lab
vga_controller vga_controller_inst(
.Clk (Clk),
.Reset (reset),
.VGA_HS (VGA_HS),
.VGA_VS (VGA_VS),
.VGA_CLK (VGA_CLK),
.VGA_BLANK_N(VGA_BLANK_N),
.VGA_SYNC_N (VGA_SYNC_N),
.DrawX (DrawX),
.DrawY (DrawY)
);
color_mapper color_mapper_inst(
.is_ball(ball),
.is_receptor(receptor),
.is_background(background),
.is_receptor_background(receptor_background),
.display_arrow(display_arrow),
.DrawX (DrawX),
.DrawY (DrawY),
.VGA_R (VGA_R),
.VGA_G (VGA_G),
.VGA_B (VGA_B)
);
ball ball_inst(
.Clk (Clk),
.Reset (reset),
.frame_clk (VGA_VS),
.DrawX (DrawX),
.DrawY (DrawY),
.keycode (keycode[7:0]),
.is_ball (ball)
);
receptor receptor_inst(
.is_receptor (receptor),
.is_receptor_background(receptor_background),
.is_background (background),
.keycode (keycode[7:0]),
.DrawX(DrawX), .DrawY(DrawY)
);
arrow arrow_inst(
.Clk (Clk),
.reset (reset),
.frame_clk (VGA_VS),
.display_signal(display_signal),
.display_arrow(display_arrow),
.DrawX (DrawX), .DrawY (DrawY)
);
// endisplay
endmodule // toplevel
// sychronizer for outputs to SRAM
module sync (input logic Clk, d, output logic q );
always_ff @ (posedge Clk)
begin
q <= d;
end
endmodule