00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __PEQ_WITH_GET_H__
00023 #define __PEQ_WITH_GET_H__
00024
00025
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();
00053 }
00054
00055
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
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