[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
相关推荐
brave and determined2 小时前
可编程逻辑器件学习(day34):半导体编年史:从法拉第的意外发现到塑造现代文明的硅基浪潮
人工智能·深度学习·fpga开发·verilog·fpga·设计规范·嵌入式设计
FPGA_Linuxer3 小时前
RFSOC PCIE 4.0读写测试
fpga开发
坏孩子的诺亚方舟4 小时前
FPGA系统架构设计实践8_复位参考设计
fpga开发·系统架构·复位
li星野4 小时前
打工人日报#20251124
fpga开发
云雾J视界16 小时前
FPGA+RISC-V架构解析:构建高效传感器数据采集系统
fpga开发·架构·uart·risc-v·i2c·adxl345
步达硬件17 小时前
【FPGA】Intel/AMD FPGA型号参数对比,供选型参考
fpga开发
国科安芯18 小时前
Buck 电路调试避坑手册:国产电源芯片纹波超标、斩波不稳定解决方案
网络·单片机·嵌入式硬件·fpga开发·性能优化
stay_cloud19 小时前
《Verilog语言与FPGA实现》课程实验
verilog·fpga·数码管
贝塔实验室1 天前
Altium Designer 6.0 初学教程-如何生成一个集成库并且实现对库的管理
linux·服务器·前端·fpga开发·硬件架构·基带工程·pcb工艺
IC_Brother1 天前
数字IC经典电路(6)—Ring Oscillator(环形振荡器)与工艺角监控
verilog·数字ic·dc综合