TLM-2.0: include/tlm/tlm_utils/peq_with_get.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# include/tlm/tlm_utils/peq_with_get.h

Go to the documentation of this file.

    00001 /*****************************************************************************
    00002
    00003   The following code is derived, directly or indirectly, from the SystemC
    00004   source code Copyright (c) 1996-2008 by all Contributors.
    00005   All Rights reserved.
    00006
    00007   The contents of this file are subject to the restrictions and limitations
    00008   set forth in the SystemC Open Source License Version 3.0 (the "License");
    00009   You may not use this file except in compliance with such restrictions and
    00010   limitations. You may obtain instructions on how to receive a copy of the
    00011   License at http://www.systemc.org/. Software distributed by Contributors
    00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
    00013   ANY KIND, either express or implied. See the License for the specific
    00014   language governing rights and limitations under the License.
    00015
    00016  *****************************************************************************/
    00017
    00018 // 12-Jan-2009  John Aynsley  Bug fix. sc_time argument to notify should be const
    00019 // 20-Mar-2009  John Aynsley  Add cancel_all() method
    00020
    00021
    00022 #ifndef __PEQ_WITH_GET_H__
    00023 #define __PEQ_WITH_GET_H__
    00024
    00025 //#include "tlm.h"
    00026 #include <systemc>
    00027 #include <map>
    00028
    00029 namespace tlm_utils {
    00030
    00031 template <class PAYLOAD>
    00032 class peq_with_get : public sc_core::sc_object
    00033 {
    00034 public:
    00035   typedef PAYLOAD transaction_type;
    00036   typedef std::pair<const sc_core::sc_time, transaction_type*> pair_type;
    00037
    00038 public:
    00039   peq_with_get(const char* name) : sc_core::sc_object(name)
    00040   {
    00041   }
    00042
    00043   void notify(transaction_type& trans, const sc_core::sc_time& t)
    00044   {
    00045     m_scheduled_events.insert(pair_type(t + sc_core::sc_time_stamp(), &trans));
    00046     m_event.notify(t);
    00047   }
    00048
    00049   void notify(transaction_type& trans)
    00050   {
    00051     m_scheduled_events.insert(pair_type(sc_core::sc_time_stamp(), &trans));
    00052     m_event.notify(); // immediate notification
    00053   }
    00054
    00055   // needs to be called until it returns 0
    00056   transaction_type* get_next_transaction()
    00057   {
    00058     if (m_scheduled_events.empty()) {
    00059       return 0;
    00060     }
    00061
    00062     sc_core::sc_time now = sc_core::sc_time_stamp();
    00063     if (m_scheduled_events.begin()->first <= now) {
    00064       transaction_type* trans = m_scheduled_events.begin()->second;
    00065       m_scheduled_events.erase(m_scheduled_events.begin());
    00066       return trans;
    00067     }
    00068
    00069     m_event.notify(m_scheduled_events.begin()->first - now);
    00070
    00071     return 0;
    00072   }
    00073
    00074   sc_core::sc_event& get_event()
    00075   {
    00076     return m_event;
    00077   }
    00078
    00079   // Cancel all events from the event queue
    00080   void cancel_all() {
    00081     m_scheduled_events.clear();
    00082     m_event.cancel();
    00083   }
    00084
    00085 private:
    00086   std::multimap<const sc_core::sc_time, transaction_type*> m_scheduled_events;
    00087   sc_core::sc_event m_event;
    00088 };
    00089
    00090 }
    00091
    00092 #endif