//----------------send_data_valid_dly/send_data_dly------------------ always @(posedge clk_User) begin if(reset == 1'b1)begin send_data_dly <= 'd0; send_data_valid_dly <= 'd0; end elsebegin send_data_dly <= {send_data_dly[7:0], send_data}; send_data_valid_dly <= {send_data_valid_dly[0], send_data_valid}; end end
// insert 2bytes 0x00 in front of the valid data assign wr_fifo_en = send_data_valid_dly[1] | send_data_valid; assign wr_fifo_din = send_data_dly[15:8];
// posedge of send_data_vlaid, used as the divider input valid signal assign send_data_valid_pos_pls = (~send_data_valid_dly[0]) & send_data_valid;
//----------------bits_per_symbol------------------ always @(posedge clk_User) begin if(reset == 1'b1)begin bits_per_symbol <= 'd0; end elsebegin bits_per_symbol <= tx_Rate << 2; end end
//----------------num_of_data_bits------------------ always @(posedge clk_User) begin if(reset == 1'b1)begin num_of_data_bits <= 'd0; end elsebegin // data region data bits, 16bit service ID + data bits + 6bit tail bits num_of_data_bits <= 16 + (packetlength<<3) + 6; end end
//----------------num_of_symbol------------------ always @(posedge clk_User) begin if(reset == 1'b1)begin num_of_symbol <= 'd0; end elseif(divider_out_valid)begin num_of_symbol <= divider_out[31:8] + (|divider_out[7:0]); end end
always @(posedge clk_User) begin if (reset == 1'b1) begin num_of_symbol_valid <= 1'b0; num_of_toyal_bit_valid <= 1'b0; end elsebegin num_of_symbol_valid <= divider_out_valid; num_of_toyal_bit_valid <= num_of_symbol_valid; end end
//----------------num_of_pad_bits------------------ always @(posedge clk_User) begin if(reset == 1'b1)begin num_of_pad_bits <= 'd0; end elseif(num_of_toyal_bit_valid == 1'b1)begin num_of_pad_bits <= num_of_total_bits - num_of_data_bits; end end
//----------------pad_flag------------------ always@(posedge clk_Modulation)begin if (reset == 1'b1) begin pad_flag <= 1'b0; end elseif((cnt_pad == (num_of_pad_bits + 6 - 1)) && (pad_flag == 1'b1))begin pad_flag <= 1'b0; end elseif (rd_fifo_en_neg_pls == 1'b1) begin pad_flag <= 1'b1; end end
//----------------cnt_pad------------------ always @(posedge clk_Modulation) begin if (reset == 1'b1) begin cnt_pad <= 'd0; end elseif((cnt_pad == (num_of_pad_bits + 6 - 1)) && (pad_flag == 1'b1))begin cnt_pad <= 'd0; end elseif (rd_fifo_en_neg_pls | pad_flag) begin cnt_pad <= cnt_pad + 1'b1; end end
//----------------data_bit------------------ always @(posedge clk_Modulation) begin if (reset == 1'b1) begin data_bit <= 1'b0; end elseif(rd_fifo_en)begin data_bit <= rd_fifo_dout; end elseif(rd_fifo_en_neg_pls | pad_flag)begin data_bit <= 1'b0; end end
always@(posedge clk_Modulation)begin if (reset == 1'b1) begin data_bit_valid <= 1'b0; end elseif(rd_fifo_en | rd_fifo_en_neg_pls | pad_flag) begin data_bit_valid <= 1'b1; end elsebegin data_bit_valid <= 1'b0; end end
//==================================================== // internal signals and registers //==================================================== reg [6:0] h1; // scramble shift register reg h2; // output of scramble shift register reg h2_valid ; // valid of scramble shift register output reg data_bit_dly ; reg scramble_data ; reg [19:0] tail_bit_start ; // start index of tail bits reg tail_bit_flag ; // tail bit flag reg [19:0] cnt_bit ; reg scramble_bit_valid_dly ; wire scramble_bit_valid_neg_pls;
//----------------h1------------------ always @(posedge clk_Modulation) begin if (reset == 1'b1) begin h1 <= SCRAMBLE_REG_INIT; end elseif (scramble_bit_valid_neg_pls) begin h1 <= SCRAMBLE_REG_INIT; end elseif(data_bit_valid) begin h1 <= {h1[5:0], h1[6]^h1[3]}; end end
//----------------h2------------------ always@(posedge clk_Modulation)begin if (reset == 1'b1) begin h2 <= 1'b0; end elseif(scramble_bit_valid_neg_pls)begin h2 <= 1'b0; end elseif(data_bit_valid)begin h2 <= h1[6]^h1[3]; end end
//----------------data_bit_dly------------------ always@(posedge clk_Modulation)begin data_bit_dly <= data_bit; end
//----------------h2_valid------------------ always @(posedge clk_Modulation) begin if(reset == 1'b1)begin h2_valid <= 1'b0; end elsebegin h2_valid <= data_bit_valid; end end
//----------------scramble_bit_valid------------------ always@(posedge clk_Modulation)begin if (reset == 1'b1) begin scramble_bit_valid <= 1'b0; end elsebegin scramble_bit_valid <= h2_valid; end end
//---------------scramble_data------------------- always @(posedge clk_Modulation) begin if (reset == 1'b1) begin scramble_data <= 1'b0; end elseif(h2_valid == 1'b1)begin scramble_data <= h2 ^ data_bit_dly; end end
//----------------tail_bit_start------------------ always@(posedge clk_Modulation)begin if (reset == 1'b1) begin tail_bit_start <= 'd0; end elsebegin tail_bit_start <= (packetlength<<3) + 16; end end
//----------------cnt_bit------------------ always @(posedge clk_Modulation) begin if (reset == 1'b1) begin cnt_bit <= 'd0; end elseif(scramble_bit_valid == 1'b1)begin cnt_bit <= cnt_bit + 1'b1; end elsebegin cnt_bit <= 'd0; end end
//----------------tail_bit_flag------------------ always @(posedge clk_Modulation) begin if(reset == 1'b1)begin tail_bit_flag <= 1'b0; end elseif(cnt_bit == (tail_bit_start+TAIL_BIT_LENGTH -1))begin tail_bit_flag <= 1'b0; end elseif(cnt_bit == (tail_bit_start - 1))begin tail_bit_flag <= 1'b1; end end
always @(*)begin if(scramble_bit_valid)begin if(tail_bit_flag)begin scramble_bit = 1'b0; end elsebegin scramble_bit = scramble_data; end end elsebegin scramble_bit = 1'b0; end end