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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [core/] [sim/] [rtl_sim/] [src/] [dbg_uart_sync.v] - Diff between revs 134 and 192

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 134 Rev 192
/*===========================================================================*/
/*===========================================================================*/
/* 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:  UART                         */
/*                            DEBUG INTERFACE:  UART                         */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Test the UART debug interface:                                            */
/* Test the UART 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;
 
 
initial
initial
   begin
   begin
      $display(" ===============================================");
      $display(" ===============================================");
      $display("|                 START SIMULATION              |");
      $display("|                 START SIMULATION              |");
      $display(" ===============================================");
      $display(" ===============================================");
`ifdef DBG_EN
`ifdef DBG_EN
`ifdef DBG_UART
`ifdef DBG_UART
      #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 RXD path
      // Enable metastablity emulation for the RXD path
      dbg_uart_rxd_meta = 1'b1;
      dbg_uart_rxd_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 < 500; ii=ii+1)
      for ( ii=0; ii < 500; 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);
 
 
           UART_PERIOD = 650 + 1*ii;
           UART_PERIOD = 650 + 1*ii;
           $display("Synchronisation test for DBG_UART_PERIOD = %5d ns  /  ii = %-d", UART_PERIOD, ii);
           $display("Synchronisation test for DBG_UART_PERIOD = %5d ns  /  ii = %-d", UART_PERIOD, ii);
 
 
           // SEND UART SYNCHRONIZATION FRAME
           // SEND UART SYNCHRONIZATION FRAME
           dbg_uart_sync;
           dbg_uart_sync;
 
 
           // READ CPU_ID
           // READ CPU_ID
           dbg_uart_rd(CPU_ID_LO);
           dbg_uart_rd(CPU_ID_LO);
           if (dbg_uart_buf !== dbg_cpu_id[15:0])
           if (dbg_uart_buf !== dbg_cpu_id[15:0])
             begin
             begin
                $display("CPU_ID_LO: read = 0x%-4h / expected = 0x%-4h", dbg_uart_buf, dbg_cpu_id[15:0]);
                $display("CPU_ID_LO: read = 0x%-4h / expected = 0x%-4h", dbg_uart_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_uart_rd(CPU_ID_HI);
           dbg_uart_rd(CPU_ID_HI);
           if (dbg_uart_buf !== dbg_cpu_id[31:16])
           if (dbg_uart_buf !== dbg_cpu_id[31:16])
             begin
             begin
                $display("CPU_ID_HI: read = 0x%-4h / expected = 0x%-4h", dbg_uart_buf, dbg_cpu_id[31:16]);
                $display("CPU_ID_HI: read = 0x%-4h / expected = 0x%-4h", dbg_uart_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
           //-----------------------------------
           //-----------------------------------
           jj = 'h4328;
           jj = 'h4328;
           dbg_uart_wr(MEM_DATA,  16'h4328);
           dbg_uart_wr(MEM_DATA,  16'h4328);
           dbg_uart_rd(MEM_DATA);
           dbg_uart_rd(MEM_DATA);
           if (dbg_uart_buf !== 16'h4328)
           if (dbg_uart_buf !== 16'h4328)
             begin
             begin
                $display("DMEM_DATA: read = 0x%-4h / expected = 0x4328", dbg_uart_buf);
                $display("DMEM_DATA: read = 0x%-4h / expected = 0x4328", dbg_uart_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_uart_wr(MEM_DATA,  16'h3280);
           dbg_uart_wr(MEM_DATA,  16'h3280);
           dbg_uart_rd(MEM_DATA);
           dbg_uart_rd(MEM_DATA);
           if (dbg_uart_buf !== 16'h3280)
           if (dbg_uart_buf !== 16'h3280)
             begin
             begin
                $display("DMEM_DATA: read = 0x%-4h / expected = 0x3280", dbg_uart_buf);
                $display("DMEM_DATA: read = 0x%-4h / expected = 0x3280", dbg_uart_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
 
 
           jj = 'h2800;
           jj = 'h2800;
           dbg_uart_wr(MEM_DATA,  16'h2800);
           dbg_uart_wr(MEM_DATA,  16'h2800);
           dbg_uart_rd(MEM_DATA);
           dbg_uart_rd(MEM_DATA);
           if (dbg_uart_buf !== 16'h2800)
           if (dbg_uart_buf !== 16'h2800)
             begin
             begin
                $display("DMEM_DATA: read = 0x%-4h / expected = 0x2800", dbg_uart_buf);
                $display("DMEM_DATA: read = 0x%-4h / expected = 0x2800", dbg_uart_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 = 'h8000;
           jj = 'h8000;
           dbg_uart_wr(MEM_DATA,  16'h8000);
           dbg_uart_wr(MEM_DATA,  16'h8000);
           dbg_uart_rd(MEM_DATA);
           dbg_uart_rd(MEM_DATA);
           if (dbg_uart_buf !== 16'h8000)
           if (dbg_uart_buf !== 16'h8000)
             begin
             begin
                $display("DMEM_DATA: read = 0x%-4h / expected = 0x8000", dbg_uart_buf);
                $display("DMEM_DATA: read = 0x%-4h / expected = 0x8000", dbg_uart_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
 
 
           jj = 'h0000;
           jj = 'h0000;
           dbg_uart_wr(MEM_DATA,  16'h0000);
           dbg_uart_wr(MEM_DATA,  16'h0000);
           dbg_uart_rd(MEM_DATA);
           dbg_uart_rd(MEM_DATA);
           if (dbg_uart_buf !== 16'h0000)
           if (dbg_uart_buf !== 16'h0000)
             begin
             begin
                $display("DMEM_DATA: read = 0x%-4h / expected = 0x0000", dbg_uart_buf);
                $display("DMEM_DATA: read = 0x%-4h / expected = 0x0000", dbg_uart_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
 
 
           jj = 'hffff;
           jj = 'hffff;
           dbg_uart_wr(MEM_DATA,  16'hffff);
           dbg_uart_wr(MEM_DATA,  16'hffff);
           dbg_uart_rd(MEM_DATA);
           dbg_uart_rd(MEM_DATA);
           if (dbg_uart_buf !== 16'hffff)
           if (dbg_uart_buf !== 16'hffff)
             begin
             begin
                $display("DMEM_DATA: read = 0x%-4h / expected = 0xffff", dbg_uart_buf);
                $display("DMEM_DATA: read = 0x%-4h / expected = 0xffff", dbg_uart_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
 
 
           jj = 'h7f7f;
           jj = 'h7f7f;
           dbg_uart_wr(MEM_DATA,  16'h7f7f);
           dbg_uart_wr(MEM_DATA,  16'h7f7f);
           dbg_uart_rd(MEM_DATA);
           dbg_uart_rd(MEM_DATA);
           if (dbg_uart_buf !== 16'h7f7f)
           if (dbg_uart_buf !== 16'h7f7f)
             begin
             begin
                $display("DMEM_DATA: read = 0x%-4h / expected = 0x7f7f", dbg_uart_buf);
                $display("DMEM_DATA: read = 0x%-4h / expected = 0x7f7f", dbg_uart_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
 
 
           jj = 'h55aa;
           jj = 'h55aa;
           dbg_uart_wr(MEM_DATA,  16'h55aa);
           dbg_uart_wr(MEM_DATA,  16'h55aa);
           dbg_uart_rd(MEM_DATA);
           dbg_uart_rd(MEM_DATA);
           if (dbg_uart_buf !== 16'h55aa)
           if (dbg_uart_buf !== 16'h55aa)
             begin
             begin
                $display("DMEM_DATA: read = 0x%-4h / expected = 0x55aa", dbg_uart_buf);
                $display("DMEM_DATA: read = 0x%-4h / expected = 0x55aa", dbg_uart_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
 
 
           jj = 'h5aa5;
           jj = 'h5aa5;
           dbg_uart_wr(MEM_DATA,  16'h5aa5);
           dbg_uart_wr(MEM_DATA,  16'h5aa5);
           dbg_uart_rd(MEM_DATA);
           dbg_uart_rd(MEM_DATA);
           if (dbg_uart_buf !== 16'h5aa5)
           if (dbg_uart_buf !== 16'h5aa5)
             begin
             begin
                $display("DMEM_DATA: read = 0x%-4h / expected = 0x5aa5", dbg_uart_buf);
                $display("DMEM_DATA: read = 0x%-4h / expected = 0x5aa5", dbg_uart_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
 
 
 
 
      //--------------------------------------------------------
      //--------------------------------------------------------
      // TRY LONGEST POSSIBLE SYNCHRONIZATION FRAME
      // TRY LONGEST POSSIBLE SYNCHRONIZATION FRAME
      //--------------------------------------------------------
      //--------------------------------------------------------
 
 
      #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);
 
 
      dbg_uart_rxd_pre = 1'b0;
      dbg_uart_rxd_pre = 1'b0;
      @(posedge dut.dbg_0.dbg_uart_0.sync_cnt[`DBG_UART_XFER_CNT_W+2]);
      @(posedge dut.dbg_0.dbg_uart_0.sync_cnt[`DBG_UART_XFER_CNT_W+2]);
      dbg_uart_rxd_pre = 1'b1;
      dbg_uart_rxd_pre = 1'b1;
 
 
      repeat(100) @(posedge mclk);
      repeat(100) @(posedge mclk);
 
 
      dbg_uart_rxd_pre = 1'b0;
      dbg_uart_rxd_pre = 1'b0;
      @(posedge dut.dbg_0.dbg_uart_0.xfer_cnt[`DBG_UART_XFER_CNT_W-1]);
      @(posedge dut.dbg_0.dbg_uart_0.xfer_cnt[`DBG_UART_XFER_CNT_W-1]);
      dbg_uart_rxd_pre = 1'b1;
      dbg_uart_rxd_pre = 1'b1;
 
 
      repeat(100) @(posedge mclk);
      repeat(100) @(posedge mclk);
 
 
 
 
      //--------------------------------------------------------
      //--------------------------------------------------------
      // 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);
 
 
      UART_PERIOD = 550;
      UART_PERIOD = 550;
      $display("Synchronisation test for DBG_UART_PERIOD = %5d ns  /  ii = %-d", UART_PERIOD, ii);
      $display("Synchronisation test for DBG_UART_PERIOD = %5d ns  /  ii = %-d", UART_PERIOD, ii);
 
 
      // SEND UART SYNCHRONIZATION FRAME
      // SEND UART SYNCHRONIZATION FRAME
      dbg_uart_sync;
      dbg_uart_sync;
 
 
      // Let the CPU run
      // Let the CPU run
      dbg_uart_wr(CPU_CTL,  16'h0002);
      dbg_uart_wr(CPU_CTL,  16'h0002);
 
 
      // Generate an IRQ
      // Generate an IRQ
      wkup[0]   = 1'b1;
      wkup[0]            = 1'b1;
      @(negedge mclk);
      @(negedge mclk);
      irq[0]    = 1'b1;
      irq[`IRQ_NR-16]    = 1'b1;
      @(negedge irq_acc[0])
      @(negedge irq_acc[`IRQ_NR-16])
      @(negedge mclk);
      @(negedge mclk);
      wkup[0]   = 1'b0;
      wkup[0]   = 1'b0;
      irq[0]    = 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(" ===============================================");
       $display(" ===============================================");
       $display("|               SIMULATION SKIPPED              |");
       $display("|               SIMULATION SKIPPED              |");
       $display("|   (serial debug interface UART not included)  |");
       $display("|   (serial debug interface UART not included)  |");
       $display(" ===============================================");
       $display(" ===============================================");
       $finish;
       $finish;
`endif
`endif
`else
`else
 
 
       $display(" ===============================================");
       $display(" ===============================================");
       $display("|               SIMULATION SKIPPED              |");
       $display("|               SIMULATION SKIPPED              |");
       $display("|      (serial debug interface not included)    |");
       $display("|      (serial debug interface not included)    |");
       $display(" ===============================================");
       $display(" ===============================================");
       $finish;
       $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(" ===============================================");
         $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.