Jump to content

Fsm


Bes

Recommended Posts

  • 3 weeks later...


SC_MODULE(Fsm) {
    sc_in<bool> clk;
    sc_in<bool> reset;
    sc_in<bool> is_valid;
    sc_in<bool> is_half_dollar;
    sc_out<bool> is_dispensed;


    SC_CTOR(Fsm) {
        SC_THREAD(fsm_thread);
        sensitive << clk.pos();
    };

    void fsm_thread() {
        typedef enum {S0=0, S1=1, S2=2, S3=3} state_e;
        state_e state = S0;
        while(true) {
            is_dispensed.write(false);
            if(reset.read() == false) {
                switch(state) {
                    case S0:
                        if(is_valid.read() == true && is_half_dollar.read() == true)
                            state = S1;
                        else
                            state = S2;
                        break;
                    case S1:
                        if(is_valid.read() == true && is_half_dollar.read() == true)
                            state = S2;
                        else 
                            state = S3;
                        break;
                    case S2:
                        if(is_valid.read() == true)
                            state = S3;
                        break;
                    case S3:
                        is_dispensed.write(true);
                        state = S0;
                        break;
                    default:
                            state = S0;
                }
            }        
            else
                state = S0;
            wait();
        }
    }//fsm_thread

};

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...