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

Subversion Repositories ht_tunnel

[/] [ht_tunnel/] [trunk/] [bench/] [vc_ht_tunnel_l1_tb/] [LogicalLayer.h] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 acastong
//LogicalLayer.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
 *   Ami Castonguay <acastong@grm.polymtl.ca>
25
 *
26
 * Alternatively, the contents of this file may be used under the terms
27
 * of the Polytechnique HyperTransport Tunnel IP Core Source Code License
28
 * (the  "PHTICSCL License", see the file PHTICSCL.txt), in which case the
29
 * provisions of PHTICSCL License are applicable instead of those
30
 * above. If you wish to allow use of your version of this file only
31
 * under the terms of the PHTICSCL License and not to allow others to use
32
 * your version of this file under the MPL, indicate your decision by
33
 * deleting the provisions above and replace them with the notice and
34
 * other provisions required by the PHTICSCL License. If you do not delete
35
 * the provisions above, a recipient may use your version of this file
36
 * under either the MPL or the PHTICSCL License."
37
 *
38
 * ***** END LICENSE BLOCK ***** */
39
 
40
#ifndef LogicalLayer_H
41
#define LogicalLayer_H
42
 
43
#include "systemc.h"
44
#include "../../rtl/systemc/core_synth/constants.h"
45
#include "PhysicalLayer.h"
46
#include <deque>
47
 
48
//Forward declaration
49
class ControlPacket;
50
class LogicalLayer;
51
 
52
///Event handler interface for the LogicalLayer module
53
class LogicalLayerInterface{
54
public:
55
        /**
56
                @description Called when a packet is received by the
57
                        LogicalLayer
58
                @param packet The received packet
59
                @param data The data associated with the packet.  It is an
60
                        array of dwords.  If the packet has data associated with
61
                        it, the size of the array is the number of dwords associated
62
                        with the packet (1-16).  Otherwise, it is NULL.
63
                @param origin The LogicalLayer that launchde the event
64
        */
65
        virtual void receivedHtPacketEvent(const ControlPacket * packet,
66 10 acastong
                const int * data,const LogicalLayer* origin)=0;
67 2 acastong
        /**
68
                Called when a periodic CRC error is detected
69
        */
70
    virtual void crcErrorDetected()=0;
71
};
72
 
73
///Module that handles logical level of the HyperTransport link.
74
/**
75
        @author Ami Castonguay
76
        @description    It takes packets and breaks it in
77
                dwords to send to the Physical layer.  It also handles the retry
78
                mode : it will send appropriate per-packet CRC's and also store
79
                a history of sent packet so that packets not sent correctly
80
                can be reset.
81
 
82
                It also handles NOPs both for transmission and for reception.  When
83
                nops are received, the buffer count of the next HT node is updated.
84
                The local buffer count is also maintained and nops are sent when
85
                necessary.
86
 
87
                When ::sendPacket is called, the packet to be sent it stored in
88
                a buffer but is not sent immediately.  It will be sent out as
89
                the simulation progresses.  If the flush function is called, it
90
                will only return when all packets in the buffer are sent.  If the
91
                next node does not have the necessary buffers to accept a packet,
92
                it is not sent unril the buffer is free.
93
 
94
                When a new packet is received, an event is generated.  A listener
95
                simply has to implement the LogicalLayerInterface and register
96
                as the interface to the LogicalLayer to be notified of received
97
                packets.
98
 
99
                The class also implements the PhysicalLayerInterface to be notified
100
                by the PhysicalLayer of the link whenever a dword is received.
101
*/
102
class LogicalLayer : public sc_module, public PhysicalLayerInterface{
103
 
104
        ///List of possible states for receiving packets
105
        enum ReceiveState{
106
                RECEIVE_IDLE,
107
                RECEIVE_SECOND_DWORD,
108
                RECEIVE_DATA,
109
                RECEIVE_NOP_CRC,
110
                RECEIVE_CRC
111
        };
112
 
113
        ///List of possible states to transmit packets
114
        enum SendState{
115
                SEND_IDLE,
116
                SEND_SECOND_DWORD,
117
                SEND_ADDR_EXT,
118
                SEND_DATA,
119
                SEND_NOP_CRC,
120
                SEND_CRC
121
        };
122
 
123
        ///Structure combining a packet, it's data and it's ack value
124
        struct PacketAndData{
125
                ///The packet
126
                ControlPacket * packet;
127
                ///Data associated with the packet (NULL if none)
128
                int * data;
129
                ///Ack value of the packet (for the retry mode)
130
                int id;
131
        };
132
 
133
        ///The retry CRC polynomial
134
        static const int PER_PACKET_CRC_POLY;
135
        ///The number of simulated buffers of thie module
136
        static const int MAX_BUFFERS;
137
 
138
public:
139
 
140
        ///SystemC Macro
141
        SC_HAS_PROCESS(LogicalLayer);
142
 
143
        ///To debug, will display all received dwords
144
        bool displayReceivedDword;
145
 
146
        ///Clock of the system
147
        sc_in<bool>     clk;
148
        ///reset of the system (negative logic)
149
        sc_in<bool> resetx;
150
 
151
        ///consctructor
152
        LogicalLayer(sc_module_name name);
153
        ///destructor
154
        virtual ~LogicalLayer();
155
 
156
        /**
157
                @description This is a PhysicalLayerInterface function called by the
158
                PhysicalLayer when a dword is received.
159
                @param dword The dword that was received
160
                @param lctl The CTL value for the lower part of the dword transmission
161
                @param hctl The CTL value for the higher part of the dword transmission
162
        */
163
        virtual void receivedDwordEvent(sc_bv<32> &dword,bool lctl,bool hctl);
164
 
165
        /**
166
                @description This is a PhysicalLayerInterface function called by the
167
                PhysicalLayer when a dword is needed to be sent out.
168
                @param dword The dword to send (return by address)
169
                @param lctl The CTL value for the lower part of the dword transmission (return by address)
170
                @param hctl The CTL value for the higher part of the dword transmission (return by address)
171
        */
172
    virtual void dwordToSendRequested(sc_bv<32> &dword,bool &lctl,bool &hctl);
173
 
174
        /**
175
                @description This is a PhysicalLayerInterface function called by the PhysicalLayer
176
                when periodic CRC error occurs
177
        */
178
    virtual void crcErrorDetected();
179
 
180
        ///To send a packet (non-blocking, packet is simply buffered)
181
        /**
182
                The function will store the packet and send it as soon as it can as the simulation
183
                advances.  Packets and the data will then be deleted by the LogicalLayer.
184
                @param packet The packet to send (memory control is given to LogicalLayer)
185
                @param data The dwords of data associated the the packet (NULL if no data to send)
186
                                (memory control is given to LogicalLayer)
187
        */
188
        void sendPacket(ControlPacket * packet,int * data);
189
 
190
        ///Blocks until all packets are sent out
191
    void flush();
192
 
193
        ///Set if the retry mode should be activated.  Will take effect after warm reset
194
        void setRetryMode(bool retry){retry_mode_after_reset = retry;};
195
        ///This will initiate a retry sequence as soon as the current packet has done sending
196
        void initiateRetrySequence();
197
 
198
        ///Sets the interface handler so that it can be notified of received packets
199
        void setInterface(LogicalLayerInterface * i){inter = i;};
200
        ///Sets the physical layer to send and receive packet to and from
201
        /**
202
                Registers the PhysicalLayer as a the PhysicalLayer to send data to and registers
203
                this object as PhysicalLayer received dword event listener
204
        */
205
        void setPhysicalLayer(PhysicalLayer * pl){
206
                physicalLayer = pl;
207
                physicalLayer->setInterface(this);
208
        };
209
 
210
        ///Allows to ignore incoming packets
211
        void setIgnoreIncoming(bool ignore){ignoreIncoming = ignore;};
212
 
213
protected:
214
 
215
        ///A process that re-initializes things when reset is asserted
216
        void reset_thread();
217
 
218
private:
219
 
220
        ///Updates buffers and ack value contained in a received NOP
221
        /**
222
                If in retry mode, acked history entries are deleted
223
        */
224
        void handleNopPacket(sc_bv<32> &dword);
225
 
226
        ///Calculate a CRC for the packet and it's data
227
        int calcultatePacketCrc(ControlPacket * pkt,int * data);
228
 
229
        ///Update a CRC with the dword and ctl value
230
        /**
231
                @param crc The current CRC value to update
232
                @param dword The dword to feed as input to the CRC unit
233
                @param ctl The ctl value to feed as input to the CRC unit
234
        */
235
        void calcultateDwordCrc(int &crc,sc_bv<32> &dword,bool ctl);
236
 
237
        ///Verifies the state of advertised buffers and checks if a sending a nop is required
238
        bool isSendingNopRequired();
239
 
240
        ///Update the value of advertised buffers when a packet is received
241
        void updateRxBufferCount(ControlPacket * receivedPacket);
242
 
243
        ///Generates a nop packet with the current ack value
244
        NopPacket * generateNopPacket();
245
 
246
        ///Queue of packets to send
247
        /**
248
                When packet are to be sent, they are added to the queue.  When the packet is sent,
249
                it is deleted from the packetQueue.  The queue is also cleared when a retry sequence
250
                is initiated or under a reset
251
        */
252
        std::deque<PacketAndData> packetQueue;
253
 
254
        ///History of packet sent (and to send)
255
        /**
256
                When packet are to be sent, they are added to the packetHistory (just like with the
257
                ::packetQueue ).  The packet from the history is deleted when it is acked.  It is
258
                cleared during reset.
259
        */
260
        std::deque<PacketAndData> packetHistory;
261
 
262
        ///The interface to notify when packets are received
263
        LogicalLayerInterface * inter;
264
        ///The physical layer to send dwords to
265
        PhysicalLayer * physicalLayer;
266
        ///The ID counter for sent packet
267
        int packetIdCounter;
268
 
269
        ///Wether or not to ignore incoming dwords
270
        bool ignoreIncoming;
271
        ///If we are currently in the retry mode
272
        bool retry_mode;
273
        ///If we should enter the retry mode after a reset
274
        bool retry_mode_after_reset;
275
        ///If a retry sequence should be initiated as soon as possible
276
        bool initiate_retry_disconnect;
277
 
278
        ///The first dword of a received packet (useful for calculating inserted NOP CRC's)
279
        sc_bv<32> firstReceivedDword;
280
        ///Current packet being received.
281
        /**  NULL at the beggining, it is always deleted before being set to a new value
282
                Created as soon as a first dword is received.  NOP's inserted in data packets
283
                are not stored here.
284
        */
285
        ControlPacket * receivedPacket;
286
        ///Data received
287
        int receivedData[16];
288
        ///The count of received data
289
        int receivedDataCount;
290
        ///The state for the reception of packets (
291
        ReceiveState receive_state;
292
        ///The ack value of received packets.  Incremented when packets are received
293
        int rx_ack_value;
294
        ///If we are currently waiting for a nop to start replaying the history
295
        bool rx_retry_waiting_for_nop;
296
 
297
 
298
        ///The state for the transmission of data
299
        SendState send_state;
300
        ///The packet currently being sent
301
        PacketAndData currentSendPacket;
302
        ///The nop packet currently being sent
303
        ControlPacket * nopSendPacket;
304
        ///Where we are in sending data
305
        int sendDataCount;
306
        ///If what is currently being sent is a disconnect nop
307
        bool disconNop;
308
 
309
        ///The state of the command buffers of the next node
310
        int nextNodeCommandBuffersFree[3];
311
        ///The state of the data buffers of the next node
312
        int nextNodeDataBuffersFree[3];
313
 
314
        ///The number of command buffers which have been advertised as free
315
        int commandBuffersAdvertised[3];
316
        ///The number of data buffers which have been advertised as free
317
        int dataBuffersAdvertised[3];
318
        ///The number of command buffers that are free
319
        int commandBuffersFree[3];
320
        ///The number of data buffers that are free
321
        int dataBuffersFree[3];
322
};
323
 
324
 
325
#endif

powered by: WebSVN 2.1.0

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