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

📄 main_spy.cpp

📁 国外开源的一个片上网络系统的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  sc_trace(tf, mips.dmem->EN3,"dmem.EN3");sc_trace(tf, mips.dmem->EN2,"dmem.EN2");  sc_trace(tf, mips.dmem->WE3,"dmem.WE3");sc_trace(tf, mips.dmem->WE2,"dmem.WE2");  sc_trace(tf, mips.dmem->CLK3,"dmem.CLK3");sc_trace(tf, mips.dmem->CLK2,"dmem.CLK2");  sc_trace(tf, mips.dmem->RST3,"dmem.RST3");sc_trace(tf, mips.dmem->RST2,"dmem.RST2");#endif  #ifdef SPYING#ifndef NOMEMVCD  sc_trace(tf, mips.dmem->dDO1,"dbgdmem.DO1");sc_trace(tf, mips.dmem->dDO0,"dbgdmem.DO0");  sc_trace(tf, mips.dmem->dADDR1,"dbgdmem.ADDR1");sc_trace(tf, mips.dmem->dADDR0,"dbgdmem.ADDR0");  sc_trace(tf, mips.dmem->dDI1,"dbgdmem.DI1");sc_trace(tf, mips.dmem->dDI0,"dbgdmem.DI0");  sc_trace(tf, mips.dmem->dEN1,"dbgdmem.EN1");sc_trace(tf, mips.dmem->dEN0,"dbgdmem.EN0");  sc_trace(tf, mips.dmem->dWE1,"dbgdmem.WE1");sc_trace(tf, mips.dmem->dWE0,"dbgdmem.WE0");  sc_trace(tf, mips.dmem->dCLK1,"dbgdmem.CLK1");sc_trace(tf, mips.dmem->dCLK0,"dbgdmem.CLK0");  sc_trace(tf, mips.dmem->dRST1,"dbgdmem.RST1");sc_trace(tf, mips.dmem->dRST0,"dbgdmem.RST0");  sc_trace(tf, mips.dmem->dDO3,"dbgdmem.DO3");sc_trace(tf, mips.dmem->dDO2,"dbgdmem.DO2");  sc_trace(tf, mips.dmem->dADDR3,"dbgdmem.ADDR3");sc_trace(tf, mips.dmem->dADDR2,"dbgdmem.ADDR2");  sc_trace(tf, mips.dmem->dDI3,"dbgdmem.DI3");sc_trace(tf, mips.dmem->dDI2,"dbgdmem.DI2");  sc_trace(tf, mips.dmem->dEN3,"dbgdmem.EN3");sc_trace(tf, mips.dmem->dEN2,"dbgdmem.EN2");  sc_trace(tf, mips.dmem->dWE3,"dbgdmem.WE3");sc_trace(tf, mips.dmem->dWE2,"dbgdmem.WE2");  sc_trace(tf, mips.dmem->dCLK3,"dbgdmem.CLK3");sc_trace(tf, mips.dmem->dCLK2,"dbgdmem.CLK2");  sc_trace(tf, mips.dmem->dRST3,"dbgdmem.RST3");sc_trace(tf, mips.dmem->dRST2,"dbgdmem.RST2");#endif#endif#endif#ifdef BROM  #ifndef NOMEMVCD  for (int i = 0; i < ROMSIZE ; i+=4)	{	  sprintf(stbuf, "memory.imem(%dh)", i);	  sc_trace(tf, mips.imem->bramh->memory[i/4], stbuf);	  sprintf(stbuf, "memory.imem(%dl)", i);	  sc_trace(tf, mips.imem->braml->memory[i/4], stbuf);	  }  sc_trace(tf, mips.imem->DOH,"imem.DOH");sc_trace(tf, mips.imem->DOL,"imem.DOL");  sc_trace(tf, mips.imem->ADDRH,"imem.ADDRH");sc_trace(tf, mips.imem->ADDRL,"imem.ADDRL");  sc_trace(tf, mips.imem->DIH,"imem.DIH");sc_trace(tf, mips.imem->DIL,"imem.DIL");  sc_trace(tf, mips.imem->ENH,"imem.ENH");sc_trace(tf, mips.imem->ENL,"imem.ENL");  sc_trace(tf, mips.imem->WEH,"imem.WEH");sc_trace(tf, mips.imem->WEL,"imem.WEL");  sc_trace(tf, mips.imem->CLKH,"imem.CLKH");sc_trace(tf, mips.imem->CLKL,"imem.CLKL");  sc_trace(tf, mips.imem->RSTH,"imem.RSTH");sc_trace(tf, mips.imem->RSTL,"imem.RSTL");#endif#else  for (int i = 0; i < ROMSIZE; i++)	{	  sprintf(stbuf, "memory.imem(%d)", i);	  sc_trace(tf, mips.imem->romfile[i], stbuf);	}#endif  #ifdef SPYING  sc_trace(tf, commi, "commi");  sc_trace(tf, commo, "commo");  sc_trace(tf, _comminout, "_comminout");  sc_trace(tf, commin, "commin");  sc_trace(tf, mips.spy->ctl, "spy.ctl");  sc_trace(tf, mips.spy->out, "spy.out");  sc_trace(tf, mips.spy->addr, "spy.addr");  sc_trace(tf, mips.spy->data, "spy.data");  sc_trace(tf, mips.spy->enable, "spy.enable");	  sc_trace(tf, mips.spy_comm->new_data, "spy_comm.nd.new_data");  sc_trace(tf, mips.spy_comm->new_data_state, "spy_comm.nd.new_data_state");  sc_trace(tf, mips.spy_comm->ctl_state, "spy_comm.ctl_state");  sc_trace(tf, mips.spy_comm->ctl_next_state, "spy_comm.ctl_next_state");  sc_trace(tf, mips.spy_comm->ctl_sending, "spy_comm.ctl_sending");  sc_trace(tf, mips.spy_comm->clock_cnt, "spy_comm.clock_cnt");  sc_trace(tf, mips.spy_comm->addr_read_2, "spy_comm.addr_read_2");  sc_trace(tf, mips.spy_comm->range_write, "spy_comm.range_write");  sc_trace(tf, mips.spy_comm->mem, "spy_comm.mem");  sc_trace(tf, mips.spy_comm->spy_comm_out, "spy_comm.spy_comm_out");	  sc_trace(tf, mips.spy_comm->sr_go, "spy_comm.sr.sr_go");  sc_trace(tf, mips.spy_comm->sr_running, "spy_comm.sr.sr_running");  sc_trace(tf, mips.spy_comm->sr_nibble, "spy_comm.sr.sr_nibble");  sc_trace(tf, mips.spy_comm->sr_rdy, "spy_comm.sr.sr_rdy");  sc_trace(tf, mips.spy_comm->sr_out, "spy_comm.sr.sr_out");  sc_trace(tf, mips.spy_comm->sr_buffer, "spy_comm.srb.sr_buffer");  sc_trace(tf, mips.spy_comm->srb_write, "spy_comm.srb.srb_write");  sc_trace(tf, mips.spy_comm->srb_shift, "spy_comm.srb.srb_shift");  sc_trace(tf, mips.spy_comm->srb_source, "spy_comm.srb.srb_source");  sc_trace(tf, mips.spy_comm->ar_addr1, "spy_comm.ar.ar_addr1");  sc_trace(tf, mips.spy_comm->ar_addr2, "spy_comm.ar.ar_addr2");  sc_trace(tf, mips.spy_comm->ar_inc, "spy_comm.ar.ar_inc");  sc_trace(tf, mips.spy_comm->ar_eq, "spy_comm.ar.ar_eq");  sc_trace(tf, mips.spy_comm->ar_w1, "spy_comm.ar.ar_w1");  sc_trace(tf, mips.spy_comm->ar_w2, "spy_comm.ar.ar_w2");#endif // SPYING#endif // NOVCD    /*********************************************************************************	Start simulation  *********************************************************************************/#ifdef SPYING  commin = 0;#endif    sc_initialize();  #ifdef SPYING    // reset the system  clk = 0; rst = 1; en = 0;   sc_cycle(period/2);  clk = 1;   sc_cycle(period/2);  rst = 0;  clk = 0;   sc_cycle(period/2);  // test the communication:     /*  // receive the mux1 signal  printf("PC+4=");  commin = 0x02 ;	commi.write(0x3); TICK(1); commin = 0x03 ; TICK(4); commin = 0x02; TICK(5);   RCV();  commin = 0x3; TICK(2); commin = 0x2; TICK(2); // eot  */	  // read RAM and ROM memories  /*  printf( "******* READ RAM\n");  READ(0x0);  printf( "******* READ ROM\n");  READ(0x1);*/  en = 1;  commin = 0;#endif  /*   *	Simulate program execution   */  int max_time = 0;  if (argc == 2) max_time = atoi(argv[1]);  if (max_time == 0) max_time = 500;  unsigned pc, last_pc=0, cnt=0;  while( max_time < 0 || sim_time < max_time )	{	  clk = 0;	  sc_cycle(period/2);	  clk = 1;	  sc_cycle(period/2);	  sim_time += period;	  	  pc = sc_uint<32>(mips.pc->out.read());	  if( pc == 0x10 ) { cout << "END: " << sim_time/period << " cycles" << endl; break; }	  if( max_time<0 && pc == 0x40 && last_pc != pc ){  		cout << cnt++ << " " << sc_time_stamp() << endl; 		cout << flush; 	  }	  last_pc = pc;	}	#ifdef SPYING  /*   *	Read back PC and RAM/ROM   */  /*  printf("PC=");  commin = 0x02 ;	commi.write(0x2); TICK(1); commin = 0x03 ; TICK(4); commin = 0x02; TICK(5);   RCV();  commin = 0x3; TICK(2); commin = 0x2; TICK(2); // eot  */    /*  if(1){	printf( "******* READ RAM\n");	READ(0x0);	printf( "******* READ ROM\n");	READ(0x1);	}*/		  mips.dmem->ram_dump("mips_ram.dump");  /*   * Another test - write memory with random data, read it back   */  /*printf( "******* WRITE RAM\n");  WRITE(0x0);  printf( "******* READ RAM\n");  READ(0x0);*/#endif#ifndef NOVCD  sc_close_vcd_trace_file(tf);#endif  return 0;}/******************************************************************************** * Helper routines ********************************************************************************/void TICK( int n ){  // execute n clock cycles  for(int t=0;t<n;t++){ 	clk = 1; 	sc_cycle(period/2); 	clk = 0; 	sc_cycle(period/2);   }}void READ( unsigned _addr, int w ){  // read w words from memory identified by _addr  cout << "READMEM " << _addr << " @" << sc_time_stamp() << endl;  commin = 0x02 ;	commi.write(_addr); TICK(1); commin = 0x03 ; TICK(4); commin = 0x02; TICK(5);  SEND(0);  SEND(w*4);	  unsigned u;  sc_lv<4> l;  commi.write("ZZZZ");  for( int i = 0 ; i < w; i++ )	{	  printf( "%d : ", i*4);	  for( int j = 0 ; j < 8 ; j++ )		{		  commin = 0x02 ;	TICK(1); commin = 0x03 ; TICK(4); 				  l = commo.read();		  u = sc_uint<4>(l);		  printf("%X",u);		  commin = 0x02; TICK(5);		}	  printf("\n");	}	  commin = 0x3; TICK(2); commin = 0x2; TICK(2); // eot	}void WRITE( unsigned _addr ){  // write to memory identified by _addr  cout << "WRITING " << _addr << " @" << sc_time_stamp() << endl;  commin = 0x02 ;	commi.write(_addr); TICK(1); commin = 0x07 ; TICK(4); commin = 0x02; TICK(5);  SEND(0);  SEND(256);  unsigned u;  for( int i = 0 ; i < 64; i++ )	{	  u = (0x1|_addr)<<28 | (i & 0xf)<<24 | (0x2|_addr)<<20 | (i+1 & 0xf)<<16 | (0x3|_addr)<<12 | 		(i+2 & 0xf)<<8 | (0x4|_addr)<<4 | (i+3 &0xf);	  printf("%d <= %08X\n",i*4,u);	  SEND(u);	}	  commin = 0x3; TICK(2); commin = 0x2; TICK(2); // eot}void SEND( unsigned v ){  // send a word to SPY_COMM  cout << "SEND " << v << " @" << sc_time_stamp() << endl;  for(unsigned i=0 ;i<8 ; i++) { 	// select i-th nibble	unsigned a = (v >> (7-i)*4) & 0xf;	// write nibble	commi.write(a) ; 	// wait	TICK(1); 	// indicate data ready	commin = 0x03 ; 	// wait	TICK(4); 	// deassert data ready	commin = 0x02; 	TICK(2);	printf("%X",a);  }  printf ("\n" );}unsigned RCV( ){  // receive a word from SPY_COMM  cout << "RCV @" << sc_time_stamp() << " ";  unsigned u = 0x0, n;  sc_lv<4> lv;  // set line to receive - disconnect the transmitter  commi.write("ZZZZ");   for(unsigned i=0 ;i<8 ; i++) { 		// clear ready	commin = 0x02 ; TICK(1); 	// assert ready	commin = 0x03 ; 	// wait	TICK(3);	// read the nibble	lv = commo.read();	n = sc_uint<4>(lv);	TICK(1); 	// clear ready	commin = 0x02;		TICK(2);	printf("%X",n);	// append nibble to the word	u <<= 4; u |= n;  }  printf ("\n" );  return u;}

⌨️ 快捷键说明

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