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

Subversion Repositories fpga-median

[/] [fpga-median/] [tags/] [fpga-filter-b1/] [sim/] [tb/] [driver.sv] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 joaocarlos
/* --------------------------------------------------------------------------------
2
 This file is part of FPGA Median Filter.
3
 
4
    FPGA Median Filter is free software: you can redistribute it and/or modify
5
    it under the terms of the GNU General Public License as published by
6
    the Free Software Foundation, either version 3 of the License, or
7
    (at your option) any later version.
8
 
9
    FPGA Median Filter is distributed in the hope that it will be useful,
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
    GNU General Public License for more details.
13
 
14
    You should have received a copy of the GNU General Public License
15
    along with FPGA Median Filter.  If not, see .
16
-------------------------------------------------------------------------------- */
17 2 joaocarlos
// +----------------------------------------------------------------------------
18
// Universidade Federal da Bahia
19
//------------------------------------------------------------------------------
20
// PROJECT: FPGA Median Filter
21
//------------------------------------------------------------------------------
22
// FILE NAME            : driver.sv
23
// AUTHOR               : Laue Rami Souza Costa de Jesus
24
// -----------------------------------------------------------------------------
25
class driver;
26
 
27
//  localparam MEMORY_WIDTH = 4331;
28
  localparam NUM_PIXELS = (`IMG_WIDTH * `IMG_HEIGHT) - 1;//102400-1;
29
 
30
  int cnt;
31
  int addr;
32
  int i;
33
  logic [31:0] r_data_bram0;
34
  logic [31:0] r_data_bram1;
35
  logic [31:0] r_data_bram2;
36
 
37
  logic [7:0] image [0:NUM_PIXELS];
38
 
39
  virtual interface dut_if dut_if;
40
 
41
  function new (virtual interface dut_if m_dut_if);
42
  begin
43
     dut_if = m_dut_if;
44
  end
45
  endfunction
46
 
47
  task init();
48
    begin
49
        $display("RESET --------");
50
        dut_if.rst_n    = 1;
51
        dut_if.start    = 0;
52
        dut_if.ch_word0 = 0;
53
        dut_if.ch_word1 = 0;
54
        dut_if.ch_word2 = 0;
55
        addr = 0;
56
        i = 0;
57
        dut_if.end_of_operation = 0;
58
        repeat(5)@(negedge dut_if.clk);
59
        dut_if.rst_n = 0;
60
        repeat(5)@(negedge dut_if.clk);
61
        dut_if.rst_n = 1;
62
        dut_if.start = 1;
63
        repeat(3)@(negedge dut_if.clk);
64
    end
65
  endtask
66
 
67
  task reorganize_lines();
68
    begin
69
      wait(dut_if.start);
70
      @(negedge dut_if.clk);
71
      while(!(dut_if.end_of_operation))begin
72
         if(dut_if.window_line_counter == 2'b00)begin
73
            dut_if.ch_word0 = dut_if.word0;
74
            dut_if.ch_word1 = dut_if.word1;
75
            dut_if.ch_word2 = dut_if.word2;
76
         end
77
         else if(dut_if.window_line_counter == 2'b01)begin
78
            dut_if.ch_word0 = dut_if.word1;
79
            dut_if.ch_word1 = dut_if.word2;
80
            dut_if.ch_word2 = dut_if.word0;
81
         end
82
         else if(dut_if.window_line_counter == 2'b10)begin
83
            dut_if.ch_word0 = dut_if.word2;
84
            dut_if.ch_word1 = dut_if.word0;
85
            dut_if.ch_word2 = dut_if.word1;
86
         end
87
         //addr = addr+1;
88
         //read 4 pixels from all memories
89
         @(negedge dut_if.clk);
90
      end
91
      dut_if.start = 0;
92
    end
93
  endtask
94
 
95
  task receive_data();
96
     fork begin
97
        while(i
98
           //seria bom ter um sinal para saber quando terminou a mediana
99
           dut_if.result[i] = dut_if.pixel1;
100
           image[i] = dut_if.pixel1;
101
           dut_if.result[i+1] = dut_if.pixel2;
102
           image[i+1] = dut_if.pixel2;
103
           dut_if.result[i+2] = dut_if.pixel3;
104
           image[i+2] = dut_if.pixel3;
105
           dut_if.result[i+3] = dut_if.pixel4;
106
           image[i+3] = dut_if.pixel4;
107
           @(negedge dut_if.clk);
108
           i = i + 4;
109
        end
110
        dut_if.end_of_operation = 1;
111
     end
112
     join_none
113
  endtask
114
 
115
  function int write_file();
116
 
117
     integer file_ID = $fopen("./image.hex", "w");
118
 
119
     for(int i=0 ; i<=NUM_PIXELS ; i++ ) begin
120
        if(image[i] === 8'bx)
121
           $fdisplay(file_ID,"%x", 8'b0);
122
        else
123
           $fdisplay(file_ID,"%x", image[i]);
124
     end
125
 
126
     $fclose(file_ID);
127
 
128
  endfunction
129
 
130
endclass

powered by: WebSVN 2.1.0

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