Network Wizard for VHDL Test Benches
Bit stuffing

Bit Stuffing

This library provides functions for bit stuffing.

Functionality

  • Perform bit-stuffing encoding and decoding of 1bit arrays.

The bit-stuffing algorithm inserts an extra bit if a sequence of bits with the same value is longer than a specified threshold.


More details in nw_bitstuff_pkg

Example use

Include the libraries:

library nw_codec;
context nw_codec.nw_codec_context;

Example: HDLC-style bit-stuffing. Assume we have a HDLC frame in the variable v_data (8bit format). A zero-bit shall be inserted after each sequence of 5 one's. The 8-bit frame is converted to 1-bit with f_repack().

v_len := f_bitstuff_enc_len(f_repack(v_data, 1), 5); -- get length of encoded data (v_data is here 8bit, and is repacked to 1bit)
v_encoded(0 to v_len - 1) := f_bitstuff_enc(f_repack(v_data, 1), 5); -- encode

Add FEC (0x7e) before and after the bit-stuffed HDLC frame:

v_encoded(0 to v_len + 15) := f_concat("01111110", f_concat(v_encoded, "01111110")); -- add FEC before and after data frame

Decoding of a bit-stuffed frame:

v_dlen := f_bitstuff_dec_len(v_encoded(0 to v_len - 1)); -- get length of decoded data
v_decoded(0 to v_dlen - 1) := f_bitstuff_dec(v_encoded(0 to v_len - 1));

See further examples in the test bench nw_codec_tb.vhd.