⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cache_memif.h

📁 国外开源的一个片上网络系统的源代码
💻 H
字号:
/* *  TU Eindhoven *  Eindhoven, The Netherlands * *  Name            :   cache_memif.h * *  Author          :   A.S.Slusarczyk@tue.nl * *  Date            :    * *  Function        :   Cache interface to the main memory (behavioral) * * */#ifndef CACHE_MEMIF_H_INCLUDED#define CACHE_MEMIF_H_INCLUDED#include "mips.h"#include "xlxram.h"SC_MODULE(CACHE_MEMIF){  sc_int<32> memory[16384];  sc_in< bool > clk;  sc_in< sc_bv<32> > addr, din;  sc_out< sc_bv<32> > dout;  sc_in< bool > ww, wb, r;  sc_out< bool > rdy;  SC_CTOR(CACHE_MEMIF){	SC_CTHREAD(thread,clk.pos());  }    void mem_init(const char *filename, int size){	vector<sc_int<32>* > v(1, memory);	init_memory( &v, size, filename);  }  void mem_dump(const char *filename, int size ){	vector<sc_int<32>* > v(1, memory);	dump_memory( &v, size, filename);  }    void thread(){		sc_int<30> wa;	sc_bv<32> a,d;	bool _r, _ww, _wb;	int rnd;		while(true){	  a = addr.read();	  d = din.read();	  // if( a.to_uint()>=RAMSIZE ) a=sc_bv<32>( a.to_uint()%RAMSIZE );	  rdy.write(true); rnd = rand()%4;	  // rdy.write(true); rnd = 0;	  	  	  	  _r = r.read(); _wb = wb.read(); _ww = ww.read();	  if( _r || _ww || _wb )		{		  //cout << "mem req " << " a=" << hex << a.to_uint() << " d=" << d.to_uint() << dec << " " << sc_time_stamp() << endl;		  while(rnd--) { 			//cout << "mem wait " << " a=" << hex << a.to_uint() << " d=" << d.to_uint() << dec << " " << sc_time_stamp() << endl;			rdy.write(false); 			wait(); 		  }		  rdy.write(true);		  		  //cout << "mem rdy " << " a=" << hex << a.to_uint() << " d=" << d.to_uint() << dec << " " << sc_time_stamp() << endl;		  wa = sc_uint<30>( sc_bv<30>(a.range(31,2)) );		  if( _r )			dout.write( sc_bv<32>(memory[wa]) );		  if( _ww )			memory[wa] = sc_int<32>(d);		  if( _wb )			{			  sc_bv<32> nd(memory[wa]);			  sc_uint<2> byte = sc_bv<2>(a.range(1,0));			  switch(byte){			  case 0 : nd.range(31,24) = d.range(7,0); break;			  case 1 : nd.range(23,16) = d.range(7,0); break;			  case 2 : nd.range(15,8) = d.range(7,0); break;			  case 3 : nd.range(7,0) = d.range(7,0); break;			  }			  memory[wa] = sc_int<32>(nd);			}		}	  	  wait();	}  }};#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -