首页 > 其他分享 >高速收发器:PHY层代码(二)

高速收发器:PHY层代码(二)

时间:2024-07-29 21:31:43浏览次数:14  
标签:begin VAILD SOF 代码 PHY sys 收发器 延迟 EOF

TX:

总结:不难,只需要注意小端发送即可;

我选取的实现思路是使用VAILD信号计数,延迟几个周期之后启动发送计数器,发送计算器在其计数数值来到VAILD信号计数器的最大值-1后结束;

思路很简单,事实上这就是一个很常见的组帧模块,和其他的没有什么本质的差别;

    always @(posedge i_sys_clk) begin
        if(i_sys_rst == 1'b1) begin
            r_o_gt_tx_data <=  w_lfsr_data;
            r_o_gt_tx_char <=  4'b0000;
        end else if(r_st_current == P_ST_ICOMMOA) begin
            r_o_gt_tx_data <= {P_Sync_Code[07-:8],P_Sync_Code[15-:8],P_Sync_Code[23-:8],P_Sync_Code[31-:8]};
            r_o_gt_tx_char <= 4'b0101;
        end else if(r_st_current == P_ST_COMMOA) begin
            r_o_gt_tx_data <= {P_Sync_Code[07-:8],P_Sync_Code[15-:8],P_Sync_Code[23-:8],P_Sync_Code[31-:8]};
            r_o_gt_tx_char <= 4'b0101;
        end else if(r_st_current == P_ST_SOF) begin
            r_o_gt_tx_data <= {w_Gt_tx_fifo_dout[15-:8],w_Gt_tx_fifo_dout[23-:8],w_Gt_tx_fifo_dout[31-:8],P_SoT_Code[07-:8]};
            r_o_gt_tx_char <= 4'b0001;
        end else if(r_st_current == P_ST_DATA) begin
            r_o_gt_tx_data <= {w_Gt_tx_fifo_dout[15-:8],w_Gt_tx_fifo_dout[23-:8],w_Gt_tx_fifo_dout[31-:8],r_Gt_tx_fifo_dout[07-:8]};
            r_o_gt_tx_char <= 4'b0000;
        end else if(r_st_current == P_ST_EOF1) begin
            if(r_i_axi_s_keep == 4'b1000) begin
                r_o_gt_tx_data <= {w_lfsr_data[07:00],P_EoT_Code[07:00],w_Gt_tx_fifo_dout[31-:8],r_Gt_tx_fifo_dout[07-:8]};
                r_o_gt_tx_char <= 4'b0100;
            end else if(r_i_axi_s_keep == 4'b1100) begin
                r_o_gt_tx_data <= {P_EoT_Code[07:00],w_Gt_tx_fifo_dout[23-:8],w_Gt_tx_fifo_dout[31-:8],r_Gt_tx_fifo_dout[07-:8]};
                r_o_gt_tx_char <= 4'b1000;
            end else if(r_i_axi_s_keep == 4'b1110) begin
                r_o_gt_tx_data <= {w_Gt_tx_fifo_dout[15-:8],w_Gt_tx_fifo_dout[23-:8],w_Gt_tx_fifo_dout[31-:8],r_Gt_tx_fifo_dout[07-:8]};
                r_o_gt_tx_char <= 4'b0000;
            end else if(r_i_axi_s_keep == 4'b1111) begin
                r_o_gt_tx_data <= {w_Gt_tx_fifo_dout[15-:8],w_Gt_tx_fifo_dout[23-:8],w_Gt_tx_fifo_dout[31-:8],r_Gt_tx_fifo_dout[07-:8]};
                r_o_gt_tx_char <= 4'b0000;
            end else begin
                r_o_gt_tx_data <= 32'h0000;
                r_o_gt_tx_char <=  4'b0000;
            end
        end else if(r_st_current == P_ST_EOF2) begin
            if(r_i_axi_s_keep == 4'b1110) begin
                r_o_gt_tx_data <= {w_lfsr_data[23-:24],P_EoT_Code[07:00]};
                r_o_gt_tx_char <=  4'b0001;
            end else if(r_i_axi_s_keep == 4'b1111) begin
                r_o_gt_tx_data <= {w_lfsr_data[15-:16],P_EoT_Code[07:00],r_Gt_tx_fifo_dout[07-:8]};
                r_o_gt_tx_char <=  4'b0010;
            end else begin
                r_o_gt_tx_data <=  w_lfsr_data;
                r_o_gt_tx_char <=  4'b0000;
            end
        end else begin
            r_o_gt_tx_data <=  w_lfsr_data;
            r_o_gt_tx_char <=  4'b0000;
        end
    end

 

RX:

总结:默认小端存储需要转大端,对齐很麻烦,准确的筛选所需的字节也很麻烦;

推荐画图来理解;

我个人的总结规律是:

0.SOF的标志作为VAILD的起始信号;

1.SOF和EOF处字节相加大于用户数据位宽的时候,需要将EOF的标志延迟两拍作为VAILD的结束信号;

2.SOF和EOF处字节小于等于用户数据位宽的时候,需要将EOF的标志延迟一拍作为VAILD的结束信号;

3.如果相加为零,则选择EOF的标志作为VAILD的结束信号;

当然,这只是一个思路,这个延迟是相对来说的,如果你用其他方式来判断SOF或者EOF,只需要按我这个相对的概念修改即可;

    always @(posedge i_sys_clk) begin
        if(i_sys_rst == 1'b1) begin
            r_o_axi_s_vaild <= 1'b0;
        end else if((r_sof_mark == 4'b0001) && (r_eof_mark == 4'b0001 || r_eof_mark == 4'b0010) && (r_d1_eof_check == 1'b1)) begin
            r_o_axi_s_vaild <= 1'b0;
        end else if((r_sof_mark == 4'b0001) && (r_eof_mark == 4'b0100 || r_eof_mark == 4'b1000) && (r_d2_eof_check == 1'b1)) begin
            r_o_axi_s_vaild <= 1'b0;
        end else if((r_sof_mark == 4'b0010) && (r_eof_mark == 4'b0001 || r_eof_mark == 4'b0010 || r_eof_mark == 4'b0100) && (r_d1_eof_check == 1'b1)) begin
            r_o_axi_s_vaild <= 1'b0;
        end else if((r_sof_mark == 4'b0010) && (r_eof_mark == 4'b1000) && (r_d2_eof_check == 1'b1)) begin
            r_o_axi_s_vaild <= 1'b0;
        end else if((r_sof_mark == 4'b0100) && (r_d1_eof_check == 1'b1)) begin
            r_o_axi_s_vaild <= 1'b0;
        end else if((r_sof_mark == 4'b1000) && (r_eof_mark == 4'b0001) && (r_eof_check == 1'b1)) begin
            r_o_axi_s_vaild <= 1'b0;
        end else if((r_sof_mark == 4'b1000) && (r_eof_mark == 4'b0010 || r_eof_mark == 4'b0100 || r_eof_mark == 4'b1000) && (r_d1_eof_check == 1'b1)) begin
            r_o_axi_s_vaild <= 1'b0;
        end else if(r_sof_check == 1'b1) begin
            r_o_axi_s_vaild <= 1'b1;
        end
    end

    always @(*) begin
        if((r_sof_mark == 4'b0001) && (r_eof_mark == 4'b0001 || r_eof_mark == 4'b0010) && (r_d1_eof_check == 1'b1)) begin
            r_o_axi_s_last <= 1'b1;
        end else if((r_sof_mark == 4'b0001) && (r_eof_mark == 4'b0100 || r_eof_mark == 4'b1000) && (r_d2_eof_check == 1'b1)) begin
            r_o_axi_s_last <= 1'b1;
        end else if((r_sof_mark == 4'b0010) && (r_eof_mark == 4'b0001 || r_eof_mark == 4'b0010 || r_eof_mark == 4'b0100) && (r_d1_eof_check == 1'b1)) begin
            r_o_axi_s_last <= 1'b1;
        end else if((r_sof_mark == 4'b0010) && (r_eof_mark == 4'b1000) && (r_d2_eof_check == 1'b1)) begin
            r_o_axi_s_last <= 1'b1;
        end else if((r_sof_mark == 4'b0100) && (r_d1_eof_check == 1'b1)) begin
            r_o_axi_s_last <= 1'b1;
        end else if((r_sof_mark == 4'b1000) && (r_eof_mark == 4'b0001) && (r_eof_check == 1'b1)) begin
            r_o_axi_s_last <= 1'b1;
        end else if((r_sof_mark == 4'b1000) && (r_eof_mark == 4'b0010 || r_eof_mark == 4'b0100 || r_eof_mark == 4'b1000) && (r_d1_eof_check == 1'b1)) begin
            r_o_axi_s_last <= 1'b1;
        end else begin
            r_o_axi_s_last <= 0;
        end
    end

    always @(posedge i_sys_clk) begin
        if(i_sys_rst == 1'b1) begin
            r_o_axi_s_data <= 32'h0000;
        end else if((r_sof_check == 1'b1)||(r_data_process == 1'b1)) begin
            if(r_sof_mark == 4'b0001) begin
                r_o_axi_s_data <= {r_2d_i_gt_rx_data[07-:08],r_3d_i_gt_rx_data[31-:24]};
            end else if(r_sof_mark == 4'b0010) begin
                r_o_axi_s_data <= {r_2d_i_gt_rx_data[15-:16],r_3d_i_gt_rx_data[31-:16]};
            end else if(r_sof_mark == 4'b0100) begin
                r_o_axi_s_data <= {r_2d_i_gt_rx_data[23-:24],r_3d_i_gt_rx_data[31-:08]};
            end else if(r_sof_mark == 4'b1000) begin
                r_o_axi_s_data <= {r_2d_i_gt_rx_data[31-:32]};
            end else begin
                r_o_axi_s_data <= 32'h0000;
            end
        end else begin
            r_o_axi_s_data <= 32'h0000;
        end
    end

    always @(posedge i_sys_clk) begin
        if(i_sys_rst == 1'b1) begin
            r_o_axi_s_keep <= 4'b0000;
        end else if((r_sof_check == 1'b1)||(r_data_process == 1'b1)) begin
            if(r_sof_mark == 4'b0001) begin
                if(r_eof_mark == 4'b0001 && r_eof_check == 1'b1) begin
                    r_o_axi_s_keep <= 4'b1110;
                end else if(r_eof_mark == 4'b0010 && r_eof_check == 1'b1) begin
                    r_o_axi_s_keep <= 4'b1111;
                end else if(r_eof_mark == 4'b0100 && r_d1_eof_check == 1'b1) begin
                    r_o_axi_s_keep <= 4'b1000;
                end else if(r_eof_mark == 4'b1000 && r_d1_eof_check == 1'b1) begin
                    r_o_axi_s_keep <= 4'b1100;
                end else begin
                    r_o_axi_s_keep <= 4'b1111;
                end
            end else if(r_sof_mark == 4'b0010) begin
                if(r_eof_mark == 4'b0001 && r_eof_check == 1'b1) begin
                    r_o_axi_s_keep <= 4'b1100;
                end else if(r_eof_mark == 4'b0010 && r_eof_check == 1'b1) begin
                    r_o_axi_s_keep <= 4'b1110;
                end else if(r_eof_mark == 4'b0100 && r_eof_check == 1'b1) begin
                    r_o_axi_s_keep <= 4'b1111;
                end else if(r_eof_mark == 4'b1000 && r_d1_eof_check == 1'b1) begin
                    r_o_axi_s_keep <= 4'b1000;
                end else begin
                    r_o_axi_s_keep <= 4'b1111;
                end
            end else if(r_sof_mark == 4'b0100) begin
                if(r_eof_mark == 4'b0001 && r_eof_check == 1'b1) begin
                    r_o_axi_s_keep <= 4'b1000;
                end else if(r_eof_mark == 4'b0010 && r_eof_check == 1'b1) begin
                    r_o_axi_s_keep <= 4'b1100;
                end else if(r_eof_mark == 4'b0100 && r_eof_check == 1'b1) begin
                    r_o_axi_s_keep <= 4'b1110;
                end else if(r_eof_mark == 4'b1000 && r_eof_check == 1'b1) begin
                    r_o_axi_s_keep <= 4'b1111;
                end else begin
                    r_o_axi_s_keep <= 4'b1111;
                end
            end else if(r_sof_mark == 4'b1000) begin
                if(r_eof_mark == 4'b0001 && r_eof_check == 1'b1) begin
                    r_o_axi_s_keep <= 4'b0000;
                end else if(r_eof_mark == 4'b0010 && r_eof_check == 1'b1) begin
                    r_o_axi_s_keep <= 4'b1000;
                end else if(r_eof_mark == 4'b0100 && r_eof_check == 1'b1) begin
                    r_o_axi_s_keep <= 4'b1100;
                end else if(r_eof_mark == 4'b1000 && r_eof_check == 1'b1) begin
                    r_o_axi_s_keep <= 4'b1110;
                end else begin
                    r_o_axi_s_keep <= 4'b1111;
                end
            end
        end else begin
            r_o_axi_s_keep <= 4'b0000;
        end
    end

 

标签:begin,VAILD,SOF,代码,PHY,sys,收发器,延迟,EOF
From: https://www.cnblogs.com/VerweileDoch/p/18331116

相关文章

  • 代码随想录 day39 零钱兑换 | 完全平方数 | 单词拆分
    零钱兑换零钱兑换解题思路还是完全背包的套路,但这次我们要求的是最小值,因此每次遍历的时候我们要找到最小值,每次给dp增加的大小不在是物品的价值而是长度,所以+1。知识点完全背包心得难点在于怎么样找到最小值完全平方数[完全平方数(https://programmercarl.com/0279.完......
  • 读《代码整洁之道》有感
     引言《代码整洁之道》是软件开发界的一本经典著作,由罗伯特·C·马丁(RobertC.Martin)编写。作为一本深入浅出的指导书籍,它详细阐述了如何编写可读、可维护、易于理解的代码。这本书不仅适合初学者,也适合有经验的开发者,因为它提供了大量实践经验和具体案例,帮助读者提高编......
  • android studio 调用第三方无源代码so
    androidstudio调用第三方无源代码so在AndroidStudio中调用第三方无源码的SO(共享库),你需要遵循以下步骤:将SO文件放置在项目中合适的位置。配置app的build.gradle文件,确保Gradle在构建应用时知道SO文件的位置。在Java/Kotlin代码中使用JNI接口加载SO库。......
  • 毕业设计|基于springboot的房屋租赁系统|代码讲解
    收藏点赞不迷路 关注作者有好处文末获取源码一、系统展示二、万字文档展示开发语言:Java数据库:MySQL技术:Spring+SpringMVC+MyBatis+Vue工具:IDEA/Ecilpse、Navicat、Maven 编号:springboot028一、系统展示二、万字文档展示5.1租客功能模块的实现5.1.1系统主......
  • 毕业设计|消防隐患在线举报系统开发+ssm小程序|代码讲解
    毕业设计|消防隐患在线举报系统开发+ssm小程序|代码讲解收藏点赞不迷路 关注作者有好处文末获取源码一、系统展示二、万字文档展示开发语言:Java数据库:MySQL技术:Spring+SpringMVC+MyBatis+Vue工具:IDEA/Ecilpse、Navicat、Maven 编号:weixin044一、系统展示二、......
  • 毕业设计|基于微信的乐室预约小程序+ssm|代码讲解
    毕业设计|基于微信的乐室预约小程序+ssm|代码讲解收藏点赞不迷路 关注作者有好处文末获取源码一、系统展示二、万字文档展示开发语言:Java数据库:MySQL技术:Spring+SpringMVC+MyBatis+Vue工具:IDEA/Ecilpse、Navicat、Maven 编号:weixin053一、系统展示二、万字文......
  • JAVA毕业设计|springboot房屋租赁系统包含文档代码讲解
     收藏点赞不迷路 关注作者有好处文末获取源码一、系统展示二、万字文档展示开发语言:Java数据库:MySQL技术:Spring+SpringMVC+MyBatis+Vue工具:IDEA/Ecilpse、Navicat、Maven 编号:springboot008一、系统展示二、万字文档展示第5章系统详细设计5.1管理员功能模......
  • JAVA毕业设计|springboot在线宠物用品交易网站的设计与实现包含文档代码讲解
    收藏点赞不迷路 关注作者有好处文末获取源码一、系统展示二、万字文档展示开发语言:Java数据库:MySQL技术:Spring+SpringMVC+MyBatis+Vue工具:IDEA/Ecilpse、Navicat、Maven 编号:springboot082一、系统展示二、万字文档展示第5章系统详细设计5.1管理员模块的......
  • ICEEMDAN算法 python代码实现
    1.安装matlab.enginepython库里没有ICEEMDAN的方法,需要通过python调用matlab的库中的ICEEMDAN。首先下载python和matlab(这里就不过多阐述了),python和matlab的版本要对应,下面是python和matlab对应的版本(仅供参考)(要记住matlab安装的位置,下面要用)从anacondapropmt进入自己创建......
  • JS:JSDoc 构建属于代码的说明书
    目录前言注释文档Q1:为什么我们需要在代码中添加注释?Q2:普通注释和文档注释有什么不同?Q3:为什么文档注释如此重要?Q4:如何写好文档注释?JSDoc:JavaScript代码的"说明书"什么是JSDoc?JSDoc能做什么?如何使用JSDoc?JSDoc的常用标签如何开始使用JSDoc?out目录简......