source: trunk/modules/half_gateway_initiator_2/caba/source/include/half_gateway_initiator_2.h @ 133

Last change on this file since 133 was 65, checked in by nipo, 14 years ago

Use proper namespaces

File size: 12.4 KB
Line 
1 /* SOCLIB_LGPL_HEADER_BEGIN
2 *
3 * This file is part of SoCLib, GNU LGPLv2.1.
4 *
5 * SoCLib is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation; version 2.1 of the License.
8 *
9 * SoCLib is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with SoCLib; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA
18 *
19 * SOCLIB_LGPL_HEADER_END
20 *
21 * Author   : Abdelmalek SI MERABET
22 * Date     : March 2010
23 * Copyright: UPMC - LIP6
24 */
25#ifndef SOCLIB_CABA_HALF_GATEWAY_INITIATOR_2_H
26#define SOCLIB_CABA_HALF_GATEWAY_INITIATOR_2_H
27
28#include <systemc>
29#include "caba_base_module.h"
30#include "generic_fifo.h"
31#include "mapping_table.h"
32#include "ring_signals_2.h"
33#include "gate_ports_2.h"
34
35//#define HI_DEBUG
36//#define HI_DEBUG_FSM
37
38namespace soclib { namespace caba {
39
40#ifdef HI_DEBUG_FSM
41namespace {
42
43        const char *ring_cmd_fsm_state_str_hi[] = {
44                "CMD_IDLE",
45                "DEFAULT",
46                "KEEP",
47        };
48        const char *ring_rsp_fsm_state_str_hi[] = {
49                "RSP_IDLE",
50                "LOCAL",
51                "RING",
52        };
53}
54#endif
55
56template<typename vci_param, int ring_cmd_data_size, int ring_rsp_data_size>
57class HalfGatewayInitiator2
58{
59
60typedef RingSignals2 ring_signal_t;
61typedef soclib::caba::GateInitiator2<ring_cmd_data_size, ring_rsp_data_size> gate_initiator_t;
62
63private:
64       
65        enum ring_rsp_fsm_state_e {
66                RSP_IDLE,    // waiting for first flit of a response packet
67                LOCAL,      // next flit of a local rsp packet
68                RING,       // next flit of a ring rsp packet
69            };
70       
71        // cmd token allocation fsm
72        enum ring_cmd_fsm_state_e {
73                CMD_IDLE,           
74                DEFAULT,       
75                KEEP,               
76            };
77       
78        // structural parameters
79        bool                m_alloc_init;
80        bool                m_local;
81        std::string         m_name;
82       
83        // internal registers
84        sc_core::sc_signal<int>     r_ring_cmd_fsm;    // ring command packet FSM (distributed)
85        sc_core::sc_signal<int>     r_ring_rsp_fsm;    // ring response packet FSM
86       
87           
88        // internal fifos
89        GenericFifo<uint64_t > m_cmd_fifo;     // fifo for the local command packet
90        GenericFifo<uint64_t > m_rsp_fifo;     // fifo for the local response packet
91       
92        // routing table
93        soclib::common::AddressDecodingTable<uint32_t, bool> m_lt;
94
95bool trace(int sc_time_stamp)
96{
97int time_stamp=0;
98char *ctime_stamp= getenv("FROM_CYCLE");
99
100if (ctime_stamp) time_stamp=atoi(ctime_stamp); 
101
102return sc_time_stamp >= time_stamp;
103
104}
105
106public :
107
108HalfGatewayInitiator2(
109        const char     *name,
110        bool            alloc_init,
111        const int       &wrapper_fifo_depth,
112        const soclib::common::MappingTable &mt,
113        const soclib::common::IntTab &ringid,
114        bool local)
115      : m_name(name),
116        m_alloc_init(alloc_init),
117        m_cmd_fifo("m_cmd_fifo", wrapper_fifo_depth),
118        m_rsp_fifo("m_rsp_fifo", wrapper_fifo_depth),
119        m_lt(mt.getIdLocalityTable(ringid)),
120        m_local(local),
121        r_ring_cmd_fsm("r_ring_cmd_fsm"),
122        r_ring_rsp_fsm("r_ring_rsp_fsm")
123 { } //  end constructor
124
125void reset()
126{
127        if(m_alloc_init)
128                r_ring_cmd_fsm = DEFAULT;
129        else
130                r_ring_cmd_fsm = CMD_IDLE;
131
132        r_ring_rsp_fsm = RSP_IDLE;
133        m_cmd_fifo.init();
134        m_rsp_fifo.init();
135}
136
137void transition(const gate_initiator_t &p_gate_initiator, const ring_signal_t p_ring_in)       
138{
139
140        bool      cmd_fifo_get = false;
141        bool      cmd_fifo_put = false;
142        uint64_t  cmd_fifo_data = 0;
143
144//      bool      rsp_fifo_get = false;
145        bool      rsp_fifo_put = false;
146        uint64_t  rsp_fifo_data = 0;
147
148#ifdef HI_DEBUG_FSM
149if( trace(sc_core::sc_time_stamp()))
150    std::cout << sc_core::sc_time_stamp() << " - " << m_name
151                                 << " - ring cmd  = " << ring_cmd_fsm_state_str_hi[r_ring_cmd_fsm] 
152                                 << " - ring rsp  = " << ring_rsp_fsm_state_str_hi[r_ring_rsp_fsm] 
153                                 << std::endl;
154#endif
155//////////// VCI CMD FSM /////////////////////////
156
157        if (p_gate_initiator.cmd_rok.read()) {
158                cmd_fifo_data = (uint64_t) p_gate_initiator.cmd_data.read();
159                cmd_fifo_put =  m_cmd_fifo.wok();
160        }
161
162        bool rsp_fifo_get = p_gate_initiator.rsp_wok.read();
163
164//////////// RING CMD FSM /////////////////////////
165        switch( r_ring_cmd_fsm ) 
166        {
167                case CMD_IDLE:   
168#ifdef HI_DEBUG
169if( trace(sc_core::sc_time_stamp()))
170std::cout << sc_core::sc_time_stamp() << " -- " << m_name << " -- r_ring_cmd_fsm : CMD_IDLE "
171          << " -- fifo ROK : " << m_cmd_fifo.rok()
172          << " -- in grant : " << p_ring_in.cmd_grant
173          << " -- fifo _data : " << std::hex << m_cmd_fifo.read()
174          << std::endl;
175#endif
176   
177                        if ( p_ring_in.cmd_grant && m_cmd_fifo.rok() ) 
178                        {
179// debug above is here
180                                r_ring_cmd_fsm = KEEP; 
181                        }
182                break;
183
184                case DEFAULT: 
185#ifdef HI_DEBUG
186if( trace(sc_core::sc_time_stamp()))
187std::cout << sc_core::sc_time_stamp() << " -- " << m_name << " -- r_ring_cmd_fsm : DEFAULT "
188          << " -- fifo ROK : " << m_cmd_fifo.rok()
189          << " -- in grant : " << p_ring_in.cmd_grant
190          << " -- fifo _data : " << std::hex << m_cmd_fifo.read()
191          << std::endl;
192#endif
193       
194                        if ( m_cmd_fifo.rok() ) 
195                        {
196// debug above is here
197                                cmd_fifo_get = p_ring_in.cmd_r; 
198                                r_ring_cmd_fsm = KEEP;             
199                        }   
200                        else if ( !p_ring_in.cmd_grant )
201                                r_ring_cmd_fsm = CMD_IDLE; 
202                break;
203
204                case KEEP:   
205 #ifdef HI_DEBUG
206if( trace(sc_core::sc_time_stamp()))
207std::cout << sc_core::sc_time_stamp() << " -- " << m_name << " -- r_ring_cmd_fsm : KEEP "
208          << " -- fifo_rok : " << m_cmd_fifo.rok()
209          << " -- in grant : " << p_ring_in.cmd_grant
210          << " -- ring_in_wok : " << p_ring_in.cmd_r
211          << " -- fifo_out_data : " << std::hex << m_cmd_fifo.read()
212          << std::endl;
213#endif
214                         
215                        if(m_cmd_fifo.rok() && p_ring_in.cmd_r ) 
216                        {
217// debug above is here
218                                cmd_fifo_get = true; 
219                                if (((int) (m_cmd_fifo.read() >> (ring_cmd_data_size - 1) ) & 0x1) == 1)  // 39
220                                { 
221                                        if ( p_ring_in.cmd_grant )
222                                                r_ring_cmd_fsm = DEFAULT; 
223                                        else   
224                                                r_ring_cmd_fsm = CMD_IDLE; 
225                                }       
226                        }     
227                break;
228
229        } // end switch ring cmd fsm
230 
231/////////// RING RSP FSM ////////////////////////
232   
233        switch( r_ring_rsp_fsm ) 
234        {
235                case RSP_IDLE: 
236                {
237                        int rsrcid   = (int)  ((p_ring_in.rsp_data >> 12 ) & 0x3FFF);
238                        bool islocal = (m_lt[rsrcid] && m_local) || (!m_lt[rsrcid] && !m_local);
239                        bool reop     = ((p_ring_in.rsp_data >> (ring_rsp_data_size - 1)) & 0x1) == 1;
240
241#ifdef HI_DEBUG
242if( trace(sc_core::sc_time_stamp()))
243        std::cout << sc_core::sc_time_stamp() << " -- " << m_name 
244              << " -- ring_rsp_fsm -- RSP_IDLE "
245              << " -- islocal : " << islocal
246              << " -- eop : " << reop
247              << " -- rsrcid : " << std::hex << rsrcid
248              << " -- in rok : " << p_ring_in.rsp_w
249              << " -- in wok : " << p_ring_in.rsp_r
250              << " -- fifo wok : " <<  m_rsp_fifo.wok()         
251              << std::endl;
252#endif
253                        if (p_ring_in.rsp_w  &&  !reop && islocal) 
254                        {   
255                                r_ring_rsp_fsm = LOCAL;
256                                rsp_fifo_put  = m_rsp_fifo.wok();
257                                rsp_fifo_data = p_ring_in.rsp_data;
258                        }
259                        if (p_ring_in.rsp_w  &&  !reop && !islocal) 
260                        {
261                                r_ring_rsp_fsm = RING; 
262                        }
263                        if (!p_ring_in.rsp_w  || reop ) 
264                        {                       
265                                r_ring_rsp_fsm = RSP_IDLE;
266                        } 
267                }
268                break;
269
270                case LOCAL:
271                {
272
273                        bool reop     = ((p_ring_in.rsp_data >> (ring_rsp_data_size - 1)) & 0x1) == 1;
274#ifdef HI_DEBUG
275if( trace(sc_core::sc_time_stamp()))
276         std::cout << sc_core::sc_time_stamp() << " -- " << m_name 
277              << " -- ring_rsp_fsm -- LOCAL "
278              << " -- in rok : " << p_ring_in.rsp_w
279              << " -- fifo wok : " <<  m_rsp_fifo.wok()   
280              << " -- in data : " << std::hex << p_ring_in.rsp_data
281              << " -- eop : " << reop
282              << std::endl;
283#endif
284
285
286                        if (p_ring_in.rsp_w && m_rsp_fifo.wok() && reop)         
287                        {
288
289                                rsp_fifo_put  = true;
290                                rsp_fifo_data = p_ring_in.rsp_data;
291                                r_ring_rsp_fsm = RSP_IDLE;             
292                        }
293                        if (!p_ring_in.rsp_w || !m_rsp_fifo.wok() || !reop)         
294                        {
295
296                                rsp_fifo_put  = p_ring_in.rsp_w && m_rsp_fifo.wok();
297                                rsp_fifo_data = p_ring_in.rsp_data;
298                                r_ring_rsp_fsm = LOCAL;             
299                        }
300                } 
301                break;
302
303                case RING:     
304                {
305                        bool reop     = ((p_ring_in.rsp_data >> (ring_rsp_data_size - 1)) & 0x1) == 1;
306
307#ifdef I_DEBUG
308if( trace(sc_core::sc_time_stamp()))
309         std::cout << sc_core::sc_time_stamp() << " -- " << m_name 
310              << " -- ring_rsp_fsm -- RING "
311              << " -- in rok : " << p_ring_in.rsp_w
312              << " -- in wok : " <<  p_ring_in.rsp_r   
313              << " -- in data : " << std::hex << p_ring_in.rsp_data
314              << " -- eop : " << reop   
315              << std::endl;
316#endif
317
318
319                        if (p_ring_in.rsp_w && reop)
320                        {
321                                r_ring_rsp_fsm = RSP_IDLE; 
322                        }
323                        else
324                        {
325                                r_ring_rsp_fsm = RING;
326                        }
327                }
328                break;
329
330        } // end switch rsp fsm
331     
332    ////////////////////////
333    //  fifos update      //
334   ////////////////////////
335
336// local cmd fifo update
337        if (  cmd_fifo_put &&  cmd_fifo_get ) m_cmd_fifo.put_and_get(cmd_fifo_data);
338        else if (  cmd_fifo_put && !cmd_fifo_get ) m_cmd_fifo.simple_put(cmd_fifo_data);
339        else if ( !cmd_fifo_put &&  cmd_fifo_get ) m_cmd_fifo.simple_get();
340       
341// local rsp fifo update
342        if (  rsp_fifo_put &&  rsp_fifo_get ) m_rsp_fifo.put_and_get(rsp_fifo_data);
343        else if (  rsp_fifo_put && !rsp_fifo_get ) m_rsp_fifo.simple_put(rsp_fifo_data);
344        else if ( !rsp_fifo_put &&  rsp_fifo_get ) m_rsp_fifo.simple_get();
345     
346}  // end Transition()
347
348///////////////////////////////////////////////////////////////////
349void genMoore(gate_initiator_t &p_gate_initiator)
350///////////////////////////////////////////////////////////////////
351{
352        p_gate_initiator.rsp_w    = m_rsp_fifo.rok();
353        p_gate_initiator.rsp_data = (sc_dt::sc_uint<ring_rsp_data_size>) m_rsp_fifo.read();
354
355        p_gate_initiator.cmd_r= m_cmd_fifo.wok();
356
357} // end genMoore
358
359///////////////////////////////////////////////////////////////////
360void update_ring_signals(ring_signal_t p_ring_in, ring_signal_t &p_ring_out)
361///////////////////////////////////////////////////////////////////
362{   
363        switch( r_ring_cmd_fsm ) 
364        {
365                case CMD_IDLE:
366                        p_ring_out.cmd_grant = p_ring_in.cmd_grant && !m_cmd_fifo.rok();
367
368                        p_ring_out.cmd_r     = p_ring_in.cmd_r;
369
370                        p_ring_out.cmd_w     = p_ring_in.cmd_w;
371                        p_ring_out.cmd_data  = p_ring_in.cmd_data;
372                break;
373       
374                case DEFAULT:       
375                        p_ring_out.cmd_grant = !( m_cmd_fifo.rok()); 
376
377                        p_ring_out.cmd_r    = 1;
378
379                        p_ring_out.cmd_w    =  m_cmd_fifo.rok();
380                        p_ring_out.cmd_data =  m_cmd_fifo.read();
381                break;
382       
383                case KEEP: 
384                        int cmd_fifo_eop = (int) ((m_cmd_fifo.read() >> (ring_cmd_data_size - 1)) & 0x1) ; //39
385                        p_ring_out.cmd_grant = m_cmd_fifo.rok() && p_ring_in.cmd_r && (cmd_fifo_eop == 1);
386
387                        p_ring_out.cmd_r    = 1;       
388
389                        p_ring_out.cmd_w    =  m_cmd_fifo.rok();
390                        p_ring_out.cmd_data =  m_cmd_fifo.read();
391                break;
392       
393        } // end switch
394
395        p_ring_out.rsp_grant = p_ring_in.rsp_grant;
396
397        p_ring_out.rsp_w    = p_ring_in.rsp_w;
398        p_ring_out.rsp_data = p_ring_in.rsp_data;
399
400        switch( r_ring_rsp_fsm ) 
401        {
402                case RSP_IDLE: 
403                {
404                        int rsrcid   = (int)  ((p_ring_in.rsp_data >> 12 ) & 0x3FFF);
405                        bool islocal = (m_lt[rsrcid] && m_local) || (!m_lt[rsrcid] && !m_local);
406                        bool reop    = ((p_ring_in.rsp_data >> (ring_rsp_data_size - 1)) & 0x1) == 1;
407
408                        if(p_ring_in.rsp_w && !reop && islocal) {
409                                p_ring_out.rsp_r = m_rsp_fifo.wok();
410                        }
411                        if(p_ring_in.rsp_w && !reop && !islocal) {
412                                p_ring_out.rsp_r = p_ring_in.rsp_r;
413                        }
414                        if(!p_ring_in.rsp_w || reop)  {
415                                p_ring_out.rsp_r = p_ring_in.rsp_r;
416                        }
417 
418                }
419                break;
420       
421                case LOCAL:
422                        p_ring_out.rsp_r = m_rsp_fifo.wok();
423                break;
424       
425                case RING:
426                        p_ring_out.rsp_r = p_ring_in.rsp_r;
427                break;   
428        } // end switch
429
430
431} // end update_ring_signals
432
433};
434
435}} // end namespace
436
437#endif // SOCLIB_CABA_HALF_GATEWAY_INITIATOR_2_H
438
Note: See TracBrowser for help on using the repository browser.