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

Subversion Repositories funbase_ip_library

[/] [funbase_ip_library/] [trunk/] [TUT/] [ip.hwp.communication/] [hibi/] [3.0/] [tb/] [sad_tb/] [packet.hh] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
/*
2
 * Author: Lasse Lehtonen
3
 *
4
 * Packet that's sent through hibi
5
 *
6
 * $Id: packet.hh 2010 2011-10-07 08:16:05Z ege $
7
 *
8
 */
9
 
10
#ifndef SAD_HIBI_PACKET_HH
11
#define SAD_HIBI_PACKET_HH
12
 
13
 
14
#include "constants.hh"
15
 
16
#include 
17
using namespace std;
18
 
19
#include 
20
using namespace sc_core;
21
using namespace sc_dt;
22
 
23
 
24
 
25
class Packet
26
{
27
public:
28
 
29
   //* Constructor
30
   Packet(unsigned int words, sc_bv source,
31
          sc_bv destination, HibiCommand command,
32
          unsigned int data1 = 0, unsigned int data2 = 0,
33
          unsigned int data3 = 0)
34
      : _words(words),
35
        _receivedWords(0),
36
        _source(source),
37
        _destination(destination),
38
        _command(command),
39
        _data(static_cast >(0)),
40
        _id(Packet::packet_id),
41
        _respSize(0)
42
   {
43
 
44
      // Packet contents depend on the command:
45
      // write, exclusive lock/release, read, config
46
      if(_command == DATA_WR ||
47
         _command == MSG_WR ||
48
         _command == DATA_WRNP ||
49
         _command == MSG_WRNP ||
50
         _command == EXCL_WR )
51
      {
52
         _data = static_cast >(Packet::packet_id);
53
      }
54
      else if(_command == EXCL_LOCK ||
55
              _command == EXCL_RELEASE )
56
      {
57
         _words = 1;
58
         _data = static_cast >(Packet::packet_id);
59
      }
60
      else if(_command == EXCL_RD ||
61
              _command == DATA_RD ||
62
              _command == MSG_RD ||
63
              _command == DATA_RDL ||
64
              _command == MSG_RDL)
65
      {
66
         _data = _source;
67
         _id = _source;
68
         _respSize = data1;
69
      }
70
      else if(_command == CFG_WR)
71
      {
72
         // data1 = cfg page, data2 = cfg slot, data3 = the data
73
         // Sent addr must contain dst id, cfg page, and cfg param index
74
         unsigned int pagesize = 2;
75
         unsigned int pagewidth = 1;
76
         unsigned int timeslots = n_time_slots_c == 0 ? 1 : n_time_slots_c;
77
         while(pagesize < 9 + timeslots*3)
78
         {
79
            pagesize *= 2;
80
            pagewidth++;
81
         }
82
         int totpages = 2;
83
         unsigned int totpageswidth = 1;
84
         while(totpages < n_cfg_pages_c)
85
         {
86
            totpages *= 2;
87
            totpageswidth++;
88
         }
89
         _data = data3;
90
         _destination.range(addr_width_c-1, addr_width_c-id_width_c) =
91
            destination.range(id_width_c-1, 0);
92
         _destination.range(totpageswidth+pagewidth-1, pagewidth) = data1;
93
         _destination.range(pagewidth-1, 0) = data2;
94
 
95
      }
96
      else if(_command == CFG_RD)
97
      {
98
         // data1 = cfg page, data2 = cfg index
99
         // Sent addr must contain dst id, cfg page, and cfg param index
100
         unsigned int pagesize = 2;
101
         unsigned int pagewidth = 1;
102
         unsigned int timeslots = n_time_slots_c == 0 ? 1 : n_time_slots_c;
103
         while(pagesize < 9 + timeslots*3)
104
         {
105
            pagesize *= 2;
106
            pagewidth++;
107
         }
108
         int totpages = 2;
109
         unsigned int totpageswidth = 1;
110
         while(totpages < n_cfg_pages_c)
111
         {
112
            totpages *= 2;
113
            totpageswidth++;
114
         }
115
         _data = _source;
116
         _destination.range(addr_width_c-1, addr_width_c-id_width_c) =
117
            destination.range(id_width_c-1, 0);
118
         _destination.range(totpageswidth+pagewidth-1, pagewidth) = data1;
119
         _destination.range(pagewidth-1, 0) = data2;
120
      }
121
      else
122
      {
123
         cout << "Unsupported command" << endl;
124
      }
125
 
126
      Packet::packet_id++;
127
   }
128
 
129
   //* Destructor
130
   ~Packet()
131
   {
132
 
133
   }
134
 
135
   //* Returns hibi command as a bit vector
136
   const sc_bv& getCommand() const
137
   { return commands_c[_command]; }
138
 
139
   //* Returns hibi command as enumeration
140
   const HibiCommand& getHibiCommand() const
141
   { return _command; }
142
 
143
   //* Returns destination address as a bit vector
144
   const sc_bv& getDstAddress() const
145
   { return _destination; }
146
 
147
   //* Returns source address as a bit vector
148
   const sc_bv& getSrcAddress() const
149
   { return _source; }
150
 
151
   //* Returns destination Id
152
   unsigned int getDstId() const
153
   {
154
      return _destination.range(addr_width_c-1, addr_width_c-id_width_c).
155
         to_uint();
156
   }
157
 
158
   //* Returns the data to send
159
   const sc_bv& getData() const
160
   { return _data; }
161
 
162
   //* Returns packet's ID
163
   const sc_uint<16>& getId() const
164
   { return _id; }
165
 
166
   //* Returns packet's size in words
167
   const unsigned int& getSize() const
168
   { return _words; }
169
 
170
   //* Returns the number of received words
171
   const unsigned int& getReceived() const
172
   { return _receivedWords; }
173
 
174
   //* Returns packet's size in words
175
   const unsigned int& getResponseSize() const
176
   { return _respSize; }
177
 
178
   //* Increments received word counter
179
   void receiveWord()
180
   {
181
      if(++_receivedWords > _words)
182
      {
183
         ostringstream oss;
184
         oss << "Received too many words for packet with id: " << _id;
185
         SC_REPORT_FATAL(oss.str().c_str(),"");
186
      }
187
   }
188
 
189
   //* True if packet has received all words already
190
   bool complete()
191
   { return _receivedWords >= _words ? true : false; }
192
 
193
private:
194
 
195
   // This helps creating unique id for all packets
196
   static sc_uint<16> packet_id;
197
 
198
   // Other params for a packet. All commands do
199
   // not need all these
200
   unsigned int        _words;         // num of data_words
201
   unsigned int        _receivedWords; // obsolete???
202
   sc_bv _source;        // return addr in read rq
203
   sc_bv _destination;   // where to send
204
   HibiCommand         _command;
205
   sc_bv _data;          // remains same during burst
206
   sc_uint<16>         _id;            // uniques
207
   unsigned int        _respSize;      // #words reutrned in reads
208
 
209
};
210
 
211
// Initializing static class member
212
sc_uint<16> Packet::packet_id = 100;
213
 
214
#endif
215
 
216
// Local Variables:
217
// mode: c++
218
// c-file-style: "ellemtel"
219
// c-basic-offset: 3
220
// End:
221
 

powered by: WebSVN 2.1.0

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