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

Subversion Repositories openhmc

[/] [openhmc/] [trunk/] [openHMC/] [sim/] [UVC/] [hmc/] [sv/] [hmc_error_injector.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
`ifndef HMC_ERROR_INJECTOR
41
`define HMC_ERROR_INJECTOR
42
 
43
class hmc_error_injector #(parameter NUM_LANES = 16) extends uvm_component;
44
 
45
        virtual hmc_sr_if#(.NUM_LANES(NUM_LANES)) ext_vif;
46
        virtual hmc_sr_if#(.NUM_LANES(NUM_LANES)) int_vif;
47
        hmc_cdr #(.NUM_LANES(NUM_LANES)) cdr;
48
 
49
 
50
        hmc_link_config link_config;
51
        hmc_local_link_config local_config;
52
        hmc_link_status link_status;
53
 
54
        logic [NUM_LANES - 1 : 0] current_value;
55
        int num_bitflips;
56
        int inserted_bitflips[];
57
 
58
        `uvm_component_param_utils_begin(hmc_error_injector#(.NUM_LANES(NUM_LANES)))
59
        `uvm_component_utils_end
60
 
61
        function new ( string name="hmc_error_injector", uvm_component parent );
62
                super.new(name, parent);
63
        endfunction : new
64
 
65
        function void build_phase(uvm_phase phase);
66
                super.build_phase(phase);
67
 
68
                if(uvm_config_db#(hmc_link_config)::get(this, "", "link_config",link_config) ) begin
69
                        uvm_config_db#(hmc_link_config)::set(this, "cdr","link_config",link_config);
70
                end else begin
71
                        `uvm_fatal(get_type_name(),"link_config is not set")
72
                end
73
 
74
                if(!uvm_config_db#(hmc_local_link_config)::get(this, "", "local_config",local_config) ) begin
75
                        `uvm_fatal(get_type_name(),"local_config is not set")
76
                end
77
 
78
                if(uvm_config_db#(virtual interface hmc_sr_if#(.NUM_LANES(NUM_LANES)))::get(this, "", "ext_vif",ext_vif) ) begin
79
                        this.ext_vif = ext_vif;
80
                end else begin
81
                        `uvm_fatal(get_type_name(),"vif is not set")
82
                end
83
 
84
                if(uvm_config_db#(virtual interface hmc_sr_if#(.NUM_LANES(NUM_LANES)))::get(this, "", "int_vif",int_vif) ) begin
85
                        this.int_vif = int_vif;
86
                end else begin
87
                        `uvm_fatal(get_type_name(),"vif is not set")
88
                end
89
 
90
                if(!uvm_config_db#(hmc_link_status)::get(this, "", "link_status",link_status) ) begin
91
                        `uvm_fatal(get_type_name(),"link_status is not set")
92
                end
93
 
94
                if (local_config.requester) begin
95
                                uvm_config_db#(virtual interface hmc_sr_if#(.NUM_LANES(NUM_LANES)))::set(this, "cdr","vif",ext_vif);
96
                end else begin
97
                        uvm_config_db#(virtual interface hmc_sr_if#(.NUM_LANES(NUM_LANES)))::set(this, "cdr","vif",int_vif);
98
                end
99
 
100
                set_config_int("cdr", "link_type", local_config.requester?REQUESTER:RESPONDER);
101
 
102
                cdr = hmc_cdr#(.NUM_LANES(NUM_LANES))::type_id::create("cdr", this);
103
        endfunction : build_phase
104
 
105
        function void connect_phase(uvm_phase phase);
106
        endfunction : connect_phase
107
 
108
 
109
        task run_phase(uvm_phase phase);
110
                #1ps;
111
                read();
112
                write();
113
                forever begin
114
                        @(cdr.int_clk)
115
                        read();
116
                        if (local_config.lane_errors_enabled && link_status.current_state >= LINK_UP)
117
                                inject_error();
118
                        write();
119
                end
120
        endtask : run_phase
121
 
122
        function void read();
123
                if (local_config.requester) begin
124
                        current_value =  ext_vif.RXP;
125
                end else begin
126
                        current_value =  int_vif.TXP;
127
                end
128
        endfunction
129
 
130
        function void write();
131
                logic [NUM_LANES - 1 : 0] inv_value;
132
 
133
                foreach(current_value[i]) begin
134
                        if (!(current_value[i] === 1'bz))
135
                                inv_value[i] = ~current_value[i];
136
                        else begin
137
                                inv_value[i] = 1'bz;
138
                        end
139
                end
140
 
141
                if (local_config.requester) begin
142
                        int_vif.RXP = current_value;
143
                        int_vif.RXN = inv_value;
144
                end else begin
145
                        ext_vif.TXP = current_value;
146
                        ext_vif.TXN = inv_value;
147
                end
148
        endfunction : write
149
 
150
        function void inject_error();
151
                int error_probability;
152
                error_prob_rand_succeeds : assert (std::randomize(error_probability)
153
                                                                        with {error_probability >= 0 && error_probability < 10000;});
154
                if (error_probability < local_config.bitflip_error_probability) begin
155
                        num_error_rand_succeeds : assert(std::randomize(num_bitflips)
156
                                                                                with {num_bitflips>0 && num_bitflips
157
                        `uvm_info(get_type_name(), $psprintf("Inserting %0d Bitflips in %s Link",num_bitflips, local_config.requester?"requester":"responder"), UVM_HIGH)
158
                        bitflip(num_bitflips);
159
                end
160
        endfunction : inject_error
161
 
162
        function void bitflip(int bits);
163
                int pos = -1;
164
                int last_pos[int];
165
                for (int i= 0; i < bits; i++) begin
166
                        while (last_pos[pos] == 1 || pos == -1)begin //-- inject bitflip only once per lane
167
                                pos_randomization_succeeds : assert (std::randomize(pos) with {pos >= 0 && pos < NUM_LANES;});
168
                        end
169
                        last_pos[pos] = 1;
170
                        current_value[pos] = ~current_value[pos];
171
                        `uvm_info(get_type_name(), $psprintf("Inserting Bitflip at %d in %s Link", pos, local_config.requester?"requester":"responder"), UVM_HIGH)
172
                end
173
        endfunction : bitflip
174
 
175
endclass : hmc_error_injector
176
 
177
 
178
`endif

powered by: WebSVN 2.1.0

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