[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
相关推荐
星夜离尘5610 小时前
UART 串口通信:从帧格式到收发回显(附完整 Verilog 实操)
fpga开发
仲南音14 小时前
Xilinx FPGA—— DDR4读写
fpga开发
思尔芯S2C19 小时前
思尔芯RCF RTL自动分割工具,助力大规模AI/HPC芯片原型验证
人工智能·fpga开发·内存模型·自动编译·ddr5·prototyping·原型验证
Terasic友晶科技1 天前
答疑解惑|Agilex 3 FPGA QSPI时钟设置注意事项
fpga开发·de23-lite·terasic·qspi flash
国科安芯2 天前
卫星星务计算机数据管理中SEU容错机制的技术实现研究——以AS32S601存储器ECC架构为例
网络·单片机·算法·fpga开发·架构·云计算·risc-v
国科安芯2 天前
卫星电推进系统阀门驱动控制中的宽温域高可靠MCU应用研究——基于AS32S601电气特性与辐照试验数据的工程分析
单片机·嵌入式硬件·fpga开发·云计算·信息与通信·卫星·抗辐射芯片
Hi202402172 天前
Vortex 3.0 + xcvu19p CMD_MEM_WRITE 调试
fpga·rtl·vortex
郝旭帅电子设计团队2 天前
图像处理是什么
图像处理·fpga开发·郝旭帅电子设计团队·郝旭帅
ARM|X86+FPGA工业主板厂家3 天前
基于ARM+FPGA平台在精密测控领域的应用:8路同步IEPE振动采集系统
arm开发·fpga开发
weixin_452600693 天前
D2632大电流低差压可调线性稳压器介绍,D2632可替换MIC29302
fpga开发·机器人·无人机·电动工具·车载摄像头