RTL Studio Open IDE

Coding & Line Codes

HDLC Bit Stuffing (5 Ones)

Inserts a zero bit after five consecutive one bits in a serial data stream for HDLC framing.

About this block

Simulate it in the Verilog IDE

Mediumverilogsimsyn

HDLC Bit Stuffing (5 Ones) is a Verilog reference block in the Coding & Line Codes catalog. Line codes, serializers, and digital encoding/decoding blocks. Marked Medium: more state or a wider datapath, still one workspace in the IDE.

An IP core implementing the HDLC bit stuffing mechanism. It inserts a '0' after five consecutive '1' bits in the data stream to ensure the flag pattern (01111110) does not appear in the payload.

This IP provides a standard, resource-efficient HDLC bit stuffing function suitable for framing layers in serial communication protocols.

It supports synchronous operation with a single clock domain using a valid/ready handshake for flow control.

  1. Choose Open in IDE. RTL Studio loads the packaged workspace for HDLC Bit Stuffing (5 Ones).
  2. Read the Verilog module in the editor. The catalog line for this block: Inserts a zero bit after five consecutive one bits in a serial data stream for HDLC framing.
  3. Run the packaged testbench with the in-browser Verilator simulator, then open the VCD in the waveform viewer.
  4. Run Yosys in the same IDE for a generic netlist. Sky130 liberty mapping is a separate Pro library option.

RTL Studio is the Verilog simulator and IDE around this block: Slang lint, Verilator, VCD waveforms, and Yosys, in the browser. Simulation guide · Yosys guide.

Features

  • Standard Compliance: Implements HDLC bit stuffing (insert '0' after five consecutive '1's).
  • Flow Control: Uses AXI-like valid/ready handshake for synchronous operation.
  • Resource Efficient: Minimal logic usage with a 3-bit counter and simple state machine.
  • Synchronous Design: Single clock domain with active-low synchronous reset.
  • Backpressure: Asserts ready_o low during the stuffing cycle to block input.

Ports

Port NameDirectionWidthDescription
clkInput1Clock signal
rst_nInput1Active-low reset
valid_iInput1Input data valid
ready_oOutput1Input ready (low during stuffing)
data_iInput1Input data bit
valid_oOutput1Output data valid
data_oOutput1Output data bit

Architecture

The module maintains a 3-bit counter for consecutive ones. It operates in two main states: normal passing and stuffing.

  1. Normal Mode: Passes input data directly to the output. The counter increments on input '1' and resets on input '0'.
  2. Stuffing Mode: When the counter reaches four (indicating five consecutive ones including the current input), the next cycle enters stuffing mode. The module outputs a '0', resets the counter, and asserts ready_o low to block further input until the stuffed bit is processed.

Verification

The testbench verifies basic data passing and stuffing logic. It checks that zeros are inserted after five consecutive ones, that the counter resets on non-one bits, and that input is blocked during the stuffing cycle.

Test CaseDescriptionExpected Result
TC1No Stuffing (000)Data passes through unchanged
TC2Single OneData passes through unchanged
TC3Four OnesData passes through unchanged
TC4Five OnesStuffed zero inserted after fifth one
TC5Six OnesStuffed zero after fifth, sixth passes

More in Coding & Line Codes

All Coding & Line Codes blocks