日常工作中实用的同步FIFO


代码和学生时代所学的有很大不同,重点是FIFO深度&宽度的可配置,分块思想,#1思想,以及同步FIFO的相关性质的处理。
(有任何问题可关注微信公众号:数字IC小宝贝儿,留言call我)

/***************************************************************
// File   : sync_fifo.v
// Auther : HoneyIC
// Time   : 2020.8.30
// Version: #1
// All rights reserved.
A synchronous fifo used in daily work, which is different from what we learned in the school.
The idea of this classification is very important, that is, separate coding of different modules.
What's more, please note that if-else in the sequential circuit is not written in full (eg. line 85).
The advantage is that a gated control circuit can be generated, which can reduce the power consumption of the circuit.
"#1" can solve many timing problems in the synthesized circuit.
***************************************************************/`timescale 1ns / 100ps//`include "para.v"
//`define DLY 1module sync_fifo #(parameter DEPTH = 'd24,parameter WIDTH = 'd8
)(// inputclk,rst_n,wr,rd,data_in,  // outputfull,empty,overun,underun,data_out
);parameter DLY = 1;parameter RPT_WIDTH = DEPTH <= 'd2    ? 'd1 :DEPTH <= 'd4    ? 'd2 :DEPTH <= 'd8    ? 'd3 :DEPTH <= 'd16   ? 'd4 :DEPTH <= 'd32   ? 'd5 :DEPTH <= 'd64   ? 'd6 :DEPTH <= 'd128  ? 'd7 :DEPTH <= 'd256  ? 'd8 :DEPTH <= 'd512  ? 'd9 :DEPTH <= 'd1024 ? 'd10: 'd11;// inputinput               clk;input               rst_n;input               wr;input               rd;input  [WIDTH-1:0]  data_in;// outputoutput [WIDTH-1:0]  data_out;output              full;output              empty;output              overun;output              underun;// registersreg [    WIDTH-1:0] dataout;integer             i;reg [    DEPTH-1:0] fifo [WIDTH-1:0];reg [RPT_WIDTH-1:0] wptr;reg [RPT_WIDTH-1:0] rptr;reg [  RPT_WIDTH:0] gap_cnt;                           // 1. full, empty, overun, underunassign full    = (gap_cnt == DEPTH);assign empty   = (gap_cnt == 0);assign overun  = wr && (!rd) && full;assign underun = (!wr) && rd && empty;// 2. Updata gap_cnt// The advantage of this writing type is that it is easy to modify, especially in large projects. assign gap_cnt_full = (gap_cnt == DEPTH);assign gap_cnt_add  = (wr && (!rd) && (!full));assign gap_cnt_sub  = ((!wr) && rd && (!empty));always @(posedge clk or negedge rst_n)if (!rst_n)gap_cnt <= #DLY 'd0;else if (gap_cnt_full)gap_cnt <= #DLY 'd0;else if (gap_cnt_add)gap_cnt <= #DLY gap_cnt + 1'b1;else if (gap_cnt_sub)gap_cnt <= #DLY gap_cnt - 1'b1;// The advantage of not writing 'else' here is that the Synthesis tool will generate gating clock.// 3. Updata wptr & rptrassign wptr_full = (wptr == (DEPTH - 1));always @(posedge clk or negedge rst_n)if (!rst_n)wptr <= 'd0;else if (wr)if (wptr_full)wptr <= #DLY 'd0;elsewptr <= #DLY wptr + 1'b1;assign rptr_full = (rptr == (DEPTH - 1)); always @(posedge clk or negedge rst_n)if (!rst_n)rptr <= #DLY 'd0;else if (rd)if (rptr_full)rptr <= #DLY 'd0;elserptr <= #DLY rptr + 1'b1;// 4. Write/Read data to/from fifo      always @(posedge clk or negedge rst_n)if (!rst_n)for (i=0; i<DEPTH; i=i+1)fifo[i] <= #DLY 'd0;else if (wr)fifo[wptr] <= #DLY data_in;assign data_out = fifo[rptr];endmodule

日常工作实用同步FIFO(已Compile)相关推荐

  1. Google Sem日常工作实用工具

    Google控制台 https://search.google.com/search-console?resource_id=https%3A%2F%2Fwww.jiukaigroup.com%2F ...

  2. 常用小工具:一款好用、实用的“日常工作安排”桌面日历

    今天同为各位上班族朋友推荐一款实用.好用的小工具,日常工作安排 的电子日历 桌面日历(DesktopCal) 先说说我的使用需求和场景吧. 1. 接到客户电话后的事件记录,备忘 2. 领导安排的任务, ...

  3. 同步fifo的串并_同步fifo

    利用verilog实现FIFO 摘要:本文先介绍了一下关于FIFO的基本概念,工作原理,功能,同步与异步的分类等.然后基于RAM实现了一个同步FIFO.该FIFO通过巧妙地应用地址位和状态位的结合实现 ...

  4. 硬件架构的艺术:同步FIFO设计

    目录 1. 概述 2. 同步FIFO设计 2.1 同步FIFO结构 2.2 同步FIFO空满信号产生 2.2.1 时序逻辑产生空满 2.2.1.1 fifo满信号产生 2.2.1.2 fifo空信号产 ...

  5. IC设计 — 同步FIFO和异步FIFO设计实现(一)

    文章目录 1. FIFO介绍 1.1 FIFO参数 1.2 full/empty 检测 1.3 同步FIFO和异步FIFO 2. FIFO设计 2.1 二进制和格雷码 2.2 同步FIFO 2.3 异 ...

  6. 数字IC手撕代码-同步FIFO

    前言: 本专栏旨在记录高频笔面试手撕代码题,以备数字前端秋招,本专栏所有文章提供原理分析.代码及波形,所有代码均经过本人验证. 目录如下: 1.数字IC手撕代码-分频器(任意偶数分频) 2.数字IC手 ...

  7. 最新 docker 日常总结-实用宝典-先收藏

    docker 日常总结-实用宝典 问题 1. IPv4 forwarding disabled 2. Docker daemon socket权限不足 原因 解决方案 3. docker启动容器后就闪 ...

  8. 外贸员的日常工作分享

    外贸人米贸搜的日常工作流程为你整理如下.希望能帮到你: 外贸业务员的职责 一.业务人员在向国外买家询价前,要了解客户的基本信息,包括是否是终端客户,年采购量,消费区域,产品的用途,规格,质量要求,我公 ...

  9. 学计算机的该不该去医院信息科,医院信息科日常工作

    医院信息科日常工作 医院信息系统(HIS)在医院的管理运行中,发挥着不可替代的作用.如何管理和维护好(HIS)是目前医院管理的一项重要的内容,本文在这方面作了一些探讨仅供参考.随着信息技术的迅猛发展和 ...

最新文章

  1. 十一、springboot WebMvcConfigurer与HandlerInterceptorAdapter使用
  2. matlab-矩阵应用
  3. C++ ODB 框架(未实践使用)
  4. python官网下载安装教程-各种版本的Python下载安装教程
  5. gcc 5.2.0 编译安装笔记-20151110
  6. DeepMind详解新WaveNet:比原来快千倍,语音更自然 | 附论文
  7. 打开CMDLINE中的 ” earlyprink “ 参数
  8. mysql stored procedures with return values
  9. 微服务网关Gateway中Path路径过滤
  10. java.io.eof_java.io.IOException: java.io.EOFException: Unexpected end of input stream错误
  11. Linux块设备IO子系统
  12. WEB测试—兼容测试
  13. jsp input输入实时校验长度并提示_HotCRC未公开发布的高版本穷举输入规则(V3.02)...
  14. Red Hat EnterPrise Linux 5.4下web服务器的综合使用(普通站点、虚拟主机、安全性、...
  15. 设计模式相关书籍推荐
  16. 学习Python的几个优质平台
  17. 关于二维数组传参问题
  18. css中找不到bordercolor,CSS里bordercolor要怎样使用
  19. AWS亚马逊服务器配置过程
  20. EMV规范(五)——脱机数据认证

热门文章

  1. 基于STM32的半导体制冷片(TEC)温度控制系统设计
  2. 自然语言处理7——LDA
  3. oracle 10046跟踪自己,Oracle 10046事件跟踪绑定变量具体值
  4. Oracle修改、锁定、解锁用户
  5. SM3国密杂凑值算法的原理和c语言实现
  6. 【TP5】获取数据库注释信息
  7. SDS离全面EC(纠删码)还有多远?
  8. wangeditor java_如何使用wangEditor将数据存放到数据库中
  9. vulnhub Troll1
  10. 光线动画技术视频开场片头PR模板 Hi-Tech Logo Animation