OpenCores
URL https://opencores.org/ocsvn/openmsp430/openmsp430/trunk

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [core/] [sim/] [rtl_sim/] [src/] [dbg_i2c_sync.v] - Blame information for rev 202

Details | Compare with Previous | View Log

Line No. Rev Author Line
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 202 olivier.gi
 
60 154 olivier.gi
      //--------------------------------------------------------
61
      // TRY VARIOUS SERIAL DEBUG INTERFACE TRANSFER
62
      // WITH DIFFERENT BAUD-RATES
63
      //--------------------------------------------------------
64 202 olivier.gi
 
65 154 olivier.gi
      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 202 olivier.gi
 
72 154 olivier.gi
           I2C_PERIOD = 600 + 1*ii;
73
           $display("Synchronisation test for DBG_I2C_PERIOD = %5d ns  /  ii = %-d", I2C_PERIOD, ii);
74
 
75 202 olivier.gi
 
76 154 olivier.gi
           // 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 202 olivier.gi
 
126 154 olivier.gi
      #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 202 olivier.gi
 
134 154 olivier.gi
      // Let the CPU run
135
      dbg_i2c_wr(CPU_CTL,  16'h0002);
136
 
137
      // Generate an IRQ
138 200 olivier.gi
      wkup[0]         = 1'b1;
139 154 olivier.gi
      @(negedge mclk);
140 200 olivier.gi
      irq[`IRQ_NR-16] = 1'b1;
141
      @(negedge irq_acc[`IRQ_NR-16])
142 154 olivier.gi
      @(negedge mclk);
143 200 olivier.gi
      wkup[0]         = 1'b0;
144
      irq[`IRQ_NR-16] = 1'b0;
145 202 olivier.gi
 
146 154 olivier.gi
      repeat(10) @(posedge mclk);
147
 
148
      stimulus_done = 1;
149
`else
150
 
151 202 olivier.gi
       tb_skip_finish("|   (serial debug interface I2C not included)   |");
152 154 olivier.gi
`endif
153
`else
154 202 olivier.gi
       tb_skip_finish("|      (serial debug interface not included)    |");
155 154 olivier.gi
`endif
156
   end
157
 
158
   task force_end_of_sim;
159
      begin
160
         repeat(10) @(posedge mclk);
161
         $display(" ===============================================");
162
         $display("|               SIMULATION FAILED               |");
163
         $display("|     (some verilog stimulus checks failed)     |");
164
         $display(" ===============================================");
165 202 olivier.gi
         $display("");
166
         tb_extra_report;
167 154 olivier.gi
         $finish;
168
      end
169
   endtask

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.