-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDE2_115_NIOS_HOST_MOUSE_VGA.v
617 lines (533 loc) · 16.1 KB
/
DE2_115_NIOS_HOST_MOUSE_VGA.v
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
// --------------------------------------------------------------------
// Copyright (c) 2010 by Terasic Technologies Inc.
// --------------------------------------------------------------------
//
// Permission:
//
// Terasic grants permission to use and modify this code for use
// in synthesis for all Terasic Development Boards and Altera Development
// Kits made by Terasic. Other use of this code, including the selling
// ,duplication, or modification of any portion is strictly prohibited.
//
// Disclaimer:
//
// This VHDL/Verilog or C/C++ source code is intended as a design reference
// which illustrates how these types of functions can be implemented.
// It is the user's responsibility to verify their design for
// consistency and functionality through the use of formal
// verification methods. Terasic provides no warranty regarding the use
// or functionality of this code.
//
// --------------------------------------------------------------------
//
// Terasic Technologies Inc
// 356 Fu-Shin E. Rd Sec. 1. JhuBei City,
// HsinChu County, Taiwan
// 302
//
// web: http://www.terasic.com/
// email: support@terasic.com
//
// --------------------------------------------------------------------
//
// Major Functions: It can realize a USB Mouse, and display the position
// with a cross on VGA,and when you move the Mouse,the
// mark will be display on the screen.
// --------------------------------------------------------------------
//
// Revision History :
// --------------------------------------------------------------------
// Ver :| Author :| Mod. Date :| Changes Made:
// V1.0 :| Peli Li :| 03/25/2010:| Initial Revision
// V2.0 :| Peli Li :| 04/19/2010:| change the vga controller core,chang the parametre of the dram and flash
// V3.0 :| Peli Li :| 06/21/2010:| change the background picture
// V4.0 :| Peli Li :| 10/19/2012:| change the phy from ISP1362 to CY7C67200
// --------------------------------------------------------------------
module DE2_115_NIOS_HOST_MOUSE_VGA(
//////// CLOCK //////////
CLOCK_50,
CLOCK2_50,
CLOCK3_50,
ENETCLK_25,
//////// Sma //////////
SMA_CLKIN,
SMA_CLKOUT,
//////// LED //////////
LEDG,
LEDR,
//////// KEY //////////
KEY,
//////// SW //////////
SW,
//////// SEG7 //////////
HEX0,
HEX1,
HEX2,
HEX3,
HEX4,
HEX5,
HEX6,
HEX7,
//////// LCD //////////
LCD_BLON,
LCD_DATA,
LCD_EN,
LCD_ON,
LCD_RS,
LCD_RW,
//////// RS232 //////////
UART_CTS,
UART_RTS,
UART_RXD,
UART_TXD,
//////// PS2 //////////
PS2_CLK,
PS2_DAT,
PS2_CLK2,
PS2_DAT2,
//////// SDCARD //////////
SD_CLK,
SD_CMD,
SD_DAT,
SD_WP_N,
//////// VGA //////////
VGA_B,
VGA_BLANK_N,
VGA_CLK,
VGA_G,
VGA_HS,
VGA_R,
VGA_SYNC_N,
VGA_VS,
//////// Audio //////////
AUD_ADCDAT,
AUD_ADCLRCK,
AUD_BCLK,
AUD_DACDAT,
AUD_DACLRCK,
AUD_XCK,
//////// I2C for EEPROM //////////
EEP_I2C_SCLK,
EEP_I2C_SDAT,
//////// I2C for Audio and Tv-Decode //////////
I2C_SCLK,
I2C_SDAT,
//////// Ethernet 0 //////////
ENET0_GTX_CLK,
ENET0_INT_N,
ENET0_MDC,
ENET0_MDIO,
ENET0_RST_N,
ENET0_RX_CLK,
ENET0_RX_COL,
ENET0_RX_CRS,
ENET0_RX_DATA,
ENET0_RX_DV,
ENET0_RX_ER,
ENET0_TX_CLK,
ENET0_TX_DATA,
ENET0_TX_EN,
ENET0_TX_ER,
ENET0_LINK100,
//////// Ethernet 1 //////////
ENET1_GTX_CLK,
ENET1_INT_N,
ENET1_MDC,
ENET1_MDIO,
ENET1_RST_N,
ENET1_RX_CLK,
ENET1_RX_COL,
ENET1_RX_CRS,
ENET1_RX_DATA,
ENET1_RX_DV,
ENET1_RX_ER,
ENET1_TX_CLK,
ENET1_TX_DATA,
ENET1_TX_EN,
ENET1_TX_ER,
ENET1_LINK100,
//////// TV Decoder //////////
TD_CLK27,
TD_DATA,
TD_HS,
TD_RESET_N,
TD_VS,
/////// USB OTG controller
OTG_DATA,
OTG_ADDR,
OTG_CS_N,
OTG_WR_N,
OTG_RD_N,
OTG_INT,
OTG_RST_N,
//////// IR Receiver //////////
IRDA_RXD,
//////// SDRAM //////////
DRAM_ADDR,
DRAM_BA,
DRAM_CAS_N,
DRAM_CKE,
DRAM_CLK,
DRAM_CS_N,
DRAM_DQ,
DRAM_DQM,
DRAM_RAS_N,
DRAM_WE_N,
//////// SRAM //////////
SRAM_ADDR,
SRAM_CE_N,
SRAM_DQ,
SRAM_LB_N,
SRAM_OE_N,
SRAM_UB_N,
SRAM_WE_N,
//////// Flash //////////
FL_ADDR,
FL_CE_N,
FL_DQ,
FL_OE_N,
FL_RST_N,
FL_RY,
FL_WE_N,
FL_WP_N,
//////// GPIO //////////
GPIO,
//////// HSMC (LVDS) //////////
// HSMC_CLKIN_N1,
// HSMC_CLKIN_N2,
HSMC_CLKIN_P1,
HSMC_CLKIN_P2,
HSMC_CLKIN0,
// HSMC_CLKOUT_N1,
// HSMC_CLKOUT_N2,
HSMC_CLKOUT_P1,
HSMC_CLKOUT_P2,
HSMC_CLKOUT0,
HSMC_D,
// HSMC_RX_D_N,
HSMC_RX_D_P,
// HSMC_TX_D_N,
HSMC_TX_D_P,
//////// EXTEND IO //////////
EX_IO
);
//=======================================================
// PARAMETER declarations
//=======================================================
//=======================================================
// PORT declarations
//=======================================================
//////////// CLOCK //////////
input CLOCK_50;
input CLOCK2_50;
input CLOCK3_50;
input ENETCLK_25;
//////////// Sma //////////
input SMA_CLKIN;
output SMA_CLKOUT;
//////////// LED //////////
output [8:0] LEDG;
output [17:0] LEDR;
//////////// KEY //////////
input [3:0] KEY;
//////////// SW //////////
input [17:0] SW;
//////////// SEG7 //////////
output [6:0] HEX0;
output [6:0] HEX1;
output [6:0] HEX2;
output [6:0] HEX3;
output [6:0] HEX4;
output [6:0] HEX5;
output [6:0] HEX6;
output [6:0] HEX7;
//////////// LCD //////////
output LCD_BLON;
inout [7:0] LCD_DATA;
output LCD_EN;
output LCD_ON;
output LCD_RS;
output LCD_RW;
//////////// RS232 //////////
output UART_CTS;
input UART_RTS;
input UART_RXD;
output UART_TXD;
//////////// PS2 //////////
inout PS2_CLK;
inout PS2_DAT;
inout PS2_CLK2;
inout PS2_DAT2;
//////////// SDCARD //////////
output SD_CLK;
inout SD_CMD;
inout [3:0] SD_DAT;
input SD_WP_N;
//////////// VGA //////////
output [7:0] VGA_B;
output VGA_BLANK_N;
output VGA_CLK;
output [7:0] VGA_G;
output VGA_HS;
output [7:0] VGA_R;
output VGA_SYNC_N;
output VGA_VS;
//////////// Audio //////////
input AUD_ADCDAT;
inout AUD_ADCLRCK;
inout AUD_BCLK;
output AUD_DACDAT;
inout AUD_DACLRCK;
output AUD_XCK;
//////////// I2C for EEPROM //////////
output EEP_I2C_SCLK;
inout EEP_I2C_SDAT;
//////////// I2C for Audio and Tv-Decode //////////
output I2C_SCLK;
inout I2C_SDAT;
//////////// Ethernet 0 //////////
output ENET0_GTX_CLK;
input ENET0_INT_N;
output ENET0_MDC;
inout ENET0_MDIO;
output ENET0_RST_N;
input ENET0_RX_CLK;
input ENET0_RX_COL;
input ENET0_RX_CRS;
input [3:0] ENET0_RX_DATA;
input ENET0_RX_DV;
input ENET0_RX_ER;
input ENET0_TX_CLK;
output [3:0] ENET0_TX_DATA;
output ENET0_TX_EN;
output ENET0_TX_ER;
input ENET0_LINK100;
//////////// Ethernet 1 //////////
output ENET1_GTX_CLK;
input ENET1_INT_N;
output ENET1_MDC;
inout ENET1_MDIO;
output ENET1_RST_N;
input ENET1_RX_CLK;
input ENET1_RX_COL;
input ENET1_RX_CRS;
input [3:0] ENET1_RX_DATA;
input ENET1_RX_DV;
input ENET1_RX_ER;
input ENET1_TX_CLK;
output [3:0] ENET1_TX_DATA;
output ENET1_TX_EN;
output ENET1_TX_ER;
input ENET1_LINK100;
//////////// TV Decoder 1 //////////
input TD_CLK27;
input [7:0] TD_DATA;
input TD_HS;
output TD_RESET_N;
input TD_VS;
//////////// USB OTG controller //////////
inout [15:0] OTG_DATA;
output [1:0] OTG_ADDR;
output OTG_CS_N;
output OTG_WR_N;
output OTG_RD_N;
input OTG_INT;
output OTG_RST_N;
//////////// IR Receiver //////////
input IRDA_RXD;
//////////// SDRAM //////////
output [12:0] DRAM_ADDR;
output [1:0] DRAM_BA;
output DRAM_CAS_N;
output DRAM_CKE;
output DRAM_CLK;
output DRAM_CS_N;
inout [31:0] DRAM_DQ;
output [3:0] DRAM_DQM;
output DRAM_RAS_N;
output DRAM_WE_N;
//////////// SRAM //////////
output [19:0] SRAM_ADDR;
output SRAM_CE_N;
inout [15:0] SRAM_DQ;
output SRAM_LB_N;
output SRAM_OE_N;
output SRAM_UB_N;
output SRAM_WE_N;
//////////// Flash //////////
output [22:0] FL_ADDR;
output FL_CE_N;
inout [7:0] FL_DQ;
output FL_OE_N;
output FL_RST_N;
input FL_RY;
output FL_WE_N;
output FL_WP_N;
//////////// GPIO //////////
inout [35:0] GPIO;
//////////// HSMC (LVDS) //////////
//input HSMC_CLKIN_N1;
//input HSMC_CLKIN_N2;
input HSMC_CLKIN_P1;
input HSMC_CLKIN_P2;
input HSMC_CLKIN0;
//output HSMC_CLKOUT_N1;
//output HSMC_CLKOUT_N2;
output HSMC_CLKOUT_P1;
output HSMC_CLKOUT_P2;
output HSMC_CLKOUT0;
inout [3:0] HSMC_D;
//input [16:0] HSMC_RX_D_N;
input [16:0] HSMC_RX_D_P;
//output [16:0] HSMC_TX_D_N;
output [16:0] HSMC_TX_D_P;
//////// EXTEND IO //////////
inout [6:0] EX_IO;
//=======================================================
// REG/WIRE declarations
//=======================================================
//seg
wire HEX0P;
wire HEX1P;
wire HEX2P;
wire HEX3P;
wire HEX4P;
wire HEX5P;
wire HEX6P;
wire HEX7P;
//vga
wire clk_25;
wire [9:0] vga_r10;
wire [9:0] vga_g10;
wire [9:0] vga_b10;
wire reset_n; //reset
//=======================================================
// ARITECTURE declarations
//=======================================================
assign reset_n = 1'b1;
assign VGA_R = vga_r10[9:2];
assign VGA_G = vga_g10[9:2];
assign VGA_B = vga_b10[9:2];
DE2_115_SOPC DE2_115_SOPC_inst(
// 1) global signals:
.clk_50(CLOCK_50),
.reset_n(reset_n),
.altpll_25(clk_25),
.altpll_io(),
.altpll_sdram(DRAM_CLK),
.altpll_sys(),
// the_key
.in_port_to_the_key(KEY),
// the_lcd
.LCD_E_from_the_lcd(LCD_EN),
.LCD_RS_from_the_lcd(LCD_RS),
.LCD_RW_from_the_lcd(LCD_RW),
.LCD_data_to_and_from_the_lcd(LCD_DATA),
// the_ledg
.out_port_from_the_ledg(LEDG),
// the_ledr
.out_port_from_the_ledr(LEDR),
// the_sdram
.zs_addr_from_the_sdram(DRAM_ADDR),
.zs_ba_from_the_sdram(DRAM_BA),
.zs_cas_n_from_the_sdram(DRAM_CAS_N),
.zs_cke_from_the_sdram(DRAM_CKE),
.zs_cs_n_from_the_sdram(DRAM_CS_N),
.zs_dq_to_and_from_the_sdram(DRAM_DQ),
.zs_dqm_from_the_sdram(DRAM_DQM),
.zs_ras_n_from_the_sdram(DRAM_RAS_N),
.zs_we_n_from_the_sdram(DRAM_WE_N),
// the_seg7
.SEG7_from_the_seg7({
HEX7P, HEX7, HEX6P, HEX6,
HEX5P, HEX5, HEX4P, HEX4,
HEX3P, HEX3, HEX2P, HEX2,
HEX1P, HEX1, HEX0P, HEX0}),
// the_sma_in
.in_port_to_the_sma_in(SMA_CLKIN),
// the_sma_out
.out_port_from_the_sma_out(SMA_CLKOUT),
// the_sram
.SRAM_ADDR_from_the_sram(SRAM_ADDR),
.SRAM_CE_n_from_the_sram(SRAM_CE_N),
.SRAM_DQ_to_and_from_the_sram(SRAM_DQ),
.SRAM_LB_n_from_the_sram(SRAM_LB_N),
.SRAM_OE_n_from_the_sram(SRAM_OE_N),
.SRAM_UB_n_from_the_sram(SRAM_UB_N),
.SRAM_WE_n_from_the_sram(SRAM_WE_N),
// the_sw
.in_port_to_the_sw(SW),
// the_usb
.usb_conduit_end_DATA(OTG_DATA), // usb_conduit_end.DATA
.usb_conduit_end_ADDR(OTG_ADDR), // .ADDR
.usb_conduit_end_RD_N(OTG_RD_N), // .RD_N
.usb_conduit_end_WR_N(OTG_WR_N), // .WR_N
.usb_conduit_end_CS_N(OTG_CS_N), // .CS_N
.usb_conduit_end_RST_N(OTG_RST_N), // .RST_N
.usb_conduit_end_INT(OTG_INT), // .INT
//VGA
.avs_s1_export_VGA_BLANK_from_the_vpg(VGA_BLANK_N),
.avs_s1_export_VGA_B_from_the_vpg(vga_b10),
.avs_s1_export_VGA_CLK_from_the_vpg(VGA_CLK),
.avs_s1_export_VGA_G_from_the_vpg(vga_g10),
.avs_s1_export_VGA_HS_from_the_vpg(VGA_HS),
.avs_s1_export_VGA_R_from_the_vpg(vga_r10),
.avs_s1_export_VGA_SYNC_from_the_vpg(VGA_SYNC_N),
.avs_s1_export_VGA_VS_from_the_vpg(VGA_VS),
.avs_s1_export_iCLK_25_to_the_vpg(clk_25)
);
// Flash Config
assign FL_RST_N = reset_n;
assign FL_WP_N = 1'b1;
// FL_RY,
///////////////////////////////////////////
// LCD config
assign LCD_BLON = 0; // not supported
assign LCD_ON = 1'b1; // alwasy on
wire io_dir;
wire action;
assign io_dir = KEY[0] & action;
///////////////////////////////////////////
// GPIO
assign GPIO[17:0] = (io_dir)?GPIO[35:18]:18'hz;
assign GPIO[35:18] = (io_dir)?GPIO[17:0]:18'hz;
///////////////////////////////////////////
// HSMC
assign HSMC_D[1:0] = (io_dir)?HSMC_D[3:2]:2'hz;
assign HSMC_D[3:2] = (io_dir)?HSMC_D[1:0]:2'hz;
assign HSMC_TX_D_P = HSMC_RX_D_P;
//assign HSMC_TX_D_N = HSMC_RX_D_N;
//assign HSMC_CLKOUT_N1 = HSMC_CLKIN_N1;
//assign HSMC_CLKOUT_N2 = HSMC_CLKIN_N2;
assign HSMC_CLKOUT_P1 = HSMC_CLKIN_P1;
assign HSMC_CLKOUT_P2 = HSMC_CLKIN_P2;
assign HSMC_CLKOUT0 = HSMC_CLKIN0;
///////////////////////////////////////////
// NET
assign ENET0_GTX_CLK = ENET0_INT_N;
//assign ENET0_GTX_CLK = ENET0_MDIO;
assign ENET0_MDC = ENET0_RX_COL;
assign ENET0_RST_N = ENET0_RX_CRS;
//assign ENET0_RX_CLK = ENET0_RX_DV;
assign ENET0_TX_DATA = ENET0_RX_DATA;
assign ENET0_TX_EN = ENET0_RX_ER;
assign ENET0_TX_ER = ENET0_TX_CLK;
assign ENET1_GTX_CLK = ENET1_INT_N;
//assign ENET1_GTX_CLK = ENET1_MDIO;
assign ENET1_MDC = ENET1_RX_COL;
assign ENET1_RST_N = ENET1_RX_CRS;
//assign ENET1_RX_CLK = ENET1_RX_DV;
assign ENET1_TX_DATA = ENET1_RX_DATA;
assign ENET1_TX_EN = ENET1_RX_ER;
assign ENET1_TX_ER = ENET1_TX_CLK;
//assign ?? = {ENET0_MDIO, ENET0_RX_CLK, ENET0_RX_DV};
//assign ?? = {ENET1_MDIO, ENET1_RX_CLK, ENET1_RX_DV};
///////////////////////////////////////////
// TV
assign TD_RESET_N = TD_VS;
assign action = FL_RY & TD_HS & TD_CLK27 & (TD_DATA == 8'hff);
///////////////////////////////////////////
// ps2
assign PS2_CLK = PS2_DAT;
assign PS2_CLK2 = PS2_DAT2;
endmodule