Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Simulation problem of greatest common divisor in Cascade simulator

Status
Not open for further replies.

james_eali

Newbie
Newbie level 1
Joined
Oct 25, 2021
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
40
My question is how to implement a GCD chip in Cascade. I've read the guide but I could not get it done. Its at the behavioral level and I'm using three states, namely, idle, compare and finish. Here is my code:

Code:
#include <cascade/Cascade.hpp>
class GCD_core : public Component
{
    DECLARE_COMPONENT(GCD_core);
public:
    GCD_core(COMPONENT_CTOR) { GCD.setType(PORT_LATCH); }
    const char *Component_name;
    Input <u32> A, B;
    Input <bit> start;
    Output <bit> done;
    Output <u32> GCD;
 
    Clock clk;

    enum states{idle, compare, finish};
 
    Signal(states, P_state);
    Signal(states, N_state);

    void reset()
    {
        done << 0;
        GCD << 0;
        P_state = idle;
        N_state = idle;
    }

    void update()
    {
        switch (P_state)
        {
        case idle:
            if (start == 1)
            {
                N_state = compare;
            }
            else
                N_state = P_state;
            break;
        case compare:
            if (A == B)
            {
                N_state = finish;
                done = 1;
                GCD << A;
            }
            else if (A > B)
            {
                A = A - B;
                N_state = P_state;
            }
            else
            {
                B = B - A;
                N_state = P_state;
            }
            break;
        case finish:
            done << 1;
            GCD << A;
            start << 0;
        default:
            N_state = idle;
            break;
        }
    }
    void archive(Archive &) {}
};
class GCD_core_TB : public Component
{
    DECLARE_COMPONENT(GCD_core_TB);
public:
    GCD_core_TB(const char *name,COMPONENT_CTOR):Component_name(name)
    {
        DUT.clk << clk;
        DUT.start << start;
        DUT.A << A;
        DUT.B << B;
        DUT.GCD << GCD;
        DUT.done << done;
    }
 
    Input(u32, A);
    Input(u32, B);
    Input(bit, start);
    Output(u32, GCD);
    Output(bit, done);

 
    Clock clk;
    void reset(){}
 
    void update()
    {
        clk.generateClock(500);
        Sim::init();
        while (1)
        {
            char buff[64];
            printf("A = ");  int a = (int)(fgets(buff, 64, stdin));
            printf("\nB = ");  int b = (int)(fgets(buff, 64, stdin));
            if (*buff == 'q')
                break;
            if (*buff == 'l')
            {
                SimArchive::loadSimulation("GCD.vcd");
                printf("Simulation restored from GCD.vcd\n");
            }
            else if (*buff == 's')
            {
                SimArchive::saveSimulation("GCD.vcd");
                printf("Simulation saved to GCD.vcd\n");
                continue;
            }
            this->A << a; this->B << b;
            Sim::run();
            printf("\nGCD is: %d", this->GCD);
            Sim::reset();
        }
    }
    void archive(Archive &) {}
    const char *Component_name;
protected:
    GCD_core DUT;
};

int main(int csz, char ** rgsz)
{
    descore::arseTraces(csz, rgsz);
    Parameter::arseCommandLine(csz, rgsz);
    GCD_core_TB chip("GCD_TEST");
    Sim::dumpSignals(chip.Component_name);
    return 0;
}

I could not find any related forum to state my problem. So I would be grateful if anyone with Cascade experience could guide me on this.
 
Last edited by a moderator:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top