SimpleLTInitiator2.h revision 12922
112837Sgabeblack@google.com/*****************************************************************************
212837Sgabeblack@google.com
312837Sgabeblack@google.com  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
412837Sgabeblack@google.com  more contributor license agreements.  See the NOTICE file distributed
512837Sgabeblack@google.com  with this work for additional information regarding copyright ownership.
612837Sgabeblack@google.com  Accellera licenses this file to you under the Apache License, Version 2.0
712837Sgabeblack@google.com  (the "License"); you may not use this file except in compliance with the
812837Sgabeblack@google.com  License.  You may obtain a copy of the License at
912837Sgabeblack@google.com
1012837Sgabeblack@google.com    http://www.apache.org/licenses/LICENSE-2.0
1112837Sgabeblack@google.com
1212837Sgabeblack@google.com  Unless required by applicable law or agreed to in writing, software
1312837Sgabeblack@google.com  distributed under the License is distributed on an "AS IS" BASIS,
1412837Sgabeblack@google.com  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1512837Sgabeblack@google.com  implied.  See the License for the specific language governing
1612837Sgabeblack@google.com  permissions and limitations under the License.
1712837Sgabeblack@google.com
1812837Sgabeblack@google.com *****************************************************************************/
1912837Sgabeblack@google.com
2012837Sgabeblack@google.com//====================================================================
2112837Sgabeblack@google.com//  Nov 06, 2008
2212837Sgabeblack@google.com//
2312837Sgabeblack@google.com//  Updated by:
2412837Sgabeblack@google.com//    Xiaopeng Qiu, JEDA Technologies, Inc
2512837Sgabeblack@google.com//    Email:  qiuxp@jedatechnologies.net
2612837Sgabeblack@google.com//
2712837Sgabeblack@google.com//  To fix violations of TLM2.0 rules, which are detected by JEDA
2812837Sgabeblack@google.com//  TLM2.0 checker.
2912837Sgabeblack@google.com//
3012837Sgabeblack@google.com//====================================================================
3113059Sgabeblack@google.com
3213203Sgabeblack@google.com#ifndef __SIMPLE_LT_INITIATOR2_H__
3313324Sgabeblack@google.com#define __SIMPLE_LT_INITIATOR2_H__
3412837Sgabeblack@google.com
3513203Sgabeblack@google.com#include "tlm.h"
3612837Sgabeblack@google.com#include "tlm_utils/simple_initiator_socket.h"
3712837Sgabeblack@google.com//#include <systemc>
3812837Sgabeblack@google.com#include <cassert>
3912837Sgabeblack@google.com//#include <iostream>
4013203Sgabeblack@google.com
4113203Sgabeblack@google.comclass SimpleLTInitiator2 : public sc_core::sc_module
4213203Sgabeblack@google.com{
4313203Sgabeblack@google.compublic:
4413203Sgabeblack@google.com  typedef tlm::tlm_generic_payload                  transaction_type;
4513203Sgabeblack@google.com  typedef tlm::tlm_phase                            phase_type;
4613203Sgabeblack@google.com  typedef tlm::tlm_sync_enum                        sync_enum_type;
4713203Sgabeblack@google.com  typedef tlm_utils::simple_initiator_socket<SimpleLTInitiator2> initiator_socket_type;
4813203Sgabeblack@google.com
4913203Sgabeblack@google.compublic:
5013203Sgabeblack@google.com  initiator_socket_type socket;
5113203Sgabeblack@google.com
5213203Sgabeblack@google.compublic:
5313203Sgabeblack@google.com  SC_HAS_PROCESS(SimpleLTInitiator2);
5413203Sgabeblack@google.com  SimpleLTInitiator2(sc_core::sc_module_name name,
5513203Sgabeblack@google.com                     unsigned int nrOfTransactions = 0x5,
5613203Sgabeblack@google.com                     unsigned int baseAddress = 0x0) :
5713203Sgabeblack@google.com    sc_core::sc_module(name),
5813059Sgabeblack@google.com    socket("socket"),
5913059Sgabeblack@google.com    mNrOfTransactions(nrOfTransactions),
6013203Sgabeblack@google.com    mBaseAddress(baseAddress),
6113324Sgabeblack@google.com    mTransactionCount(0)
6213238Sgabeblack@google.com  {
6313203Sgabeblack@google.com    // Initiator thread
6413324Sgabeblack@google.com    SC_THREAD(run);
6513324Sgabeblack@google.com  }
6613203Sgabeblack@google.com
6713268Sgabeblack@google.com  bool initTransaction(transaction_type& trans)
6813324Sgabeblack@google.com  {
6913324Sgabeblack@google.com    if (mTransactionCount < mNrOfTransactions) {
7013324Sgabeblack@google.com      trans.set_address(mBaseAddress + 4*mTransactionCount);
7113203Sgabeblack@google.com      mData = mTransactionCount;
7213059Sgabeblack@google.com      trans.set_command(tlm::TLM_WRITE_COMMAND);
7313048Sgabeblack@google.com
7412837Sgabeblack@google.com    } else if (mTransactionCount < 2 * mNrOfTransactions) {
7512837Sgabeblack@google.com      trans.set_address(mBaseAddress + 4*(mTransactionCount - mNrOfTransactions));
76      mData = 0;
77      trans.set_command(tlm::TLM_READ_COMMAND);
78
79    } else {
80      return false;
81    }
82
83    trans.set_data_ptr(reinterpret_cast<unsigned char*>(&mData));
84    trans.set_data_length(4);
85    trans.set_streaming_width(4);
86    trans.set_dmi_allowed(false);
87    trans.set_response_status(tlm::TLM_INCOMPLETE_RESPONSE);
88
89    ++mTransactionCount;
90    return true;
91  }
92
93  void logStartTransation(transaction_type& trans)
94  {
95    if (trans.get_command() == tlm::TLM_WRITE_COMMAND) {
96      std::cout << name() << ": Send write request: A = 0x"
97                << std::hex << (unsigned int)trans.get_address()
98                << ", D = 0x" << mData << std::dec
99                << " @ " << sc_core::sc_time_stamp() << std::endl;
100
101    } else {
102      std::cout << name() << ": Send read request: A = 0x"
103                << std::hex << (unsigned int)trans.get_address() << std::dec
104                << " @ " << sc_core::sc_time_stamp() << std::endl;
105    }
106  }
107
108  void logEndTransaction(transaction_type& trans)
109  {
110    if (trans.get_response_status() != tlm::TLM_OK_RESPONSE) {
111      std::cout << name() << ": Received error response @ "
112                << sc_core::sc_time_stamp() << std::endl;
113
114    } else {
115      std::cout << name() <<  ": Received ok response";
116      if (trans.get_command() == tlm::TLM_READ_COMMAND) {
117        std::cout << ": D = 0x" << std::hex << mData << std::dec;
118      }
119      std::cout << " @ " << sc_core::sc_time_stamp() << std::endl;
120    }
121  }
122
123  void run()
124  {
125    transaction_type trans;
126    sc_core::sc_time t;
127
128    while (initTransaction(trans)) {
129      // Create transaction and initialise t
130      t = sc_core::SC_ZERO_TIME;
131
132      logStartTransation(trans);
133
134      socket->b_transport(trans, t);
135      wait(t);
136
137      logEndTransaction(trans);
138    }
139    wait();
140
141  }
142
143private:
144  sc_core::sc_event mEndEvent;
145  unsigned int mNrOfTransactions;
146  unsigned int mBaseAddress;
147  unsigned int mTransactionCount;
148  unsigned int mData;
149};
150
151#endif
152