[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
相关推荐
千寻xun5 小时前
一、理论篇-NVME协议学习笔记
笔记·学习·fpga开发·nvme ssd·nvme协议
nuoxin11418 小时前
HR4988替代A4988-富利威
网络·人工智能·嵌入式硬件·fpga开发·dsp开发
一口一口吃成大V19 小时前
vivado的bit 和 bin的区别
fpga开发
尤老师FPGA2 天前
HDMI数据的接收发送实验(十八)
fpga开发
北京青翼科技2 天前
青翼科技 JFM7K325T FPGA+FT-M6678 DSP 的全国产化信号处理平台丨FPGA开发板
fpga开发·数据采集卡·fmc子卡·fpga开发板·ad采集卡·图像处理卡·dsp信号处理
zlinear数据采集卡2 天前
从0到1硬核拆解:工业级数据采集卡的隔离设计与Modbus通信实战
arm开发·单片机·嵌入式硬件·fpga开发·开源
FakeOccupational2 天前
fpga系列 HDL:Microchip FPGA开发软件 Libero Soc FPGA 在线逻辑分析
fpga开发
FPGA技术联盟3 天前
如何在跨时钟域分析中处理好复位信号?
fpga开发
国科安芯3 天前
基于ASM1042S2S的箭载通信网络抗辐射加固方案研究
服务器·网络·嵌入式硬件·fpga开发·架构·信号处理
YYRAN_ZZU4 天前
Lattice 自定义IP业务逻辑核
嵌入式硬件·fpga开发