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

Subversion Repositories openhmc

[/] [openhmc/] [trunk/] [openHMC/] [sim/] [UVC/] [hmc/] [sv/] [hmc_requester_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_REQUESTER_SEQUENCE_SV
40
`define HMC_REQUESTER_SEQUENCE_SV
41
 
42
/* sequence is incomplete and not tested */
43
/* Use at your own risk */
44
 
45
class hmc_requester_sequence extends uvm_sequence;
46
 
47
        rand int delay;
48
        rand hmc_packet response;
49
        rand bit error_response;
50
    event item_available;
51
 
52
        hmc_packet response_queue[$];
53
 
54
        constraint delay_c {
55
                delay dist {0:=4, [0:9]:=8, [10:30]:=2, [31:100]:=1};
56
        }
57
 
58
        `uvm_object_utils(hmc_requester_sequence)
59
 
60
        `uvm_declare_p_sequencer(hmc_requester_sequencer)
61
 
62
        function new(string name="hmc_requester_sequence");
63
                super.new(name);
64
        endfunction : new
65
 
66
        task create_response_packet(hmc_packet request);
67
                int response_length = 1;
68
                int new_timestamp;
69
                bit [127:0] rand_flit;
70
                bit [127:0] payload_flits [$];
71
 
72
                `uvm_info(get_type_name(),$psprintf("Generating response for a %s @%0x",request.command.name(), request.address),UVM_HIGH)
73
 
74
                `uvm_create(response);
75
 
76
                void'(this.randomize(error_response));
77
                void'(this.randomize(delay));
78
 
79
                new_timestamp = delay * 500ps + $time;
80
 
81
                if (request.get_command_type() == HMC_READ_TYPE) begin : read
82
 
83
                        case (request.command)
84
                                HMC_READ_16 : response_length = 2;
85
                                HMC_READ_32 : response_length = 3;
86
                                HMC_READ_48 : response_length = 4;
87
                                HMC_READ_64 : response_length = 5;
88
                                HMC_READ_80 : response_length = 6;
89
                                HMC_READ_96 : response_length = 7;
90
                                HMC_READ_112 : response_length = 8;
91
                                HMC_READ_128 : response_length = 9;
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) 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
                                        position = response_queue.size(); // Break
154
                                end
155
                        end
156
                end
157
 
158
                        // Signal via event that a response has been added
159
                        -> item_available;
160
 
161
        endtask : enqueue_response_packet
162
 
163
        task body();
164
 
165
                void'(this.randomize());
166
 
167
                fork
168
                        // Convert requests to responses
169
                        forever begin : tranlsate_loop
170
                                hmc_packet packet;
171
                                p_sequencer.req_mailbox.get(packet);
172
                                create_response_packet(packet);
173
                        end : tranlsate_loop
174
 
175
                        //
176
                        begin
177
                                hmc_packet packet;
178
 
179
                                forever begin : send_loop
180
 
181
                                        if (response_queue.size() > 0) begin
182
                                                int time_to_wait;
183
 
184
                                                time_to_wait = response_queue[0].timestamp - $time;
185
                                                if (time_to_wait <= 0) begin
186
                                                        packet = response_queue.pop_front();
187
                                                        uvm_report_info(get_type_name(), $psprintf("Sending response packet: %s", packet.command.name()), UVM_HIGH);
188
                                                        `uvm_send(packet)
189
                                                end else begin
190
                                                        #time_to_wait;
191
                                                end
192
                                        end
193
                                        else begin
194
                                                // Wait for items to get added to the queue
195
                                                if (response_queue.size() == 0)
196
                                                        @(item_available);
197
                                        end
198
 
199
                                end : send_loop
200
                        end
201
                join
202
 
203
        endtask : body
204
 
205
endclass : hmc_requester_sequence
206
 
207
`endif // HMC_REQUESTER_SEQUENCE_SV
208
 

powered by: WebSVN 2.1.0

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