Jump to content

Recommended Posts

Hello all,

Am trying to create SPI (serial peripheral interface) and am not using any control, status registers; but inturn am making up two of them , master and slave and give two inputs to both of them and chek the output accordingly ..Am unable to fetch the output. But before that I wanted to just try out data getting transferred from master to slave. The data to be sent is 32 bit data but in chunks of 8 bits.

Main_proj.cpp is the main file.. it links up both master as well as slave..!! According to our model, we r thinking to construct a top level module to this master and slave( that is in main_proj.cpp) and send the test inputs to both master as well as slave( to dreg and dreg2 registers via ext and ext1) and achieve a full duplex communication by transferring this data to each other and store them in dreg1 and dreg3 ...!!

What do I have to do to enable the communication to happen between master and slave. And I was unable to use read() and write() commands and so used the c++ way of assignment ..!

We used systemc v2.2 ..!!

Any suggestions would definitely help me. I am a beginner still. So any further explanation or links might be helpful.

Thanks in advance.

/********* main_cpp.h ***********************************/

#include "master.h"

#include "slave.h"

int sc_main(int argc, char *argv[])

{

sc_core::sc_clock clk("clk", 20, 0.5,0, true);

sc_signal<bool> m2,s2;

master d1("d1");

//d1.mosi(m1);

d1.ext(m2);

slave d2("d2");

//d2.miso(s1);

d2.ext1(s2);

SC_MODULE(top)

{

sc_in <sc_uint<32> > minput;

sc_in <sc_uint<32> > sinput;

sc_out <sc_uint<32> > moutput;

sc_out <sc_uint<32> > soutput;

SC_CTOR(top)

{

SC_METHOD(top1);

sensitive<<clk.pos();

minput= 0xffff;

sinput=0x0f0f;

}

void top1()

{

m2.write(minput.read);

s2.write(sinput.read);

}

};

d2.dreg3.range(7,0)=(d1.dreg.range(7,0));

d1.dreg1.range(7,0)=(d2.dreg2.range(7,0));

wait();

d2.dreg3.range(15,8)=(d1.dreg.range(15,8));

d1.dreg1.range(15,8)=(d2.dreg2.range(15,8));

wait();

d2.dreg3.range(23,16)=(d1.dreg.range(23,16));

d1.dreg1.range(23,16)=(d2.dreg2.range(23,16));

wait();

d2.dreg3.range(32,24)=(d1.dreg.range(32,24));

d1.dreg1.range(32,24)=(d2.dreg2.range(32,24));

wait();

};

/********* master.h******************************/

#include "systemc.h"

SC_MODULE(master)

{

// port declarations

sc_out<sc_uint<8> > mosi;

sc_in<sc_uint<8> > miso;

sc_in<bool>ss;

sc_out<bool> sck;

sc_in<bool> clk;

// sc_core::sc_clock clk;

sc_in <sc_uint<32> > ext;

// local variables declaration

sc_uint<32> dreg;

sc_uint<32> dreg1;

//constructor declaration

SC_CTOR(master)

{

wait();

SC_METHOD(mas);

sensitive<<clk.pos();

dreg=ext;

}

//function process

void mas()

{

sck = clk;

mosi.write=(dreg.range(7,0).read);

wait();

mosi=(dreg.range(15,8));

wait();

mosi=(dreg.range(23,16));

wait();

mosi=(dreg.range(32,24));

wait();

}

};

/**************************slave.h*********************/

#include "systemc.h"

SC_MODULE(slave)

{

// port declarations

sc_out<sc_uint<8> > mosi;

sc_in<sc_uint<8> > miso;

// sc_in<bool>ss;

sc_in<bool> sck;

sc_in<sc_uint<32> > ext1;

// local variables declaration

sc_uint<32> dreg2;

sc_uint<32> dreg3;

//constructor declaration

SC_CTOR(slave)

{

wait();

SC_METHOD(slv);

sensitive<<sck.pos();

dreg2=ext1;

}

//function process

void slv()

{

miso=(dreg2.range(7,0));

wait();

miso=(dreg2.range(15,8));

wait();

miso=(dreg2.range(23,16));

wait();

miso=(dreg2.range(32,24));

wait();

}

};

/**********************makefile*********************/

export SYSTEMC_HOME=/systemc-2.2.0

g++ -Wno-deprecated -m32 -I. -I$SYSTEMC_HOME/include -c main_proj.cpp

export SC_SIGNAL_WRITE_CHECK=DISABLE

g++ -m32 -L. -L$SYSTEMC_HOME/lib-linux -o sim main_proj.o -lsystemc -lm

./sim

Share this post


Link to post
Share on other sites

Hi,

the first thing to do is compile your code, and fix the errors. Then post the corrected code if it still doesn't function correctly. There's no point posting code won't even compile and run. If you can't figure out why it won't compile or run, then please post the resulting error messages.

You might also find our simple tutorial helpful

http://www.doulos.com/knowhow/systemc/tutorial/modules_and_processes/

regards

Alan

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×