112027Sjungma@eit.uni-kl.de/*****************************************************************************
212027Sjungma@eit.uni-kl.de
312027Sjungma@eit.uni-kl.de  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
412027Sjungma@eit.uni-kl.de  more contributor license agreements.  See the NOTICE file distributed
512027Sjungma@eit.uni-kl.de  with this work for additional information regarding copyright ownership.
612027Sjungma@eit.uni-kl.de  Accellera licenses this file to you under the Apache License, Version 2.0
712027Sjungma@eit.uni-kl.de  (the "License"); you may not use this file except in compliance with the
812027Sjungma@eit.uni-kl.de  License.  You may obtain a copy of the License at
912027Sjungma@eit.uni-kl.de
1012027Sjungma@eit.uni-kl.de    http://www.apache.org/licenses/LICENSE-2.0
1112027Sjungma@eit.uni-kl.de
1212027Sjungma@eit.uni-kl.de  Unless required by applicable law or agreed to in writing, software
1312027Sjungma@eit.uni-kl.de  distributed under the License is distributed on an "AS IS" BASIS,
1412027Sjungma@eit.uni-kl.de  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1512027Sjungma@eit.uni-kl.de  implied.  See the License for the specific language governing
1612027Sjungma@eit.uni-kl.de  permissions and limitations under the License.
1712027Sjungma@eit.uni-kl.de
1812027Sjungma@eit.uni-kl.de *****************************************************************************/
1912027Sjungma@eit.uni-kl.de
2012027Sjungma@eit.uni-kl.de// 12-Jan-2009  John Aynsley  Bug fix. sc_time argument to notify should be const
2112027Sjungma@eit.uni-kl.de// 20-Mar-2009  John Aynsley  Add cancel_all() method
2212027Sjungma@eit.uni-kl.de
2312027Sjungma@eit.uni-kl.de
2412027Sjungma@eit.uni-kl.de#ifndef __PEQ_WITH_GET_H__
2512027Sjungma@eit.uni-kl.de#define __PEQ_WITH_GET_H__
2612027Sjungma@eit.uni-kl.de
2712027Sjungma@eit.uni-kl.de#include <systemc>
2812027Sjungma@eit.uni-kl.de//#include <tlm>
2912027Sjungma@eit.uni-kl.de#include <map>
3012027Sjungma@eit.uni-kl.de
3112027Sjungma@eit.uni-kl.denamespace tlm_utils {
3212027Sjungma@eit.uni-kl.de
3312027Sjungma@eit.uni-kl.detemplate <class PAYLOAD>
3412027Sjungma@eit.uni-kl.declass peq_with_get : public sc_core::sc_object
3512027Sjungma@eit.uni-kl.de{
3612027Sjungma@eit.uni-kl.depublic:
3712027Sjungma@eit.uni-kl.de  typedef PAYLOAD transaction_type;
3812027Sjungma@eit.uni-kl.de  typedef std::pair<const sc_core::sc_time, transaction_type*> pair_type;
3912027Sjungma@eit.uni-kl.de
4012027Sjungma@eit.uni-kl.depublic:
4112027Sjungma@eit.uni-kl.de  peq_with_get(const char* name) : sc_core::sc_object(name)
4212027Sjungma@eit.uni-kl.de  {
4312027Sjungma@eit.uni-kl.de  }
4412027Sjungma@eit.uni-kl.de
4512027Sjungma@eit.uni-kl.de  void notify(transaction_type& trans, const sc_core::sc_time& t)
4612027Sjungma@eit.uni-kl.de  {
4712027Sjungma@eit.uni-kl.de    m_scheduled_events.insert(pair_type(t + sc_core::sc_time_stamp(), &trans));
4812027Sjungma@eit.uni-kl.de    m_event.notify(t);
4912027Sjungma@eit.uni-kl.de  }
5012027Sjungma@eit.uni-kl.de
5112027Sjungma@eit.uni-kl.de  void notify(transaction_type& trans)
5212027Sjungma@eit.uni-kl.de  {
5312027Sjungma@eit.uni-kl.de    m_scheduled_events.insert(pair_type(sc_core::sc_time_stamp(), &trans));
5412027Sjungma@eit.uni-kl.de    m_event.notify(); // immediate notification
5512027Sjungma@eit.uni-kl.de  }
5612027Sjungma@eit.uni-kl.de
5712027Sjungma@eit.uni-kl.de  // needs to be called until it returns 0
5812027Sjungma@eit.uni-kl.de  transaction_type* get_next_transaction()
5912027Sjungma@eit.uni-kl.de  {
6012027Sjungma@eit.uni-kl.de    if (m_scheduled_events.empty()) {
6112027Sjungma@eit.uni-kl.de      return 0;
6212027Sjungma@eit.uni-kl.de    }
6312027Sjungma@eit.uni-kl.de
6412027Sjungma@eit.uni-kl.de    sc_core::sc_time now = sc_core::sc_time_stamp();
6512027Sjungma@eit.uni-kl.de    if (m_scheduled_events.begin()->first <= now) {
6612027Sjungma@eit.uni-kl.de      transaction_type* trans = m_scheduled_events.begin()->second;
6712027Sjungma@eit.uni-kl.de      m_scheduled_events.erase(m_scheduled_events.begin());
6812027Sjungma@eit.uni-kl.de      return trans;
6912027Sjungma@eit.uni-kl.de    }
7012027Sjungma@eit.uni-kl.de
7112027Sjungma@eit.uni-kl.de    m_event.notify(m_scheduled_events.begin()->first - now);
7212027Sjungma@eit.uni-kl.de
7312027Sjungma@eit.uni-kl.de    return 0;
7412027Sjungma@eit.uni-kl.de  }
7512027Sjungma@eit.uni-kl.de
7612027Sjungma@eit.uni-kl.de  sc_core::sc_event& get_event()
7712027Sjungma@eit.uni-kl.de  {
7812027Sjungma@eit.uni-kl.de    return m_event;
7912027Sjungma@eit.uni-kl.de  }
8012027Sjungma@eit.uni-kl.de
8112027Sjungma@eit.uni-kl.de  // Cancel all events from the event queue
8212027Sjungma@eit.uni-kl.de  void cancel_all() {
8312027Sjungma@eit.uni-kl.de    m_scheduled_events.clear();
8412027Sjungma@eit.uni-kl.de    m_event.cancel();
8512027Sjungma@eit.uni-kl.de  }
8612027Sjungma@eit.uni-kl.de
8712027Sjungma@eit.uni-kl.deprivate:
8812027Sjungma@eit.uni-kl.de  std::multimap<const sc_core::sc_time, transaction_type*> m_scheduled_events;
8912027Sjungma@eit.uni-kl.de  sc_core::sc_event m_event;
9012027Sjungma@eit.uni-kl.de};
9112027Sjungma@eit.uni-kl.de
9212027Sjungma@eit.uni-kl.de}
9312027Sjungma@eit.uni-kl.de
9412027Sjungma@eit.uni-kl.de#endif
95