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