0

在从事 SystemC 项目时,我发现我可能对信号和端口有一些混淆的想法。假设我有这样的事情:

//cell.hpp

SC_MODULE(Cell)
{ 
   sc_in<sc_uint<16> > datain; 
   sc_in<sc_uint<1> > addr_en;
   sc_in<sc_uint<1> >  enable;
   sc_out<sc_uint<16> > dataout;

   SC_CTOR(Cell)
   {
     SC_THREAD(memory_cell);
        sensitive << enable << datain << addr_en;
   }
   private:
   void memory_cell();
};



//cell.cpp

void Cell::memory_cell()
{  
   unsigned short data_cell=11;

   while(true)
   {     
      //wait for some input
      wait();     

      if (enable->read()==1 && addr_en->read()==1)
      {        
         data_cell=datain->read();        
      }

      else
      {
         if(enable->read()==0 && addr_en->read()==1)
         {
            dataout->write(data_cell);
         }
     }
   }
}





//test.cpp

SC_MODULE(TestBench)
{
   sc_signal<sc_uint<1> > address_en_s;
   sc_signal<sc_uint<16> > datain_s;  
   sc_signal<sc_uint<1> >  enable_s;
   sc_signal<sc_uint<16> > dataout_s;   

   Cell cella;

   SC_CTOR(TestBench) : cella("cella")
   {
        // Binding
        cella.addr_en(address_en_s);
        cella.datain(datain_s);
        cella.enable(enable_s);
        cella.dataout(dataout_s);               
        SC_THREAD(stimulus_thread);                        
   }


  private:
    void stimulus_thread() {  

//write a value:    
        datain_s.write(81);    
        address_en_s.write(1);    
        enable_s.write(1);         
        wait(SC_ZERO_TIME);


//read what we have written:
        enable_s.write(0);
        address_en_s.write(1);
        wait(SC_ZERO_TIME);

        cout << "Output value: " << dataout_s.read() << endl;


//let's cycle the memory again:       
        address_en_s.write(0);         
        wait(SC_ZERO_TIME);
        cout << "Output value: " << dataout_s.read() << endl;

    }   
};

我试过运行这个模块,我注意到一些奇怪的东西(至少,对我来说很奇怪):当刺激写入一个值(81)时,在wait(SC_ZERO_TIME)内存线程找到它之后datainenable并且address_enable值已经更新。这是我预期会发生的。当刺激改变enable_es值时也会发生同样的情况,以便在内存线程中运行另一个循环并将data_cell值复制到内存单元dataout端口中。我不明白的是为什么在内存模块写入其dataout端口并再次进入wait()while循环开头的语句后,刺激模块仍然具有其旧值dataout_s通道 (0),而不是刚刚被内存模块复制的新值 (81)。然后,如果我运行另一个内存循环周期(例如更改激励通道上的一些值),数据输出通道最终会更新。

换句话说,如果我写入刺激通道然后切换到内存线程,内存会发现更新的值。但是如果内存线程写入它的端口,然后我切换到激励线程,线程仍然会在其通道上看到旧值(绑定到内存端口)。

4

1 回答 1

0

由于错误的增量周期同步,上面的示例没有按我的预期工作。

一般来说,假设我们有两个线程在两个模块上运行,A 和 B,通过通道连接。如果我在 delta 周期 1 期间在线程 A 中写了一些东西,它只会在 delta 周期 2 期间在线程 B 中可用。如果线程 B 在其 delta 周期 2 期间写了一些东西,线程 A 必须等到 delta 周期 3 才能读取它。

意识到这一点,刺激线程需要两个连续wait(SC_ZERO_TIME)的语句才能从内存中读取正确的输出,因为它必须转发其增量值。

于 2014-08-14T15:54:37.113 回答