Jump to content
Sign in to follow this  
mahbod72

memory definition

Recommended Posts

Hi
is this memory definition is true?
SC_MODULE(mem16)
{
  sc_in <sc_lv <16> > in1;
  sc_out <sc_lv <16> > out1;
  sc_in <sc_lv <12> > addr;
  sc_in <bool> ld;
  sc_in_clk clk;
  int i;
  void write_data();
  sc_lv <16> ram_data[4096];
  SC_CTOR(mem16)
  {
    SC_METHOD(write_data);
    sensitive << addr << ld << in1 << clk ;
	//memory initialization
	ram_data[0]="0000000000000001";
	ram_data[1]="0000000000000011";
	ram_data[2]="0000000000000111";
	ram_data[3]="0000000000001111";
	ram_data[4]="0000000000011111";
	ram_data[5]="0000000000111111";
	ram_data[6]="0000000001111111";
    //for (i=7; i++; i<4095)
    //ram_data[i] = 0;

  }
};
void mem16::write_data()
{
	
  out1 = ram_data[addr.read().to_int()];
  if(clk){
  if (ld) {
    ram_data[addr.read().to_int()] = in1;
  }
	}
}

 

Share this post


Link to post
Share on other sites

good point

sc_unit() is better

i use this and problem is solved

tank you

 sc_lv<12> addr_lv = addr.read();
  sc_uint<12> add = addr_lv;
  
  out1 = ram_data[add];
  if(clk){
  if (ld) {
    ram_data[add] = in1;
  }

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
Sign in to follow this  

×