[8] | 1 | /* -*- c++ -*- |
---|
| 2 | * SOCLIB_LGPL_HEADER_BEGIN |
---|
| 3 | * |
---|
| 4 | * This file is part of SoCLib, GNU LGPLv2.1. |
---|
| 5 | * |
---|
| 6 | * SoCLib is free software; you can redistribute it and/or modify it |
---|
| 7 | * under the terms of the GNU Lesser General Public License as published |
---|
| 8 | * by the Free Software Foundation; version 2.1 of the License. |
---|
| 9 | * |
---|
| 10 | * SoCLib is distributed in the hope that it will be useful, but |
---|
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 13 | * Lesser General Public License for more details. |
---|
| 14 | * |
---|
| 15 | * You should have received a copy of the GNU Lesser General Public |
---|
| 16 | * License along with SoCLib; if not, write to the Free Software |
---|
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
---|
| 18 | * 02110-1301 USA |
---|
| 19 | * |
---|
| 20 | * SOCLIB_LGPL_HEADER_END |
---|
| 21 | * |
---|
| 22 | * Author : Abdelmalek SI MERABET |
---|
| 23 | * Date : March 2010 |
---|
| 24 | * |
---|
| 25 | * Copyright: UPMC - LIP6 |
---|
| 26 | */ |
---|
| 27 | #include "vci_initiator.h" |
---|
| 28 | #include "generic_fifo.h" |
---|
| 29 | #include "mapping_table.h" |
---|
| 30 | #include "ring_signals_2.h" |
---|
| 31 | |
---|
| 32 | //#define T_DEBUG |
---|
| 33 | //#define TR_DEBUG |
---|
| 34 | //#define T_DEBUG_FSM |
---|
| 35 | |
---|
| 36 | namespace soclib { namespace caba { |
---|
| 37 | #ifdef T_DEBUG_FSM |
---|
| 38 | namespace { |
---|
| 39 | const char *vci_cmd_fsm_state_str_t[] = { |
---|
| 40 | "CMD_FIRST_HEADER", |
---|
| 41 | "CMD_SECOND_HEADER", |
---|
| 42 | "WDATA", |
---|
| 43 | }; |
---|
| 44 | const char *vci_rsp_fsm_state_str_t[] = { |
---|
| 45 | "RSP_HEADER", |
---|
| 46 | "RSP_DATA", |
---|
| 47 | }; |
---|
| 48 | const char *ring_rsp_fsm_state_str_t[] = { |
---|
| 49 | "RSP_IDLE", |
---|
| 50 | "DEFAULT", |
---|
| 51 | "KEEP", |
---|
| 52 | }; |
---|
| 53 | const char *ring_cmd_fsm_state_str_t[] = { |
---|
| 54 | "CMD_IDLE", |
---|
| 55 | "BROADCAST_0", |
---|
| 56 | "BROADCAST_1", |
---|
| 57 | "LOCAL", |
---|
| 58 | "RING", |
---|
| 59 | }; |
---|
| 60 | } |
---|
| 61 | #endif |
---|
| 62 | |
---|
| 63 | template<typename vci_param, int ring_cmd_data_size, int ring_rsp_data_size> |
---|
| 64 | class VciRingTarget |
---|
| 65 | { |
---|
| 66 | |
---|
| 67 | typedef typename vci_param::fast_addr_t vci_addr_t; |
---|
| 68 | typedef RingSignals2 ring_signal_t; |
---|
| 69 | typedef soclib::caba::VciInitiator<vci_param> vci_initiator_t; |
---|
| 70 | |
---|
| 71 | private: |
---|
| 72 | enum vci_cmd_fsm_state_e { |
---|
| 73 | CMD_FIRST_HEADER, // first flit for a ring cmd packet (read or write) |
---|
| 74 | CMD_SECOND_HEADER, // second flit for a ring cmd packet |
---|
| 75 | WDATA, // data flit for a ring cmd write packet |
---|
| 76 | }; |
---|
| 77 | |
---|
| 78 | enum vci_rsp_fsm_state_e { |
---|
| 79 | RSP_HEADER, // first flit for a ring rsp packet (read or write) |
---|
| 80 | DATA, // next flit for a ring rsp packet |
---|
| 81 | }; |
---|
| 82 | |
---|
| 83 | enum ring_cmd_fsm_state_e { |
---|
| 84 | CMD_IDLE, // waiting for first flit of a command packet |
---|
| 85 | BROADCAST_0, |
---|
| 86 | BROADCAST_1, |
---|
| 87 | LOCAL, // next flit of a local cmd packet |
---|
| 88 | RING, // next flit of a ring cmd packet |
---|
| 89 | }; |
---|
| 90 | |
---|
| 91 | // cmd token allocation fsm |
---|
| 92 | enum ring_rsp_fsm_state_e { |
---|
| 93 | RSP_IDLE, |
---|
| 94 | DEFAULT, |
---|
| 95 | KEEP, |
---|
| 96 | }; |
---|
| 97 | |
---|
| 98 | // structural parameters |
---|
| 99 | bool m_alloc_target; |
---|
| 100 | int m_tgtid; |
---|
| 101 | std::string m_name; |
---|
| 102 | |
---|
| 103 | // internal registers |
---|
| 104 | sc_signal<int> r_ring_cmd_fsm; // ring command packet FSM |
---|
| 105 | sc_signal<int> r_ring_rsp_fsm; // ring response packet FSM |
---|
| 106 | sc_signal<int> r_vci_cmd_fsm; // vci command packet FSM |
---|
| 107 | sc_signal<int> r_vci_rsp_fsm; // vci response packet FSM |
---|
| 108 | |
---|
| 109 | sc_signal<sc_uint<vci_param::S> > r_srcid; |
---|
| 110 | sc_signal<sc_uint<2> > r_cmd; |
---|
| 111 | sc_signal<sc_uint<vci_param::T> > r_trdid; |
---|
| 112 | sc_signal<sc_uint<vci_param::P> > r_pktid; |
---|
| 113 | sc_signal<sc_uint<vci_param::K> > r_plen; |
---|
| 114 | sc_signal<sc_uint<1> > r_contig; |
---|
| 115 | sc_signal<sc_uint<1> > r_const; |
---|
| 116 | sc_signal<sc_uint<vci_param::N> > r_addr; |
---|
| 117 | |
---|
| 118 | // internal fifos |
---|
| 119 | GenericFifo<uint64_t > m_cmd_fifo; // fifo for the local command paquet |
---|
| 120 | GenericFifo<uint64_t > m_rsp_fifo; // fifo for the local response paquet |
---|
| 121 | |
---|
| 122 | // routing table |
---|
| 123 | soclib::common::AddressDecodingTable<vci_addr_t, int> m_rt; |
---|
| 124 | // locality table |
---|
| 125 | soclib::common::AddressDecodingTable<vci_addr_t, bool> m_lt; |
---|
| 126 | |
---|
| 127 | bool trace(int sc_time_stamp) |
---|
| 128 | { |
---|
| 129 | int time_stamp=0; |
---|
| 130 | char *ctime_stamp= getenv("FROM_CYCLE"); |
---|
| 131 | |
---|
| 132 | if (ctime_stamp) time_stamp=atoi(ctime_stamp); |
---|
| 133 | |
---|
| 134 | return sc_time_stamp >= time_stamp; |
---|
| 135 | |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | public : |
---|
| 139 | |
---|
| 140 | VciRingTarget( |
---|
| 141 | const char *name, |
---|
| 142 | bool alloc_target, |
---|
| 143 | const int &wrapper_fifo_depth, |
---|
| 144 | const soclib::common::MappingTable &mt, |
---|
| 145 | const soclib::common::IntTab &ringid, |
---|
| 146 | const int &tgtid) |
---|
| 147 | : m_name(name), |
---|
| 148 | m_alloc_target(alloc_target), |
---|
| 149 | m_cmd_fifo("m_cmd_fifo", wrapper_fifo_depth), |
---|
| 150 | m_rsp_fifo("m_rsp_fifo", wrapper_fifo_depth), |
---|
| 151 | m_rt(mt.getRoutingTable<typename vci_param::fast_addr_t>(ringid)), |
---|
| 152 | m_lt(mt.getLocalityTable<typename vci_param::fast_addr_t>(ringid)), |
---|
| 153 | m_tgtid(tgtid), |
---|
| 154 | r_ring_cmd_fsm("r_ring_cmd_fsm"), |
---|
| 155 | r_ring_rsp_fsm("r_ring_rsp_fsm"), |
---|
| 156 | r_vci_cmd_fsm("r_vci_cmd_fsm"), |
---|
| 157 | r_vci_rsp_fsm("r_vci_rsp_fsm"), |
---|
| 158 | r_srcid("r_srcid"), |
---|
| 159 | r_cmd("r_cmd"), |
---|
| 160 | r_trdid("r_trdid"), |
---|
| 161 | r_pktid("r_pktid"), |
---|
| 162 | r_plen("r_plen"), |
---|
| 163 | r_contig("r_contig"), |
---|
| 164 | r_const("r_const"), |
---|
| 165 | r_addr("r_addr") |
---|
| 166 | |
---|
| 167 | {} // end constructor |
---|
| 168 | |
---|
| 169 | void reset() |
---|
| 170 | { |
---|
| 171 | if(m_alloc_target) |
---|
| 172 | r_ring_rsp_fsm = DEFAULT; |
---|
| 173 | else |
---|
| 174 | r_ring_rsp_fsm = RSP_IDLE; |
---|
| 175 | |
---|
| 176 | r_vci_cmd_fsm = CMD_FIRST_HEADER; |
---|
| 177 | r_vci_rsp_fsm = RSP_HEADER; |
---|
| 178 | r_ring_cmd_fsm = CMD_IDLE; |
---|
| 179 | m_cmd_fifo.init(); |
---|
| 180 | m_rsp_fifo.init(); |
---|
| 181 | } |
---|
| 182 | void transition(const vci_initiator_t &p_vci, const ring_signal_t p_ring_in) |
---|
| 183 | { |
---|
| 184 | |
---|
| 185 | bool cmd_fifo_get = false; |
---|
| 186 | bool cmd_fifo_put = false; |
---|
| 187 | uint64_t cmd_fifo_data = 0; |
---|
| 188 | |
---|
| 189 | bool rsp_fifo_get = false; |
---|
| 190 | bool rsp_fifo_put = false; |
---|
| 191 | uint64_t rsp_fifo_data = 0; |
---|
| 192 | |
---|
| 193 | #ifdef T_DEBUG_FSM |
---|
| 194 | std::cout << "--------------------------------------------" << std::endl; |
---|
| 195 | std::cout << " vci cmd fsm = " << vci_cmd_fsm_state_str_t[r_vci_cmd_fsm] << std::endl |
---|
| 196 | << " vci rsp fsm = " << vci_rsp_fsm_state_str_t[r_vci_rsp_fsm] << std::endl |
---|
| 197 | << " ring cmd fsm = " << ring_cmd_fsm_state_str_t[r_ring_cmd_fsm] << std::endl |
---|
| 198 | << " ring rsp fsm = " << ring_rsp_fsm_state_str_t[r_ring_rsp_fsm] << std::endl; |
---|
| 199 | #endif |
---|
| 200 | |
---|
| 201 | //////////// VCI CMD FSM ///////////////////////// |
---|
| 202 | switch ( r_vci_cmd_fsm ) |
---|
| 203 | { |
---|
| 204 | |
---|
| 205 | case CMD_FIRST_HEADER: |
---|
| 206 | if (m_cmd_fifo.rok() == true) |
---|
| 207 | { |
---|
| 208 | #ifdef T_DEBUG |
---|
| 209 | if( trace(sc_time_stamp())) |
---|
| 210 | std::cout << sc_time_stamp() << " -- " << m_name |
---|
| 211 | << " -- r_vci_cmd_fsm -- CMD_FIRST_HEADER " |
---|
| 212 | << " -- fifo_rok : " << m_cmd_fifo.rok() |
---|
| 213 | << " -- fifo_data : " << std::hex << m_cmd_fifo.read() |
---|
| 214 | << std::endl; |
---|
| 215 | #endif |
---|
| 216 | |
---|
| 217 | cmd_fifo_get = true; |
---|
| 218 | |
---|
| 219 | if (m_cmd_fifo.read() & 0x1 == 0x1) // broadcast |
---|
| 220 | { |
---|
| 221 | #ifdef I_DEBUG |
---|
| 222 | std::cout << sc_time_stamp() << " -- " << m_name << " -- broadcast " << std::endl; |
---|
| 223 | #endif |
---|
| 224 | r_addr = (sc_uint<vci_param::N>) 0x3; |
---|
[10] | 225 | r_srcid = (sc_uint<vci_param::S>) (m_cmd_fifo.read() >> 21); |
---|
[8] | 226 | r_cmd = (sc_uint<2>) 0x2; |
---|
| 227 | r_contig = (sc_uint<1>) 0x1; |
---|
| 228 | r_const = (sc_uint<1>) 0x0; |
---|
| 229 | r_plen = (sc_uint<vci_param::K>) 0x04; |
---|
| 230 | r_pktid = (sc_uint<vci_param::P>) 0x0; |
---|
[10] | 231 | r_trdid = (sc_uint<vci_param::T>) ((m_cmd_fifo.read() >> 17) & 0xF); |
---|
[8] | 232 | |
---|
| 233 | r_vci_cmd_fsm = WDATA; |
---|
| 234 | } |
---|
| 235 | else |
---|
| 236 | { |
---|
| 237 | r_addr = (sc_uint<vci_param::N>) (m_cmd_fifo.read() << 1); |
---|
| 238 | r_vci_cmd_fsm = CMD_SECOND_HEADER; |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | |
---|
| 242 | } // end if rok |
---|
| 243 | break; |
---|
| 244 | |
---|
| 245 | case CMD_SECOND_HEADER: |
---|
| 246 | if ( m_cmd_fifo.rok() ) |
---|
| 247 | { |
---|
| 248 | |
---|
| 249 | #ifdef T_DEBUG |
---|
| 250 | if( trace(sc_time_stamp())) |
---|
| 251 | std::cout << sc_time_stamp() << " -- " << m_name |
---|
| 252 | << " -- r_vci_cmd_fsm -- CMD_SECOND_HEADER " |
---|
| 253 | << " -- r_addr : " << std::hex << r_addr |
---|
| 254 | << " -- fifo_rok : " << m_cmd_fifo.rok() |
---|
| 255 | << " -- fifo_data : " << m_cmd_fifo.read() |
---|
| 256 | << " -- vci cmdack : " << p_vci.cmdack.read() |
---|
| 257 | << std::endl; |
---|
| 258 | #endif |
---|
| 259 | if(((int) (m_cmd_fifo.read() >> (ring_cmd_data_size - 1) ) & 0x1) == 1) // read command |
---|
| 260 | { |
---|
| 261 | |
---|
| 262 | if (p_vci.cmdack.read()) |
---|
| 263 | { |
---|
| 264 | |
---|
| 265 | cmd_fifo_get = true; |
---|
| 266 | r_vci_cmd_fsm = CMD_FIRST_HEADER; |
---|
| 267 | } |
---|
| 268 | } |
---|
| 269 | else // write command |
---|
| 270 | { |
---|
| 271 | #ifdef T_DEBUG |
---|
| 272 | if( trace(sc_time_stamp())) |
---|
| 273 | std::cout << sc_time_stamp() << " -- " << m_name |
---|
| 274 | << " -- r_vci_cmd_fsm -- CMD_SECOND_HEADER & !EOP (WRITE)" |
---|
| 275 | << std::endl; |
---|
| 276 | #endif |
---|
| 277 | cmd_fifo_get = true; |
---|
| 278 | r_srcid = (sc_uint<vci_param::S>) (m_cmd_fifo.read() >> 20) ; |
---|
| 279 | r_cmd = (sc_uint<2>) ((m_cmd_fifo.read() >> 18) & 0x3); |
---|
| 280 | r_contig = (sc_uint<1>) ((m_cmd_fifo.read() >> 17) & 0x1); |
---|
| 281 | r_const = (sc_uint<1>) ((m_cmd_fifo.read() >> 16) & 0x1); |
---|
| 282 | r_plen = (sc_uint<vci_param::K>) ((m_cmd_fifo.read() >> 8) & 0xFF); |
---|
| 283 | r_pktid = (sc_uint<vci_param::P>) ((m_cmd_fifo.read() >> 4) & 0xF); |
---|
| 284 | r_trdid = (sc_uint<vci_param::T>) (m_cmd_fifo.read() & 0xF); |
---|
| 285 | r_vci_cmd_fsm = WDATA; |
---|
| 286 | } |
---|
| 287 | } |
---|
| 288 | break; |
---|
| 289 | |
---|
| 290 | case WDATA: |
---|
| 291 | #ifdef T_DEBUG |
---|
| 292 | if( trace(sc_time_stamp())) |
---|
| 293 | std::cout << sc_time_stamp() << " -- " << m_name |
---|
| 294 | << " -- r_vci_cmd_fsm -- WDATA " |
---|
| 295 | << " -- vci_cmdack : " << p_vci.cmdack.read() |
---|
| 296 | << " -- fifo_rok : " << m_cmd_fifo.rok() |
---|
| 297 | << " -- fifo_data : " << std::hex << m_cmd_fifo.read() |
---|
| 298 | << " -- r_plen : " << r_plen.read() |
---|
| 299 | << std::endl; |
---|
| 300 | #endif |
---|
| 301 | if ( p_vci.cmdack.read() && m_cmd_fifo.rok() ) |
---|
| 302 | { |
---|
| 303 | |
---|
| 304 | cmd_fifo_get = true; |
---|
| 305 | sc_uint<1> contig = r_contig; |
---|
| 306 | if(contig == 0x1) |
---|
| 307 | r_addr = r_addr.read() + vci_param::B ; |
---|
| 308 | if(( (m_cmd_fifo.read() >> (ring_cmd_data_size - 1) ) & 0x1) == 1) |
---|
| 309 | r_vci_cmd_fsm = CMD_FIRST_HEADER; |
---|
| 310 | else |
---|
| 311 | r_vci_cmd_fsm = WDATA; |
---|
| 312 | } // end if cmdack |
---|
| 313 | break; |
---|
| 314 | |
---|
| 315 | } // end switch r_vci_cmd_fsm |
---|
| 316 | |
---|
| 317 | /////////// VCI RSP FSM ///////////////////////// |
---|
| 318 | switch ( r_vci_rsp_fsm ) |
---|
| 319 | { |
---|
| 320 | case RSP_HEADER: |
---|
| 321 | |
---|
| 322 | if((p_vci.rspval.read() == true) && (m_rsp_fifo.wok())) |
---|
| 323 | { |
---|
| 324 | #ifdef T_DEBUG |
---|
| 325 | if( trace(sc_time_stamp())) |
---|
| 326 | std::cout << sc_time_stamp() << " -- " << m_name |
---|
| 327 | << " -- r_vci_rsp_fsm -- RSP_HEADER " |
---|
| 328 | << " -- fifo_rsp_wok : " << m_rsp_fifo.wok() |
---|
| 329 | << " -- vci_rspval : " << p_vci.rspval.read() |
---|
| 330 | << " -- rsrcid : " << std::hex << p_vci.rsrcid.read() |
---|
| 331 | << " -- rerror : " << p_vci.rerror.read() |
---|
| 332 | << std::endl; |
---|
| 333 | #endif |
---|
| 334 | rsp_fifo_data = (((uint64_t) p_vci.rsrcid.read() & 0x3FFF) << 12) | |
---|
| 335 | (((uint64_t) p_vci.rerror.read() & 0x1) << 8) | |
---|
| 336 | (((uint64_t) p_vci.rpktid.read() & 0xF) << 4) | |
---|
| 337 | ((uint64_t) p_vci.rtrdid.read() & 0xF); |
---|
| 338 | rsp_fifo_put = true; |
---|
| 339 | r_vci_rsp_fsm = DATA; |
---|
| 340 | } |
---|
| 341 | break; |
---|
| 342 | |
---|
| 343 | case DATA: |
---|
| 344 | |
---|
| 345 | if((p_vci.rspval.read() == true) && (m_rsp_fifo.wok())) |
---|
| 346 | { |
---|
| 347 | #ifdef T_DEBUG |
---|
| 348 | if( trace(sc_time_stamp())) |
---|
| 349 | std::cout << sc_time_stamp() << " -- " << m_name |
---|
| 350 | << " -- r_vci_rsp_fsm -- RSP_DATA " |
---|
| 351 | << " -- fifo_rsp_wok : " << m_rsp_fifo.wok() |
---|
| 352 | << " -- vci_rspval : " << p_vci.rspval.read() |
---|
| 353 | << " -- rdata : " << std::hex << p_vci.rdata.read() |
---|
| 354 | << " -- reop : " << p_vci.reop.read() |
---|
| 355 | << std::endl; |
---|
| 356 | #endif |
---|
| 357 | |
---|
| 358 | rsp_fifo_put = true; |
---|
| 359 | rsp_fifo_data = (uint64_t) p_vci.rdata.read(); |
---|
| 360 | |
---|
| 361 | if (p_vci.reop.read()) |
---|
| 362 | { |
---|
| 363 | rsp_fifo_data = rsp_fifo_data | (((uint64_t) 0x1) << (ring_rsp_data_size-1)) ; |
---|
| 364 | r_vci_rsp_fsm = RSP_HEADER; |
---|
| 365 | } |
---|
| 366 | } |
---|
| 367 | break; |
---|
| 368 | |
---|
| 369 | } // end switch r_vci_rsp_fsm |
---|
| 370 | |
---|
| 371 | //////////// RING RSP FSM (distributed) ///////////////////////// |
---|
| 372 | |
---|
| 373 | switch( r_ring_rsp_fsm ) |
---|
| 374 | { |
---|
| 375 | case RSP_IDLE: |
---|
| 376 | #ifdef TR_DEBUG |
---|
| 377 | if( trace(sc_time_stamp())) |
---|
| 378 | std::cout << sc_time_stamp() << " -- " << m_name << " -- ring_rsp_fsm : RSP_IDLE" |
---|
| 379 | << " -- fifo rok : " << m_rsp_fifo.rok() |
---|
| 380 | << " -- in rok : " << p_ring_in.rsp_w |
---|
| 381 | << " -- in wok : " << p_ring_in.rsp_r |
---|
| 382 | << " -- in rsp grant : " << p_ring_in.rsp_grant |
---|
| 383 | << " -- in rsp data : " << p_ring_in.rsp_data |
---|
| 384 | << std::endl; |
---|
| 385 | #endif |
---|
| 386 | if ( p_ring_in.rsp_grant && m_rsp_fifo.rok() ) |
---|
| 387 | |
---|
| 388 | r_ring_rsp_fsm = KEEP; |
---|
| 389 | |
---|
| 390 | break; |
---|
| 391 | |
---|
| 392 | case DEFAULT: |
---|
| 393 | |
---|
| 394 | if ( m_rsp_fifo.rok()) |
---|
| 395 | { |
---|
| 396 | #ifdef TR_DEBUG |
---|
| 397 | if( trace(sc_time_stamp())) |
---|
| 398 | std::cout << sc_time_stamp() << " -- " << m_name << " -- ring_rsp_fsm : DEFAULT " |
---|
| 399 | << " -- fifo data : " << std::hex << m_rsp_fifo.read() |
---|
| 400 | << std::endl; |
---|
| 401 | #endif |
---|
| 402 | rsp_fifo_get = p_ring_in.rsp_r; //true; |
---|
| 403 | r_ring_rsp_fsm = KEEP; |
---|
| 404 | } |
---|
| 405 | else if ( !p_ring_in.rsp_grant ) |
---|
| 406 | r_ring_rsp_fsm = RSP_IDLE; |
---|
| 407 | break; |
---|
| 408 | |
---|
| 409 | case KEEP: |
---|
| 410 | |
---|
| 411 | if(m_rsp_fifo.rok() && p_ring_in.rsp_r) |
---|
| 412 | { |
---|
| 413 | #ifdef TR_DEBUG |
---|
| 414 | if( trace(sc_time_stamp())) |
---|
| 415 | std::cout << sc_time_stamp() << " -- " << m_name << " -- ring_rsp_fsm : KEEP " |
---|
| 416 | << " -- fifo rok : " << m_rsp_fifo.rok() |
---|
| 417 | << " -- in wok : " << p_ring_in.rsp_r |
---|
| 418 | << " -- fifo data : " << std::hex << m_rsp_fifo.read() |
---|
| 419 | << std::endl; |
---|
| 420 | #endif |
---|
| 421 | rsp_fifo_get = true; |
---|
| 422 | if ((int) ((m_rsp_fifo.read() >> 32 ) & 0x1) == 1) |
---|
| 423 | { |
---|
| 424 | if ( p_ring_in.rsp_grant ) |
---|
| 425 | r_ring_rsp_fsm = DEFAULT; |
---|
| 426 | else |
---|
| 427 | r_ring_rsp_fsm = RSP_IDLE; |
---|
| 428 | } |
---|
| 429 | } |
---|
| 430 | break; |
---|
| 431 | |
---|
| 432 | } // end switch ring cmd fsm |
---|
| 433 | |
---|
| 434 | /////////// RING CMD FSM //////////////////////// |
---|
| 435 | switch( r_ring_cmd_fsm ) |
---|
| 436 | { |
---|
| 437 | |
---|
| 438 | case CMD_IDLE: |
---|
| 439 | { // for variable scope |
---|
| 440 | |
---|
| 441 | vci_addr_t rtgtid = (vci_addr_t) ((p_ring_in.cmd_data >> 1) << 2); |
---|
| 442 | bool islocal = m_lt[rtgtid] && (m_rt[rtgtid] == (vci_addr_t) m_tgtid); |
---|
| 443 | bool brdcst = (p_ring_in.cmd_data & 0x1) == 0X1 ; |
---|
| 444 | bool eop = ( (int) ((p_ring_in.cmd_data >> (ring_cmd_data_size - 1) ) & 0x1) == 1); |
---|
| 445 | |
---|
| 446 | #ifdef TR_DEBUG |
---|
| 447 | if( trace(sc_time_stamp())) |
---|
| 448 | std::cout << sc_time_stamp() << " -- " << m_name |
---|
| 449 | << " - ring_cmd_fsm -- CMD_IDLE " |
---|
| 450 | << " - in rok : " << p_ring_in.cmd_w |
---|
| 451 | << " - isloc : " << islocal |
---|
| 452 | << " - addr : " << std::hex << rtgtid |
---|
| 453 | << " - brdcst : " << brdcst |
---|
| 454 | << " - in wok : " << p_ring_in.cmd_r |
---|
| 455 | << " - fifo wok : " << m_cmd_fifo.wok() |
---|
| 456 | << " - eop : " << eop |
---|
| 457 | << std::endl; |
---|
| 458 | #endif |
---|
| 459 | if(p_ring_in.cmd_w && !eop && brdcst && !m_cmd_fifo.wok()) { |
---|
| 460 | r_ring_cmd_fsm = BROADCAST_0; |
---|
| 461 | } |
---|
| 462 | |
---|
| 463 | if(p_ring_in.cmd_w && !eop && brdcst && m_cmd_fifo.wok()) { |
---|
| 464 | r_ring_cmd_fsm = BROADCAST_1; |
---|
| 465 | cmd_fifo_put = true; |
---|
| 466 | cmd_fifo_data = p_ring_in.cmd_data; |
---|
| 467 | |
---|
| 468 | } |
---|
| 469 | |
---|
| 470 | if (p_ring_in.cmd_w && !eop && !brdcst && islocal) { |
---|
| 471 | r_ring_cmd_fsm = LOCAL; |
---|
| 472 | cmd_fifo_put = m_cmd_fifo.wok(); |
---|
| 473 | cmd_fifo_data = p_ring_in.cmd_data; |
---|
| 474 | |
---|
| 475 | } |
---|
| 476 | |
---|
| 477 | if (p_ring_in.cmd_w && !eop && !brdcst && !islocal) { |
---|
| 478 | r_ring_cmd_fsm = RING; |
---|
| 479 | } |
---|
| 480 | |
---|
| 481 | if (!p_ring_in.cmd_w || eop) { |
---|
| 482 | r_ring_cmd_fsm = CMD_IDLE; |
---|
| 483 | } |
---|
| 484 | |
---|
| 485 | } |
---|
| 486 | |
---|
| 487 | break; |
---|
| 488 | |
---|
| 489 | case BROADCAST_0: |
---|
| 490 | |
---|
| 491 | #ifdef TR_DEBUG |
---|
| 492 | if( trace(sc_time_stamp())) |
---|
| 493 | std::cout << sc_time_stamp() << " -- " << m_name |
---|
| 494 | << " -- ring_cmd_fsm -- BROADCAST_0 " |
---|
| 495 | << " -- ringin cmd rok : " << p_ring_in.cmd_w |
---|
| 496 | << " -- ringin cmd wok : " << p_ring_in.cmd_r |
---|
| 497 | << " -- ringin data : " << std::hex << p_ring_in.cmd_data |
---|
| 498 | << " -- fifo cmd wok : " << m_cmd_fifo.wok() |
---|
| 499 | << std::endl; |
---|
| 500 | #endif |
---|
| 501 | if ( m_cmd_fifo.wok() ) |
---|
| 502 | { |
---|
| 503 | cmd_fifo_data = p_ring_in.cmd_data; |
---|
| 504 | r_ring_cmd_fsm = BROADCAST_1; |
---|
| 505 | |
---|
| 506 | } else { |
---|
| 507 | r_ring_cmd_fsm = BROADCAST_0; |
---|
| 508 | } |
---|
| 509 | |
---|
| 510 | break; |
---|
| 511 | |
---|
| 512 | case BROADCAST_1: |
---|
| 513 | { |
---|
| 514 | #ifdef TR_DEBUG |
---|
| 515 | if( trace(sc_time_stamp())) |
---|
| 516 | std::cout << sc_time_stamp() << " -- " << m_name |
---|
| 517 | << " -- ring_cmd_fsm -- BROADCAST_1 " |
---|
| 518 | << " -- ringin cmd rok : " << p_ring_in.cmd_w |
---|
| 519 | << " -- ringin cmd wok : " << p_ring_in.cmd_r |
---|
| 520 | << " -- ringin data : " << std::hex << p_ring_in.cmd_data |
---|
| 521 | << " -- fifo cmd wok : " << m_cmd_fifo.wok() |
---|
| 522 | << std::endl; |
---|
| 523 | #endif |
---|
| 524 | |
---|
| 525 | bool eop = ( (int) ((p_ring_in.cmd_data >> (ring_cmd_data_size - 1) ) & 0x1) == 1); |
---|
| 526 | |
---|
| 527 | if ( p_ring_in.cmd_w && m_cmd_fifo.wok() && eop ) |
---|
| 528 | { |
---|
| 529 | cmd_fifo_data = p_ring_in.cmd_data; |
---|
| 530 | cmd_fifo_put = 1; |
---|
| 531 | r_ring_cmd_fsm = CMD_IDLE; |
---|
| 532 | |
---|
| 533 | } |
---|
| 534 | else { |
---|
| 535 | r_ring_cmd_fsm = BROADCAST_1; |
---|
| 536 | } |
---|
| 537 | |
---|
| 538 | } |
---|
| 539 | break; |
---|
| 540 | |
---|
| 541 | case LOCAL: |
---|
| 542 | { |
---|
| 543 | |
---|
| 544 | bool eop = ( (int) ((p_ring_in.cmd_data >> (ring_cmd_data_size - 1) ) & 0x1) == 1); |
---|
| 545 | #ifdef TR_DEBUG |
---|
| 546 | if( trace(sc_time_stamp())) |
---|
| 547 | std::cout << sc_time_stamp() << " -- " << m_name |
---|
| 548 | << " -- ring_cmd_fsm -- LOCAL " |
---|
| 549 | << " -- in cmd rok : " << p_ring_in.cmd_w |
---|
| 550 | << " -- in cmd wok : " << p_ring_in.cmd_r |
---|
| 551 | << " -- in data : " << std::hex << p_ring_in.cmd_data |
---|
| 552 | << " -- fifo wok : " << m_cmd_fifo.wok() |
---|
| 553 | << " -- eop : " << eop |
---|
| 554 | << std::endl; |
---|
| 555 | #endif |
---|
| 556 | |
---|
| 557 | if ( p_ring_in.cmd_w && m_cmd_fifo.wok() && eop ) |
---|
| 558 | { |
---|
| 559 | |
---|
| 560 | cmd_fifo_put = true; |
---|
| 561 | cmd_fifo_data = p_ring_in.cmd_data; |
---|
| 562 | r_ring_cmd_fsm = CMD_IDLE; |
---|
| 563 | |
---|
| 564 | } |
---|
| 565 | |
---|
| 566 | if ( !p_ring_in.cmd_w || !m_cmd_fifo.wok() || !eop ) |
---|
| 567 | { |
---|
| 568 | |
---|
| 569 | cmd_fifo_put = p_ring_in.cmd_w && m_cmd_fifo.wok(); |
---|
| 570 | cmd_fifo_data = p_ring_in.cmd_data; |
---|
| 571 | r_ring_cmd_fsm = LOCAL; |
---|
| 572 | |
---|
| 573 | } |
---|
| 574 | } |
---|
| 575 | break; |
---|
| 576 | |
---|
| 577 | case RING: |
---|
| 578 | { |
---|
| 579 | |
---|
| 580 | bool eop = ( (int) ((p_ring_in.cmd_data >> (ring_cmd_data_size - 1) ) & 0x1) == 1); |
---|
| 581 | |
---|
| 582 | #ifdef TR_DEBUG |
---|
| 583 | if( trace(sc_time_stamp())) |
---|
| 584 | std::cout << sc_time_stamp() << " -- " << m_name |
---|
| 585 | << " -- ring_cmd_fsm -- RING " |
---|
| 586 | << " -- in cmd rok : " << p_ring_in.cmd_w |
---|
| 587 | << " -- in data : " << std::hex << p_ring_in.cmd_data |
---|
| 588 | << " -- in wok : " << p_ring_in.cmd_r |
---|
| 589 | << " -- eop : " << eop |
---|
| 590 | << std::endl; |
---|
| 591 | #endif |
---|
| 592 | if ( p_ring_in.cmd_w && eop ) { |
---|
| 593 | r_ring_cmd_fsm = CMD_IDLE; |
---|
| 594 | } |
---|
| 595 | else { |
---|
| 596 | r_ring_cmd_fsm = RING; |
---|
| 597 | } |
---|
| 598 | } |
---|
| 599 | break; |
---|
| 600 | |
---|
| 601 | } // end switch cmd fsm |
---|
| 602 | |
---|
| 603 | //////////////////////// |
---|
| 604 | // fifos update // |
---|
| 605 | //////////////////////// |
---|
| 606 | |
---|
| 607 | // local cmd fifo update |
---|
| 608 | if ( cmd_fifo_put && cmd_fifo_get ) m_cmd_fifo.put_and_get(cmd_fifo_data); |
---|
| 609 | else if ( cmd_fifo_put && !cmd_fifo_get ) m_cmd_fifo.simple_put(cmd_fifo_data); |
---|
| 610 | else if ( !cmd_fifo_put && cmd_fifo_get ) m_cmd_fifo.simple_get(); |
---|
| 611 | // local rsp fifo update |
---|
| 612 | if ( rsp_fifo_put && rsp_fifo_get ) m_rsp_fifo.put_and_get(rsp_fifo_data); |
---|
| 613 | else if ( rsp_fifo_put && !rsp_fifo_get ) m_rsp_fifo.simple_put(rsp_fifo_data); |
---|
| 614 | else if ( !rsp_fifo_put && rsp_fifo_get ) m_rsp_fifo.simple_get(); |
---|
| 615 | |
---|
| 616 | } // end Transition() |
---|
| 617 | |
---|
| 618 | /////////////////////////////////////////////////////////////////// |
---|
| 619 | void genMoore(vci_initiator_t &p_vci) |
---|
| 620 | /////////////////////////////////////////////////////////////////// |
---|
| 621 | { |
---|
| 622 | if( r_vci_rsp_fsm == RSP_HEADER ) |
---|
| 623 | p_vci.rspack = false; |
---|
| 624 | else |
---|
| 625 | p_vci.rspack = m_rsp_fifo.wok(); |
---|
| 626 | |
---|
| 627 | switch ( r_vci_cmd_fsm ) |
---|
| 628 | { |
---|
| 629 | case CMD_FIRST_HEADER: |
---|
| 630 | p_vci.cmdval = false; |
---|
| 631 | |
---|
| 632 | break; |
---|
| 633 | |
---|
| 634 | case CMD_SECOND_HEADER: |
---|
| 635 | if(((int) (m_cmd_fifo.read() >> (ring_cmd_data_size - 1) ) & 0x1) == 1) // eop |
---|
| 636 | { |
---|
| 637 | p_vci.cmdval = m_cmd_fifo.rok(); |
---|
| 638 | p_vci.address = (sc_uint<vci_param::N>) r_addr.read(); |
---|
| 639 | p_vci.cmd = (sc_uint<2>) ((m_cmd_fifo.read() >> 18) & 0x3); |
---|
| 640 | p_vci.be = 0xF; |
---|
| 641 | p_vci.wdata = 0; |
---|
| 642 | p_vci.pktid = (sc_uint<vci_param::P>) ((m_cmd_fifo.read() >> 4) & 0xF); |
---|
| 643 | p_vci.srcid = (sc_uint<vci_param::S>) (m_cmd_fifo.read() >> 20) ; |
---|
| 644 | p_vci.trdid = (sc_uint<vci_param::T>) (m_cmd_fifo.read() & 0xF); |
---|
| 645 | p_vci.plen = (sc_uint<vci_param::K>) ((m_cmd_fifo.read() >> 8) & 0xFF); |
---|
| 646 | p_vci.eop = true; |
---|
| 647 | sc_uint<1> cons = (sc_uint<1>) ((m_cmd_fifo.read() >> 16) & 0x1) ; |
---|
| 648 | if (cons == 0x1) |
---|
| 649 | p_vci.cons = true; |
---|
| 650 | else |
---|
| 651 | p_vci.cons = false; |
---|
| 652 | sc_uint<1> contig = (sc_uint<1>) ((m_cmd_fifo.read() >> 17) & 0x1); |
---|
| 653 | if(contig == 0x1) |
---|
| 654 | p_vci.contig = true; |
---|
| 655 | else |
---|
| 656 | p_vci.contig = false; |
---|
| 657 | } |
---|
| 658 | else |
---|
| 659 | p_vci.cmdval = false; |
---|
| 660 | break; |
---|
| 661 | |
---|
| 662 | case WDATA: |
---|
| 663 | { // for variable scope |
---|
| 664 | |
---|
| 665 | p_vci.cmdval = m_cmd_fifo.rok(); |
---|
| 666 | p_vci.address = (sc_uint<vci_param::N>) r_addr.read(); |
---|
| 667 | p_vci.be = (sc_uint<vci_param::B>)((m_cmd_fifo.read() >> 32) & 0xF); |
---|
| 668 | p_vci.cmd = r_cmd; |
---|
| 669 | p_vci.wdata = (sc_uint<32>)(m_cmd_fifo.read()); |
---|
| 670 | p_vci.pktid = r_pktid; |
---|
| 671 | p_vci.srcid = r_srcid; |
---|
| 672 | p_vci.trdid = r_trdid; |
---|
| 673 | p_vci.plen = r_plen; |
---|
| 674 | sc_uint<1> cons = r_const; |
---|
| 675 | if (cons == 0x1) |
---|
| 676 | p_vci.cons = true; |
---|
| 677 | else |
---|
| 678 | p_vci.cons = false; |
---|
| 679 | sc_uint<1> contig = r_contig; |
---|
| 680 | if(contig == 0x1) |
---|
| 681 | p_vci.contig = true; |
---|
| 682 | else |
---|
| 683 | p_vci.contig = false; |
---|
| 684 | if(((int) (m_cmd_fifo.read() >> (ring_cmd_data_size - 1) ) & 0x1) == 1) |
---|
| 685 | p_vci.eop = true; |
---|
| 686 | else |
---|
| 687 | p_vci.eop = false; |
---|
| 688 | } |
---|
| 689 | break; |
---|
| 690 | |
---|
| 691 | } // end switch fsm |
---|
| 692 | } // end genMoore |
---|
| 693 | |
---|
| 694 | /////////////////////////////////////////////////////////////////// |
---|
| 695 | void update_ring_signals(ring_signal_t p_ring_in, ring_signal_t &p_ring_out) |
---|
| 696 | /////////////////////////////////////////////////////////////////// |
---|
| 697 | { |
---|
| 698 | |
---|
| 699 | switch( r_ring_rsp_fsm ) |
---|
| 700 | { |
---|
| 701 | case RSP_IDLE: |
---|
| 702 | p_ring_out.rsp_grant = p_ring_in.rsp_grant && !m_rsp_fifo.rok(); |
---|
| 703 | |
---|
| 704 | p_ring_out.rsp_w = p_ring_in.rsp_w; |
---|
| 705 | p_ring_out.rsp_data = p_ring_in.rsp_data; |
---|
| 706 | |
---|
| 707 | p_ring_out.rsp_r = p_ring_in.rsp_r; |
---|
| 708 | break; |
---|
| 709 | |
---|
| 710 | case DEFAULT: |
---|
| 711 | p_ring_out.rsp_grant = !( m_rsp_fifo.rok()); |
---|
| 712 | |
---|
| 713 | p_ring_out.rsp_w = m_rsp_fifo.rok(); |
---|
| 714 | p_ring_out.rsp_data = m_rsp_fifo.read(); |
---|
| 715 | |
---|
| 716 | p_ring_out.rsp_r = 1; |
---|
| 717 | break; |
---|
| 718 | |
---|
| 719 | case KEEP: |
---|
| 720 | int rsp_fifo_eop = (int) ((m_rsp_fifo.read() >> 32) & 0x1); |
---|
| 721 | p_ring_out.rsp_grant = m_rsp_fifo.rok() && p_ring_in.rsp_r && (rsp_fifo_eop == 1); |
---|
| 722 | |
---|
| 723 | p_ring_out.rsp_w = m_rsp_fifo.rok(); |
---|
| 724 | p_ring_out.rsp_data = m_rsp_fifo.read(); |
---|
| 725 | |
---|
| 726 | p_ring_out.rsp_r = 1; |
---|
| 727 | |
---|
| 728 | break; |
---|
| 729 | |
---|
| 730 | } // end switch |
---|
| 731 | |
---|
| 732 | p_ring_out.cmd_w = p_ring_in.cmd_w; |
---|
| 733 | p_ring_out.cmd_data = p_ring_in.cmd_data; |
---|
| 734 | |
---|
| 735 | p_ring_out.cmd_grant = p_ring_in.cmd_grant; |
---|
| 736 | |
---|
| 737 | switch( r_ring_cmd_fsm ) |
---|
| 738 | { |
---|
| 739 | case CMD_IDLE: |
---|
| 740 | { |
---|
| 741 | vci_addr_t rtgtid = (vci_addr_t) ((p_ring_in.cmd_data >> 1) << 2); |
---|
| 742 | bool islocal = m_lt[rtgtid] && (m_rt[rtgtid] == (vci_addr_t) m_tgtid); |
---|
| 743 | bool brdcst = (p_ring_in.cmd_data & 0x1) == 0X1 ; |
---|
| 744 | bool eop = ( (int) ((p_ring_in.cmd_data >> (ring_cmd_data_size - 1) ) & 0x1) == 1); |
---|
| 745 | |
---|
| 746 | if(p_ring_in.cmd_w && !eop && brdcst && !m_cmd_fifo.wok()) { |
---|
| 747 | p_ring_out.cmd_r = m_cmd_fifo.wok() && p_ring_in.cmd_r; |
---|
| 748 | } |
---|
| 749 | |
---|
| 750 | if(p_ring_in.cmd_w && !eop && brdcst && m_cmd_fifo.wok()) { |
---|
| 751 | p_ring_out.cmd_r = m_cmd_fifo.wok() && p_ring_in.cmd_r; |
---|
| 752 | |
---|
| 753 | } |
---|
| 754 | |
---|
| 755 | if (p_ring_in.cmd_w && !eop && !brdcst && islocal) { |
---|
| 756 | p_ring_out.cmd_r = m_cmd_fifo.wok(); |
---|
| 757 | |
---|
| 758 | } |
---|
| 759 | |
---|
| 760 | if (p_ring_in.cmd_w && !eop && !brdcst && !islocal) { |
---|
| 761 | p_ring_out.cmd_r = p_ring_in.cmd_r; |
---|
| 762 | } |
---|
| 763 | |
---|
| 764 | if (!p_ring_in.cmd_w || eop) { |
---|
| 765 | p_ring_out.cmd_r = p_ring_in.cmd_r; |
---|
| 766 | } |
---|
| 767 | |
---|
| 768 | |
---|
| 769 | } |
---|
| 770 | break; |
---|
| 771 | |
---|
| 772 | case BROADCAST_0: |
---|
| 773 | p_ring_out.cmd_r = m_cmd_fifo.wok() && p_ring_in.cmd_r; |
---|
| 774 | break; |
---|
| 775 | |
---|
| 776 | case BROADCAST_1: |
---|
| 777 | p_ring_out.cmd_r = m_cmd_fifo.wok() && p_ring_in.cmd_r; |
---|
| 778 | break; |
---|
| 779 | |
---|
| 780 | case LOCAL: |
---|
| 781 | |
---|
| 782 | p_ring_out.cmd_r = m_cmd_fifo.wok(); |
---|
| 783 | break; |
---|
| 784 | |
---|
| 785 | case RING: |
---|
| 786 | |
---|
| 787 | p_ring_out.cmd_r = p_ring_in.cmd_r; |
---|
| 788 | break; |
---|
| 789 | } // end switch |
---|
| 790 | |
---|
| 791 | } // end update_ring_signals |
---|
| 792 | |
---|
| 793 | }; |
---|
| 794 | |
---|
| 795 | }} // end namespace |
---|
| 796 | |
---|
| 797 | |
---|