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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [core/] [sim/] [rtl_sim/] [src/] [dbg_i2c_sync.v] - Diff between revs 200 and 202

Only display areas with differences | Details | Blame | View Log

Rev 200 Rev 202
/*===========================================================================*/
/*===========================================================================*/
/* Copyright (C) 2001 Authors                                                */
/* Copyright (C) 2001 Authors                                                */
/*                                                                           */
/*                                                                           */
/* This source file may be used and distributed without restriction provided */
/* This source file may be used and distributed without restriction provided */
/* that this copyright statement is not removed from the file and that any   */
/* that this copyright statement is not removed from the file and that any   */
/* derivative work contains the original copyright notice and the associated */
/* derivative work contains the original copyright notice and the associated */
/* disclaimer.                                                               */
/* disclaimer.                                                               */
/*                                                                           */
/*                                                                           */
/* This source file is free software; you can redistribute it and/or modify  */
/* This source file is free software; you can redistribute it and/or modify  */
/* it under the terms of the GNU Lesser General Public License as published  */
/* it under the terms of the GNU Lesser General Public License as published  */
/* by the Free Software Foundation; either version 2.1 of the License, or    */
/* by the Free Software Foundation; either version 2.1 of the License, or    */
/* (at your option) any later version.                                       */
/* (at your option) any later version.                                       */
/*                                                                           */
/*                                                                           */
/* This source is distributed in the hope that it will be useful, but WITHOUT*/
/* This source is distributed in the hope that it will be useful, but WITHOUT*/
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or     */
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or     */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public       */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public       */
/* License for more details.                                                 */
/* License for more details.                                                 */
/*                                                                           */
/*                                                                           */
/* You should have received a copy of the GNU Lesser General Public License  */
/* You should have received a copy of the GNU Lesser General Public License  */
/* along with this source; if not, write to the Free Software Foundation,    */
/* along with this source; if not, write to the Free Software Foundation,    */
/* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA        */
/* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA        */
/*                                                                           */
/*                                                                           */
/*===========================================================================*/
/*===========================================================================*/
/*                            DEBUG INTERFACE:  I2C                         */
/*                            DEBUG INTERFACE:  I2C                         */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Test the I2C debug interface:                                            */
/* Test the I2C debug interface:                                            */
/*                        - Check synchronization of the serial              */
/*                        - Check synchronization of the serial              */
/*                          debug interface input.                           */
/*                          debug interface input.                           */
/*                                                                           */
/*                                                                           */
/* Author(s):                                                                */
/* Author(s):                                                                */
/*             - Olivier Girard,    olgirard@gmail.com                       */
/*             - Olivier Girard,    olgirard@gmail.com                       */
/*                                                                           */
/*                                                                           */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* $Rev: 95 $                                                                */
/* $Rev: 95 $                                                                */
/* $LastChangedBy: olivier.girard $                                          */
/* $LastChangedBy: olivier.girard $                                          */
/* $LastChangedDate: 2011-02-24 21:37:57 +0100 (Thu, 24 Feb 2011) $          */
/* $LastChangedDate: 2011-02-24 21:37:57 +0100 (Thu, 24 Feb 2011) $          */
/*===========================================================================*/
/*===========================================================================*/
 
 
`define VERY_LONG_TIMEOUT
`define VERY_LONG_TIMEOUT
 
 
integer    ii;
integer    ii;
reg [15:0] jj;
reg [15:0] jj;
integer    kk;
integer    kk;
 
 
initial
initial
   begin
   begin
      $display(" ===============================================");
      $display(" ===============================================");
      $display("|                 START SIMULATION              |");
      $display("|                 START SIMULATION              |");
      $display(" ===============================================");
      $display(" ===============================================");
`ifdef DBG_EN
`ifdef DBG_EN
`ifdef DBG_I2C
`ifdef DBG_I2C
      #1 dbg_en = 1;
      #1 dbg_en = 1;
      repeat(30) @(posedge mclk);
      repeat(30) @(posedge mclk);
      stimulus_done = 0;
      stimulus_done = 0;
 
 
      // Enable metastablity emulation for the SCL and SDA master path
      // Enable metastablity emulation for the SCL and SDA master path
      dbg_scl_master_meta     = 1'b1;
      dbg_scl_master_meta     = 1'b1;
      dbg_sda_master_out_meta = 1'b1;
      dbg_sda_master_out_meta = 1'b1;
 
 
      //--------------------------------------------------------
      //--------------------------------------------------------
      // TRY VARIOUS SERIAL DEBUG INTERFACE TRANSFER
      // TRY VARIOUS SERIAL DEBUG INTERFACE TRANSFER
      // WITH DIFFERENT BAUD-RATES
      // WITH DIFFERENT BAUD-RATES
      //--------------------------------------------------------
      //--------------------------------------------------------
 
 
      for ( ii=0; ii < 200; ii=ii+1)
      for ( ii=0; ii < 200; ii=ii+1)
        begin
        begin
           #1 reset_n = 0;
           #1 reset_n = 0;
           repeat(1) @(posedge mclk);
           repeat(1) @(posedge mclk);
           #1 reset_n = 1;
           #1 reset_n = 1;
           repeat(10) @(posedge mclk);
           repeat(10) @(posedge mclk);
 
 
           I2C_PERIOD = 600 + 1*ii;
           I2C_PERIOD = 600 + 1*ii;
           $display("Synchronisation test for DBG_I2C_PERIOD = %5d ns  /  ii = %-d", I2C_PERIOD, ii);
           $display("Synchronisation test for DBG_I2C_PERIOD = %5d ns  /  ii = %-d", I2C_PERIOD, ii);
 
 
 
 
           // READ CPU_ID
           // READ CPU_ID
           dbg_i2c_rd(CPU_ID_LO);
           dbg_i2c_rd(CPU_ID_LO);
           if (dbg_i2c_buf !== dbg_cpu_id[15:0])
           if (dbg_i2c_buf !== dbg_cpu_id[15:0])
             begin
             begin
                $display("CPU_ID_LO: read = 0x%-4h / expected = 0x%-4h", dbg_i2c_buf, dbg_cpu_id[15:0]);
                $display("CPU_ID_LO: read = 0x%-4h / expected = 0x%-4h", dbg_i2c_buf, dbg_cpu_id[15:0]);
                tb_error("====== CPU_ID_LO incorrect (test 1) =====");
                tb_error("====== CPU_ID_LO incorrect (test 1) =====");
                force_end_of_sim;
                force_end_of_sim;
             end
             end
           dbg_i2c_rd(CPU_ID_HI);
           dbg_i2c_rd(CPU_ID_HI);
           if (dbg_i2c_buf !== dbg_cpu_id[31:16])
           if (dbg_i2c_buf !== dbg_cpu_id[31:16])
             begin
             begin
                $display("CPU_ID_HI: read = 0x%-4h / expected = 0x%-4h", dbg_i2c_buf, dbg_cpu_id[31:16]);
                $display("CPU_ID_HI: read = 0x%-4h / expected = 0x%-4h", dbg_i2c_buf, dbg_cpu_id[31:16]);
                tb_error("====== CPU_ID_HI incorrect (test 1) =====");
                tb_error("====== CPU_ID_HI incorrect (test 1) =====");
                force_end_of_sim;
                force_end_of_sim;
             end
             end
 
 
           //-----------------------------------
           //-----------------------------------
           // MAKE SOME READ/WRITE ACCESS
           // MAKE SOME READ/WRITE ACCESS
           //-----------------------------------
           //-----------------------------------
 
 
           for ( kk=0; kk < 10; kk=kk+1)
           for ( kk=0; kk < 10; kk=kk+1)
             begin
             begin
 
 
                jj = 'h4328;
                jj = 'h4328;
                dbg_i2c_wr(MEM_DATA,  16'h5555);
                dbg_i2c_wr(MEM_DATA,  16'h5555);
                dbg_i2c_rd(MEM_DATA);
                dbg_i2c_rd(MEM_DATA);
                if (dbg_i2c_buf !== 16'h5555)
                if (dbg_i2c_buf !== 16'h5555)
                  begin
                  begin
                     $display("DMEM_DATA: read = 0x%-4h / expected = 0x5555", dbg_i2c_buf);
                     $display("DMEM_DATA: read = 0x%-4h / expected = 0x5555", dbg_i2c_buf);
                     tb_error("====== MEM_DATA incorrect (test 1) =====");
                     tb_error("====== MEM_DATA incorrect (test 1) =====");
                     force_end_of_sim;
                     force_end_of_sim;
                  end
                  end
 
 
                jj = 'h3280;
                jj = 'h3280;
                dbg_i2c_wr(MEM_DATA,  16'haaaa);
                dbg_i2c_wr(MEM_DATA,  16'haaaa);
                dbg_i2c_rd(MEM_DATA);
                dbg_i2c_rd(MEM_DATA);
                if (dbg_i2c_buf !== 16'haaaa)
                if (dbg_i2c_buf !== 16'haaaa)
                  begin
                  begin
                     $display("DMEM_DATA: read = 0x%-4h / expected = 0xaaaa", dbg_i2c_buf);
                     $display("DMEM_DATA: read = 0x%-4h / expected = 0xaaaa", dbg_i2c_buf);
                     tb_error("====== MEM_DATA incorrect (test 2) =====");
                     tb_error("====== MEM_DATA incorrect (test 2) =====");
                     force_end_of_sim;
                     force_end_of_sim;
                  end
                  end
             end
             end
        end
        end
 
 
 
 
      //--------------------------------------------------------
      //--------------------------------------------------------
      // END OF TEST
      // END OF TEST
      //--------------------------------------------------------
      //--------------------------------------------------------
 
 
      #1 reset_n = 0;
      #1 reset_n = 0;
      repeat(1) @(posedge mclk);
      repeat(1) @(posedge mclk);
      #1 reset_n = 1;
      #1 reset_n = 1;
      repeat(10) @(posedge mclk);
      repeat(10) @(posedge mclk);
 
 
      I2C_PERIOD = 600;
      I2C_PERIOD = 600;
      $display("Synchronisation test for DBG_I2C_PERIOD = %5d ns  /  ii = %-d", I2C_PERIOD, ii);
      $display("Synchronisation test for DBG_I2C_PERIOD = %5d ns  /  ii = %-d", I2C_PERIOD, ii);
 
 
      // Let the CPU run
      // Let the CPU run
      dbg_i2c_wr(CPU_CTL,  16'h0002);
      dbg_i2c_wr(CPU_CTL,  16'h0002);
 
 
      // Generate an IRQ
      // Generate an IRQ
      wkup[0]         = 1'b1;
      wkup[0]         = 1'b1;
      @(negedge mclk);
      @(negedge mclk);
      irq[`IRQ_NR-16] = 1'b1;
      irq[`IRQ_NR-16] = 1'b1;
      @(negedge irq_acc[`IRQ_NR-16])
      @(negedge irq_acc[`IRQ_NR-16])
      @(negedge mclk);
      @(negedge mclk);
      wkup[0]         = 1'b0;
      wkup[0]         = 1'b0;
      irq[`IRQ_NR-16] = 1'b0;
      irq[`IRQ_NR-16] = 1'b0;
 
 
      repeat(10) @(posedge mclk);
      repeat(10) @(posedge mclk);
 
 
      stimulus_done = 1;
      stimulus_done = 1;
`else
`else
 
 
       $display(" ===============================================");
       tb_skip_finish("|   (serial debug interface I2C not included)   |");
       $display("|               SIMULATION SKIPPED              |");
 
       $display("|   (serial debug interface I2C not included)   |");
 
       $display(" ===============================================");
 
       $finish;
 
`endif
`endif
`else
`else
 
       tb_skip_finish("|      (serial debug interface not included)    |");
       $display(" ===============================================");
 
       $display("|               SIMULATION SKIPPED              |");
 
       $display("|      (serial debug interface not included)    |");
 
       $display(" ===============================================");
 
       $finish;
 
`endif
`endif
   end
   end
 
 
   task force_end_of_sim;
   task force_end_of_sim;
      begin
      begin
         repeat(10) @(posedge mclk);
         repeat(10) @(posedge mclk);
         $display(" ===============================================");
         $display(" ===============================================");
         $display("|               SIMULATION FAILED               |");
         $display("|               SIMULATION FAILED               |");
         $display("|     (some verilog stimulus checks failed)     |");
         $display("|     (some verilog stimulus checks failed)     |");
         $display(" ===============================================");
         $display(" ===============================================");
 
         $display("");
 
         tb_extra_report;
         $finish;
         $finish;
      end
      end
   endtask
   endtask
 
 

powered by: WebSVN 2.1.0

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