编译时出现endmodule错误

时间:2014-04-21 19:06:33

标签: verilog system-verilog

我正在尝试在Verilog中编写内存测试算法。这段代码是其中的一部分。我正在尝试编写状态机来设置读取选择信号。我收到编译错误,如:

  

靠近“endcase”:语法错误,意外的endcase。

任何帮助都将不胜感激。

这是我的代码:

module testarch (q, clk, reset, data_in, r_s);

input clk;
input reset;
output [0:2] q;
output data_in;
output r_s;

reg data_in; 
reg [0:2] q;    // address location
reg [0:2] state;       // state machine
reg r_s;
integer done=0;
reg [0:1] l=0;

 always@(posedge clk or posedge reset or state)
    begin //1
    if(reset)
        begin
        state <= 1;
        q<=0;
        end
     else
        begin
        case(state)
        1 : //first four stages
            begin
            repeat (8)
                begin
                @(posedge clk)
                    begin
                    while (!done)
                    begin
                    case(l)
                        0: 
                        begin
                        q<=q;
                        end
                        1: 
                        begin
                        q<=q;
                        end
                        2: 
                        begin
                        q<=q;
                        end
                        3: 
                        begin
                        q<=q+1;
                        done<=1;
                        end
                        endcase
                    end
                    end

                 @(negedge clk)
                    begin
                    while (!done)
                    begin
                    case(l)
                        0: 
                        begin
                        l<=l+1;
                        r_s<=1;
                        end
                        1: 
                        begin
                        l<=l+1;
                        r_s<=1;
                        data_in<=1;
                        end
                        2:
                        begin
                        l<=l+1;
                        r_s<=1;
                        data_in<=0;
                        end
                        3: 
                        begin
                        l<=l+1;
                        r_s<=1;
                        data_in<=0;
                        end
                        endcase
                    end
                    end
                end // end repeat
            endcase
         end //end else
     //end //end always
 endmodule 

1 个答案:

答案 0 :(得分:2)

在标有评论“结束重复”和“结束重复”的结尾之间缺少“结束”(因为在关闭案例之前需要关闭重复之前有一个“开始”)

这并不完全是显而易见的,因为您使用的缩进样式令人困惑。我重新缩放代码,以便我可以看到发生了什么,我建议将来使用更接近这个的样式,因为它确实更容易找到这样的问题:

module testarch (q, clk, reset, data_in, r_s);

input clk;
input reset;
output [0:2] q;
output data_in;
output r_s;

reg data_in; 
reg [0:2] q;    // address location
reg [0:2] state;       // state machine
reg r_s;
integer done=0;
reg [0:1] l=0;

 always@(posedge clk or posedge reset or state)
 begin //1
    if(reset)
    begin
        state <= 1;
        q<=0;
    end
    else
    begin
        case(state)
         1 : //first four stages
             begin
                repeat (8)
                begin
                    @(posedge clk)
                    begin
                        while (!done)
                        begin
                           case(l)
                            0: 
                               begin
                                   q<=q;
                               end
                            1: 
                               begin
                                   q<=q;
                               end
                            2: 
                               begin
                                   q<=q;
                               end
                            3: 
                               begin
                                   q<=q+1;
                                   done<=1;
                               end 
                           endcase
                        end
                    end

                    @(negedge clk)
                    begin
                        while (!done)
                        begin
                            case(l)
                             0: 
                                begin
                                    l<=l+1;
                                    r_s<=1;
                                end
                             1: 
                                begin
                                    l<=l+1;
                                    r_s<=1;
                                    data_in<=1;
                                end
                             2:
                                begin
                                    l<=l+1;
                                    r_s<=1;
                                    data_in<=0;
                                end
                             3: 
                                begin
                                    l<=l+1;
                                    r_s<=1;
                                    data_in<=0;
                                end
                            endcase
                        end
                    end
                 end // end repeat
               // MISSING "end" SHOULD BE HERE!
            endcase
         end //end else
     //end //end always
 endmodule