OpenCores
URL https://opencores.org/ocsvn/fpga-median/fpga-median/trunk

Subversion Repositories fpga-median

[/] [fpga-median/] [trunk/] [sim/] [tb/] [driver.sv] - Diff between revs 2 and 9

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

Rev 2 Rev 9
 
/* --------------------------------------------------------------------------------
 
 This file is part of FPGA Median Filter.
 
 
 
    FPGA Median Filter is free software: you can redistribute it and/or modify
 
    it under the terms of the GNU General Public License as published by
 
    the Free Software Foundation, either version 3 of the License, or
 
    (at your option) any later version.
 
 
 
    FPGA Median Filter is distributed in the hope that it will be useful,
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
    GNU General Public License for more details.
 
 
 
    You should have received a copy of the GNU General Public License
 
    along with FPGA Median Filter.  If not, see .
 
-------------------------------------------------------------------------------- */
// +----------------------------------------------------------------------------
// +----------------------------------------------------------------------------
// Universidade Federal da Bahia
// Universidade Federal da Bahia
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// PROJECT: FPGA Median Filter
// PROJECT: FPGA Median Filter
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// FILE NAME            : driver.sv
// FILE NAME            : driver.sv
// AUTHOR               : Laue Rami Souza Costa de Jesus
// AUTHOR               : Laue Rami Souza Costa de Jesus
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
class driver;
class driver;
//  localparam MEMORY_WIDTH = 4331;
//  localparam MEMORY_WIDTH = 4331;
  localparam NUM_PIXELS = (`IMG_WIDTH * `IMG_HEIGHT) - 1;//102400-1;
  localparam NUM_PIXELS = (`IMG_WIDTH * `IMG_HEIGHT) - 1;//102400-1;
  int cnt;
  int cnt;
  int addr;
  int addr;
  int i;
  int i;
  logic [31:0] r_data_bram0;
  logic [31:0] r_data_bram0;
  logic [31:0] r_data_bram1;
  logic [31:0] r_data_bram1;
  logic [31:0] r_data_bram2;
  logic [31:0] r_data_bram2;
  logic [7:0] image [0:NUM_PIXELS];
  logic [7:0] image [0:NUM_PIXELS];
  virtual interface dut_if dut_if;
  virtual interface dut_if dut_if;
  function new (virtual interface dut_if m_dut_if);
  function new (virtual interface dut_if m_dut_if);
  begin
  begin
     dut_if = m_dut_if;
     dut_if = m_dut_if;
  end
  end
  endfunction
  endfunction
  task init();
  task init();
    begin
    begin
        $display("RESET --------");
        $display("RESET --------");
        dut_if.rst_n    = 1;
        dut_if.rst_n    = 1;
        dut_if.start    = 0;
        dut_if.start    = 0;
        dut_if.ch_word0 = 0;
        dut_if.ch_word0 = 0;
        dut_if.ch_word1 = 0;
        dut_if.ch_word1 = 0;
        dut_if.ch_word2 = 0;
        dut_if.ch_word2 = 0;
        addr = 0;
        addr = 0;
        i = 0;
        i = 0;
        dut_if.end_of_operation = 0;
        dut_if.end_of_operation = 0;
        repeat(5)@(negedge dut_if.clk);
        repeat(5)@(negedge dut_if.clk);
        dut_if.rst_n = 0;
        dut_if.rst_n = 0;
        repeat(5)@(negedge dut_if.clk);
        repeat(5)@(negedge dut_if.clk);
        dut_if.rst_n = 1;
        dut_if.rst_n = 1;
        dut_if.start = 1;
        dut_if.start = 1;
        repeat(3)@(negedge dut_if.clk);
        repeat(3)@(negedge dut_if.clk);
    end
    end
  endtask
  endtask
  task reorganize_lines();
  task reorganize_lines();
    begin
    begin
      wait(dut_if.start);
      wait(dut_if.start);
      @(negedge dut_if.clk);
      @(negedge dut_if.clk);
      while(!(dut_if.end_of_operation))begin
      while(!(dut_if.end_of_operation))begin
         if(dut_if.window_line_counter == 2'b00)begin
         if(dut_if.window_line_counter == 2'b00)begin
            dut_if.ch_word0 = dut_if.word0;
            dut_if.ch_word0 = dut_if.word0;
            dut_if.ch_word1 = dut_if.word1;
            dut_if.ch_word1 = dut_if.word1;
            dut_if.ch_word2 = dut_if.word2;
            dut_if.ch_word2 = dut_if.word2;
         end
         end
         else if(dut_if.window_line_counter == 2'b01)begin
         else if(dut_if.window_line_counter == 2'b01)begin
            dut_if.ch_word0 = dut_if.word1;
            dut_if.ch_word0 = dut_if.word1;
            dut_if.ch_word1 = dut_if.word2;
            dut_if.ch_word1 = dut_if.word2;
            dut_if.ch_word2 = dut_if.word0;
            dut_if.ch_word2 = dut_if.word0;
         end
         end
         else if(dut_if.window_line_counter == 2'b10)begin
         else if(dut_if.window_line_counter == 2'b10)begin
            dut_if.ch_word0 = dut_if.word2;
            dut_if.ch_word0 = dut_if.word2;
            dut_if.ch_word1 = dut_if.word0;
            dut_if.ch_word1 = dut_if.word0;
            dut_if.ch_word2 = dut_if.word1;
            dut_if.ch_word2 = dut_if.word1;
         end
         end
         //addr = addr+1;
         //addr = addr+1;
         //read 4 pixels from all memories
         //read 4 pixels from all memories
         @(negedge dut_if.clk);
         @(negedge dut_if.clk);
      end
      end
      dut_if.start = 0;
      dut_if.start = 0;
    end
    end
  endtask
  endtask
  task receive_data();
  task receive_data();
     fork begin
     fork begin
        while(i
        while(i
           //seria bom ter um sinal para saber quando terminou a mediana
           //seria bom ter um sinal para saber quando terminou a mediana
           dut_if.result[i] = dut_if.pixel1;
           dut_if.result[i] = dut_if.pixel1;
           image[i] = dut_if.pixel1;
           image[i] = dut_if.pixel1;
           dut_if.result[i+1] = dut_if.pixel2;
           dut_if.result[i+1] = dut_if.pixel2;
           image[i+1] = dut_if.pixel2;
           image[i+1] = dut_if.pixel2;
           dut_if.result[i+2] = dut_if.pixel3;
           dut_if.result[i+2] = dut_if.pixel3;
           image[i+2] = dut_if.pixel3;
           image[i+2] = dut_if.pixel3;
           dut_if.result[i+3] = dut_if.pixel4;
           dut_if.result[i+3] = dut_if.pixel4;
           image[i+3] = dut_if.pixel4;
           image[i+3] = dut_if.pixel4;
           @(negedge dut_if.clk);
           @(negedge dut_if.clk);
           i = i + 4;
           i = i + 4;
        end
        end
        dut_if.end_of_operation = 1;
        dut_if.end_of_operation = 1;
     end
     end
     join_none
     join_none
  endtask
  endtask
  function int write_file();
  function int write_file();
     integer file_ID = $fopen("./image.hex", "w");
     integer file_ID = $fopen("./image.hex", "w");
     for(int i=0 ; i<=NUM_PIXELS ; i++ ) begin
     for(int i=0 ; i<=NUM_PIXELS ; i++ ) begin
        if(image[i] === 8'bx)
        if(image[i] === 8'bx)
           $fdisplay(file_ID,"%x", 8'b0);
           $fdisplay(file_ID,"%x", 8'b0);
        else
        else
           $fdisplay(file_ID,"%x", image[i]);
           $fdisplay(file_ID,"%x", image[i]);
     end
     end
     $fclose(file_ID);
     $fclose(file_ID);
  endfunction
  endfunction
endclass
endclass
 
 

powered by: WebSVN 2.1.0

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