Jump to content

Usage of Sc_event_or_list


jcmel

Recommended Posts

Hello everybody,

I try to use an sc_event_or_list object to catch multiple events but I don't know how to identify the event which occurs. 

the idea is to schedule the transmission of commands at a specific time

After the wait(_allEvents) I would like to test that event changed.

Thanks in advance for your help.

 

Jean-Claude

 

 

 

Here is a part of the code:

 

class Scheduler : public sc_module
{
public:  
    // Constructor
                                                                Scheduler(sc_module_name name);
    // Destructor
                                                                ~Scheduler();
    // Methods
    void                                                    setSchedule(const T_SCHEDULE& schedule);
    void                                                    setDebug(bool debug)                                            { _isDebug =  debug; }
    void                                                    start();
    void                                                    setTimeSynchro();

    // Spawn Thread
    void                                                    threadReceiveEvents();

private:
    static const int                    _MAX_EVTS;

    bool                                    _isDebug;
    sc_vector<sc_event>         _evts;
    T_SCHEDULE                    _schedule;
    sc_event_or_list                  _allEvents;
    sc_time                               _startTime;

};

 

 

const int Scheduler::_MAX_EVTS = 10;

SC_HAS_PROCESS(Scheduler);
Scheduler::Scheduler(sc_module_name name):
    sc_module(name),
    _isDebug(false),
    _evts("scheduler_evts", _MAX_EVTS)
{}

Scheduler::~Scheduler()
{}

void Scheduler::setSchedule(const T_SCHEDULE& schedule)
{
    if (_isDebug)
    {
        std::cout << sc_time_stamp() << "\tScheduler::setSchedule" << std::endl;
        for (unsigned int i = 0; i< schedule.size(); i++)
        {
            Command* cmd = schedule;
            cmd->display();
        }
    }

    _schedule = schedule;

    // Associate event to each command
    for (unsigned int i = 0; i< _schedule.size(); i++)
    {
        _allEvents |= _evts;
    }

    // Spawn process
    sc_process_handle handle = sc_spawn(
            sc_bind(&Scheduler::threadReceiveEvents, this)
            );


}

void Scheduler::start()
{
    if (_isDebug)
    {
        std::cout << sc_time_stamp() << "\tScheduler::start >>> notify Events..." << std::endl;
    }
    for (unsigned int i = 0; i< _schedule.size(); i++)
    {
        Command* cmd = _schedule;
        double time = cmd->getTime();
        sc_time_unit timeUnit = cmd->getUnit();
        _evts.notify(time, timeUnit);
    }

}


void Scheduler::setTimeSynchro()
{
    if (_isDebug)
    {
        std::cout << sc_time_stamp() << "\tScheduler::setTimeSynchro" << std::endl;
    }

    // Observe current time
    sc_time now(sc_time_stamp());
    _startTime = now;
}


void Scheduler::threadReceiveEvents()
{
    if (_isDebug)
    {
        std::cout << sc_time_stamp() << "\tScheduler::threadReceiveEvents() spawned..." << std::endl;
    }

    while (true)
    {
        wait(_allEvents);

        std::cout << sc_time_stamp() << "\tScheduler::threadReceiveEvents() >>> Event received at " << sc_time_stamp() - _startTime << " from " << _startTime << std::endl;
    }
}

Link to comment
Share on other sites

Hi Jean-Claude,

in SystemC, there is currently no way to identify whether an event has been triggered during/before the current evaluation phase in the simulation.  See e.g. http://forums.accellera.org/topic/4925-/(and other threads) for earlier discussions. 

Btw: I find allEvents a confusing name for an sc_event_or_list.  To me, wait(allEvents) sounds like waiting for all events to be triggered, whereas an or-list will trigger if any event in the list is notified.

 

Greetings from Duisburg,

  Philipp

Link to comment
Share on other sites

Hi Philip,

 

I am agree with you, the name is not well chosen.

 

I read many threads on the subject but I don't find any solution.  In the thread above, it is proposed to use instead sc_signal<bool> which has an event() method  but  I don't know how.

I need to trigger the signal at a specific time like an event.

 

Thanks.

 

Jean-Claude

Link to comment
Share on other sites

Hi Jean-Claude,

    one option would be to create an a process sensitive to each event, and then in that process assign (or perhaps toggle the value) of an sc_signal<bool>. You can then make a process sensitive to all the boolean signals, and find out which signal changed by calling the signal's event method.

 

It's a bit messy, but it would work.

 

You could combine the process, the event, and the boolean signal into a hierarchical channel (perhaps using sc_event_queue for guidance),

 

regards

Alan

Link to comment
Share on other sites

Hi,

I am wondering  if it's possible to clear a sc_event_or_list before adding the sc_event in the loop.

In the class reference I don't see a method to do this.

On 22/11/2016 at 5:01 PM, jcmel said:

// Associate event to each command
    for (unsigned int i = 0; i< _schedule.size(); i++)
    {
        _orEvents |= _evts;
    }

regards

 

Jean-Claude

Link to comment
Share on other sites

  • 7 months later...
On 12/1/2016 at 5:27 PM, jcmel said:

I am wondering  if it's possible to clear a sc_event_or_list before adding the sc_event in the loop.

Yes, there is currently no explicit function for this. But you can assign an empty one first:

_orEvents = sc_event_or_list();

There is a caveat that this might break processes that are currently waiting for the previous elements in the list.  But if you're sure that nothing is currently waiting of the list, the above example Should Work™.

Hope that (still) helps,
  Philipp

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...