1 |
154 |
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: I2C */
|
25 |
|
|
/*---------------------------------------------------------------------------*/
|
26 |
|
|
/* Test the I2C 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 |
|
|
integer kk;
|
44 |
|
|
|
45 |
|
|
initial
|
46 |
|
|
begin
|
47 |
|
|
$display(" ===============================================");
|
48 |
|
|
$display("| START SIMULATION |");
|
49 |
|
|
$display(" ===============================================");
|
50 |
|
|
`ifdef DBG_EN
|
51 |
|
|
`ifdef DBG_I2C
|
52 |
|
|
#1 dbg_en = 1;
|
53 |
|
|
repeat(30) @(posedge mclk);
|
54 |
|
|
stimulus_done = 0;
|
55 |
|
|
|
56 |
|
|
// Enable metastablity emulation for the SCL and SDA master path
|
57 |
|
|
dbg_scl_master_meta = 1'b1;
|
58 |
|
|
dbg_sda_master_out_meta = 1'b1;
|
59 |
|
|
|
60 |
|
|
//--------------------------------------------------------
|
61 |
|
|
// TRY VARIOUS SERIAL DEBUG INTERFACE TRANSFER
|
62 |
|
|
// WITH DIFFERENT BAUD-RATES
|
63 |
|
|
//--------------------------------------------------------
|
64 |
|
|
|
65 |
|
|
for ( ii=0; ii < 200; ii=ii+1)
|
66 |
|
|
begin
|
67 |
|
|
#1 reset_n = 0;
|
68 |
|
|
repeat(1) @(posedge mclk);
|
69 |
|
|
#1 reset_n = 1;
|
70 |
|
|
repeat(10) @(posedge mclk);
|
71 |
|
|
|
72 |
|
|
I2C_PERIOD = 600 + 1*ii;
|
73 |
|
|
$display("Synchronisation test for DBG_I2C_PERIOD = %5d ns / ii = %-d", I2C_PERIOD, ii);
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
// READ CPU_ID
|
77 |
|
|
dbg_i2c_rd(CPU_ID_LO);
|
78 |
|
|
if (dbg_i2c_buf !== dbg_cpu_id[15:0])
|
79 |
|
|
begin
|
80 |
|
|
$display("CPU_ID_LO: read = 0x%-4h / expected = 0x%-4h", dbg_i2c_buf, dbg_cpu_id[15:0]);
|
81 |
|
|
tb_error("====== CPU_ID_LO incorrect (test 1) =====");
|
82 |
|
|
force_end_of_sim;
|
83 |
|
|
end
|
84 |
|
|
dbg_i2c_rd(CPU_ID_HI);
|
85 |
|
|
if (dbg_i2c_buf !== dbg_cpu_id[31:16])
|
86 |
|
|
begin
|
87 |
|
|
$display("CPU_ID_HI: read = 0x%-4h / expected = 0x%-4h", dbg_i2c_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 |
|
|
|
96 |
|
|
for ( kk=0; kk < 10; kk=kk+1)
|
97 |
|
|
begin
|
98 |
|
|
|
99 |
|
|
jj = 'h4328;
|
100 |
|
|
dbg_i2c_wr(MEM_DATA, 16'h5555);
|
101 |
|
|
dbg_i2c_rd(MEM_DATA);
|
102 |
|
|
if (dbg_i2c_buf !== 16'h5555)
|
103 |
|
|
begin
|
104 |
|
|
$display("DMEM_DATA: read = 0x%-4h / expected = 0x5555", dbg_i2c_buf);
|
105 |
|
|
tb_error("====== MEM_DATA incorrect (test 1) =====");
|
106 |
|
|
force_end_of_sim;
|
107 |
|
|
end
|
108 |
|
|
|
109 |
|
|
jj = 'h3280;
|
110 |
|
|
dbg_i2c_wr(MEM_DATA, 16'haaaa);
|
111 |
|
|
dbg_i2c_rd(MEM_DATA);
|
112 |
|
|
if (dbg_i2c_buf !== 16'haaaa)
|
113 |
|
|
begin
|
114 |
|
|
$display("DMEM_DATA: read = 0x%-4h / expected = 0xaaaa", dbg_i2c_buf);
|
115 |
|
|
tb_error("====== MEM_DATA incorrect (test 2) =====");
|
116 |
|
|
force_end_of_sim;
|
117 |
|
|
end
|
118 |
|
|
end
|
119 |
|
|
end
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
//--------------------------------------------------------
|
123 |
|
|
// END OF TEST
|
124 |
|
|
//--------------------------------------------------------
|
125 |
|
|
|
126 |
|
|
#1 reset_n = 0;
|
127 |
|
|
repeat(1) @(posedge mclk);
|
128 |
|
|
#1 reset_n = 1;
|
129 |
|
|
repeat(10) @(posedge mclk);
|
130 |
|
|
|
131 |
|
|
I2C_PERIOD = 600;
|
132 |
|
|
$display("Synchronisation test for DBG_I2C_PERIOD = %5d ns / ii = %-d", I2C_PERIOD, ii);
|
133 |
|
|
|
134 |
|
|
// Let the CPU run
|
135 |
|
|
dbg_i2c_wr(CPU_CTL, 16'h0002);
|
136 |
|
|
|
137 |
|
|
// Generate an IRQ
|
138 |
|
|
wkup[0] = 1'b1;
|
139 |
|
|
@(negedge mclk);
|
140 |
|
|
irq[0] = 1'b1;
|
141 |
|
|
@(negedge irq_acc[0])
|
142 |
|
|
@(negedge mclk);
|
143 |
|
|
wkup[0] = 1'b0;
|
144 |
|
|
irq[0] = 1'b0;
|
145 |
|
|
|
146 |
|
|
repeat(10) @(posedge mclk);
|
147 |
|
|
|
148 |
|
|
stimulus_done = 1;
|
149 |
|
|
`else
|
150 |
|
|
|
151 |
|
|
$display(" ===============================================");
|
152 |
|
|
$display("| SIMULATION SKIPPED |");
|
153 |
|
|
$display("| (serial debug interface I2C not included) |");
|
154 |
|
|
$display(" ===============================================");
|
155 |
|
|
$finish;
|
156 |
|
|
`endif
|
157 |
|
|
`else
|
158 |
|
|
|
159 |
|
|
$display(" ===============================================");
|
160 |
|
|
$display("| SIMULATION SKIPPED |");
|
161 |
|
|
$display("| (serial debug interface not included) |");
|
162 |
|
|
$display(" ===============================================");
|
163 |
|
|
$finish;
|
164 |
|
|
`endif
|
165 |
|
|
end
|
166 |
|
|
|
167 |
|
|
task force_end_of_sim;
|
168 |
|
|
begin
|
169 |
|
|
repeat(10) @(posedge mclk);
|
170 |
|
|
$display(" ===============================================");
|
171 |
|
|
$display("| SIMULATION FAILED |");
|
172 |
|
|
$display("| (some verilog stimulus checks failed) |");
|
173 |
|
|
$display(" ===============================================");
|
174 |
|
|
$finish;
|
175 |
|
|
end
|
176 |
|
|
endtask
|