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

📄 test.v

📁 简单的一个8位RISC
💻 V
📖 第 1 页 / 共 2 页
字号:
//// Copyright (c) 1999 Thomas Coonan (tcoonan@mindspring.com)////    This source code is free software; you can redistribute it//    and/or modify it in source code form under the terms of the GNU//    General Public License as published by the Free Software//    Foundation; either version 2 of the License, or (at your option)//    any later version.////    This program is distributed in the hope that it will be useful,//    but WITHOUT ANY WARRANTY; without even the implied warranty of//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the//    GNU General Public License for more details.////    You should have received a copy of the GNU General Public License//    along with this program; if not, write to the Free Software//    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA//`timescale 1ns / 10psmodule test;// For 50Mhz, period is 20ns, so set CLKHI to 10 and CLKLO to 10parameter CLKHI = 10;parameter CLKLO = 10;// Define some codes for each instruction opcode.  These have nothing to do// with the actual encoding of the instructions.  This is for display purposes.//parameter NOP	= 1;parameter MOVWF	= 2;parameter CLRW	= 3;parameter CLRF	= 4;parameter SUBWF	= 5;parameter DECF	= 6;parameter IORWF	= 7;parameter ANDWF	= 8;parameter XORWF	= 9;parameter ADDWF	= 10;parameter MOVF	= 11;parameter COMF	= 12;parameter INCF	= 13;parameter DECFSZ = 14;parameter RRF	= 15;parameter RLF	= 16;parameter SWAPF	= 17;parameter INCFSZ = 18;parameter BCF	= 19;parameter BSF	= 20;parameter BTFSC	= 21;parameter BTFSS	= 22;parameter OPTION = 23;parameter SLEEP	= 24;parameter CLRWDT = 25;parameter TRIS	= 26;parameter RETLW	= 27;parameter CALL	= 28;parameter GOTO	= 29;parameter MOVLW	= 30;parameter IORLW	= 31;parameter ANDLW	= 32;parameter XORLW	= 33;// *** Basic Interface to the PICCPUreg		clk;reg		reset;// Declare I/O Port connectionsreg  [7:0]	porta; // INPUTwire [7:0]	portb; // OUTPUTwire [7:0]	portc; // OUTPUT// Declare ROM and rom signalswire [10:0]	pramaddr;wire [11:0]	pramdata;// *** Expansion Interfacewire [7:0]	expdin;wire [7:0]	expdout;wire [6:0]	expaddr;wire		expread;wire		expwrite;// Debug output ports on the core.  These are just internal signals brought out so// they can be observed.//wire [7:0]	debugw;wire [10:0]	debugpc;wire [11:0]	debuginst;wire [7:0]	debugstatus; // Instantiate one CPU to be tested.cpu cpu (   .clk		(clk),   .reset	(reset),   .paddr	(pramaddr),   .pdata	(pramdata),   .portain	(porta),   .portbout	(portb),   .portcout	(portc),   .expdin	(expdin),   .expdout	(expdout),   .expaddr	(expaddr),   .expread	(expread),   .expwrite	(expwrite),   .debugw	(debugw),   .debugpc	(debugpc),   .debuginst	(debuginst),   .debugstatus	(debugstatus));// Instantiate the Program RAM.pram pram (   .clk		(clk),   .address	(pramaddr),   .we		(1'b0),			// This testbench doesn't allow writing to PRAM   .din		(12'b000000000000),	// This testbench doesn't allow writing to PRAM   .dout	(pramdata));// Output of the DDS in the Expansion module (see section on the DDS Demo in docs).wire [7:0] dds_out;// Instantiate one PICEXP (Expansion) module.  This one is a DDS circuit.exp exp(   .clk		(clk),   .reset	(reset),   .expdin	(expdin),   .expdout	(expdout),   .expaddr	(expaddr),   .expread	(expread),   .expwrite	(expwrite),   .dds_out	(dds_out));// This is the only initial block in the test module and this is where// you select what test you want to do.//initial begin   $display ("Free-RISC8.  Version 1.0");      // Just uncomment out the test you want to run!      // ** This is our top-level "Basic Confidence" test.   basic;      // ** This is the DDS example.  Make sure the DDS circuit is in the Verilog command line.   //dds_test;end// Event should be emitted by any task to kill simulation.  Tasks should// use this to close files, etc.//event ENDSIM;// Capture some datatask capture_data;   begin      $dumpfile ("risc8.vcd");      $dumpvars (0, test);      @(ENDSIM);      $dumpflush;   endendtask// Resettask reset_pic;   begin      reset = 1;      #200;      reset = 0;      $display ("End RESET.");   endendtask  // Drive the clock inputtask drive_clock;   begin      clk  = 0;      forever begin         #(CLKLO) clk = 1;         #(CLKHI) clk = 0;      end   endendtask// *************  BASIC CONFIDENCE Test Tasks **************//// BASIC CONFIDENCE Test.//// This task will fork off all the other necessary tasks to cause reset, drive the clock, etc. etc.//// task basic;      integer  num_outputs;   integer  num_matches;   integer  num_mismatches;      begin      $display ("Free-RISC8 1.0.  This is the BASIC CONFIDENCE TEST.");      #1;         $display ("Loading program memory with %s", "basic.rom");      $readmemh ("basic.rom", pram.mem);      fork         // Capture data         capture_data;                  // Run the clock         drive_clock;                  // Do a reset         reset_pic;                  // Monitor the number of cycles and set an absolute maximum number of cycles.         monitor_cycles (5000);                  // More specific monitors         //monitor_inst;         monitor_portb;         monitor_portc;                  // Drive PORTA with a toggling pattern.  This is for one of the subtests.         //         basic_drive_porta;                  // Monitor the counting pattern on PORTB.  This is our self-checking scheme for the test.         //          begin            //             num_outputs = 9;  // Expect exactly 7 changes on the PORTB (0..6).                        // Call the following task which will watch PORTB for the patterns.            //            basic_monitor_output_signature (num_outputs, num_matches, num_mismatches);                        // See how we did!            repeat (2) @(posedge clk);            $display ("Done monitoring for output signature.  %0d Matches, %0d Mismatches.", num_matches, num_mismatches);            if (num_matches == num_outputs && num_mismatches == 0) begin               $display ("SUCCESS.");            end            else begin               $display ("Test FAILED!!");            end                        // We are done.  Throw the ENDSIM event.            ->ENDSIM;            #0;            $finish;         end                  // Catch end of simulation event due to max number of cycles or pattern from PIC code.         begin            @(ENDSIM);  // Catch the event.                        // Got it!            $display ("End of simulation signalled.  Killing simulation in a moment.");            #0; // Let anything else see this event...            $finish;         end      join   endendtask// Monitor PORTB for an incrementing pattern.  This is how we are doing our self-checking.// A good run will count from ZERO up to some number.//task basic_monitor_output_signature;   input   num_outputs;   output  num_matches;   output  num_mismatches;      integer  num_outputs;   integer  num_matches;   integer  num_mismatches;      integer      i;   reg [7:0]    expected_output;   begin      num_matches    = 0;      num_mismatches = 0;            expected_output = 8'h00;            i = 0;      while (i < num_outputs) begin         // Wait for any change on output port B.         @(portb);         #1;  // Wait for a moment for any wiggling on different               // bits to seetle out, just in case there's any gate-level going on..         if (portb == expected_output) begin            $display ("MONITOR_OUTPUT_SIGNATURE: Expected output observed on PORTB: %h", portb);            num_matches = num_matches + 1;         end         else begin            $display ("MONITOR_OUTPUT_SIGNATURE: Unexpected output on PORTB: %h", portb);            num_mismatches = num_mismatches + 1;         end                     expected_output = expected_output + 1;         i = i + 1;      end   endendtasktask basic_drive_porta;   begin      forever begin         porta = 8'h55;         repeat (32) @(posedge clk);         porta = 8'hAA;         repeat (32) @(posedge clk);      end   endendtask// *************  DDS Demo Test Tasks **************//// DDS Test.//// This task will fork off all the other necessary tasks to cause reset, drive the clock, etc. etc.//// In a waveform viewer, check out PORTC[1:0] and also check out the 'dds_out' output.// You should see a modulated sine wave (e.g. FSK).//task dds_test;      begin      $display ("Free-RISC8 1.0.  This is the DDS Demo.");

⌨️ 快捷键说明

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