verilog code slice 학습 성장 기념

19953 단어
//=== 1.high pulse to(2) high level
`ifndef DLY       
`define DLY 1     
`endif            
//only for sync clk signal.
module PUL2LVL_H (/*autoarg*/
    //Inputs
    clk_bus, brst_n, sig_in, 

    //Outputs
    sig_out);

parameter  DW = 10;

input  clk_bus;//clock
input  brst_n;//reset
input  sig_in;
output  sig_out;
reg  [DW-1:0]     sig_dly;    
wire              sig_out;    

always @(posedge clk_bus or negedge brst_n) begin
    if (!brst_n) begin
        sig_dly[DW-1:0] <= #`DLY 'b0;
    end
    else begin
        sig_dly[DW-1:0] <= #`DLY {sig_dly[DW-2:0],sig_in};
    end
end
assign sig_out = |sig_dly | sig_in;
endmodule

//        code,        。
//replace keyword 
//eg:r_keyword_p2l_cnt -> r_aaaa_p2l_cnt
////================= fresh version
//reg [6:0] r_keyword_p2l_cnt;
//reg r_keyword_hl;
//wire w_keyword_p2l_cnt_eq_keyword_size_1;
//assign w_keyword_p2l_cnt_eq_keyword_size_1 = r_keyword_p2l_cnt == w_keyword_size_1;
//always @(posedge i_clk or negedge i_rst_n)begin
//    if (!i_rst_n) begin
//        r_keyword_hl <= 1'b0;
//    end
//    else begin
//        if(i_keyword_condition) begin
//            r_keyword_hl <= 1'b1;
//        end
//        else if(w_keyword_p2l_cnt_eq_keyword_size_1) begin
//            r_keyword_hl <= 1'b0;
//        end
//        else begin
//            r_keyword_hl <= r_keyword_hl;
//        end
//    end
//end
//always @(posedge i_clk or negedge i_rst_n)begin
//    if (!i_rst_n) begin
//        r_keyword_p2l_cnt <= 7'h0;
//    end
//    else begin
//        if(w_keyword_p2l_cnt_eq_keyword_size_1)begin
//            r_keyword_p2l_cnt <= 7'h0;
//        end
//        else if(r_keyword_hl)begin
//            r_keyword_p2l_cnt <= r_keyword_p2l_cnt + 1'b1;
//        end
//        else begin
//            r_keyword_p2l_cnt <= r_keyword_p2l_cnt;
//        end
//    end
//end
////================= 


//=== 2.delay match, this style is suitable for >10 delay (not usually use)
//dly     ,      ,       。  code    。
////replace: _keyword _condition1 _condition2
////eg: j_keyword -> j_aaaaaaaa
//localparam DELAY_keyword = 19;
//genvar j_keyword;
//generate 
//    for(j_keyword = 0; j_keyword < DELAY_keyword; j_keyword= j_keyword + 1)begin:dly_keyword
//        reg r_keyword_delay;
//        if(j_keyword == 0)begin
//            always@(posedge i_clk or negedge i_rst_n)
//            if(!i_rst_n)begin
//                r_keyword_delay <= 1'd0;
//            end
//            else begin
//                dly_keyword[j_keyword].r_keyword_delay <= i_keyword; 
//            end
//        end
//        else begin
//            always@(posedge i_clk or negedge i_rst_n)
//            if(!i_rst_n)begin
//                r_keyword_delay <= 1'd0;
//            end
//            else begin
//                dly_keyword[j_keyword].r_keyword_delay <= dly_keyword[j_keyword-1].r_keyword_delay; 
//            end
//        end
//    end
//endgenerate
////choose a specified delay from a delay array according to a condition
//reg r_keyword_dly;
//always @(posedge i_clk or negedge i_rst_n)begin
//    if (!i_rst_n) begin
//        r_keyword_dly <= 1'd0;
//    end
//    else begin
//        if(i_condition1) begin
//            r_keyword_dly <= dly_keyword[PAR_condition1 -1].r_keyword_delay;
//        end
//        else if(i_condition2) begin
//            r_keyword_dly <= dly_keyword[PAR_condition2 -1].r_keyword_delay;
//        end
//    end
//end


//=== 3.produce a rise edge of a given signal
//replace _keyword
wire w_keyword_rsdg ;
reg r_keyword_r1 ;
always @(posedge i_clk or negedge i_rst_n)begin
    if (!i_rst_n) begin
        r_keyword_r1 <= 1'b0;
    end
    else begin
        r_keyword_r1 <= w_keyword;
    end
end
assign w_keyword_rsdg = w_keyword & !r_keyword_r1;

 
기호수를 더하면 비트의 넓이를 다 채우고 추가해야 한다(verilog-1995)
wire[7:0] a, b;
wire[8:0] sum1;
wire[9:0] sum2;
assign sum1 = {a[7],a} + {b[7],b};
assign sum2 = {sum1[8],sum1} + 10‘d23;

verilog-2001이면signed 키워드를 직접 사용할 수 있습니다
wire signed [7:0] a, b;
wire signed [8:0] sum1;
wire signed [9:0] sum2;
assign sum1 = a + b;
assign sum2 = sum1 + 10‘d23;

사실 하드웨어에 대해 이렇게 말하는 기호가 없는 것은 모두 이진법이다.verilog-1995 쓰기를 사용하면 더욱 통용된다.

Q:why design compiler 2010 think this is not right? A:Because i_wghtGridH is a variable.
integer i,j;
always @(posedge i_clk or negedge i_rst_n)begin
    if(!i_rst_n)begin
        for(i = 0; i < i_wghtGridH; i = i + 1)begin
            for(j = 0; j < i_wghtGridW; j = j + 1)begin
                r_WeightoNWeights0a[i][j] <= 5'd0;
            end
        end
    end
    else begin
        r_WeightoNWeights0a[texel_cnt_y_r2][texel_cnt_x_r2] <= w_WeightoNWeights0;
    end 
end
//This is ok.
reg [4:0] r_WeightoNWeights0a [7:0][7:0];
integer i,j;
always @(posedge i_clk or negedge i_rst_n)begin
    if(!i_rst_n)begin
        for(i = 0; i < 8; i = i + 1)begin //num_plp can use wire ??
            for(j = 0; j < 8; j = j + 1)begin
                r_WeightoNWeights0a[i][j] <= 5'd0;
            end
        end
    end
    else begin
        r_WeightoNWeights0a[texel_cnt_y_r2][texel_cnt_x_r2] <= w_WeightoNWeights0;
    end
end

좋은 웹페이지 즐겨찾기