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

Subversion Repositories ht_tunnel

[/] [ht_tunnel/] [trunk/] [bench/] [decoder_l2/] [decoder_l2_tb.h] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 acastong
//decoder_l2_tb.h
2
/* ***** BEGIN LICENSE BLOCK *****
3
 * Version: MPL 1.1
4
 *
5
 * The contents of this file are subject to the Mozilla Public License Version
6
 * 1.1 (the "License"); you may not use this file except in compliance with
7
 * the License. You may obtain a copy of the License at
8
 * http://www.mozilla.org/MPL/
9
 *
10
 * Software distributed under the License is distributed on an "AS IS" basis,
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
 * for the specific language governing rights and limitations under the
13
 * License.
14
 *
15
 * The Original Code is HyperTransport Tunnel IP Core.
16
 *
17
 * The Initial Developer of the Original Code is
18
 * Ecole Polytechnique de Montreal.
19
 * Portions created by the Initial Developer are Copyright (C) 2005
20
 * the Initial Developer. All Rights Reserved.
21
 *
22
 * Contributor(s):
23
 *   Ami Castonguay <acastong@grm.polymtl.ca>
24
 *
25
 * Alternatively, the contents of this file may be used under the terms
26
 * of the Polytechnique HyperTransport Tunnel IP Core Source Code License
27
 * (the  "PHTICSCL License", see the file PHTICSCL.txt), in which case the
28
 * provisions of PHTICSCL License are applicable instead of those
29
 * above. If you wish to allow use of your version of this file only
30
 * under the terms of the PHTICSCL License and not to allow others to use
31
 * your version of this file under the MPL, indicate your decision by
32
 * deleting the provisions above and replace them with the notice and
33
 * other provisions required by the PHTICSCL License. If you do not delete
34
 * the provisions above, a recipient may use your version of this file
35
 * under either the MPL or the PHTICSCL License."
36
 *
37
 * ***** END LICENSE BLOCK ***** */
38
 
39
#ifndef DECODER_L2_TB_H
40
#define DECODER_L2_TB_H
41
 
42
#include "../../rtl/systemc/core_synth/synth_datatypes.h"
43
#include <deque>
44
 
45
 
46
///Testbench for the decoder_l2 module
47
class decoder_l2_tb : public sc_module{
48
public:
49
        ///Contains all data important to check validity of what is sent to databuffer
50
        /** An instance of the struct is added to the queue when a data packet is
51
                sent to the databuffer and is checked when the packet is sent to the
52
                databuffer.  The variable address_requested is false at the beggining and
53
                is set to be true when the packet address is requested (it is modified
54
                in the queue).
55
        */
56
        struct DataBufferEntry{
57
                int size;///<Size in dwords of the data packet (minus 1)
58
                int data[16];///<Content of the data packet
59
                bool badcrc;///<If a bad CRC accompanies the data packet
60
                                        ///<Currently not used but potentially there to check if the
61
                                        ///<data packet is dropped in case of bad per packet CRC
62
                bool address_requested;///<Set to true when decoder asks for address from Databuffer
63
                VirtualChannel vc;///<The virtual channel this data packet belongs to
64
        };
65
 
66
        ///A packet to be sent to the reordering module
67
        struct ReorderingEntry{
68
                syn_ControlPacketComplete pkt;
69
                bool has_data;
70
        };
71
 
72
        ///Information contained in a nop
73
        struct NopEntry{
74
                sc_uint<8>      cd_nop_ack_value_fc;
75
                sc_bv<12>       cd_nopinfo_fc;
76
        };
77
 
78
        ///clk signal
79
        sc_in<bool> clk;
80
        ///Warm Reset to initialize module
81
        sc_out < bool >                 resetx;
82
 
83
        //*******************************
84
        //      Signals for Control Buffer
85
        //*******************************
86
 
87
        /**Packet to be transmitted to control buffer module*/
88
    sc_in< syn_ControlPacketComplete >  cd_packet_ro;
89
        /**Enables control buffer module to read cd_packet_ro port*/
90
        sc_in< bool >                                           cd_available_ro;
91
        /**If we're currently receiving data.  This is used by the ro to know
92
        if we have finished receiving the data of a packet, so it can know if
93
        it can send it.*/
94
        sc_in<bool>                                             cd_data_pending_ro;
95
        /**Where we are storing data.   This is used by the ro to know
96
        if we have finished receiving the data of a packet, so it can know if
97
        it can send it.*/
98
        sc_in<sc_uint<BUFFERS_ADDRESS_WIDTH> >  cd_data_pending_addr_ro;
99
 
100
        //*******************************
101
        //      Signals for Data Buffer
102
        //*******************************       
103
 
104
        ///ddress of data in data buffer module
105
        sc_out< sc_uint<BUFFERS_ADDRESS_WIDTH> >                db_address_cd;
106
        ///Get an address form data buffer module
107
        sc_in< bool >                           cd_getaddr_db;
108
        ///Size of data packet to be written
109
        sc_in< sc_uint<4> >             cd_datalen_db;
110
        ///Virtual channel where data will be written
111
        sc_in< VirtualChannel > cd_vctype_db;
112
        ///Data to be written in data buffer module
113
        sc_in< sc_bv<32> >              cd_data_db;
114
        ///Enables data buffer to read cd_data_db port
115
        sc_in< bool >                           cd_write_db;
116
 
117
#ifdef RETRY_MODE_ENABLED
118
        ///Erase signal for packet stomping
119
        sc_in< bool >                           cd_drop_db;
120
#endif
121
 
122
 
123
        //*************************************
124
        // Signals to CSR
125
        //*************************************
126
 
127
        ///A protocol error has been detected
128
        sc_in< bool >                   cd_protocol_error_csr;
129
        ///A sync packet has been received
130
        sc_in< bool >                   cd_sync_detected_csr;
131
#ifdef RETRY_MODE_ENABLED
132
        ///If retry mode is active
133
        sc_out< bool >                  csr_retry;
134
#endif
135
 
136
        //*******************************
137
        //      Signals from link
138
        //*******************************
139
 
140
        ///Bit vector input from the FIFO 
141
        sc_out< sc_bv<32> >             lk_dword_cd;
142
        ///Control bit
143
        sc_out< bool >                  lk_hctl_cd;
144
        ///Control bit
145
        sc_out< bool >                  lk_lctl_cd;
146
        ///FIFO is ready to be read from
147
        sc_out< bool >                  lk_available_cd;
148
 
149
#ifdef RETRY_MODE_ENABLED
150
        ///If a retry sequence is initiated by link
151
        sc_out< bool >                  lk_initiate_retry_disconnect;
152
#endif
153
        //*******************************
154
        //      Signals for Forwarding module
155
        //*******************************
156
 
157
#ifdef RETRY_MODE_ENABLED
158
        ///History count
159
        sc_in< sc_uint<8> >             cd_rx_next_pkt_to_ack_fc;
160
        ///rxPacketToAck (retry mode)
161
        sc_in< sc_uint<8> >     cd_nop_ack_value_fc;
162
#endif
163
 
164
        ///Info registered from NOP word
165
        sc_in< sc_bv<12> >      cd_nopinfo_fc;
166
        ///Signal that new nop info are available
167
        sc_in< bool >                   cd_nop_received_fc;
168
 
169
#ifdef RETRY_MODE_ENABLED
170
        ///Start the sequence for a retry disconnect
171
        sc_in< bool >                   cd_initiate_retry_disconnect;
172
        ///A stomped packet has been received
173
        sc_in<bool>                     cd_received_stomped_csr;
174
        ///Let the reordering know we received a non flow control stomped packet
175
        /**  When this situation happens, packet available bit does not become
176
                 asserted but the correct packet is sent, which can be used to know
177
                 from which VC to free a flow control credit.
178
        */
179
        sc_in<bool> cd_received_non_flow_stomped_ro;
180
#endif
181
        ///The link can start a sequence for a ldtstop disconnect
182
        sc_in< bool >                   cd_initiate_nonretry_disconnect_lk;
183
 
184
 
185
        ///SystemC Macro
186
        SC_HAS_PROCESS(decoder_l2_tb);
187
 
188
        ///Queue of data packet that will be sent to databuffer
189
        std::deque<DataBufferEntry> databuffer_queue;
190
        ///Qeue of command packet that will be sent to reordering
191
        std::deque<ReorderingEntry> reordering_queue;
192
        ///Queue of information that will be sent out when nops are received
193
        std::deque<NopEntry> nop_queue;
194
        ///List of ack values associated with packet sent to databuffer
195
        std::deque<sc_uint<8> > ack_value;
196
 
197
        ///Stores the latest data address given out by the databuffer
198
        sc_uint<BUFFERS_ADDRESS_WIDTH> last_databuffer_address;
199
 
200
        ///If an error was detected by the testbench
201
        bool error;
202
        /** Stores with various degrees of delay when the decoder request to
203
                get an address from the databuffer.  Used to calculate when the
204
                decoder should start to say that there is data pending.
205
        */
206
        //@{
207
        sc_signal<bool> delayed_start_writing_data;
208
        sc_signal<bool> delayed_start_writing_data2;
209
        sc_signal<bool> delayed_start_writing_data3;
210
        //@}
211
 
212
        ///Asserted while the decoder is writing data to databuffer
213
        sc_signal<bool> writing_data;
214
 
215
        /**
216
                Expected values of different control signals from the decoder
217
                The value is the maximum number of cycles before it should be
218
                asserted.  Set to zero when it is asserted
219
        */
220
        //@{
221
        int     expect_cd_initiate_retry_disconnect;
222
        int expect_cd_received_stomped_csr;
223
        int expect_cd_initiate_nonretry_disconnect_lk;
224
        //@}
225
 
226
        ///Calculated CRC as testbench sends a packet to decoder that has no data
227
        unsigned crc1;
228
        ///Calculated CRC as testbench sends a packet to decoder with data
229
        unsigned crc2;
230
        ///Module constructor
231
        decoder_l2_tb(sc_module_name name);
232
        ///Module desctructor
233
        virtual ~decoder_l2_tb(){}
234
 
235
        ///Main control thread of the testbench
236
        void stimulate_input();
237
        ///Validates that nop_received is correct, along with freed buffers and ack values
238
        void nop_info_validation();
239
        ///Validates that what is sent to the databuffer is correct
240
        void databuffer_validation();
241
        ///Validates that disconnect (retry or not) and stomped signals are good
242
        void disconnect_retry_validation();
243
        ///Validates that whas is sent to the reordering is correct
244
        void reordering_validation();
245
        ///Display the message and set that an error was received
246
        void displayError(const char * error_message);
247
 
248
        ///Sends a dword to the databuffer (contains wait)
249
        void send_dword(sc_bv<32> dword,bool lctl, bool hctl);
250
        ///Send random nop to decoder
251
        void send_nop();
252
        ///Send target done packet to decoder
253
        void send_tgtdone();
254
        ///Send read packet to decoder
255
        void send_read();
256
        ///Send write packet to decoder
257
        void send_write();
258
        ///Takes care of sending a random write header packet
259
        /**@param datalength_m1 The number minus one of dwords
260
                          of data that will follow the header
261
        */
262
        void send_write_header(int datalength_m1);
263
        ///Creates a databuffer entry: random dword to send for databuffer
264
        /**@param datalength_m1 The number minus one of dwords of data
265
           @param vc The virtual channel the data belongs to
266
           @return The generated databuffer entry
267
        */
268
        DataBufferEntry generate_data_packet(int datalength_m1,
269
                                                                                VirtualChannel vc);
270
        ///Sends a data packet
271
        /**@description Allows to sent part of a datapacket at a time with
272
                        the offset and last parameters
273
           @param entry The datapacket to send
274
       @param offset From where to start the datapacket
275
           @param last What is the last position to send
276
        */
277
        void send_data_packet(DataBufferEntry &entry,
278
                                                int offset,int last);
279
        ///Send a packet with a 64 bit extension
280
        void send_ext();
281
        ///Send an extended flow control packet
282
        void send_ext_fc();
283
        ///Send an extended flow control packet (64 bit version)
284
        void send_ext_fc64();
285
        ///Send a packet with data and a targetdone inserted inside it
286
        void send_tgtdone_in_data();
287
        ///Send a packet with data and a flow control packet inserted inside it
288
        void send_fc_in_data();
289
        ///Send a packet with data and a 64 bit flow control packet inserted inside it
290
        void send_fc64_in_data();
291
        ///Send a packet with data and a nop packet inserted inside it
292
        void send_nop_in_data();
293
        ///Send a disconnect nop
294
        void send_discon_nop();
295
 
296
        ///Get a random 32-bit vector
297
        void getRandomVector(sc_bv<32> &vector);
298
        ///Get a random 64-bit vector
299
        void getRandomVector(sc_bv<64> &vector);
300
        ///Add a reordering entry to the queue for a dword packet
301
        void addReorderingEntry(sc_bv<32> &vector,bool hasData);
302
        ///Add a reordering entry to the queue for a qword packet
303
        void addReorderingEntry(sc_bv<64> &vector,bool hasData);
304
        ///Update the CRC1 value
305
        /**
306
                @param dword The dword to use for per packet CRC calculation
307
                @param lctl The lctl to use for per packet CRC calculation
308
                @param hctl The hctl to use for per packet CRC calculation
309
        */
310
        void calculate_crc1(sc_bv<32> dword,bool lctl, bool hctl);
311
        ///Update the CRC2 value
312
        /**
313
                @param dword The dword to use for per packet CRC calculation
314
                @param lctl The lctl to use for per packet CRC calculation
315
                @param hctl The hctl to use for per packet CRC calculation
316
        */
317
        void calculate_crc2(sc_bv<32> dword,bool lctl, bool hctl);
318
        ///Update per packet CRC with the data
319
        /**
320
                @param crc The crc value to update
321
                @param data The combined dword and CTL vector to use for calculations
322
        */
323
        void calculate_crc(unsigned &crc,sc_bv<34> &data);
324
 
325
};
326
 
327
#endif
328
 

powered by: WebSVN 2.1.0

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