[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
相关推荐
FPGA小迷弟13 小时前
FPGA 与卫星:从星载硬件到在轨智能的完整技术解析
fpga开发·架构·fpga·1024程序员节·无线电
NamoAmitabha12814 小时前
CPU 内部结构是什么?---deepseek
fpga开发
abc light15 小时前
ARM 裸机开发(6)——时钟树与定时器
arm开发·单片机·fpga开发
156082072191 天前
JFMZQ28DR、JFMZQ68DR、RFsoc XCZU47DR、XCZU48DR 信号处理板
fpga开发·信号处理
XMAIPC_Robot1 天前
-40~85℃宽温实测:RK3588 机器人控制器硬件底座,长时间 SLAM 定位稳定性验证
人工智能·fpga开发·机器人·边缘计算·arm+fpga·rk3588+fpga
樱木花道長1 天前
AMD Ross 深度系列 8:FAQ 七问七答(文末附网盘链接)
人工智能·fpga开发
FPGA小迷弟1 天前
FPGA 与无人机:从飞控实时性到智能载荷的硬件加速实践
人工智能·ai·fpga开发·架构·无人机·ai编程
低慢小uav1 天前
(已解决)Zynq芯片lwip协议栈,使用tcp作为服务器Service,接收大量数据时,长度接收正常,接收对数据校验,校验和异常分析
网络协议·tcp/ip·fpga开发
szxinmai主板定制专家1 天前
ARM+FPGA 数控机床控制器:选 CODESYS SoftMotion CNC,还是基于 LinuxCNC 自研搭建?架构、授权、实时性、量产风险深度对比
arm开发·fpga开发·codesys·数据采集卡·linuxcnc·rk3576
女神下凡1 天前
芯参谋(79):嵌入式学习进阶_(硬件与软件)深入实践指南
arm开发·单片机·嵌入式硬件·学习·fpga开发·设计规范