| 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 */
|
| 25 |
|
|
/*---------------------------------------------------------------------------*/
|
| 26 |
|
|
/* Test the debug interface: */
|
| 27 |
|
|
/* - CPU Control features. */
|
| 28 |
|
|
/* */
|
| 29 |
|
|
/* Author(s): */
|
| 30 |
|
|
/* - Olivier Girard, olgirard@gmail.com */
|
| 31 |
|
|
/* */
|
| 32 |
|
|
/*---------------------------------------------------------------------------*/
|
| 33 |
|
|
/* $Rev: 95 $ */
|
| 34 |
|
|
/* $LastChangedBy: olivier.girard $ */
|
| 35 |
|
|
/* $LastChangedDate: 2011-02-24 21:37:57 +0100 (Thu, 24 Feb 2011) $ */
|
| 36 |
|
|
/*===========================================================================*/
|
| 37 |
|
|
|
| 38 |
|
|
|
| 39 |
|
|
integer test_nr;
|
| 40 |
|
|
integer test_var;
|
| 41 |
|
|
|
| 42 |
|
|
integer dco_clk_counter;
|
| 43 |
|
|
always @ (negedge dco_clk)
|
| 44 |
|
|
dco_clk_counter <= dco_clk_counter+1;
|
| 45 |
|
|
|
| 46 |
|
|
integer dbg_clk_counter;
|
| 47 |
|
|
always @ (negedge dbg_clk)
|
| 48 |
|
|
dbg_clk_counter <= dbg_clk_counter+1;
|
| 49 |
|
|
|
| 50 |
|
|
|
| 51 |
|
|
initial
|
| 52 |
|
|
begin
|
| 53 |
|
|
$display(" ===============================================");
|
| 54 |
|
|
$display("| START SIMULATION |");
|
| 55 |
|
|
$display(" ===============================================");
|
| 56 |
|
|
`ifdef DBG_EN
|
| 57 |
154 |
olivier.gi |
`ifdef DBG_UART
|
| 58 |
134 |
olivier.gi |
`ifdef ASIC
|
| 59 |
|
|
test_nr = 0;
|
| 60 |
|
|
#1 dbg_en = 0;
|
| 61 |
|
|
repeat(30) @(posedge dco_clk);
|
| 62 |
|
|
stimulus_done = 0;
|
| 63 |
|
|
|
| 64 |
|
|
// Make sure the CPU always starts executing when the
|
| 65 |
|
|
// debug interface is disabled during POR.
|
| 66 |
|
|
// Also make sure that the debug interface clock is stopped
|
| 67 |
|
|
// and that it is under reset
|
| 68 |
|
|
//--------------------------------------------------------
|
| 69 |
|
|
dbg_en = 0;
|
| 70 |
|
|
test_nr = 1;
|
| 71 |
|
|
|
| 72 |
|
|
@(negedge dco_clk) dbg_clk_counter = 0;
|
| 73 |
|
|
|
| 74 |
|
|
repeat(300) @(posedge dco_clk);
|
| 75 |
|
|
if (r14 === 16'h0000) tb_error("====== CPU is stopped event though the debug interface is disabled - test 1 =====");
|
| 76 |
|
|
if (dbg_clk_counter !== 0) tb_error("====== DBG_CLK is not stopped (test 1) =====");
|
| 77 |
|
|
if (dbg_rst == 1'b0) tb_error("====== DBG_RST signal is not active (test 3) =====");
|
| 78 |
|
|
test_var = r14;
|
| 79 |
|
|
|
| 80 |
|
|
|
| 81 |
|
|
// Make sure that enabling the debug interface after the POR
|
| 82 |
|
|
// don't stop the cpu
|
| 83 |
|
|
// Also make sure that the debug interface clock is running
|
| 84 |
|
|
// and that its reset is released
|
| 85 |
|
|
//--------------------------------------------------------
|
| 86 |
|
|
dbg_en = 1;
|
| 87 |
|
|
test_nr = 2;
|
| 88 |
|
|
|
| 89 |
|
|
@(negedge dco_clk) dbg_clk_counter = 0;
|
| 90 |
|
|
|
| 91 |
|
|
repeat(300) @(posedge dco_clk);
|
| 92 |
|
|
if (r14 === test_var[15:0]) tb_error("====== CPU is stopped when the debug interface is disabled after POR - test 4 =====");
|
| 93 |
|
|
if (dbg_clk_counter == 0) tb_error("====== DBG_CLK is not running (test 5) =====");
|
| 94 |
|
|
if (dbg_rst !== 1'b0) tb_error("====== DBG_RST signal is active (test 6) =====");
|
| 95 |
|
|
|
| 96 |
|
|
|
| 97 |
|
|
// Make sure that disabling the CPU with debug enabled
|
| 98 |
|
|
// will stop the CPU
|
| 99 |
|
|
// Also make sure that the debug interface clock is stopped
|
| 100 |
|
|
// and that it is NOT under reset
|
| 101 |
|
|
//--------------------------------------------------------
|
| 102 |
|
|
cpu_en = 0;
|
| 103 |
|
|
dbg_en = 1;
|
| 104 |
|
|
test_nr = 3;
|
| 105 |
|
|
|
| 106 |
|
|
#(6*50);
|
| 107 |
|
|
test_var = r14;
|
| 108 |
|
|
dbg_clk_counter = 0;
|
| 109 |
|
|
|
| 110 |
|
|
#(300*50);
|
| 111 |
|
|
if (r14 !== test_var[15:0]) tb_error("====== CPU is not stopped (test 7) =====");
|
| 112 |
|
|
if (dbg_clk_counter !== 0) tb_error("====== DBG_CLK is not running (test 8) =====");
|
| 113 |
|
|
if (dbg_rst !== 1'b0) tb_error("====== DBG_RST signal is active (test 9) =====");
|
| 114 |
|
|
|
| 115 |
|
|
cpu_en = 1;
|
| 116 |
|
|
repeat(6) @(negedge dco_clk);
|
| 117 |
|
|
|
| 118 |
|
|
|
| 119 |
|
|
// Create POR with debug enable and observe the
|
| 120 |
|
|
// behavior depending on the DBG_RST_BRK_EN define
|
| 121 |
|
|
//--------------------------------------------------------
|
| 122 |
|
|
dbg_en = 1;
|
| 123 |
|
|
test_nr = 4;
|
| 124 |
|
|
|
| 125 |
|
|
@(posedge dco_clk); // Generate POR
|
| 126 |
|
|
reset_n = 1'b0;
|
| 127 |
|
|
@(posedge dco_clk);
|
| 128 |
|
|
reset_n = 1'b1;
|
| 129 |
|
|
|
| 130 |
|
|
repeat(300) @(posedge dco_clk);
|
| 131 |
|
|
`ifdef DBG_RST_BRK_EN
|
| 132 |
|
|
if (r14 !== 16'h0000) tb_error("====== CPU is not stopped with the debug interface enabled and DBG_RST_BRK_EN=1 - test 3 =====");
|
| 133 |
|
|
`else
|
| 134 |
|
|
if (r14 === 16'h0000) tb_error("====== CPU is stopped with the debug interface enabled and DBG_RST_BRK_EN=0 - test 3 =====");
|
| 135 |
|
|
`endif
|
| 136 |
|
|
|
| 137 |
|
|
// Send uart synchronization frame
|
| 138 |
|
|
dbg_uart_tx(DBG_SYNC);
|
| 139 |
|
|
|
| 140 |
|
|
// Check CPU_CTL reset value
|
| 141 |
|
|
dbg_uart_rd(CPU_CTL);
|
| 142 |
|
|
`ifdef DBG_RST_BRK_EN
|
| 143 |
|
|
if (dbg_uart_buf !== 16'h0030) tb_error("====== CPU_CTL wrong reset value - test 4 =====");
|
| 144 |
|
|
`else
|
| 145 |
|
|
if (dbg_uart_buf !== 16'h0010) tb_error("====== CPU_CTL wrong reset value - test 4 =====");
|
| 146 |
|
|
`endif
|
| 147 |
|
|
|
| 148 |
|
|
|
| 149 |
|
|
// Make sure that DBG_EN resets the debug interface
|
| 150 |
|
|
//--------------------------------------------------------
|
| 151 |
|
|
test_nr = 5;
|
| 152 |
|
|
|
| 153 |
|
|
// Let the CPU run
|
| 154 |
|
|
dbg_uart_wr(CPU_CTL, 16'h0002);
|
| 155 |
|
|
|
| 156 |
|
|
repeat(300) @(posedge dco_clk);
|
| 157 |
|
|
dbg_uart_wr(CPU_CTL, 16'h0000);
|
| 158 |
|
|
dbg_uart_wr(MEM_DATA, 16'haa55);
|
| 159 |
|
|
dbg_uart_rd(CPU_CTL);
|
| 160 |
|
|
if (dbg_uart_buf !== 16'h0000) tb_error("====== CPU_CTL write access failed - test 5 =====");
|
| 161 |
|
|
dbg_uart_rd(MEM_DATA);
|
| 162 |
|
|
if (dbg_uart_buf !== 16'haa55) tb_error("====== MEM_DATA write access failed - test 6 =====");
|
| 163 |
|
|
|
| 164 |
|
|
|
| 165 |
|
|
test_var = r14; // Backup the current register value
|
| 166 |
|
|
|
| 167 |
|
|
|
| 168 |
|
|
@(posedge dco_clk); // Resets the debug interface
|
| 169 |
|
|
dbg_en = 1'b0;
|
| 170 |
|
|
repeat(2) @(posedge dco_clk);
|
| 171 |
|
|
dbg_en = 1'b1;
|
| 172 |
|
|
|
| 173 |
|
|
// Make sure that the register was not reseted
|
| 174 |
|
|
if (r14 < test_var) tb_error("====== CPU was reseted with DBG_EN - test 7 =====");
|
| 175 |
|
|
repeat(2) @(posedge dco_clk);
|
| 176 |
|
|
|
| 177 |
|
|
// Send uart synchronization frame
|
| 178 |
|
|
dbg_uart_tx(DBG_SYNC);
|
| 179 |
|
|
|
| 180 |
|
|
// Check CPU_CTL reset value
|
| 181 |
|
|
dbg_uart_rd(CPU_CTL);
|
| 182 |
|
|
`ifdef DBG_RST_BRK_EN
|
| 183 |
|
|
if (dbg_uart_buf !== 16'h0030) tb_error("====== CPU_CTL wrong reset value - test 8 =====");
|
| 184 |
|
|
`else
|
| 185 |
|
|
if (dbg_uart_buf !== 16'h0010) tb_error("====== CPU_CTL wrong reset value - test 8 =====");
|
| 186 |
|
|
`endif
|
| 187 |
|
|
dbg_uart_rd(MEM_DATA);
|
| 188 |
|
|
if (dbg_uart_buf !== 16'h0000) tb_error("====== MEM_DATA read access failed - test 9 =====");
|
| 189 |
|
|
|
| 190 |
|
|
|
| 191 |
|
|
// Make sure that RESET_N resets the debug interface
|
| 192 |
|
|
//--------------------------------------------------------
|
| 193 |
|
|
test_nr = 6;
|
| 194 |
|
|
|
| 195 |
|
|
// Let the CPU run
|
| 196 |
|
|
dbg_uart_wr(CPU_CTL, 16'h0002);
|
| 197 |
|
|
|
| 198 |
|
|
repeat(300) @(posedge dco_clk);
|
| 199 |
|
|
dbg_uart_wr(CPU_CTL, 16'h0000);
|
| 200 |
|
|
dbg_uart_wr(MEM_DATA, 16'haa55);
|
| 201 |
|
|
dbg_uart_rd(CPU_CTL);
|
| 202 |
|
|
if (dbg_uart_buf !== 16'h0000) tb_error("====== CPU_CTL write access failed - test 10 =====");
|
| 203 |
|
|
dbg_uart_rd(MEM_DATA);
|
| 204 |
|
|
if (dbg_uart_buf !== 16'haa55) tb_error("====== MEM_DATA write access failed - test 11 =====");
|
| 205 |
|
|
|
| 206 |
|
|
test_nr = 7;
|
| 207 |
|
|
|
| 208 |
|
|
@(posedge dco_clk); // Generates POR
|
| 209 |
|
|
reset_n = 1'b0;
|
| 210 |
|
|
repeat(2) @(posedge dco_clk);
|
| 211 |
|
|
reset_n = 1'b1;
|
| 212 |
|
|
|
| 213 |
|
|
// Make sure that the register was reseted
|
| 214 |
|
|
if (r14 !== 16'h0000) tb_error("====== CPU was not reseted with RESET_N - test 12 =====");
|
| 215 |
|
|
repeat(2) @(posedge dco_clk);
|
| 216 |
|
|
|
| 217 |
|
|
// Send uart synchronization frame
|
| 218 |
|
|
dbg_uart_tx(DBG_SYNC);
|
| 219 |
|
|
|
| 220 |
|
|
test_nr = 8;
|
| 221 |
|
|
|
| 222 |
|
|
// Check CPU_CTL reset value
|
| 223 |
|
|
dbg_uart_rd(CPU_CTL);
|
| 224 |
|
|
`ifdef DBG_RST_BRK_EN
|
| 225 |
|
|
if (dbg_uart_buf !== 16'h0030) tb_error("====== CPU_CTL wrong reset value - test 8 =====");
|
| 226 |
|
|
`else
|
| 227 |
|
|
if (dbg_uart_buf !== 16'h0010) tb_error("====== CPU_CTL wrong reset value - test 8 =====");
|
| 228 |
|
|
`endif
|
| 229 |
|
|
dbg_uart_rd(MEM_DATA);
|
| 230 |
|
|
if (dbg_uart_buf !== 16'h0000) tb_error("====== MEM_DATA read access failed - test 9 =====");
|
| 231 |
|
|
|
| 232 |
|
|
|
| 233 |
|
|
// Let the CPU run
|
| 234 |
|
|
dbg_uart_wr(CPU_CTL, 16'h0002);
|
| 235 |
|
|
|
| 236 |
|
|
test_nr = 9;
|
| 237 |
|
|
|
| 238 |
|
|
// Generate IRQ to terminate the test pattern
|
| 239 |
|
|
irq[1] = 1'b1;
|
| 240 |
|
|
@(r13);
|
| 241 |
|
|
irq[1] = 1'b0;
|
| 242 |
|
|
|
| 243 |
|
|
stimulus_done = 1;
|
| 244 |
|
|
|
| 245 |
|
|
`else
|
| 246 |
|
|
$display(" ===============================================");
|
| 247 |
|
|
$display("| SIMULATION SKIPPED |");
|
| 248 |
|
|
$display("| (this test is not supported in FPGA mode) |");
|
| 249 |
|
|
$display(" ===============================================");
|
| 250 |
|
|
$finish;
|
| 251 |
|
|
`endif
|
| 252 |
|
|
`else
|
| 253 |
|
|
|
| 254 |
|
|
$display(" ===============================================");
|
| 255 |
|
|
$display("| SIMULATION SKIPPED |");
|
| 256 |
154 |
olivier.gi |
$display("| (serial debug interface UART not included) |");
|
| 257 |
|
|
$display(" ===============================================");
|
| 258 |
|
|
$finish;
|
| 259 |
|
|
`endif
|
| 260 |
|
|
`else
|
| 261 |
|
|
|
| 262 |
|
|
$display(" ===============================================");
|
| 263 |
|
|
$display("| SIMULATION SKIPPED |");
|
| 264 |
134 |
olivier.gi |
$display("| (serial debug interface not included) |");
|
| 265 |
|
|
$display(" ===============================================");
|
| 266 |
|
|
$finish;
|
| 267 |
|
|
`endif
|
| 268 |
|
|
end
|
| 269 |
|
|
|