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

Subversion Repositories openhmc

[/] [openhmc/] [trunk/] [openHMC/] [sim/] [UVC/] [hmc/] [sv/] [hmc_responder_sequence.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
`ifndef HMC_RESPONDER_SEQUENCE_SV
40
`define HMC_RESPONDER_SEQUENCE_SV
41
 
42
class hmc_responder_sequence extends uvm_sequence;
43
 
44
        rand int delay;
45
        rand hmc_packet response;
46
        rand bit error_response;
47
    event item_available;
48
 
49
        hmc_packet response_queue[$];
50
 
51
        constraint delay_c {
52
                delay dist {0:=4, [0:9]:=8, [10:30]:=2, [31:100]:=1};
53
        }
54
 
55
        `uvm_object_utils(hmc_responder_sequence)
56
 
57
        `uvm_declare_p_sequencer(hmc_responder_sequencer)
58
 
59
        function new(string name="hmc_responder_sequence");
60
                super.new(name);
61
        endfunction : new
62
 
63
        task create_response_packet(hmc_packet request);
64
                int response_length = 1;
65
                int new_timestamp;
66
                bit [127:0] rand_flit;
67
                bit [127:0] payload_flits [$];
68
 
69
                `uvm_info(get_type_name(),$psprintf("Generating response for a %s @%0x",request.command.name(), request.address),UVM_HIGH)
70
 
71
                `uvm_create(response);
72
 
73
                void'(this.randomize(error_response));
74
                void'(this.randomize(delay));
75
 
76
                new_timestamp = delay * 500ps + $time;
77
 
78
                if (request.get_command_type() == HMC_READ_TYPE ||
79
                        request.get_command_type() == HMC_MODE_READ_TYPE
80
                ) begin : read
81
 
82
                        case (request.command)
83
                                HMC_READ_16 : response_length = 2;
84
                                HMC_READ_32 : response_length = 3;
85
                                HMC_READ_48 : response_length = 4;
86
                                HMC_READ_64 : response_length = 5;
87
                                HMC_READ_80 : response_length = 6;
88
                                HMC_READ_96 : response_length = 7;
89
                                HMC_READ_112 : response_length = 8;
90
                                HMC_READ_128 : response_length = 9;
91
                                HMC_MODE_READ_TYPE : response_length = 1;
92
                        endcase
93
 
94
                        // Randomize the packet
95
                        void'(response.randomize() with {
96
                                command == HMC_READ_RESPONSE;
97
                                address == request.address; // for debugging
98
                                packet_length == response_length;
99
                                duplicate_length == response_length;
100
                                tag == request.tag;
101
                                error_status == 0 || error_response;
102
                        });
103
 
104
                        for (int i=0; i
105
                                randomize_flit_successful : assert (std::randomize(rand_flit))
106
                                payload_flits.push_front(rand_flit);
107
                        end
108
 
109
                        response.payload = payload_flits;
110
                        response.timestamp = new_timestamp;
111
                        enqueue_response_packet(response);
112
 
113
                end : read
114
                else if (request.get_command_type() == HMC_WRITE_TYPE || request.get_command_type() == HMC_MISC_WRITE_TYPE) begin : write
115
 
116
                        response_length = 1;
117
 
118
                        void'(response.randomize() with {
119
                                command == HMC_WRITE_RESPONSE;
120
                                address == request.address; // for debugging
121
                                packet_length == response_length;
122
                                duplicate_length == response_length;
123
                                tag == request.tag;
124
                                error_status == 0 || error_response;
125
                        });
126
 
127
                        response.timestamp = new_timestamp;
128
                        enqueue_response_packet(response);
129
 
130
                end : write
131
                // Posted Writes are allowed, but get no response
132
                else if (       request.get_command_type() != HMC_POSTED_WRITE_TYPE &&
133
                                        request.get_command_type() != HMC_POSTED_MISC_WRITE_TYPE
134
                ) begin : error
135
                        uvm_report_fatal(get_type_name(), $psprintf("Unsupported command type %s", request.command.name()));
136
                end : error
137
 
138
        endtask : create_response_packet
139
 
140
        task enqueue_response_packet(hmc_packet response);
141
                        // Insert at the end when the queue is empty or
142
                if (response_queue.size() == 0 ||
143
                        // when the timestamp is larger than the tail of the queue
144
                        response.timestamp >= response_queue[response_queue.size()-1].timestamp) begin
145
                        response_queue.push_back(response);
146
                        // Insert at the beginning of the queue when the timestamp is small
147
                end else if (response.timestamp <= response_queue[0].timestamp) begin
148
                        response_queue.push_front(response);
149
                end else begin
150
                        for (int position=1;position < response_queue.size(); position++) begin
151
                                if (response.timestamp < response_queue[position].timestamp) begin
152
                                        //response_queue = {response_queue[0:position-1], response, response_queue[position:$]};
153
                                        response_queue.insert(position-1,response);
154
                                        position = response_queue.size(); // Break
155
                                end
156
                        end
157
                end
158
 
159
                        // Signal via event that a response has been added
160
                        -> item_available;
161
 
162
        endtask : enqueue_response_packet
163
 
164
        task body();
165
 
166
                void'(this.randomize());
167
 
168
                fork
169
                        // Convert requests to responses
170
                        forever begin : translate_loop
171
                                hmc_packet packet;
172
                                p_sequencer.req_mailbox.get(packet);
173
                                create_response_packet(packet);
174
                        end : translate_loop
175
 
176
                        //
177
                        begin
178
                                hmc_packet packet;
179
 
180
                                forever begin : send_loop
181
 
182
                                        if (response_queue.size() > 0) begin
183
                                                int time_to_wait;
184
 
185
                                                time_to_wait = response_queue[0].timestamp - $time;
186
                                                if (time_to_wait <= 0) begin
187
                                                        packet = response_queue.pop_front();
188
                                                        uvm_report_info(get_type_name(), $psprintf("Sending response packet: %s", packet.command.name()), UVM_HIGH);
189
                                                        `uvm_send(packet)
190
                                                end else begin
191
                                                        #time_to_wait;
192
                                                end
193
                                        end
194
                                        else begin
195
                                                // Wait for items to get added to the queue
196
                                                if (response_queue.size() == 0)
197
                                                        @(item_available);
198
                                        end
199
 
200
                                end : send_loop
201
                        end
202
                join
203
 
204
        endtask : body
205
 
206
endclass : hmc_responder_sequence
207
 
208
`endif // HMC_RESPONDER_SEQUENCE_SV
209
 

powered by: WebSVN 2.1.0

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