1 |
2 |
acastong |
// cd_state_machine_l3.h
|
2 |
|
|
|
3 |
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
4 |
|
|
* Version: MPL 1.1
|
5 |
|
|
*
|
6 |
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
7 |
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
8 |
|
|
* the License. You may obtain a copy of the License at
|
9 |
|
|
* http://www.mozilla.org/MPL/
|
10 |
|
|
*
|
11 |
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
12 |
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
13 |
|
|
* for the specific language governing rights and limitations under the
|
14 |
|
|
* License.
|
15 |
|
|
*
|
16 |
|
|
* The Original Code is HyperTransport Tunnel IP Core.
|
17 |
|
|
*
|
18 |
|
|
* The Initial Developer of the Original Code is
|
19 |
|
|
* Ecole Polytechnique de Montreal.
|
20 |
|
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
21 |
|
|
* the Initial Developer. All Rights Reserved.
|
22 |
|
|
*
|
23 |
|
|
* Contributor(s):
|
24 |
|
|
* Max-Elie Salomon
|
25 |
|
|
* Ami Castonguay <acastong@grm.polymtl.ca>
|
26 |
|
|
*
|
27 |
|
|
* Alternatively, the contents of this file may be used under the terms
|
28 |
|
|
* of the Polytechnique HyperTransport Tunnel IP Core Source Code License
|
29 |
|
|
* (the "PHTICSCL License", see the file PHTICSCL.txt), in which case the
|
30 |
|
|
* provisions of PHTICSCL License are applicable instead of those
|
31 |
|
|
* above. If you wish to allow use of your version of this file only
|
32 |
|
|
* under the terms of the PHTICSCL License and not to allow others to use
|
33 |
|
|
* your version of this file under the MPL, indicate your decision by
|
34 |
|
|
* deleting the provisions above and replace them with the notice and
|
35 |
|
|
* other provisions required by the PHTICSCL License. If you do not delete
|
36 |
|
|
* the provisions above, a recipient may use your version of this file
|
37 |
|
|
* under either the MPL or the PHTICSCL License."
|
38 |
|
|
*
|
39 |
|
|
* ***** END LICENSE BLOCK ***** */
|
40 |
|
|
|
41 |
|
|
#ifndef CD_STATE_MACHINE_L3_H
|
42 |
|
|
#define CD_STATE_MACHINE_L3_H
|
43 |
|
|
|
44 |
|
|
#include "../core_synth/synth_datatypes.h"
|
45 |
|
|
#include "../core_synth/constants.h"
|
46 |
|
|
|
47 |
|
|
/**
|
48 |
|
|
States of the state machine
|
49 |
|
|
*/
|
50 |
|
|
enum vm_state {
|
51 |
|
|
CONTROL_st, /**<Reception of a control command*/
|
52 |
|
|
ADD_st, /**<Reception of an address for a command*/
|
53 |
|
|
ADD_WDATA_st, /**<Reception of an address for a command
|
54 |
|
|
with data associated*/
|
55 |
|
|
FC64_st, /**<Waiting for the second part of a 64 bit flow control
|
56 |
|
|
control packet*/
|
57 |
|
|
|
58 |
|
|
DATA1_st, /**<Reception of data, inserted control command
|
59 |
|
|
or CRC of data */
|
60 |
|
|
INS2_st, /**<Reception of address for a packet inserted in a data stream*/
|
61 |
|
|
INS2_FC64_st, /**<Reception of second dword of a 64 bit flow control packet*/
|
62 |
|
|
|
63 |
|
|
CONTROL_EXT_st, /**<64 bit address extension received, waiting for the following
|
64 |
|
|
standard control packet */
|
65 |
|
|
CONTROL_EXT2_st, /**<64 bit address extension received, waiting for the following
|
66 |
|
|
standard control packet, after which we go back to waiting
|
67 |
|
|
for data*/
|
68 |
|
|
#ifdef RETRY_MODE_ENABLED
|
69 |
|
|
CRC_st, /**<Reception of a CRC check word for non data control packet
|
70 |
|
|
that is stored in the buffers*/
|
71 |
|
|
DATACRC_st, /**<Reception of a CRC check word for data packet*/
|
72 |
|
|
CRC_NOP_st, /**<Reception of a CRC check word for a NOP*/
|
73 |
|
|
CRC_EXTFC_st, /**<Reception of a CRC check word for an extended flow control*/
|
74 |
|
|
|
75 |
|
|
DATA2_st, /**< Reception of CRC or request (wihout data)inserted inside
|
76 |
|
|
a data packet*/
|
77 |
|
|
DATA2_NOP_st, /**< Reception of CRC of NOP packet inserted inside
|
78 |
|
|
a data packet*/
|
79 |
|
|
DATA2_FC_st, /**< Reception of CRC of extended flow control packet inserted inside
|
80 |
|
|
a data packet*/
|
81 |
|
|
SEND_DISC_st, /**< Send a disconnect to the failed link */
|
82 |
|
|
#endif
|
83 |
|
|
|
84 |
|
|
PRTCL_ERR_st, /**< A protocol error was detected */
|
85 |
|
|
PRTCL_ERR_CLR_DATA_st, /** <A protocol error was detected, and the partial
|
86 |
|
|
(or corrupted) data in the buffers has to be dropped before
|
87 |
|
|
we keep on going*/
|
88 |
|
|
SYNC_st /**< Chain is in a SYNC state */
|
89 |
|
|
|
90 |
|
|
};
|
91 |
|
|
|
92 |
|
|
///State machine sub-module for the decoder module
|
93 |
|
|
|
94 |
|
|
/**
|
95 |
|
|
@class cd_state_machine_l3
|
96 |
|
|
@description State machine that controls the decoder. This is the core
|
97 |
|
|
of the decoder module. The role of the decoder is to properly direct
|
98 |
|
|
received packets : the state machine keeps track of what is received
|
99 |
|
|
and where it should go. The state machine becomes complex because
|
100 |
|
|
packets can arrive in many different orders. Some packets can also
|
101 |
|
|
be malformed and errors must be generated.
|
102 |
|
|
|
103 |
|
|
@author Ami Castonguay
|
104 |
|
|
|
105 |
|
|
*/
|
106 |
|
|
class cd_state_machine_l3 : public sc_module
|
107 |
|
|
|
108 |
|
|
{
|
109 |
|
|
//*******************************
|
110 |
|
|
// Internal signals
|
111 |
|
|
//*******************************
|
112 |
|
|
///Next state of the machine
|
113 |
|
|
sc_signal<vm_state> nextState;
|
114 |
|
|
///State of the machine
|
115 |
|
|
sc_signal<vm_state> currentState;
|
116 |
|
|
///Next packet to be selected
|
117 |
|
|
sc_signal< bool > nextSelCtlPckt;
|
118 |
|
|
///Next value of a packet being available in the output register
|
119 |
|
|
sc_signal< bool > next_controlEnable;
|
120 |
|
|
///Packet being available in the CTL output register
|
121 |
|
|
/**
|
122 |
|
|
This is not equivalent to cd_available_ro because in non retry
|
123 |
|
|
mode, a packet must wait until another control packet is received
|
124 |
|
|
before being commited, because of the possibility of a reset
|
125 |
|
|
corrupting a packet in transmission
|
126 |
|
|
*/
|
127 |
|
|
sc_signal< bool > controlEnable;
|
128 |
|
|
///Packet being available in the CTL with data output register
|
129 |
|
|
sc_signal< bool > controlDataEnable;
|
130 |
|
|
///Shows current state in console for debugging
|
131 |
|
|
//bool smComments;
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
#ifdef RETRY_MODE_ENABLED
|
135 |
|
|
//Counter for number of sync receveid
|
136 |
|
|
sc_signal<sc_uint<3> > sync_count;
|
137 |
|
|
//next value of counter for number of sync receveid
|
138 |
|
|
sc_signal<sc_uint<3> > next_sync_count;
|
139 |
|
|
#endif
|
140 |
|
|
|
141 |
|
|
public:
|
142 |
|
|
|
143 |
|
|
//*******************************
|
144 |
|
|
// Inputs
|
145 |
|
|
//*******************************
|
146 |
|
|
|
147 |
|
|
///Clock to synchronize module
|
148 |
|
|
sc_in<bool> clk;
|
149 |
|
|
///Input bit vector
|
150 |
|
|
sc_in< sc_bv<32> > dWordIn;
|
151 |
|
|
|
152 |
|
|
#ifdef RETRY_MODE_ENABLED
|
153 |
|
|
///Retry mode or not
|
154 |
|
|
sc_in< bool > csr_retry;
|
155 |
|
|
sc_in< bool > lk_initiate_retry_disconnect;
|
156 |
|
|
#endif
|
157 |
|
|
|
158 |
|
|
///Control bit
|
159 |
|
|
sc_in< bool > lk_lctl_cd;
|
160 |
|
|
///Control bit
|
161 |
|
|
sc_in< bool > lk_hctl_cd;
|
162 |
|
|
/// Data available from the fifo
|
163 |
|
|
sc_in< bool > lk_available_cd;
|
164 |
|
|
|
165 |
|
|
#ifdef RETRY_MODE_ENABLED
|
166 |
|
|
///If the signal on the input matches the calculated CRC1
|
167 |
|
|
sc_in< bool > crc1_good;
|
168 |
|
|
///If the signal on the input matches the calculated CRC2
|
169 |
|
|
sc_in< bool > crc2_good;
|
170 |
|
|
///If the signal on the input is the inverse of the calculated CRC1
|
171 |
|
|
sc_in< bool > crc1_stomped;
|
172 |
|
|
///If the signal on the input is the inverse of the calculated CRC2
|
173 |
|
|
sc_in< bool > crc2_stomped;
|
174 |
|
|
#endif
|
175 |
|
|
|
176 |
|
|
|
177 |
|
|
///Flag indicating the next valid data dword will be the last
|
178 |
|
|
sc_in< bool > end_of_count;
|
179 |
|
|
///Flag indicating the last data dword has been received
|
180 |
|
|
//sc_in< bool > count_done;
|
181 |
|
|
|
182 |
|
|
///Reset signal (active low)
|
183 |
|
|
sc_in< bool > resetx;
|
184 |
|
|
|
185 |
|
|
//*******************************
|
186 |
|
|
// Outputs
|
187 |
|
|
//*******************************
|
188 |
|
|
#ifdef RETRY_MODE_ENABLED
|
189 |
|
|
///To add the input vector to the calculation of CRC1
|
190 |
|
|
sc_out< bool > crc1_enable;
|
191 |
|
|
///To add the input vector to the calculation of CRC2
|
192 |
|
|
sc_out< bool > crc2_enable;
|
193 |
|
|
///Reset the CRC1 value
|
194 |
|
|
sc_out< bool > crc1_reset;
|
195 |
|
|
///Reset the CRC2 value
|
196 |
|
|
sc_out< bool > crc2_reset;
|
197 |
|
|
///If CTL is activated, should CRC2 be calculated instead of CRC1
|
198 |
|
|
sc_out< bool > crc2_if_ctl;
|
199 |
|
|
#endif
|
200 |
|
|
|
201 |
|
|
///Get an address from data buffer and set data count
|
202 |
|
|
sc_out< bool > getAddressSetCnt;
|
203 |
|
|
///Enable data to be read by data buffer
|
204 |
|
|
sc_out< bool > cd_write_db;
|
205 |
|
|
#ifdef RETRY_MODE_ENABLED
|
206 |
|
|
///Erase data from data buffer (stomp)
|
207 |
|
|
sc_out< bool > cd_drop_db;
|
208 |
|
|
#endif
|
209 |
|
|
|
210 |
|
|
///Enable control command to be read by control buffer
|
211 |
|
|
sc_out< bool > cd_available_ro;
|
212 |
|
|
///Select which control packet will drive the output (the one with data or the one without)
|
213 |
|
|
sc_out< bool > selCtlPckt;
|
214 |
|
|
///Enable first half of a control word that will have data
|
215 |
|
|
sc_out< bool > enCtlwData1;
|
216 |
|
|
///Enable second half of a control word that will have data
|
217 |
|
|
sc_out< bool > enCtlwData2;
|
218 |
|
|
///Enable first half of a control word that will NOT have data
|
219 |
|
|
sc_out< bool > enCtl1;
|
220 |
|
|
///Enable second half of a control word that will NOT have data
|
221 |
|
|
sc_out< bool > enCtl2;
|
222 |
|
|
///Enable the NOP count to be set
|
223 |
|
|
sc_out< bool > setNopCnt;
|
224 |
|
|
///Flag to be activated following reception of an address extension
|
225 |
|
|
sc_out< bool > error64Bits;
|
226 |
|
|
///Flag to be activated following reception of an address extension
|
227 |
|
|
sc_out< bool > error64BitsCtlwData;
|
228 |
|
|
|
229 |
|
|
///Flag to be activated upon detection of a protocol error
|
230 |
|
|
sc_out< bool > cd_protocol_error_csr;
|
231 |
|
|
///Flag to be activated upon detection of a sync error/packet
|
232 |
|
|
sc_out< bool > cd_sync_detected_csr;
|
233 |
|
|
///Notify that the nop has been received
|
234 |
|
|
/**
|
235 |
|
|
This is not always the same as setNopCnt because in the retry mode,
|
236 |
|
|
the nop CRC has to be received and validated before we notify that we
|
237 |
|
|
have new data.
|
238 |
|
|
*/
|
239 |
|
|
sc_out<bool> send_nop_notification;
|
240 |
|
|
|
241 |
|
|
|
242 |
|
|
/**When not in retry mode and we receive a disconnect nop, the link simply
|
243 |
|
|
turns off it's receivers until LDTSTOP stops. This signal CANNOT be activated
|
244 |
|
|
when csr_retry is asserted*/
|
245 |
|
|
sc_out<bool> cd_initiate_nonretry_disconnect_lk;
|
246 |
|
|
|
247 |
|
|
#ifdef RETRY_MODE_ENABLED
|
248 |
|
|
///Let the CSR know we received a stomped packet
|
249 |
|
|
sc_out<bool> cd_received_stomped_csr;
|
250 |
|
|
|
251 |
|
|
///Let the CSR know we received a non flow control stomped packet
|
252 |
|
|
sc_out<bool> cd_received_non_flow_stomped_ro;
|
253 |
|
|
|
254 |
|
|
/**When in retry mode, we immediately go to reset mode for both
|
255 |
|
|
receiver and transmitter. This signal cannot be activated when
|
256 |
|
|
csr_retry is not asserted*/
|
257 |
|
|
sc_out<bool> cd_initiate_retry_disconnect;
|
258 |
|
|
sc_signal<bool> next_cd_initiate_retry_disconnect;
|
259 |
|
|
#endif
|
260 |
|
|
/**If we're currently receiving data. This is used by the ro to know
|
261 |
|
|
if we have finished receiving the data of a packet, so it can know if
|
262 |
|
|
it can send it.*/
|
263 |
|
|
sc_signal<bool> cd_data_pending_ro_buf;
|
264 |
|
|
/**
|
265 |
|
|
It is also used to know if a data packet has been commited to prevent
|
266 |
|
|
data corruption because of reset
|
267 |
|
|
*/
|
268 |
|
|
sc_out<bool> cd_data_pending_ro;
|
269 |
|
|
|
270 |
|
|
|
271 |
|
|
|
272 |
|
|
/**
|
273 |
|
|
This combinational process is responsible with calculating the
|
274 |
|
|
next state based on the current state and/or the value received
|
275 |
|
|
as a doubleword bit vector input.
|
276 |
|
|
*/
|
277 |
|
|
void getnextst();
|
278 |
|
|
/**
|
279 |
|
|
This sequential process is responsible with updating the current
|
280 |
|
|
state of the machine and other sequential outputs, as well as
|
281 |
|
|
processing the reset (nClear) signal.
|
282 |
|
|
*/
|
283 |
|
|
void setstate();
|
284 |
|
|
/**
|
285 |
|
|
This combinational process is responsible with setting the outputs
|
286 |
|
|
of the state machine according to the current state and/or the value
|
287 |
|
|
received as a doubleword bit vector input.
|
288 |
|
|
|
289 |
|
|
*/
|
290 |
|
|
void stateoutputs();
|
291 |
|
|
|
292 |
|
|
/**
|
293 |
|
|
Because not all nodes of a HyperTransport chain receive a reset
|
294 |
|
|
simultaneously, we only commit data once a new control packet
|
295 |
|
|
has been received. Data packets work a bit differently : in non-retry
|
296 |
|
|
mode, they must be sent to the RO immediately for ordering reasons. In
|
297 |
|
|
their case, before sending out a Data packet, the RO checks with the
|
298 |
|
|
decoder to see if it had been commited so we don't need to hold it out.
|
299 |
|
|
*/
|
300 |
|
|
void output_packet_selection();
|
301 |
|
|
|
302 |
|
|
///SystemC Macro
|
303 |
|
|
SC_HAS_PROCESS(cd_state_machine_l3);
|
304 |
|
|
|
305 |
|
|
/// Module constructor
|
306 |
|
|
cd_state_machine_l3(sc_module_name name);
|
307 |
|
|
};
|
308 |
|
|
|
309 |
|
|
#endif
|