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

Subversion Repositories ht_tunnel

[/] [ht_tunnel/] [tags/] [START/] [bench/] [core/] [PacketContainer.h] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 acastong
//PacketContainer.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
 
40
#ifndef PacketContainer_H
41
#define PacketContainer_H
42
 
43
#ifndef SC_USER_DEFINED_MAX_NUMBER_OF_PROCESSES
44
#define SC_USER_DEFINED_MAX_NUMBER_OF_PROCESSES
45
#define SC_VC6_MAX_NUMBER_OF_PROCESSES 20
46
#endif
47
#include <systemc.h>
48
 
49
#include "ControlPacket.h"
50
 
51
///Container for ControlPacket pointers
52
/**
53
        This class is a safe way to exchange <code>ControlPacket</code>
54
        over a <code>sc_signal</code>.  It is a modified automatic pointer
55
        that never releases it's pointer, but instead creates
56
        a copy of an object unless it is explicitely asked
57
        to take control.
58
 
59
        Since it never gives control of it's internal pointer,
60
        the object inside the container always stays valid!
61
        A NOP packet is constructed by default.
62
 
63
        Caution has to be taken when using this.  When passing
64
        a pointer to the constructor, the container will take
65
        control of the packet.  If an object is passed, then
66
        a copy of the object will be made.
67
 
68
        @see ControlPacket
69
        @author Ami Castonguay
70
*/
71
class PacketContainer{
72
 
73
        ///To output the packet on an <code>ostream</code>
74
        /**
75
                Called to output the internal packet to an output stream.
76
 
77
                @param out The stream to output to
78
                @param c   The container that contains the packet to output
79
                @return ostream The stream <code>out</code>
80
        */
81
        friend ostream& operator<<(ostream& out, const PacketContainer & c);
82
        friend void sc_trace(sc_trace_file *tf, const PacketContainer& v,
83
        const sc_string& NAME);
84
 
85
protected:
86
 
87
        ///The actual packet contained
88
        ControlPacket* pkt;
89
 
90
        ///If the packet was constructed by default (nop)
91
        bool defaultPacket;
92
 
93
        ///Initial Packet value
94
        /**
95
                sc_trace(...) requires to be called on an object which has a
96
                lifetime of the complete simulation.  Since the internal pkt
97
                object is constantly allocated and destroyed, it is not possible
98
                to trace the object.  Instead, when de PacketContainer is allocated
99
                with a new packet, the bufferedBitVector is updated with the initial
100
                value of the packet.  That variable can then be traved without problem.
101
 
102
                Any change to the packet bit vector will not appear in the
103
                bufferedBitVector since it is only a snapshot of the initial value.
104
        */
105
        sc_bv<64> bufferedBitVector;
106
 
107
public:
108
 
109
        ///Default constructor
110
        /**
111
                Default constructor
112
        */
113
        PacketContainer();
114
 
115
        ///Constructor to take over packet
116
        /**
117
                This constructor will take control of the packet.
118
                It will take care to free the memory of the pointer
119
                when the destructor is called.
120
 
121
                @param pkt_ref The packet to take control of
122
        */
123
        PacketContainer(ControlPacket* pkt_ref);
124
 
125
        ///Copy constructor
126
        /**
127
                The constructor will create a PacketContainer that has an internal packet
128
                identical packet (a copy) to the one inside the container passed as parameter
129
 
130
                @param container The container to copy
131
        */
132
        PacketContainer(const PacketContainer &container);
133
 
134
        ///Assign a new value to the packet container
135
        /**
136
                This operator will delete the internal packet and replace it with an
137
                identical packet (a copy) to the one inside the container passed as parameter
138
 
139
                @param container The container that contains the packet to copy
140
                @return This packet
141
        */
142
        PacketContainer& operator=(const PacketContainer &container);
143
 
144
        ///Assign a new value to the packet container
145
        /**
146
                This operator will delete the internal packet and replace it with an
147
                identical packet (a copy) to the one passed as parameter
148
 
149
                @param new_pkt The packet to copy
150
                @return This packet
151
        */
152
        PacketContainer& operator=(const ControlPacket &new_pkt);
153
 
154
 
155
        ///If packet is valid
156
        /**
157
                When a container is created from the default constructor,
158
                a default NOP packet is created.  This returns wether or not
159
                it's that default packet that is contained in the container.
160
 
161
                @return If the container was assigned with a packet
162
        */
163
        bool isValidPacket() const;
164
 
165
 
166
        ///Take control of the pointer
167
        /**
168
                This will take control of the packet.
169
                It will take care to free the memory of the pointer
170
                when the destructor is called.
171
 
172
                @param new_pkt The packet to take control of
173
        */
174
        void takeControl(ControlPacket *new_pkt);
175
 
176
        ///Give away control of the internal packet
177
        /**
178
                This will returns the pointer to the internal
179
                packet and creates a new default packet internally.  The returned
180
                pointer will not be deleted when the destructor is called.
181
 
182
                @return The pointer to the internal packet
183
        */
184
        ControlPacket* giveControl();
185
 
186
        ///Get the reference to the internal packet
187
        /**
188
                @return The pointer to the internal packet
189
        */
190
        ControlPacket* getPacketRef() const{
191
                return pkt;
192
        }
193
 
194
        ///Get the packet object
195
        /**
196
                @return The internal packet
197
        */
198
        ControlPacket& operator* () const{
199
                return *pkt;
200
        }
201
 
202
        ///Operator to access the packet members
203
        /**
204
                This operator allows to access members on the internal packet
205
                directly from the the container object.
206
 
207
                Eg :
208
                <code>
209
                Container c;//Creates a default NopPacket
210
                VirtualChannel vc = c->getVirtualChannel();Directly access member method
211
                </code>
212
 
213
                @return The pointer to the internal packet
214
        */
215
    ControlPacket* operator-> () const{
216
                return pkt;
217
        }
218
 
219
        /**
220
                Deletes the packet stored in the container
221
        */
222
        ~PacketContainer();
223
 
224
        ///To check if two packets have identical content
225
        bool operator== (const PacketContainer & test) const;
226
 
227
        ///To check if two packets have different content
228
        inline bool operator!= (const PacketContainer &test) const {return !(*this == test);}
229
 
230
        //Those two operators actually use the underlying ControlPacket equivalent
231
        //operator, hence why it is as simply as return *pkt.
232
        /**
233
                @return The 64 bits vector of the packet
234
        */
235
        inline operator sc_bv<64>() const {return *pkt;}
236
 
237
        /**
238
                @return The least significant 32 bits of the packet.
239
        */
240
        inline operator sc_bv<32>() const {return *pkt;}
241
 
242
 
243
};
244
 
245
 
246
#endif

powered by: WebSVN 2.1.0

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