source: trunk/modules/vci_vdspin_initiator_wrapper/caba/source/src/vci_vdspin_initiator_wrapper.cpp @ 284

Last change on this file since 284 was 284, checked in by joannou, 11 years ago

Updated of the vci trdid/rtrdid and pktid/rpktid fields for the direct network.
The pktid values are commented in the components'headers that use them.

  • In the vci_vdspin_*_wrapper components
    • added the transmission of the pktid/rpktid field
  • In the vci_cc_vcache_wrapper_v4
    • updated gen_moore() to transmit a valid pktid
    • updated transition(), RSP_FSM now checks the rpktid
  • In the vci_mem_cache_v4
    • transition(), tests originally performed on trdid now use pktid
    • gen_moore() transmit rpktid
    • !!! THE L1_MULTI_CACHE MECHANISM IS NO LONGER COMPATIBLE !!!
  • In vci_block_device_tsar_v4
    • updated gen_moore function to transmit a valid pktid

Also renamed the "SC" states in "CAS" states in the concerned FSMs on the vci_cc_vcache_wrapper_v4 and the vci_mem_cache_v4

File size: 14.5 KB
Line 
1/* -*- c++ -*-
2  * File : vci_vdspin_initiator_wrapper.cpp
3  * Copyright (c) UPMC, Lip6
4  * Authors : Alain Greiner
5  *
6  * SOCLIB_LGPL_HEADER_BEGIN
7  *
8  * This file is part of SoCLib, GNU LGPLv2.1.
9  *
10  * SoCLib is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU Lesser General Public License as published
12  * by the Free Software Foundation; version 2.1 of the License.
13  *
14  * SoCLib is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with SoCLib; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA
23  *
24  * SOCLIB_LGPL_HEADER_END
25  */
26
27#include "../include/vci_vdspin_initiator_wrapper.h"
28
29namespace soclib { namespace caba {
30
31#define tmpl(x) template<typename vci_param, int dspin_cmd_width, int dspin_rsp_width> x VciVdspinInitiatorWrapper<vci_param, dspin_cmd_width, dspin_rsp_width>
32
33//////////////////////////////////////////////////////////:////////////////////////////////
34tmpl(/**/)::VciVdspinInitiatorWrapper(sc_module_name             name,
35                      size_t                cmd_fifo_depth,
36                      size_t                rsp_fifo_depth)
37           : soclib::caba::BaseModule(name),
38                 p_clk("p_clk"),
39                 p_resetn("p_resetn"),
40                 p_dspin_out("p_dspin_out"),
41                 p_dspin_in("p_dspin_in"),
42                 p_vci("p_vci"),
43                 r_cmd_fsm("r_cmd_fsm"),
44                 r_rsp_fsm("r_rsp_fsm"),
45             r_fifo_cmd("r_fifo_cmd", cmd_fifo_depth),
46             r_fifo_rsp("r_fifo_rsp", rsp_fifo_depth)
47{
48    SC_METHOD (transition);
49    dont_initialize();
50    sensitive << p_clk.pos();
51    SC_METHOD (genMoore);
52    dont_initialize();
53    sensitive  << p_clk.neg();
54
55    assert( (dspin_cmd_width == 40) && "The DSPIN CMD flit width must have 40 bits");
56    assert( (dspin_rsp_width == 33) && "The DSPIN RSP flit width must have 33 bits");
57    assert( (vci_param::N    <= 40) && "The VCI ADDRESS field cannot have more than 40 bits");
58    assert( (vci_param::B    == 4) && "The VCI DATA filds must have 32 bits");
59    assert( (vci_param::K    == 8) && "The VCI PLEN field cannot have more than 8 bits");
60    assert( (vci_param::S    <= 14) && "The VCI SRCID field cannot have more than 8 bits");
61    assert( (vci_param::T    <= 8) && "The VCI TRDID field cannot have more than 8 bits");
62    assert( (vci_param::E    == 2) && "The VCI RERROR field cannot have more than 2 bits");
63
64} //  end constructor
65
66/////////////////////////
67tmpl(void)::transition()
68{
69    sc_uint<dspin_cmd_width>    cmd_fifo_data;
70    bool                cmd_fifo_write;
71    bool                cmd_fifo_read;
72
73    sc_uint<dspin_rsp_width>    rsp_fifo_data;
74    bool                rsp_fifo_write;
75    bool                rsp_fifo_read;
76
77    if (p_resetn == false)
78        {
79        r_fifo_cmd.init();
80        r_fifo_rsp.init();
81        r_cmd_fsm = CMD_IDLE;
82        r_rsp_fsm = RSP_IDLE;
83        return;
84    } // end reset
85
86    /////////////////////////////////////////////////////////////
87    // VCI command packet to DSPIN command packet
88    // The VCI packet is analysed, translated,
89    // and the DSPIN packet is stored in the fifo_cmd
90    /////////////////////////////////////////////////////////////
91    // - A N flits VCI write command packet is translated
92    //   to a N+2 flits DSPIN command.
93    // - A single flit VCI read command packet is translated
94    //   to a 2 flits DSPIN command.
95    // - A single flit VCI broadcast packet is translated to
96    //   a 2 flits DSPIN command.
97    // A DSPIN flit is written in the fifo_cmd in all states
98    // but a VCI flit is consumed only in the CMD_READ,
99    // CMD_BROACAST,  and CMD_WDATA states.
100    //////////////////////////////////////////////////////////////
101
102    // cmd_fifo_read
103    cmd_fifo_read = p_dspin_out.read.read();
104
105    // r_cmd_fsm, cmd_fifo_write and cmd_fifo_data
106    cmd_fifo_write = false;        // default value
107
108    switch(r_cmd_fsm) {
109        case CMD_IDLE:        // write first DSPIN flit into fifo_cmd
110            {
111                if( p_vci.cmdval && r_fifo_cmd.wok() )
112                {
113                    cmd_fifo_write = true;
114                    sc_uint<dspin_cmd_width> address = (sc_uint<dspin_cmd_width>)p_vci.address.read();
115                    sc_uint<dspin_cmd_width> srcid   = (sc_uint<dspin_cmd_width>)p_vci.srcid.read();
116                    sc_uint<dspin_cmd_width> trdid   = (sc_uint<dspin_cmd_width>)p_vci.trdid.read();
117                    sc_uint<dspin_cmd_width> cmd     = (sc_uint<dspin_cmd_width>)p_vci.cmd.read();
118
119                    bool is_broadcast = ( (address & 0x3) != 0);
120                    bool is_read = ((cmd == vci_param::CMD_READ) || (cmd == vci_param::CMD_LOCKED_READ));
121
122                    if ( vci_param::N == 40 ) address = address >> 1;
123                    else                      address = address << (39 - vci_param::N);
124
125                    if ( is_broadcast )    // VCI broacast command
126                    {
127                        r_cmd_fsm     = CMD_BROADCAST;
128                        cmd_fifo_data = (address      & 0x7FFFF80000LL) |
129                                        ((srcid << 5) & 0x000007FFE0LL) |
130                                        ((trdid << 1) & 0x000000001ELL) |
131                                                        0x0000000001LL;
132                    }
133                    else if (is_read )            // VCI READ  command
134                    {
135                        r_cmd_fsm     = CMD_READ;
136                        cmd_fifo_data = address & 0x7FFFFFFFFELL;
137                    }
138                    else                 // VCI WRITE command
139                    {
140                        r_cmd_fsm     = CMD_WRITE;
141                        cmd_fifo_data = address & 0x7FFFFFFFFELL;
142                    }
143                }
144         break;
145        }
146        case CMD_BROADCAST:        // write second DSPIN flit in case of broadcast
147            {
148                if( p_vci.cmdval && r_fifo_cmd.wok() )
149                {
150                    cmd_fifo_write   = true;
151                    sc_uint<dspin_cmd_width> data = (sc_uint<dspin_cmd_width>)p_vci.wdata.read();
152                    sc_uint<dspin_cmd_width> be   = (sc_uint<dspin_cmd_width>)p_vci.be.read();
153                    cmd_fifo_data    = (data       & 0x00FFFFFFFFLL) |
154                                       ((be << 32) & 0x0300000000LL) |
155                                                     0x8000000000LL;
156                    r_cmd_fsm = CMD_IDLE;
157                }
158                break;
159            }
160            case CMD_READ:    // write second DSPIN flit in case of read/write
161            case CMD_WRITE:
162            {
163                if( p_vci.cmdval && r_fifo_cmd.wok() )
164                {
165                    cmd_fifo_write      = true;
166                    sc_uint<dspin_cmd_width> srcid   = (sc_uint<dspin_cmd_width>)p_vci.srcid.read();
167                    sc_uint<dspin_cmd_width> pktid   = (sc_uint<dspin_cmd_width>)p_vci.pktid.read();
168                    sc_uint<dspin_cmd_width> trdid   = (sc_uint<dspin_cmd_width>)p_vci.trdid.read();
169                    sc_uint<dspin_cmd_width> cmd     = (sc_uint<dspin_cmd_width>)p_vci.cmd.read();
170                    sc_uint<dspin_cmd_width> plen    = (sc_uint<dspin_cmd_width>)p_vci.plen.read();
171                    sc_uint<dspin_cmd_width> be      = (sc_uint<dspin_cmd_width>)p_vci.be.read();
172                    cmd_fifo_data                    = ((be    << 1 ) & 0x000000001ELL) |
173                                                       ((pktid << 5 ) & 0x00000001E0LL) |
174                                                       ((trdid << 9 ) & 0x0000001E00LL) |
175                                                       ((plen  << 13) & 0x00001FE000LL) |
176                                                       ((cmd   << 23) & 0x0001800000LL) |
177                                                       ((srcid << 25) & 0x7FFE000000LL) ;
178                    if ( p_vci.contig.read() ) cmd_fifo_data = cmd_fifo_data | 0x0000400000LL ;
179                    if ( p_vci.cons.read()   ) cmd_fifo_data = cmd_fifo_data | 0x0000200000LL ;
180
181                    if( r_cmd_fsm == CMD_READ )  // read command
182                    {
183                        r_cmd_fsm = CMD_IDLE;
184                        cmd_fifo_data = cmd_fifo_data    | 0x8000000000LL ;
185                    }
186                    else            // write command
187                    {
188                        r_cmd_fsm = CMD_WDATA;
189                    }
190        }
191        break;
192            }
193        case CMD_WDATA:
194            {
195                if( p_vci.cmdval && r_fifo_cmd.wok() )
196                {
197                    cmd_fifo_write = true;
198                    sc_uint<dspin_cmd_width> data = (sc_uint<dspin_cmd_width>)p_vci.wdata.read();
199                    sc_uint<dspin_cmd_width> be   = (sc_uint<dspin_cmd_width>)p_vci.be.read();
200                    cmd_fifo_data                 = (data       & 0x00FFFFFFFFLL) |
201                                                    ((be << 32) & 0x0F00000000LL) ;
202
203                    if ( p_vci.eop.read() )
204                    {
205                        cmd_fifo_data = cmd_fifo_data | 0x8000000000LL;
206                        r_cmd_fsm = CMD_IDLE;
207                    }
208                }
209                break;
210            }
211    } // end switch r_cmd_fsm
212
213    // fifo_cmd
214    if((cmd_fifo_write == true)  && (cmd_fifo_read == false)) { r_fifo_cmd.simple_put(cmd_fifo_data); }
215    if((cmd_fifo_write == true)  && (cmd_fifo_read == true))  { r_fifo_cmd.put_and_get(cmd_fifo_data); }
216    if((cmd_fifo_write == false) && (cmd_fifo_read == true))  { r_fifo_cmd.simple_get(); }
217
218    //////////////////////////////////////////////////////////////
219    // DSPIN response packet to VCI response packet
220    // The DSPIN packet is stored in the fifo_rsp
221    // The FIFO output is analysed and translated to a VCI packet
222    //////////////////////////////////////////////////////////////
223    // - A N+1 flits DSPIN read response packet is translated
224    //   to a N flits VCI response.
225    // - A single flit DSPIN write response packet is translated
226    //   to a single flit VCI response.
227    // A valid DSPIN flit in the fifo_rsp is always consumed
228    // in the CMD_IDLE state, but no VCI flit is transmitted.
229    // The VCI flits are sent in the RSP_READ & RSP_WRITE states.
230    //////////////////////////////////////////////////////////////
231
232    // rsp_fifo_write, rsp_fifo_data
233    rsp_fifo_write = p_dspin_in.write.read();
234    rsp_fifo_data  = p_dspin_in.data.read();
235
236    // r_rsp_fsm, rsp_fifo_read
237        rsp_fifo_read = false;        // default value
238
239    switch(r_rsp_fsm) {
240        case RSP_IDLE:
241            {
242        if( r_fifo_rsp.rok() )
243                {
244            rsp_fifo_read = true;
245                    r_rsp_buf = r_fifo_rsp.read();
246                    if ( (r_fifo_rsp.read() & 0x000020000LL) == 0 )  r_rsp_fsm = RSP_READ;
247                    else                              r_rsp_fsm = RSP_WRITE;
248        }
249        break;
250            }
251        case RSP_READ:
252        {
253        if( r_fifo_rsp.rok() && p_vci.rspack.read() )
254                {
255            rsp_fifo_read = true;
256                    if ( (r_fifo_rsp.read() & 0x100000000LL) ) r_rsp_fsm = RSP_IDLE;
257        }
258        break;
259            }
260            case RSP_WRITE:
261            {
262                if ( p_vci.rspack.read() ) r_rsp_fsm = RSP_IDLE;
263            }
264    } // end switch r_rsp_fsm
265
266    // fifo_rsp
267    if((rsp_fifo_write == true)  && (rsp_fifo_read == false)) { r_fifo_rsp.simple_put(rsp_fifo_data); }
268    if((rsp_fifo_write == true)  && (rsp_fifo_read == true))  { r_fifo_rsp.put_and_get(rsp_fifo_data); }
269    if((rsp_fifo_write == false) && (rsp_fifo_read == true))  { r_fifo_rsp.simple_get(); }
270
271}; // end transition
272
273//////////////////////
274tmpl(void)::genMoore()
275{
276    // VCI CMD interface
277        if ( ( r_cmd_fsm.read() == CMD_IDLE ) || ( r_cmd_fsm.read() == CMD_WRITE ) )
278        {
279            p_vci.cmdack = false;
280        }
281    else
282        {
283            p_vci.cmdack = r_fifo_cmd.wok();
284        }
285
286    // VCI RSP interface
287    if ( r_rsp_fsm.read() == RSP_IDLE )
288        {
289            p_vci.rspval = false;
290        }
291        else if ( r_rsp_fsm.read() == RSP_WRITE )
292        {
293            p_vci.rspval = true;
294            p_vci.rdata  = 0;
295            p_vci.rsrcid = (sc_uint<vci_param::S>)((r_rsp_buf.read() & 0x0FFFC0000LL) >> 18);
296            p_vci.rpktid = (sc_uint<vci_param::T>)((r_rsp_buf.read() & 0x000000F00LL) >> 8);
297            p_vci.rtrdid = (sc_uint<vci_param::P>)((r_rsp_buf.read() & 0x00000F000LL) >> 12);
298            p_vci.rerror = (sc_uint<vci_param::E>)((r_rsp_buf.read() & 0x000030000LL) >> 16);
299            p_vci.reop   = true;
300        }
301        else if ( r_rsp_fsm.read() == RSP_READ )
302        {
303            p_vci.rspval = r_fifo_rsp.rok();
304            p_vci.rdata  = (sc_uint<8*vci_param::B>)(r_fifo_rsp.read() & 0x0FFFFFFFFLL);
305            p_vci.rsrcid = (sc_uint<vci_param::S>)((r_rsp_buf.read()   & 0x0FFFC0000LL) >> 18);
306            p_vci.rpktid = (sc_uint<vci_param::T>)((r_rsp_buf.read()   & 0x000000F00LL) >> 8);
307            p_vci.rtrdid = (sc_uint<vci_param::P>)((r_rsp_buf.read()   & 0x00000F000LL) >> 12);
308            p_vci.rerror = (sc_uint<vci_param::E>)((r_rsp_buf.read()   & 0x000030000LL) >> 16);
309            p_vci.reop   = ((r_fifo_rsp.read() & 0x100000000LL) == 0x100000000LL);
310        }
311
312        // DSPIN_OUT interface
313        p_dspin_out.write = r_fifo_cmd.rok();
314        p_dspin_out.data  = r_fifo_cmd.read();
315
316        // DSPIN_IN interface
317        p_dspin_in.read   = r_fifo_rsp.wok();
318
319}; // end genMoore
320
321/////////////////////////
322tmpl(void)::print_trace()
323{
324    const char* cmd_str[] = {
325    "CMD_IDLE     ",
326    "CMD_BROADCAST",
327    "CMD_READ     ",
328    "CMD_WRITE    ",
329    "CMD_WDATA    ",
330    };
331    const char* rsp_str[] = {
332    "RSP_IDLE     ",
333    "RSP_READ     ",
334    "RSP_WRITE    ",
335    };
336
337    std::cout << name() << " : " << cmd_str[r_cmd_fsm.read()]
338                        << " | " << rsp_str[r_rsp_fsm.read()]
339                        << " | fifo_cmd = " << r_fifo_cmd.filled_status()
340                        << " | fifo_rsp = " << r_fifo_rsp.filled_status()
341                        << std::endl;
342}
343
344}} // end namespace
345
346// Local Variables:
347// tab-width: 4
348// c-basic-offset: 4
349// c-file-offsets:((innamespace . 0)(inline-open . 0))
350// indent-tabs-mode: nil
351// End:
352
353// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
Note: See TracBrowser for help on using the repository browser.