Quantcast
Channel: SystemC Language Forum RSS Feed
Viewing all articles
Browse latest Browse all 595

sc_start warning W571 indicates the signal/port binding fail?

$
0
0

Questions:

After Signal/Port binding, when signal changed, the sensitive list will cause SC_METHOD registered method to run.

 

Q1. Why sometime this works (e.g. the first "trigger AAA" in the SystemC version) while sometimes fail (e.g. the first "trigger BBB") and caused warning W571?

Q2. Why the first time "trigger BBB" caused warning W571, while the immediate second time "trigger BBB" succeeded?

 

n order to simulate statemachine's trigger an Event (event can have parameters), I used a pointer type as this: sc_signal<Event*>, sc_in<Event*>.

Note: In the sentence above the "trigger", "event" refers to UML, might not be the same as SystemC.

Q3. Is this the normal way to achieve this task in SystemC? (I mean define a pointer typed signal/port)

 

In initially implemented in pure C++, then when I'm now learning SystemC, I adopt these features:

    SC_METHOD / sensitive / sc_in.read / sc_signal / binding between signal and port / sc_start

 

Q4. What's your suggestion to implement a statemachine like my program in SystemC? (As a beginner, I might missed lots of cool features in SystemC)

 

===========================================

I had a simple statemachine as attached picture shows

cmd_run.jpg

 

Or you like my hand draw as follows:

                                 ---AAA-->
 Initial ---> [  State1 ]                 [ State2  ] ---CCC--> Final
                                 <--BBB---

--------------------------------------------

I've implement this statemachine in C++ firstly. and here is the running result:

cmd_run2.jpg

 

--------------------------------------------

Then I re-wrote the program in SystemC, most of the code is the same.

 

Then I met this warning W571. To be honest, I think this warning is correct because there is no activity. But Why there is no activity where I thought there should be is the question.

 

I suspect that the binding between signal/port is not handing well. I've pasted my SystemC source at the bottom.

 

Here is the running result from SystemC:

--------------------------------------------

ma@mma01 ~/sc

$ g++ -I. -I$SYSTEMC_HOME/include -L. -L$SYSTEMC_HOME/lib-cygwin -Wl,-rpath=$SYSTEMC_HOME/lib-cygwin -o MyClass MyClass.cpp -lsystemc -lm

mma@mma01 ~/sc
$ ./MyClass

             SystemC 2.3.0-ASI --- Sep  4 2013 12:33:28
        Copyright © 1996-2012 by all Contributors,
        ALL RIGHTS RESERVED

>> Operation Menu:
>>   run STATEMACHINE
>>   trigger AAA,BBB,CCC
>>   exit
run STATEMACHINE
Initial__TO__State1 Effect
STATEMACHINE_STATE1 ENTRY
>> Operation Menu:
>>   run STATEMACHINE
>>   trigger AAA,BBB,CCC
>>   exit
trigger AAA
STATEMACHINE_STATE1 EXIT
State1__TO__State2 Effect
STATEMACHINE_STATE2 ENTRY
>> Operation Menu:
>>   run STATEMACHINE
>>   trigger AAA,BBB,CCC
>>   exit
trigger BBB

Warning: (W571) no activity or clock movement for sc_start() invocation
In file: ../../../../src/sysc/kernel/sc_simcontext.cpp:1606

>> Operation Menu:
>>   run STATEMACHINE
>>   trigger AAA,BBB,CCC
>>   exit
trigger BBB
STATEMACHINE_STATE2 EXIT
State2__TO__State1 Effect
STATEMACHINE_STATE1 ENTRY
>> Operation Menu:
>>   run STATEMACHINE
>>   trigger AAA,BBB,CCC
>>   exit

-------------------------------------------

#include "systemc.h"
using namespace std;

enum StateBehaviorEnum
{
    ENTRY,
    EXIT,
};
enum EventEnum
{
    NOEVENT,
    CCC,
    AAA,
    BBB
};

enum StateMachineEnum
{
    NOSTATEMACHINE,
    STATEMACHINE
};
enum StateEnum
{
    NOSTATE,
    STATEMACHINE_STATE1,
    STATEMACHINE_STATE2    
};

class Event {
public:
    Event(EventEnum eventEnum_)
    {
        eventEnum = eventEnum_;
    };
    EventEnum eventEnum;
};


SC_MODULE ( MyClass )
{
    SC_CTOR(MyClass)
    {
        SC_METHOD(eventListener);
        dont_initialize();
        sensitive << m_event;

        currentState = NOSTATE;
    }

    void eventListener()
    {
        Event* event = m_event.read();
        if(event)
            dispatch(event);
    }

    sc_in<Event*>   m_event;

    StateEnum currentState;
    
    void dispatch(Event* event)
    {
        switch (currentState) {
            case STATEMACHINE_STATE1:
                switch (event->eventEnum) {
                    case AAA:
                        StateMachine_State1(EXIT);
                        cout << "State1__TO__State2 " << "Effect" << endl;
                        StateMachine_State2(ENTRY);
                        break;
                }
                break;
            case STATEMACHINE_STATE2:
                switch (event->eventEnum) {
                    case CCC:
                        StateMachine_State2(EXIT);
                        cout << "State2__TO__Final " << "Effect" << endl;
                        currentState = NOSTATE;
                        break;
                    case BBB:
                        StateMachine_State2(EXIT);
                        cout << "State2__TO__State1 " << "Effect" << endl;
                        StateMachine_State1(ENTRY);
                        break;
                }
                break;
        }
        if(event)
            delete event;
    }

    void StateMachine_State1(StateBehaviorEnum behavior)
    {
        currentState = STATEMACHINE_STATE1;
        switch (behavior) {
            case ENTRY:
                cout << "STATEMACHINE_STATE1 " << "ENTRY" << endl;
                break;
            case EXIT:
                cout << "STATEMACHINE_STATE1 " << "EXIT" << endl;
                break;
        }
    }
    void StateMachine_State2(StateBehaviorEnum behavior)
    {
        currentState = STATEMACHINE_STATE2;
        switch (behavior) {
            case ENTRY:
                cout << "STATEMACHINE_STATE2 " << "ENTRY" << endl;
                break;
            case EXIT:
                cout << "STATEMACHINE_STATE2 " << "EXIT" << endl;
                break;
        }
    }
};
void showMenu()
{
    cout << ">> Operation Menu:" << endl;
    cout << ">>   run STATEMACHINE" << endl;
    cout << ">>   trigger AAA,BBB,CCC" << endl;
    cout << ">>   exit" << endl;
}

int sc_main (int argc, char* argv[]) {
    sc_signal<Event*>   eventSubject;
    MyClass  context("CONTEXT");
    context.m_event(eventSubject);
    while (true) {
        showMenu();
        string in = "";
        getline(cin, in);
        if (in.find("run ") != string::npos)
        {
            if(in.substr(4).compare("STATEMACHINE") == 0)
            {
                if(context.currentState == NOSTATE) {
                    cout << "Initial__TO__State1 " << "Effect" << endl;
                    context.StateMachine_State1(ENTRY);
                }                
            }
        }
        else if (in.find("trigger ") != string::npos)
        {
            if(in.substr(8).compare("AAA") == 0)
                eventSubject = new Event(AAA);
            else if(in.substr(8).compare("BBB") == 0)
                eventSubject = new Event(BBB);
            else if(in.substr(8).compare("CCC") == 0)
                eventSubject = new Event(CCC);
            else
                eventSubject = NULL;

            sc_start();
        }
        else if (in.find("exit") != string::npos)
        {
            break;
        }
    }    
    return 0;// Terminate simulation
}


Viewing all articles
Browse latest Browse all 595

Trending Articles