[HDLBits] Fsm hdlc

Synchronous HDLC framing involves decoding a continuous bit stream of data to look for bit patterns that indicate the beginning and end of frames (packets). Seeing exactly 6 consecutive 1s (i.e., 01111110) is a "flag" that indicate frame boundaries. To avoid the data stream from accidentally containing "flags", the sender inserts a zero after every 5 consecutive 1s which the receiver must detect and discard. We also need to signal an error if there are 7 or more consecutive 1s.

Create a finite state machine to recognize these three sequences:

  • 0111110: Signal a bit needs to be discarded (disc).
  • 01111110: Flag the beginning/end of a frame (flag).
  • 01111111...: Error (7 or more 1s) (err).

When the FSM is reset, it should be in a state that behaves as though the previous input were 0.

Here are some example sequences that illustrate the desired operation.

复制代码
module top_module(
    input clk,
    input reset,    // Synchronous reset
    input in,
    output disc,
    output flag,
    output err);
	//0-5识别为1,5为0跳discard,为1跳6.6为1跳error,为0跳flag
    reg [3:0]state,next;
    parameter discard=7,flagg=8,error=9;
    always@(*)begin
        case(state)
            0:next<=in?1:0;
            1:next<=in?2:0;
            2:next<=in?3:0;
            3:next<=in?4:0;
            4:next<=in?5:0;
            5:next<=in?6:discard;
            6:next<=in?error:flagg;
            discard:next<=in?1:0;
            flagg:next<=in?1:0;
            error:next<=in?error:0;
        endcase
    end
    always@(posedge clk) begin
        if(reset)
            state<=0;
        else
            state<=next;
    end
    assign disc=state==discard;
    assign flag=state==flagg;
    assign err=state==error;
endmodule
相关推荐
ERROR:991 天前
AMD Ross没有介入Vivado的私生活
fpga开发
Riwuarua1 天前
从近似 0 基础开始 FPGA 开发——Part.18:FPGA 复位系统与可靠启动设计
fpga开发
智感子2 天前
测控链路:从传感器到上位机
人工智能·嵌入式硬件·fpga开发
szxinmai主板定制专家3 天前
基于Zynq的高精度多通道数据采集卡完整解决方案(工业振动/高速采集/边缘传输)
fpga开发·zynq·数据采集卡
szxinmai主板定制专家3 天前
基于TI AM62x+FPGA的24bit高精度数据采集卡设计(振动/风电/发动机监测)
人工智能·fpga开发·arm+fpga·rk3588+fpga
szxinmai主板定制专家3 天前
基于 ARM+FPGA 雕刻机控制系统的设计
arm开发·人工智能·fpga开发·rk3576·半导体设备
吉他英雄一里4 天前
zynq入门教程
fpga开发·zynq
XMAIPC_Robot4 天前
RK3576/RK3588+FPGA+AI数据采集系统:实时性与边缘AI算力兼顾
人工智能·fpga开发·机器人·数据采集·rk3588+fpga·rk3576+fpga
FPGA小徐5 天前
通信系统核心技术概念解析
fpga
156082072195 天前
JFMRFVU3P5G的bit正常,但烧录mcs程序后加载异常
fpga开发