1 |
2 |
acastong |
//history_buffer_l3.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 |
|
|
#ifndef HISTORY_BUFFER_L3_TB_H
|
39 |
|
|
#define HISTORY_BUFFER_L3_TB_H
|
40 |
|
|
|
41 |
|
|
#include "../../../rtl/systemc/core_synth/synth_datatypes.h"
|
42 |
|
|
#include <deque>
|
43 |
|
|
#include <string>
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
class history_buffer_l3_tb : public sc_module{
|
48 |
|
|
|
49 |
|
|
struct RetryEntry{
|
50 |
|
|
int size;
|
51 |
|
|
int identification;
|
52 |
|
|
int dwords[18];
|
53 |
|
|
};
|
54 |
|
|
|
55 |
|
|
public:
|
56 |
|
|
|
57 |
|
|
///The output dword when playing back history
|
58 |
|
|
sc_in <sc_bv<32> > history_packet;
|
59 |
|
|
///When the complete history has finished playing back
|
60 |
|
|
sc_in <bool > history_playback_done;
|
61 |
|
|
///To begin the playback of the history from the last acked packet
|
62 |
|
|
sc_out <bool > begin_history_playback;
|
63 |
|
|
///If the playback of the history is ready
|
64 |
|
|
sc_in <bool > history_playback_ready;
|
65 |
|
|
///To consume the data produced by the history buffer
|
66 |
|
|
sc_out <bool > consume_history;
|
67 |
|
|
///The room left in the history, to allow the flow control to know if a packet can be sent
|
68 |
|
|
sc_in <bool > room_available_in_history;
|
69 |
|
|
///To add a dword to the history
|
70 |
|
|
sc_out <bool > add_to_history;
|
71 |
|
|
///To add a new entry to the history, to be done before starting to add to the history
|
72 |
|
|
sc_out <bool > new_history_entry;
|
73 |
|
|
///The size (minus 1) of the new history entry
|
74 |
|
|
sc_out <sc_uint<5> > new_history_entry_size_m1;
|
75 |
|
|
|
76 |
|
|
///dword being sent to the link, so it can be stored in the buffer
|
77 |
|
|
sc_out<sc_bv<32> > fc_dword_lk;
|
78 |
|
|
|
79 |
|
|
///When a nop was received : read the new ack_value
|
80 |
|
|
sc_out<bool> nop_received;
|
81 |
|
|
///The value acked from the next HT node
|
82 |
|
|
sc_out<sc_uint<8> > ack_value;
|
83 |
|
|
|
84 |
|
|
///Reset
|
85 |
|
|
sc_out<bool> resetx;
|
86 |
|
|
|
87 |
|
|
///Clock
|
88 |
|
|
sc_in<bool> clk;
|
89 |
|
|
|
90 |
|
|
//////////////////////////////////////////
|
91 |
|
|
// Memory interface - synchronous
|
92 |
|
|
/////////////////////////////////////////
|
93 |
|
|
|
94 |
|
|
sc_in<bool> history_memory_write;
|
95 |
|
|
sc_in<sc_uint<LOG2_HISTORY_MEMORY_SIZE> > history_memory_write_address;
|
96 |
|
|
sc_in<sc_bv<32> > history_memory_write_data;
|
97 |
|
|
sc_in<sc_uint<LOG2_HISTORY_MEMORY_SIZE> > history_memory_read_address;
|
98 |
|
|
sc_out<sc_bv<32> > history_memory_output;
|
99 |
|
|
|
100 |
|
|
///SystemC Macro
|
101 |
|
|
SC_HAS_PROCESS(history_buffer_l3_tb);
|
102 |
|
|
|
103 |
|
|
///Consctructor
|
104 |
|
|
history_buffer_l3_tb(sc_module_name name);
|
105 |
|
|
|
106 |
|
|
///The memory that is accessed through the synchronous memory interface
|
107 |
|
|
unsigned int history_memory[HISTORY_MEMORY_SIZE];
|
108 |
|
|
|
109 |
|
|
///Takes care of writing and reading to memory
|
110 |
|
|
void simulate_memory();
|
111 |
|
|
|
112 |
|
|
///This is the main thread that stimulates the design to test it
|
113 |
|
|
/** Other functinos are called from here*/
|
114 |
|
|
void stimulus();
|
115 |
|
|
|
116 |
|
|
///Plays back all the history and verifies that it is correct
|
117 |
|
|
void playback_history();
|
118 |
|
|
|
119 |
|
|
///Ack a certain number of packets that are in the history
|
120 |
|
|
/** Acked packets are not played back in a replay sequence
|
121 |
|
|
@param number The number of packets to ack
|
122 |
|
|
*/
|
123 |
|
|
void ack_packets(int number);
|
124 |
|
|
|
125 |
|
|
///Sends random packet to store in the history buffer
|
126 |
|
|
/** Warning : Does not check for memory overflow
|
127 |
|
|
@param number The number of packets to send in history
|
128 |
|
|
*/
|
129 |
|
|
void send_random_packets(int number);
|
130 |
|
|
|
131 |
|
|
///Generate a random entry (packet) to store in the history
|
132 |
|
|
void generateRandomEntry(RetryEntry * e);
|
133 |
|
|
|
134 |
|
|
///A software kept version of the history for comparison purpose
|
135 |
|
|
std::deque<RetryEntry> simulated_history;
|
136 |
|
|
|
137 |
|
|
///Number of elements stored in the history
|
138 |
|
|
int current_history_size;
|
139 |
|
|
|
140 |
|
|
///What the ack number for packets being written
|
141 |
|
|
/** Increased whenever a packet is written to the buffer
|
142 |
|
|
*/
|
143 |
|
|
int write_ack_number;
|
144 |
|
|
///What packets have beem acked
|
145 |
|
|
/** Incremented whenever packets are acked
|
146 |
|
|
*/
|
147 |
|
|
int read_ack_number;
|
148 |
|
|
|
149 |
|
|
///Simulated position of the write pointer of the history module
|
150 |
|
|
int internal_write_pos;
|
151 |
|
|
|
152 |
|
|
};
|
153 |
|
|
|
154 |
|
|
///An exception class thrown when an error is detected
|
155 |
|
|
class SimulationException{
|
156 |
|
|
public:
|
157 |
|
|
std::string data;
|
158 |
|
|
SimulationException(std::string msg) : data(msg) {}
|
159 |
|
|
};
|
160 |
|
|
|
161 |
|
|
#endif
|
162 |
|
|
|