-
Notifications
You must be signed in to change notification settings - Fork 1
/
top.v
131 lines (115 loc) · 2.95 KB
/
top.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
/* Hardware test for Arrow CYC1000
*
* Instructions:
*
* 1. Compile logic part
* - Regenerate Qsys source code if necessary.
* - If you make changes on the Qsys, you will have to generate BSP again in Eclipse tools
*
* 2. Convert programming files (.SOF --> .JIC for EPCQ16)
* - Recommend to "burn" the logic part in non-volatile memory of the board so it is saved
* when power is off. Then we will focus only on Eclipse and treat the board as an "Arduino"
* - Go to File -> Convert Programming Files -> Open conversion setup data -> jic_generate.cof
* - Select JIC file on programmer & burn it to the board
*
* 3. RESTART THE BOARD. This must be a "hard restart" or unplug & plug back the board to force
* reload of configuration memory. NIOS CPU WON'T START UP WITHOUT THIS
*
* 4. Tools -> Nios II Software build tools for Eclipse
* - Select as workspace the same directory of this Quartus project
*
*
*/
module top (
input CLK12M,
output [7:0] LED,
input USER_BTN,
input CLK_X,
input SEN_INT1,
input SEN_INT2,
input SEN_SDI,
input SEN_SDO,
input SEN_SPC,
input SEN_CS,
output CKE,
output RAS,
output WE,
output CS,
output CAS,
input D11_R,
input D12_R,
input AIN_X,
input ADBUS_4,
input ADBUS_7,
input [7:0] PIO,
input [5:0] BDBUS,
inout [15:0] DQ,
output [1:0] DQM,
output [11:0] A,
output [1:0] BA,
input [14:0] D,
input [7:0] AIN,
output MEM_CLK
);
wire nreset;
assign nreset = USER_BTN;
wire CLK48M;
wire [7:0] nios_leds;
// PLL generate 48MHz clock
// Freq. of c0 and c1 are the same (48MHz), but the phase of c0 (MEM_CLK) is shifted
// so that edges occur in the middle of the valid signal window.
// See the section "Clock, PLL and Timing Considerations" of the "SDRAM Controller Core" document:
// https://www.intel.cn/content/dam/altera-www/global/zh_CN/pdfs/literature/hb/nios2/n2cpu_nii51005.pdf
my_pll pll0(
.areset(~nreset),
.inclk0(CLK12M),
.c0(MEM_CLK),
.c1(CLK48M),
.locked()
);
// To test CLK48M is good
reg [31:0] div_counter;
reg div_out;
always @(posedge CLK48M, negedge nreset)
if (~nreset) begin
div_counter <= 'b0;
div_out <= 'b0;
end else begin
if (div_counter == 32'd10000000) begin
div_counter <= 'b0;
div_out <= 1'b1;
end else begin
div_counter <= div_counter + 32'b1;
div_out <= 1'b0;
end
end
// Counter
reg [7:0] leds_reg;
always @(posedge CLK48M, negedge nreset)
if (~nreset) begin
leds_reg <= 8'b1;
end else begin
if (div_out) begin
leds_reg <= leds_reg + 8'b1;
end
end
wire [7:0] nios_pio0;
wire reset_request;
my_nios u0 (
.clk_clk (CLK48M),
.reset_reset_n (nreset & ~reset_request),
.reset_request_reset (reset_request),
.pio0_export (nios_pio0),
.pio1_export (leds_reg),
.sdram_addr (A),
.sdram_ba (BA),
.sdram_cas_n (CAS),
.sdram_cke (CKE),
.sdram_cs_n (CS),
.sdram_dq (DQ),
.sdram_dqm (DQM),
.sdram_ras_n (RAS),
.sdram_we_n (WE),
);
assign LED = {leds_reg[3:0], nios_pio0[3:0]};
endmodule