1 |
134 |
olivier.gi |
/*===========================================================================*/
|
2 |
|
|
/* Copyright (C) 2001 Authors */
|
3 |
|
|
/* */
|
4 |
|
|
/* This source file may be used and distributed without restriction provided */
|
5 |
|
|
/* that this copyright statement is not removed from the file and that any */
|
6 |
|
|
/* derivative work contains the original copyright notice and the associated */
|
7 |
|
|
/* disclaimer. */
|
8 |
|
|
/* */
|
9 |
|
|
/* This source file is free software; you can redistribute it and/or modify */
|
10 |
|
|
/* it under the terms of the GNU Lesser General Public License as published */
|
11 |
|
|
/* by the Free Software Foundation; either version 2.1 of the License, or */
|
12 |
|
|
/* (at your option) any later version. */
|
13 |
|
|
/* */
|
14 |
|
|
/* This source is distributed in the hope that it will be useful, but WITHOUT*/
|
15 |
|
|
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
|
16 |
|
|
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
|
17 |
|
|
/* License for more details. */
|
18 |
|
|
/* */
|
19 |
|
|
/* You should have received a copy of the GNU Lesser General Public License */
|
20 |
|
|
/* along with this source; if not, write to the Free Software Foundation, */
|
21 |
|
|
/* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
|
22 |
|
|
/* */
|
23 |
|
|
/*===========================================================================*/
|
24 |
|
|
/* DEBUG INTERFACE: UART */
|
25 |
|
|
/*---------------------------------------------------------------------------*/
|
26 |
|
|
/* Test the UART debug interface: */
|
27 |
|
|
/* - Check synchronization of the serial */
|
28 |
|
|
/* debug interface input. */
|
29 |
|
|
/* */
|
30 |
|
|
/* Author(s): */
|
31 |
|
|
/* - Olivier Girard, olgirard@gmail.com */
|
32 |
|
|
/* */
|
33 |
|
|
/*---------------------------------------------------------------------------*/
|
34 |
|
|
/* $Rev: 95 $ */
|
35 |
|
|
/* $LastChangedBy: olivier.girard $ */
|
36 |
|
|
/* $LastChangedDate: 2011-02-24 21:37:57 +0100 (Thu, 24 Feb 2011) $ */
|
37 |
|
|
/*===========================================================================*/
|
38 |
|
|
|
39 |
|
|
`define VERY_LONG_TIMEOUT
|
40 |
|
|
|
41 |
|
|
integer ii;
|
42 |
|
|
reg [15:0] jj;
|
43 |
|
|
|
44 |
|
|
initial
|
45 |
|
|
begin
|
46 |
|
|
$display(" ===============================================");
|
47 |
|
|
$display("| START SIMULATION |");
|
48 |
|
|
$display(" ===============================================");
|
49 |
|
|
`ifdef DBG_EN
|
50 |
|
|
`ifdef DBG_UART
|
51 |
|
|
#1 dbg_en = 1;
|
52 |
|
|
repeat(30) @(posedge mclk);
|
53 |
|
|
stimulus_done = 0;
|
54 |
|
|
|
55 |
|
|
// Enable metastablity emulation for the RXD path
|
56 |
|
|
dbg_uart_rxd_meta = 1'b1;
|
57 |
|
|
|
58 |
|
|
//--------------------------------------------------------
|
59 |
|
|
// TRY VARIOUS SERIAL DEBUG INTERFACE TRANSFER
|
60 |
|
|
// WITH DIFFERENT BAUD-RATES
|
61 |
|
|
//--------------------------------------------------------
|
62 |
|
|
|
63 |
|
|
for ( ii=0; ii < 500; ii=ii+1)
|
64 |
|
|
begin
|
65 |
|
|
#1 reset_n = 0;
|
66 |
|
|
repeat(1) @(posedge mclk);
|
67 |
|
|
#1 reset_n = 1;
|
68 |
|
|
repeat(10) @(posedge mclk);
|
69 |
|
|
|
70 |
|
|
UART_PERIOD = 650 + 1*ii;
|
71 |
|
|
$display("Synchronisation test for DBG_UART_PERIOD = %5d ns / ii = %-d", UART_PERIOD, ii);
|
72 |
|
|
|
73 |
|
|
// SEND UART SYNCHRONIZATION FRAME
|
74 |
|
|
dbg_uart_sync;
|
75 |
|
|
|
76 |
|
|
// READ CPU_ID
|
77 |
|
|
dbg_uart_rd(CPU_ID_LO);
|
78 |
|
|
if (dbg_uart_buf !== dbg_cpu_id[15:0])
|
79 |
|
|
begin
|
80 |
|
|
$display("CPU_ID_LO: read = 0x%-4h / expected = 0x%-4h", dbg_uart_buf, dbg_cpu_id[15:0]);
|
81 |
|
|
tb_error("====== CPU_ID_LO incorrect (test 1) =====");
|
82 |
|
|
force_end_of_sim;
|
83 |
|
|
end
|
84 |
|
|
dbg_uart_rd(CPU_ID_HI);
|
85 |
|
|
if (dbg_uart_buf !== dbg_cpu_id[31:16])
|
86 |
|
|
begin
|
87 |
|
|
$display("CPU_ID_HI: read = 0x%-4h / expected = 0x%-4h", dbg_uart_buf, dbg_cpu_id[31:16]);
|
88 |
|
|
tb_error("====== CPU_ID_HI incorrect (test 1) =====");
|
89 |
|
|
force_end_of_sim;
|
90 |
|
|
end
|
91 |
|
|
|
92 |
|
|
//-----------------------------------
|
93 |
|
|
// MAKE SOME READ/WRITE ACCESS
|
94 |
|
|
//-----------------------------------
|
95 |
|
|
jj = 'h4328;
|
96 |
|
|
dbg_uart_wr(MEM_DATA, 16'h4328);
|
97 |
|
|
dbg_uart_rd(MEM_DATA);
|
98 |
|
|
if (dbg_uart_buf !== 16'h4328)
|
99 |
|
|
begin
|
100 |
|
|
$display("DMEM_DATA: read = 0x%-4h / expected = 0x4328", dbg_uart_buf);
|
101 |
|
|
tb_error("====== MEM_DATA incorrect (test 1) =====");
|
102 |
|
|
force_end_of_sim;
|
103 |
|
|
end
|
104 |
|
|
|
105 |
|
|
jj = 'h3280;
|
106 |
|
|
dbg_uart_wr(MEM_DATA, 16'h3280);
|
107 |
|
|
dbg_uart_rd(MEM_DATA);
|
108 |
|
|
if (dbg_uart_buf !== 16'h3280)
|
109 |
|
|
begin
|
110 |
|
|
$display("DMEM_DATA: read = 0x%-4h / expected = 0x3280", dbg_uart_buf);
|
111 |
|
|
tb_error("====== MEM_DATA incorrect (test 2) =====");
|
112 |
|
|
force_end_of_sim;
|
113 |
|
|
end
|
114 |
|
|
|
115 |
|
|
jj = 'h2800;
|
116 |
|
|
dbg_uart_wr(MEM_DATA, 16'h2800);
|
117 |
|
|
dbg_uart_rd(MEM_DATA);
|
118 |
|
|
if (dbg_uart_buf !== 16'h2800)
|
119 |
|
|
begin
|
120 |
|
|
$display("DMEM_DATA: read = 0x%-4h / expected = 0x2800", dbg_uart_buf);
|
121 |
|
|
tb_error("====== MEM_DATA incorrect (test 1) =====");
|
122 |
|
|
force_end_of_sim;
|
123 |
|
|
end
|
124 |
|
|
|
125 |
|
|
jj = 'h8000;
|
126 |
|
|
dbg_uart_wr(MEM_DATA, 16'h8000);
|
127 |
|
|
dbg_uart_rd(MEM_DATA);
|
128 |
|
|
if (dbg_uart_buf !== 16'h8000)
|
129 |
|
|
begin
|
130 |
|
|
$display("DMEM_DATA: read = 0x%-4h / expected = 0x8000", dbg_uart_buf);
|
131 |
|
|
tb_error("====== MEM_DATA incorrect (test 2) =====");
|
132 |
|
|
force_end_of_sim;
|
133 |
|
|
end
|
134 |
|
|
|
135 |
|
|
jj = 'h0000;
|
136 |
|
|
dbg_uart_wr(MEM_DATA, 16'h0000);
|
137 |
|
|
dbg_uart_rd(MEM_DATA);
|
138 |
|
|
if (dbg_uart_buf !== 16'h0000)
|
139 |
|
|
begin
|
140 |
|
|
$display("DMEM_DATA: read = 0x%-4h / expected = 0x0000", dbg_uart_buf);
|
141 |
|
|
tb_error("====== MEM_DATA incorrect (test 2) =====");
|
142 |
|
|
force_end_of_sim;
|
143 |
|
|
end
|
144 |
|
|
|
145 |
|
|
jj = 'hffff;
|
146 |
|
|
dbg_uart_wr(MEM_DATA, 16'hffff);
|
147 |
|
|
dbg_uart_rd(MEM_DATA);
|
148 |
|
|
if (dbg_uart_buf !== 16'hffff)
|
149 |
|
|
begin
|
150 |
|
|
$display("DMEM_DATA: read = 0x%-4h / expected = 0xffff", dbg_uart_buf);
|
151 |
|
|
tb_error("====== MEM_DATA incorrect (test 2) =====");
|
152 |
|
|
force_end_of_sim;
|
153 |
|
|
end
|
154 |
|
|
|
155 |
|
|
jj = 'h7f7f;
|
156 |
|
|
dbg_uart_wr(MEM_DATA, 16'h7f7f);
|
157 |
|
|
dbg_uart_rd(MEM_DATA);
|
158 |
|
|
if (dbg_uart_buf !== 16'h7f7f)
|
159 |
|
|
begin
|
160 |
|
|
$display("DMEM_DATA: read = 0x%-4h / expected = 0x7f7f", dbg_uart_buf);
|
161 |
|
|
tb_error("====== MEM_DATA incorrect (test 2) =====");
|
162 |
|
|
force_end_of_sim;
|
163 |
|
|
end
|
164 |
|
|
|
165 |
|
|
jj = 'h55aa;
|
166 |
|
|
dbg_uart_wr(MEM_DATA, 16'h55aa);
|
167 |
|
|
dbg_uart_rd(MEM_DATA);
|
168 |
|
|
if (dbg_uart_buf !== 16'h55aa)
|
169 |
|
|
begin
|
170 |
|
|
$display("DMEM_DATA: read = 0x%-4h / expected = 0x55aa", dbg_uart_buf);
|
171 |
|
|
tb_error("====== MEM_DATA incorrect (test 2) =====");
|
172 |
|
|
force_end_of_sim;
|
173 |
|
|
end
|
174 |
|
|
|
175 |
|
|
jj = 'h5aa5;
|
176 |
|
|
dbg_uart_wr(MEM_DATA, 16'h5aa5);
|
177 |
|
|
dbg_uart_rd(MEM_DATA);
|
178 |
|
|
if (dbg_uart_buf !== 16'h5aa5)
|
179 |
|
|
begin
|
180 |
|
|
$display("DMEM_DATA: read = 0x%-4h / expected = 0x5aa5", dbg_uart_buf);
|
181 |
|
|
tb_error("====== MEM_DATA incorrect (test 2) =====");
|
182 |
|
|
force_end_of_sim;
|
183 |
|
|
end
|
184 |
|
|
end
|
185 |
|
|
|
186 |
|
|
|
187 |
|
|
//--------------------------------------------------------
|
188 |
|
|
// TRY LONGEST POSSIBLE SYNCHRONIZATION FRAME
|
189 |
|
|
//--------------------------------------------------------
|
190 |
|
|
|
191 |
|
|
#1 reset_n = 0;
|
192 |
|
|
repeat(1) @(posedge mclk);
|
193 |
|
|
#1 reset_n = 1;
|
194 |
|
|
repeat(10) @(posedge mclk);
|
195 |
|
|
|
196 |
|
|
dbg_uart_rxd_pre = 1'b0;
|
197 |
|
|
@(posedge dut.dbg_0.dbg_uart_0.sync_cnt[`DBG_UART_XFER_CNT_W+2]);
|
198 |
|
|
dbg_uart_rxd_pre = 1'b1;
|
199 |
|
|
|
200 |
|
|
repeat(100) @(posedge mclk);
|
201 |
|
|
|
202 |
|
|
dbg_uart_rxd_pre = 1'b0;
|
203 |
|
|
@(posedge dut.dbg_0.dbg_uart_0.xfer_cnt[`DBG_UART_XFER_CNT_W-1]);
|
204 |
|
|
dbg_uart_rxd_pre = 1'b1;
|
205 |
|
|
|
206 |
|
|
repeat(100) @(posedge mclk);
|
207 |
|
|
|
208 |
|
|
|
209 |
|
|
//--------------------------------------------------------
|
210 |
|
|
// END OF TEST
|
211 |
|
|
//--------------------------------------------------------
|
212 |
|
|
|
213 |
|
|
#1 reset_n = 0;
|
214 |
|
|
repeat(1) @(posedge mclk);
|
215 |
|
|
#1 reset_n = 1;
|
216 |
|
|
repeat(10) @(posedge mclk);
|
217 |
|
|
|
218 |
|
|
UART_PERIOD = 550;
|
219 |
|
|
$display("Synchronisation test for DBG_UART_PERIOD = %5d ns / ii = %-d", UART_PERIOD, ii);
|
220 |
|
|
|
221 |
|
|
// SEND UART SYNCHRONIZATION FRAME
|
222 |
|
|
dbg_uart_sync;
|
223 |
|
|
|
224 |
|
|
// Let the CPU run
|
225 |
|
|
dbg_uart_wr(CPU_CTL, 16'h0002);
|
226 |
|
|
|
227 |
|
|
// Generate an IRQ
|
228 |
|
|
wkup[0] = 1'b1;
|
229 |
|
|
@(negedge mclk);
|
230 |
|
|
irq[0] = 1'b1;
|
231 |
|
|
@(negedge irq_acc[0])
|
232 |
|
|
@(negedge mclk);
|
233 |
|
|
wkup[0] = 1'b0;
|
234 |
|
|
irq[0] = 1'b0;
|
235 |
|
|
|
236 |
|
|
repeat(10) @(posedge mclk);
|
237 |
|
|
|
238 |
|
|
stimulus_done = 1;
|
239 |
|
|
`else
|
240 |
|
|
|
241 |
|
|
$display(" ===============================================");
|
242 |
|
|
$display("| SIMULATION SKIPPED |");
|
243 |
|
|
$display("| (serial debug interface UART not included) |");
|
244 |
|
|
$display(" ===============================================");
|
245 |
|
|
$finish;
|
246 |
|
|
`endif
|
247 |
|
|
`else
|
248 |
|
|
|
249 |
|
|
$display(" ===============================================");
|
250 |
|
|
$display("| SIMULATION SKIPPED |");
|
251 |
|
|
$display("| (serial debug interface not included) |");
|
252 |
|
|
$display(" ===============================================");
|
253 |
|
|
$finish;
|
254 |
|
|
`endif
|
255 |
|
|
end
|
256 |
|
|
|
257 |
|
|
task force_end_of_sim;
|
258 |
|
|
begin
|
259 |
|
|
repeat(10) @(posedge mclk);
|
260 |
|
|
$display(" ===============================================");
|
261 |
|
|
$display("| SIMULATION FAILED |");
|
262 |
|
|
$display("| (some verilog stimulus checks failed) |");
|
263 |
|
|
$display(" ===============================================");
|
264 |
|
|
$finish;
|
265 |
|
|
end
|
266 |
|
|
endtask
|