Verilog HDL Code控制单元和测试台代码[端口尺寸不匹配]?

时间:2015-03-22 23:38:29

标签: verilog

实际上,我多次检查,我无法解决这些错误。

这样的错误:

# ** Warning: (vsim-3015) processor.v(41): [PCDPC] - Port size (1) does not match connection size (32) for port 'RF_DATA_W'. The port definition is at: control_unit.v(35).
#    Time: 0 ps  Iteration: 0  Instance: /DA_VINCI_TB/da_vinci_inst/processor_inst/cu_inst File: control_unit.v
# ** Warning: (vsim-3015) processor.v(41): [PCDPC] - Port size (1) does not match connection size (26) for port 'RF_ADDR_W'. The port definition is at: control_unit.v(35).
#    Time: 0 ps  Iteration: 0  Instance: /DA_VINCI_TB/da_vinci_inst/processor_inst/cu_inst File: control_unit.v
# ** Warning: (vsim-3015) processor.v(41): [PCDPC] - Port size (1) does not match connection size (26) for port 'RF_ADDR_R1'. The port definition is at: control_unit.v(35).
#    Time: 0 ps  Iteration: 0  Instance: /DA_VINCI_TB/da_vinci_inst/processor_inst/cu_inst File: control_unit.v
# ** Warning: (vsim-3015) processor.v(41): [PCDPC] - Port size (1) does not match connection size (26) for port 'RF_ADDR_R2'. The port definition is at: control_unit.v(35).
#    Time: 0 ps  Iteration: 0  Instance: /DA_VINCI_TB/da_vinci_inst/processor_inst/cu_inst File: control_unit.v
# ** Warning: (vsim-3015) processor.v(41): [PCDPC] - Port size (1) does not match connection size (32) for port 'ALU_OP1'. The port definition is at: control_unit.v(36).
#    Time: 0 ps  Iteration: 0  Instance: /DA_VINCI_TB/da_vinci_inst/processor_inst/cu_inst File: control_unit.v
# ** Warning: (vsim-3015) processor.v(41): [PCDPC] - Port size (1) does not match connection size (32) for port 'ALU_OP2'. The port definition is at: control_unit.v(36).
#    Time: 0 ps  Iteration: 0  Instance: /DA_VINCI_TB/da_vinci_inst/processor_inst/cu_inst File: control_unit.v
# ** Warning: (vsim-3015) processor.v(41): [PCDPC] - Port size (1) does not match connection size (6) for port 'ALU_OPRN'. The port definition is at: control_unit.v(36).
#    Time: 0 ps  Iteration: 0  Instance: /DA_VINCI_TB/da_vinci_inst/processor_inst/cu_inst File: control_unit.v
# ** Warning: (vsim-3015) processor.v(41): [PCDPC] - Port size (1) does not match connection size (26) for port 'MEM_ADDR'. The port definition is at: control_unit.v(36).
#    Time: 0 ps  Iteration: 0  Instance: /DA_VINCI_TB/da_vinci_inst/processor_inst/cu_inst File: control_unit.v

处理器

`include "prj_definition.v"
module PROC_CS147_SEC05(DATA, ADDR, READ, WRITE, CLK, RST);
    // output list
    output [`ADDRESS_INDEX_LIMIT:0] ADDR;
    output READ, WRITE;
    // input list
    input  CLK, RST;
    // inout list
    inout [`DATA_INDEX_LIMIT:0] DATA;

    // net section
    wire [`DATA_INDEX_LIMIT:0] rf_data_w, rf_data_r1, rf_data_r2, alu_op1, alu_op2, alu_result;
    wire [`ADDRESS_INDEX_LIMIT:0] rf_addr_w,  rf_addr_r1, rf_addr_r2;
    wire [`ALU_OPRN_INDEX_LIMIT:0] alu_oprn;
    wire rf_read, rf_write;
    wire zero;

    // instantiation section
    // Control unit
    CONTROL_UNIT cu_inst (.MEM_DATA(DATA),        .RF_DATA_W(rf_data_w),   .RF_ADDR_W(rf_addr_w),   .RF_ADDR_R1(rf_addr_r1), 
                          .RF_ADDR_R2(rf_addr_r2), .RF_READ(rf_read),       .RF_WRITE(rf_write),     .ALU_OP1(alu_op1), 
                          .ALU_OP2(alu_op2),      .ALU_OPRN(alu_oprn),     .MEM_ADDR(ADDR),          .MEM_READ(READ), 
                          .MEM_WRITE(WRITE),      .RF_DATA_R1(rf_data_r1), .RF_DATA_R2(rf_data_r2), .ALU_RESULT(alu_result), 
                          .ZERO(zero),            .CLK(CLK),               .RST(RST));
    // register file
    REGISTER_FILE_32x32 rf_inst (.DATA_R1(rf_data_r1), .DATA_R2(rf_data_r2), .ADDR_R1(rf_addr_r1), .ADDR_R2(rf_addr_r2), 
                                 .DATA_W(rf_data_w),   .ADDR_W(rf_addr_w),   .READ(rf_read),      .WRITE(rf_write), 
                                 .CLK(CLK),            .RST(RST));
    // alu
    ALU alu_inst (.OUT(alu_result), .ZERO(zero), .OP1(alu_op1), .OP2(alu_op2), .OPRN(alu_oprn));

endmodule;

控制单元代码

`include "prj_definition.v"
module CONTROL_UNIT(MEM_DATA, RF_DATA_W, RF_ADDR_W, RF_ADDR_R1, RF_ADDR_R2, RF_READ, RF_WRITE,
                    ALU_OP1, ALU_OP2, ALU_OPRN, MEM_ADDR, MEM_READ, MEM_WRITE,
                    RF_DATA_R1, RF_DATA_R2, ALU_RESULT, ZERO, CLK, RST); 

// Output signals
// Outputs for register file 
output [`DATA_INDEX_LIMIT:0] RF_DATA_W;
output [`ADDRESS_INDEX_LIMIT:0] RF_ADDR_W, RF_ADDR_R1, RF_ADDR_R2;
output RF_READ, RF_WRITE;
// Outputs for ALU
output [`DATA_INDEX_LIMIT:0]  ALU_OP1, ALU_OP2;
output  [`ALU_OPRN_INDEX_LIMIT:0] ALU_OPRN;
// Outputs for memory
output [`ADDRESS_INDEX_LIMIT:0]  MEM_ADDR;
output MEM_READ, MEM_WRITE;

// Input signals
input [`DATA_INDEX_LIMIT:0] RF_DATA_R1, RF_DATA_R2, ALU_RESULT;
input ZERO, CLK, RST;

// Inout signal
inout [`DATA_INDEX_LIMIT:0] MEM_DATA;

// State nets
wire [2:0] proc_state;

//holds program counter value, stores the current instruction, stack pointer register


reg MEM_READ, MEM_WRITE;
reg MEM_ADDR;
reg ALU_OP1, ALU_OP2;
reg ALU_OPRN;
reg RF_ADDR_W, RF_ADDR_R1, RF_ADDR_R2;
reg RF_DATA_W;
reg [1:0] state, next_state;




PROC_SM state_machine(.STATE(proc_state),.CLK(CLK),.RST(RST));

always @ (posedge CLK)
begin
    if (RST)
        state <= RST;
    else
        state <= next_state;

end

always @ (state)
begin 
    MEM_READ = 1'b0; MEM_WRITE = 1'b0; MEM_ADDR = 1'b0;
    ALU_OP1 = 1'b0; ALU_OP2 = 1'b0; ALU_OPRN = 1'b0;  
    RF_ADDR_R1 = 1'b0; RF_ADDR_R2 = 1'b0; RF_ADDR_W = 1'b0; RF_DATA_W = 1'b0;
    case( state )
        `PROC_FETCH : begin
            next_state = `PROC_DECODE; 
            MEM_READ = 1'b1; 
            RF_ADDR_R1 = 1'b0; RF_ADDR_R2 = 1'b0;
            RF_ADDR_W = 1'b1;
    end
        `PROC_DECODE : begin
            next_state = `PROC_EXE;
            MEM_ADDR = 1'b1;
            ALU_OP1 = 1'b1; ALU_OP2 = 1'b1; ALU_OPRN = 1'b1; 
            MEM_WRITE = 1'b1;
            RF_ADDR_R1 = 1'b1; RF_ADDR_R2 = 1'b1;
    end
        `PROC_EXE : begin
            next_state = `PROC_MEM;
            ALU_OP1 = 1'b1; ALU_OP2 = 1'b1; ALU_OPRN = 1'b1; 
            RF_ADDR_R1 = 1'b0;
    end
        `PROC_MEM: begin
            next_state = `PROC_WB;
            MEM_READ = 1'b1; MEM_WRITE = 1'b0;
    end
        `PROC_WB: begin
            next_state = `PROC_FETCH; 
            MEM_READ = 1'b1; MEM_WRITE = 1'b0;
    end
    endcase

end
endmodule;





module PROC_SM(STATE,CLK,RST);
// list of inputs
input CLK, RST;
// list of outputs
output [2:0] STATE;

// input list
input CLK, RST;
// output list
output STATE;

reg [2:0] STATE;
reg [1:0] state;
reg [1:0] next_state;

reg PC_REG, INST_REG, SP_REF;

`define PROC_FETCH    3'h0
`define PROC_DECODE   3'h1
`define PROC_EXE      3'h2
`define PROC_MEM      3'h3
`define PROC_WB       3'h4

// initiation of state
initial
begin
  state = 2'bxx;
  next_state = `PROC_FETCH;  
end

// reset signal handling
always @ (posedge RST)
begin
    state = `PROC_FETCH;
    next_state = `PROC_FETCH;
end
always @ (posedge CLK)
begin
    state = next_state;   
end
always @(state)
begin
    if (state === `PROC_FETCH)
    begin 
        next_state = `PROC_DECODE; 

        print_instruction(INST_REG);
    end

    if (state === `PROC_DECODE)
    begin 
       next_state = `PROC_EXE; 

    end

    if (state === `PROC_EXE)
    begin 
       next_state = `PROC_MEM; 

       print_instruction(SP_REF);
    end

    if (state === `PROC_MEM)
    begin 
        next_state = `PROC_WB; 

    end

    if (state === `PROC_WB)
    begin 
        next_state = `PROC_FETCH; 

        print_instruction(PC_REG);
    end
end

task print_instruction;
input [`DATA_INDEX_LIMIT:0] inst;

reg [5:0] opcode; 
reg [4:0] rs;
reg [4:0] rt;
reg [4:0] rd;
reg [4:0] shamt; reg [5:0] funct; reg [15:0] immediate; reg [25:0] address;
begin
// parse the instruction
// R-type
{opcode, rs, rt, rd, shamt, funct} = inst;
// I-type
{opcode, rs, rt, immediate } = inst;
// J-type
{opcode, address} = inst;
$write("@ %6dns -> [0X%08h] ", $time, inst);
case(opcode)          // R-Type 
    6'h00 : begin
            case(funct)
                6'h20: $write("add  r[%02d], r[%02d], r[%02d];", rs, rt, rd);
                6'h22: $write("sub  r[%02d], r[%02d], r[%02d];", rs, rt, rd);
                6'h2c: $write("mul  r[%02d], r[%02d], r[%02d];", rs, rt, rd);
                6'h24: $write("and  r[%02d], r[%02d], r[%02d];", rs, rt, rd);
                6'h25: $write("or   r[%02d], r[%02d], r[%02d];", rs, rt, rd);
                6'h27: $write("nor  r[%02d], r[%02d], r[%02d];", rs, rt, rd);
                6'h2a: $write("slt  r[%02d], r[%02d], r[%02d];", rs, rt, rd);
                6'h00: $write("sll  r[%02d], %2d, r[%02d];", rs, shamt, rd);
                6'h02: $write("srl  r[%02d], 0X%02h, r[%02d];", rs, shamt, rd);
                6'h08: $write("jr   r[%02d];", rs);
                default: $write("");
            endcase
        end

                // I-type
                6'h08 : $write("addi  r[%02d], r[%02d], 0X%04h;", rs, rt, immediate);
                6'h1d : $write("muli  r[%02d], r[%02d], 0X%04h;", rs, rt, immediate);
                6'h0c : $write("andi  r[%02d], r[%02d], 0X%04h;", rs, rt, immediate);
                6'h0d : $write("ori   r[%02d], r[%02d], 0X%04h;", rs, rt, immediate);
                6'h0f : $write("lui   r[%02d], 0X%04h;", rt, immediate);
                6'h0a : $write("slti  r[%02d], r[%02d], 0X%04h;", rs, rt, immediate);
                6'h04 : $write("beq   r[%02d], r[%02d], 0X%04h;", rs, rt, immediate);
                6'h05 : $write("bne   r[%02d], r[%02d], 0X%04h;", rs, rt, immediate);
                6'h23 : $write("lw    r[%02d], r[%02d], 0X%04h;", rs, rt, immediate);
                6'h2b : $write("sw    r[%02d], r[%02d], 0X%04h;", rs, rt, immediate);

                 // J-Type
                6'h02 : $write("jmp 0X%07h;", address);
                6'h03 : $write("jal 0X%07h;", address);
                6'h1b : $write("push;"); 
                6'h1c : $write("pop;"); 
                default: $write(""); 
            endcase
            $write ("\n");
        end 
endtask

end module;

1 个答案:

答案 0 :(得分:2)

所有ADDR_ *的宽度不匹配:

  • 在REGISTER_FILE_32x32中,它是[`REG_ADDR_INDEX_LIMIT:0]
  • 在REGISTER_FILE_32X32_tb中,它是[`ADDRESS_INDEX_LIMIT:0]

`REG_ADDR_INDEX_LIMIT!== `ADDRESS_INDEX_LIMIT