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

Subversion Repositories ht_tunnel

[/] [ht_tunnel/] [trunk/] [bench/] [core/] [ControlPacket.cpp] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 acastong
//ControlPacket.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
#include "ht_datatypes.h"
41
 
42
bool ControlPacket::outputExtraInformation = false;
43
 
44
PacketContainer ControlPacket::createPacketFromDword(const sc_bv<32> &dWord){
45
 
46
        //First start by finding the type of packet
47
        sc_bv<6> cmd = dWord(5 , 0);
48
        PacketType pkt_type = getPacketType(cmd);
49
        PacketCommand pkt_command = getPacketCommand(cmd);
50
 
51
        //Create a default packet
52
        ControlPacket* pkt = NULL;
53
 
54
        //From the packet type, create an object of the appropriate
55
        //derived class and return it
56
        if(pkt_type == INFO){
57
                if(pkt_command == SYNC)         pkt = new SyncPacket(dWord);
58
                else if(pkt_command == NOP) pkt = new NopPacket(dWord);
59
        }
60
        else if(pkt_type == RESPONSE){
61
                if(pkt_command == RD_RESPONSE)          pkt = new ReadResponsePacket(dWord);
62
                else if(pkt_command == TGTDONE)         pkt = new TargetDonePacket(dWord);
63
        }
64
        else if(pkt_type == REQUEST)
65
        {
66
                if(pkt_command == FLUSH)                        pkt = new FlushPacket(dWord);
67
                else if (pkt_command == FENCE)          pkt = new FencePacket(dWord);
68
                else if (pkt_command == READ)           pkt = new ReadPacket(dWord);
69
                else if (pkt_command == WRITE)          pkt = new WritePacket(dWord);
70
                else if (pkt_command == BROADCAST)      pkt = new BroadcastPacket(dWord);
71
                else if (pkt_command == ATOMIC)         pkt = new AtomicPacket(dWord);
72
        }
73
        return PacketContainer(pkt);
74
}
75
 
76
PacketContainer ControlPacket::createPacketFromQuadWord(const sc_bv<64> &qWord){
77
 
78
        //First start by finding the type of packet
79
        sc_bv<6> cmd = qWord(5 , 0);
80
        PacketType pkt_type = getPacketType(cmd);
81
        PacketCommand pkt_command = getPacketCommand(cmd);
82
 
83
        //Create a default packet
84
        ControlPacket *pkt = NULL;
85
 
86
        //From the packet type, create an object of the appropriate
87
        //derived class and return it
88
        if(pkt_type == INFO){
89
                if(pkt_command == SYNC)         pkt = new SyncPacket(qWord);
90
                else                                            pkt = new NopPacket(qWord);
91
        }
92
        else if(pkt_type == RESPONSE){
93
                if(pkt_command == RD_RESPONSE)          pkt = new ReadResponsePacket(qWord);
94
                else if(pkt_command == TGTDONE)         pkt = new TargetDonePacket(qWord);
95
        }
96
        else if(pkt_type == REQUEST)
97
        {
98
                if(pkt_command == FLUSH)                        pkt = new FlushPacket(qWord);
99
                else if (pkt_command == FENCE)          pkt = new FencePacket(qWord);
100
                else if (pkt_command == READ)           pkt = new ReadPacket(qWord);
101
                else if (pkt_command == WRITE)          pkt = new WritePacket(qWord);
102
                else if (pkt_command == BROADCAST)      pkt = new BroadcastPacket(qWord);
103
                else if (pkt_command == ATOMIC)         pkt = new AtomicPacket(qWord);
104
        }
105
        return PacketContainer(pkt);
106
}
107
 
108
void ControlPacket::setSecondDword(const sc_bv<32> &dWord){
109
        bv.range(63,32) = dWord;
110
}
111
 
112
/**
113
        To know the exact command of the packet
114
*/
115
PacketCommand ControlPacket::getPacketCommand() const{
116
        sc_bv<6> cmd = bv.range(5,0);
117
        return getPacketCommand(cmd);
118
}
119
 
120
/**
121
        To parse a cmd vector
122
*/
123
PacketCommand ControlPacket::getPacketCommand(const sc_bv<6> &cmd){
124
 
125
        //Check the command vector against all known
126
        //sequences
127
        if(cmd == "000000")
128
                return NOP;
129
        else if(cmd == "111111")
130
                return SYNC;
131
        else if(cmd == "110000")
132
                return RD_RESPONSE;
133
        else if(cmd == "110011")
134
                return TGTDONE;
135
        else if(cmd.range(4 , 3) == "01")
136
                return WRITE;
137
        else if(cmd.range(5 , 4) == "01")
138
                return READ;
139
        else if(cmd == "111010")
140
                return BROADCAST;
141
        else if(cmd == "111100")
142
                return FENCE;
143
        else if(cmd == "111101")
144
                return ATOMIC;
145
        else if(cmd == "110111")
146
                return EXTENDED_FLOW;
147
        else if(cmd == "000010")
148
                return FLUSH;
149
        else if(cmd == "111110")
150
                return ADDR_EXT;
151
        else
152
                return RESERVED_CMD;
153
}
154
 
155
/**
156
        To know the type of packet from a command vector
157
*/
158
PacketType ControlPacket::getPacketType(const sc_bv<6> &cmd){
159
 
160
        //Check the command vector against all known
161
        //sequences
162
        if(cmd == "000000" || cmd == "111111" || cmd == "110111"){
163
                return INFO;
164
        }
165
        else if(cmd == "110000" || cmd == "110011"){
166
                return RESPONSE;
167
        }
168
        else if(cmd.range(5 , 3) == "001" || cmd.range(5 , 3) == "101"
169
                        || cmd.range(5 , 4) == "01" || cmd == "111010"
170
                        || cmd == "111100" || cmd == "111101" || cmd == "000010")
171
        {
172
                return REQUEST;
173
        }
174
        else if(cmd == "111101"){
175
                return ADDR_EXT_TYPE;
176
        }
177
        else{
178
                return RESERVED_TYPE;
179
        }
180
}
181
 
182
 
183
//extern function to allow the ControlPacket to be used as an sc_signal
184
void sc_trace(sc_trace_file *tf, const ControlPacket& v,
185
const sc_string& NAME) {
186
        sc_trace(tf,v.getVector(), NAME);
187
}
188
 
189
//To test if the content of another packet is identical
190
bool ControlPacket::operator== (const ControlPacket &test_pkt) const{
191
        return test_pkt.bv == bv;
192
}
193
 
194
//To output the bit content of the packet
195
ostream &operator<<(ostream &out,const ControlPacket &pkt){
196
        out << pkt.getVector().to_string(SC_HEX);
197
        if(ControlPacket::outputExtraInformation){
198
                out << endl << "Virtual channel : " << pkt.getVirtualChannel() << endl;
199
                out << "PacketType : " << pkt.getPacketType() << endl;
200
                out << "PacketCommand : " << pkt.getPacketCommand() << endl;
201
                out << "HasData : " << pkt.hasDataAssociated() << "  Length : " << ((unsigned)pkt.getDataLengthm1() + 1) << endl;
202
        }
203
        return out;
204
}
205
 
206
sc_bv<32> ControlPacket::createAddressExtensionDoubleWord(sc_bv<24> &addressExtension){
207
        sc_bv<32> tempVector;
208
        sc_bv<6> command = "111110";
209
        tempVector.range(5,0) = command;
210
        tempVector.range(31,8) = addressExtension;
211
        return tempVector;
212
}
213
 
214
 

powered by: WebSVN 2.1.0

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