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/*****************************************************************************
2112027Sjungma@eit.uni-kl.de
2212027Sjungma@eit.uni-kl.de  sc_event_queue.h -- Event Queue Facility Definitions
2312027Sjungma@eit.uni-kl.de
2412027Sjungma@eit.uni-kl.de  Original Author: Ulli Holtmann, Synopsys, Inc.
2512027Sjungma@eit.uni-kl.de
2612027Sjungma@eit.uni-kl.de  CHANGE LOG IS AT THE END OF THE FILE
2712027Sjungma@eit.uni-kl.de *****************************************************************************/
2812027Sjungma@eit.uni-kl.de
2912027Sjungma@eit.uni-kl.de#ifndef SC_EVENT_QUEUE_H
3012027Sjungma@eit.uni-kl.de#define SC_EVENT_QUEUE_H
3112027Sjungma@eit.uni-kl.de
3212027Sjungma@eit.uni-kl.de
3312027Sjungma@eit.uni-kl.de/*
3412027Sjungma@eit.uni-kl.de  Class sc_event_queue
3512027Sjungma@eit.uni-kl.de
3612027Sjungma@eit.uni-kl.de  A queue that can contain any number of pending notifications.
3712027Sjungma@eit.uni-kl.de  The queue has a similiar interface like an sc_event but has different
3812027Sjungma@eit.uni-kl.de  semantics: it can carry any number of pending notification. The
3912027Sjungma@eit.uni-kl.de  general rule is that _every_ call to notify() will cause a
4012027Sjungma@eit.uni-kl.de  corresponding trigger at the specified wall-clock time that can be
4112027Sjungma@eit.uni-kl.de  observed (the only exception is when notifications are explicitly
4212027Sjungma@eit.uni-kl.de  cancelled).
4312027Sjungma@eit.uni-kl.de
4412027Sjungma@eit.uni-kl.de  If multiple notifications are pending at the same wall-clock
4512027Sjungma@eit.uni-kl.de  time, then the event queue will trigger in different delta cycles
4612027Sjungma@eit.uni-kl.de  in order to ensure that sensitive processes can notice each
4712027Sjungma@eit.uni-kl.de  trigger. The first trigger happens in the earliest delta cycle
4812027Sjungma@eit.uni-kl.de  possible which is the same behavior as a normal timed event.
4912027Sjungma@eit.uni-kl.de
5012027Sjungma@eit.uni-kl.de*/
5112027Sjungma@eit.uni-kl.de
5212027Sjungma@eit.uni-kl.de#include "sysc/communication/sc_interface.h"
5312027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_module.h"
5412027Sjungma@eit.uni-kl.de#include "sysc/kernel/sc_event.h"
5512027Sjungma@eit.uni-kl.de#include "sysc/communication/sc_port.h"
5612027Sjungma@eit.uni-kl.de
5712027Sjungma@eit.uni-kl.denamespace sc_core {
5812027Sjungma@eit.uni-kl.de
5912027Sjungma@eit.uni-kl.de
6012027Sjungma@eit.uni-kl.de// ---------------------------------------------------------------------------
6112027Sjungma@eit.uni-kl.de// sc_event_queue_if
6212027Sjungma@eit.uni-kl.de// ---------------------------------------------------------------------------
6312027Sjungma@eit.uni-kl.de
6412027Sjungma@eit.uni-kl.declass sc_event_queue_if : public virtual sc_interface
6512027Sjungma@eit.uni-kl.de{
6612027Sjungma@eit.uni-kl.depublic:
6712027Sjungma@eit.uni-kl.de    virtual void notify (double when, sc_time_unit base) =0;
6812027Sjungma@eit.uni-kl.de    virtual void notify (const sc_time& when) =0;
6912027Sjungma@eit.uni-kl.de    virtual void cancel_all() =0;
7012027Sjungma@eit.uni-kl.de};
7112027Sjungma@eit.uni-kl.de
7212027Sjungma@eit.uni-kl.de// ---------------------------------------------------------------------------
7312027Sjungma@eit.uni-kl.de// sc_event_queue: a queue that can contain any number of pending
7412027Sjungma@eit.uni-kl.de// delta, or timed events.
7512027Sjungma@eit.uni-kl.de// ---------------------------------------------------------------------------
7612027Sjungma@eit.uni-kl.de
7712027Sjungma@eit.uni-kl.declass sc_event_queue:
7812027Sjungma@eit.uni-kl.de  public sc_event_queue_if,
7912027Sjungma@eit.uni-kl.de  public sc_module
8012027Sjungma@eit.uni-kl.de{
8112027Sjungma@eit.uni-kl.de public:
8212027Sjungma@eit.uni-kl.de
8312027Sjungma@eit.uni-kl.de    SC_HAS_PROCESS( sc_event_queue );
8412027Sjungma@eit.uni-kl.de
8512027Sjungma@eit.uni-kl.de    sc_event_queue( sc_module_name name_ = sc_gen_unique_name("event_queue") );
8612027Sjungma@eit.uni-kl.de    ~sc_event_queue();
8712027Sjungma@eit.uni-kl.de
8812027Sjungma@eit.uni-kl.de    // API of sc_object
8912027Sjungma@eit.uni-kl.de    inline virtual const char* kind() const { return "sc_event_queue"; }
9012027Sjungma@eit.uni-kl.de
9112027Sjungma@eit.uni-kl.de    //
9212027Sjungma@eit.uni-kl.de    // API of sc_event_queue_if
9312027Sjungma@eit.uni-kl.de    //
9412027Sjungma@eit.uni-kl.de    inline virtual void notify (double when, sc_time_unit base);
9512027Sjungma@eit.uni-kl.de           virtual void notify (const sc_time& when);
9612027Sjungma@eit.uni-kl.de           virtual void cancel_all();
9712027Sjungma@eit.uni-kl.de
9812027Sjungma@eit.uni-kl.de    //
9912027Sjungma@eit.uni-kl.de    // API for using the event queue in processes
10012027Sjungma@eit.uni-kl.de    //
10112027Sjungma@eit.uni-kl.de
10212027Sjungma@eit.uni-kl.de    // get the default event
10312027Sjungma@eit.uni-kl.de    inline virtual const sc_event& default_event() const;
10412027Sjungma@eit.uni-kl.de
10512027Sjungma@eit.uni-kl.de/*
10612027Sjungma@eit.uni-kl.de    //
10712027Sjungma@eit.uni-kl.de    // Possible extensions:
10812027Sjungma@eit.uni-kl.de    //
10912027Sjungma@eit.uni-kl.de
11012027Sjungma@eit.uni-kl.de    // Cancel an events at a specific time
11112027Sjungma@eit.uni-kl.de    void cancel (const sc_time& when);
11212027Sjungma@eit.uni-kl.de    void cancel (double when, sc_time_unit base);
11312027Sjungma@eit.uni-kl.de
11412027Sjungma@eit.uni-kl.de    // How many events are pending altogether?
11512027Sjungma@eit.uni-kl.de    unsigned pending() const;
11612027Sjungma@eit.uni-kl.de
11712027Sjungma@eit.uni-kl.de    // How many events are pending at the specific time?
11812027Sjungma@eit.uni-kl.de    unsigned pending(const sc_time& when) const;
11912027Sjungma@eit.uni-kl.de    unsigned pending(double when, sc_time_unit base) const;
12012027Sjungma@eit.uni-kl.de*/
12112027Sjungma@eit.uni-kl.de
12212027Sjungma@eit.uni-kl.de private:
12312027Sjungma@eit.uni-kl.de    void fire_event();
12412027Sjungma@eit.uni-kl.de
12512027Sjungma@eit.uni-kl.de private:
12612027Sjungma@eit.uni-kl.de    sc_ppq<sc_time*> m_ppq;
12712027Sjungma@eit.uni-kl.de    sc_event m_e;
12812027Sjungma@eit.uni-kl.de    sc_dt::uint64 m_change_stamp;
12912027Sjungma@eit.uni-kl.de    unsigned m_pending_delta;
13012027Sjungma@eit.uni-kl.de};
13112027Sjungma@eit.uni-kl.de
13212027Sjungma@eit.uni-kl.deinline
13312027Sjungma@eit.uni-kl.devoid sc_event_queue::notify (double when, sc_time_unit base )
13412027Sjungma@eit.uni-kl.de{
13512027Sjungma@eit.uni-kl.de	notify( sc_time(when,base) );
13612027Sjungma@eit.uni-kl.de}
13712027Sjungma@eit.uni-kl.de
13812027Sjungma@eit.uni-kl.deinline
13912027Sjungma@eit.uni-kl.deconst sc_event& sc_event_queue::default_event() const
14012027Sjungma@eit.uni-kl.de{
14112027Sjungma@eit.uni-kl.de  return m_e;
14212027Sjungma@eit.uni-kl.de}
14312027Sjungma@eit.uni-kl.de
14412027Sjungma@eit.uni-kl.de
14512027Sjungma@eit.uni-kl.de//
14612027Sjungma@eit.uni-kl.de// Using event queue as a port
14712027Sjungma@eit.uni-kl.de//
14812027Sjungma@eit.uni-kl.detypedef sc_port<sc_event_queue_if,1,SC_ONE_OR_MORE_BOUND> sc_event_queue_port;
14912027Sjungma@eit.uni-kl.de
15012027Sjungma@eit.uni-kl.de} // namespace sc_core
15112027Sjungma@eit.uni-kl.de
15212027Sjungma@eit.uni-kl.de// $Log: sc_event_queue.h,v $
15312027Sjungma@eit.uni-kl.de// Revision 1.5  2011/08/26 20:45:40  acg
15412027Sjungma@eit.uni-kl.de//  Andy Goodrich: moved the modification log to the end of the file to
15512027Sjungma@eit.uni-kl.de//  eliminate source line number skew when check-ins are done.
15612027Sjungma@eit.uni-kl.de//
15712027Sjungma@eit.uni-kl.de// Revision 1.4  2011/04/05 20:48:09  acg
15812027Sjungma@eit.uni-kl.de//  Andy Goodrich: changes to make sure that event(), posedge() and negedge()
15912027Sjungma@eit.uni-kl.de//  only return true if the clock has not moved.
16012027Sjungma@eit.uni-kl.de//
16112027Sjungma@eit.uni-kl.de// Revision 1.3  2011/02/18 20:23:45  acg
16212027Sjungma@eit.uni-kl.de//  Andy Goodrich: Copyright update.
16312027Sjungma@eit.uni-kl.de//
16412027Sjungma@eit.uni-kl.de// Revision 1.2  2008/05/20 16:45:52  acg
16512027Sjungma@eit.uni-kl.de//  Andy Goodrich: changed which unique name generator is used from the
16612027Sjungma@eit.uni-kl.de//  global one to the one for sc_modules.
16712027Sjungma@eit.uni-kl.de//
16812027Sjungma@eit.uni-kl.de// Revision 1.1.1.1  2006/12/15 20:20:04  acg
16912027Sjungma@eit.uni-kl.de// SystemC 2.3
17012027Sjungma@eit.uni-kl.de//
17112027Sjungma@eit.uni-kl.de// Revision 1.4  2006/11/28 20:30:48  acg
17212027Sjungma@eit.uni-kl.de//  Andy Goodrich: updated from 2.2 source. sc_event_queue constructors
17312027Sjungma@eit.uni-kl.de//  collapsed into a single constructor with an optional argument to get
17412027Sjungma@eit.uni-kl.de//  the sc_module_name stack done correctly. Class name prefixing added
17512027Sjungma@eit.uni-kl.de//  to sc_semaphore calls to wait() to keep gcc 4.x happy.
17612027Sjungma@eit.uni-kl.de//
17712027Sjungma@eit.uni-kl.de// Revision 1.3  2006/01/13 18:47:42  acg
17812027Sjungma@eit.uni-kl.de// Added $Log command so that CVS comments are reproduced in the source.
17912027Sjungma@eit.uni-kl.de//
18012027Sjungma@eit.uni-kl.de
18112027Sjungma@eit.uni-kl.de#endif // SC_EVENT_QUEUE_H
182