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

Subversion Repositories openhmc

[/] [openhmc/] [trunk/] [openHMC/] [sim/] [tb/] [common/] [src/] [tag_handler.sv] - Blame information for rev 15

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 15 juko
/*
2
 *                              .--------------. .----------------. .------------.
3
 *                             | .------------. | .--------------. | .----------. |
4
 *                             | | ____  ____ | | | ____    ____ | | |   ______ | |
5
 *                             | ||_   ||   _|| | ||_   \  /   _|| | | .' ___  || |
6
 *       ___  _ __   ___ _ __  | |  | |__| |  | | |  |   \/   |  | | |/ .'   \_|| |
7
 *      / _ \| '_ \ / _ \ '_ \ | |  |  __  |  | | |  | |\  /| |  | | || |       | |
8
 *       (_) | |_) |  __/ | | || | _| |  | |_ | | | _| |_\/_| |_ | | |\ `.___.'\| |
9
 *      \___/| .__/ \___|_| |_|| ||____||____|| | ||_____||_____|| | | `._____.'| |
10
 *           | |               | |            | | |              | | |          | |
11
 *           |_|               | '------------' | '--------------' | '----------' |
12
 *                              '--------------' '----------------' '------------'
13
 *
14
 *  openHMC - An Open Source Hybrid Memory Cube Controller
15
 *  (C) Copyright 2014 Computer Architecture Group - University of Heidelberg
16
 *  www.ziti.uni-heidelberg.de
17
 *  B6, 26
18
 *  68159 Mannheim
19
 *  Germany
20
 *
21
 *  Contact: openhmc@ziti.uni-heidelberg.de
22
 *  http://ra.ziti.uni-heidelberg.de/openhmc
23
 *
24
 *   This source file is free software: you can redistribute it and/or modify
25
 *   it under the terms of the GNU Lesser General Public License as published by
26
 *   the Free Software Foundation, either version 3 of the License, or
27
 *   (at your option) any later version.
28
 *
29
 *   This source file is distributed in the hope that it will be useful,
30
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
31
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32
 *   GNU Lesser General Public License for more details.
33
 *
34
 *   You should have received a copy of the GNU Lesser General Public License
35
 *   along with this source file.  If not, see .
36
 *
37
 *
38
 */
39
 
40
//
41
//
42
// tag handler
43
//
44
//
45
 
46
`ifndef TAG_HANDLER_SV
47
`define TAG_HANDLER_SV
48
 
49
class tag_handler  extends uvm_component;
50
 
51
        int tag_count = 512;            //-- tags available at the beginning
52
        bit tags_in_use[];              //-- bitmap of current used tags
53
        int tag_fifo[$];
54
        int transaction_count;
55
        int max_tags_in_use;
56
        int num_tags_in_use;
57
        int used_tag;
58
 
59
    event tag_avail_event;
60
 
61
        covergroup tags_used_cg;
62
                TAGS_USED : coverpoint used_tag{
63
                        bins valid_tags [] = {[0:tag_count-1]};
64
                        bins illegal_tags = {[tag_count:$]};
65
                        }
66
        endgroup
67
 
68
    `uvm_analysis_imp_decl(_hmc_rsp)
69
    uvm_analysis_imp_hmc_rsp #(hmc_packet, tag_handler) hmc_rsp_port;
70
 
71
        `uvm_component_utils_begin(tag_handler)
72
                `uvm_field_int(tag_count, UVM_DEFAULT)
73
        `uvm_component_utils_end
74
 
75
        function new ( string name="tag_handler", uvm_component parent );
76
                super.new(name, parent);
77
                tags_used_cg = new();
78
        endfunction : new
79
 
80
        function void build_phase(uvm_phase phase);
81
                hmc_rsp_port = new("hmc_rsp_port",this);
82
 
83
                tags_in_use = new [tag_count];
84
 
85
                max_tags_in_use = 0;
86
                transaction_count = 0;
87
                reset();
88
        endfunction : build_phase
89
 
90
        function void reset();
91
 
92
                foreach (tags_in_use[i]) begin
93
                        tags_in_use[i] =0;
94
                end
95
 
96
                num_tags_in_use = 0;
97
                tag_fifo = {};
98
 
99
                for (int i=0; i< tag_count; i++)
100
                        tag_fifo.push_back(tag_count-1-i);
101
        endfunction : reset
102
 
103
        task get_tag(ref int tag );
104
                //-- wait until at least 1 tag available
105
                if (tag_fifo.size() == 0) begin
106
                        `uvm_info(get_type_name(), $psprintf("get_tag: no tags available...waiting"), UVM_HIGH)
107
                        @(tag_avail_event);
108
                        `uvm_info(get_type_name(), $psprintf("get_tag: one tag is now available"), UVM_HIGH)
109
                end
110
 
111
                //-- flag tag as used
112
                tag = tag_fifo.pop_front();
113
                tags_in_use[tag] = 1'b1;
114
                used_tag = tag;
115
                tags_used_cg.sample();
116
 
117
                num_tags_in_use++;
118
                if (num_tags_in_use > max_tags_in_use)
119
                        max_tags_in_use = num_tags_in_use;
120
        endtask : get_tag
121
 
122
                task try_get_tag(ref int tag );
123
                //-- wait until at least 1 tag available
124
                if (tag_fifo.size() == 0) begin
125
                        `uvm_info(get_type_name(), $psprintf("get_tag: no tags available...returning NULL"), UVM_HIGH)
126
                        tag = -1;
127
                end else begin
128
 
129
                        //-- flag tag as used
130
                        tag = tag_fifo.pop_front();
131
                        tags_in_use[tag] = 1'b1;
132
                        used_tag = tag;
133
                        tags_used_cg.sample();
134
 
135
                        num_tags_in_use++;
136
                        if (num_tags_in_use > max_tags_in_use)
137
                                max_tags_in_use = num_tags_in_use;
138
                end
139
        endtask : try_get_tag
140
 
141
        function void release_tag(input int tag);
142
                if (!tags_in_use[tag])
143
                        `uvm_fatal(get_type_name(), $psprintf("release_tag: tag (%0d) not in use!", tag))
144
                //-- release tag
145
                tags_in_use[tag] = 1'b0;
146
                num_tags_in_use--;
147
                transaction_count++;
148
                tag_fifo.push_back(tag);
149
 
150
                //-- signal that tag is available
151
                -> tag_avail_event;
152
        endfunction : release_tag
153
 
154
        function void write_hmc_rsp(input hmc_packet packet);
155
                if (packet.command != HMC_ERROR_RESPONSE)
156
                        release_tag(packet.tag);
157
        endfunction : write_hmc_rsp
158
 
159
        function void idle_check();
160
                if (num_tags_in_use > 0)
161
                        for (int i=0; i
162
                                if (tags_in_use[i])
163
                                        `uvm_fatal(get_type_name(), $psprintf("%0d tags still in use, first one is %0d!", num_tags_in_use, i))
164
                if (tag_fifo.size() != tag_count)
165
                        `uvm_fatal(get_type_name(), $psprintf("tag FIFO should have num_tags (%0d) entries it has %0d!", tag_count, tag_fifo.size()))
166
        endfunction : idle_check
167
 
168
        function void check_phase(uvm_phase phase);
169
                idle_check();
170
        endfunction : check_phase
171
 
172
        function void report_phase(uvm_phase phase);
173
                `uvm_info(get_type_name(),$psprintf("max_tags_in_use %0d, transaction_count %0d", max_tags_in_use, transaction_count), UVM_LOW)
174
        endfunction : report_phase
175
 
176
endclass : tag_handler
177
 
178
`endif // TAG_HANDLER_SV

powered by: WebSVN 2.1.0

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