16、【简答题】请用Verilog写出以下逻辑
Interface signals如下:
input clk_ck;
input rst_b(async reset);
input req_in;
output req_in_ack;
input [31:0] data_in;
output data_out_vld;
output [31:0] data_out;
模块功能需求如下:
2)当req_in和req_in_ack都为高时,说明本模块有能力接收data_in的数据;
3)在data_in的数据中找到特殊字符32’hA1B9_0000,特殊字符前的数据全部丢弃,特殊字符后的资料全部收下来;
4)当sync_fifo为非空的时候,将数据读出放到data_out上,并用data_out_vld指示数据的有效性。(15分)
解析:本题目主要考察了利用同步fifo实现对输入序列的检测
本题是一道关于同步fifo应用的题目,遇到这种类型的题目首先要根据题目中的要求逐条分析,然后依次在草稿纸上画出大致的模块框图、波形图,再编写RTL代码。
首先根据Interface signals需求1携带的信息,绘制出的模块框图如下所示:
然后根据需求2改进模块框图如下:
然后绘制波形图如下所示:
filter_data_store模块的HDL代码如下所示:
//------------------
01modulefilter_data_store(
02inputwireclk_ck,
03inputwirerst_b,
04inputwirereq_in,
05inputwire[31:0]data_in,
06
07outputregreq_in_ack,
08outputwire[31:0]data_out,
09outputregdata_out_vld
10);
11
12regdata_start;
13regdata_start_reg;
14wire[31:0]dout;
15wirefull;
16wireempty;
17
18always@(posedgeclk_ck ornegedgerst_b)
19if(!rst_b)
20req_in_ack <=1'b0;
21elseif(full ==1'b0)
22req_in_ack <=1'b1;
23elseif(empty ==1'b1)
24req_in_ack <=1'b0;
25
26always@(posedgeclk_ck ornegedgerst_b)
27if(!rst_b)
28data_start <=1'b0;
29elseif(req_in ==1'b1&&req_in_ack ==1'b1&&data_in ==32'hA1B9_0000)
30data_start <=1'b1;
31elseif(req_in ==1'b0)
32data_start <=1'b0;
33
34always@(posedgeclk_ck ornegedgerst_b)
35if(!rst_b)
36data_start_reg <=1'b0;
37else
38data_start_reg <=data_start;
39
40//-------sync_fifo_inst-------
41sync_fifo sync_fifo_inst(
42.clk_ck(clk_ck),//input clk_ck
43.rst_b (rst_b),//inputrst_b
44.wr_en (data_start),//inputwr_en
45.din (data_in),//input [31:0] din
46.rd_en (~empty),//input rd_en
47
48.dout (dout),//output [31:0] dout
49.full (full),//output full
50.empty (empty)//output empty
51);
52
53assigndata_out =dout;
54
55always@(posedgeclk_ck ornegedgerst_b)
56if(!rst_b)
57data_out_vld <=1'b0;
58elseif(data_start ==1'b0&&data_start_reg ==1'b1)
59data_out_vld <=1'b0;
60elseif(data_start_reg ==1'b1)
61data_out_vld <=1'b1;
62
63endmodule
//----------------还需要一个同步fifo模块,如果有时间建议自己用逻辑手写一个同步fifo。同步fifo模块的HDL代码如下所示://----------------01modulesync_fifo(02inputwireclk_ck,03inputwirerst_b,04inputwirewr_en,05inputwire[31:0]din,06inputwirerd_en,0708outputwire[31:0]dout,09outputwirefull,10outputwireempty11);1213reg[4:0]wr_cnt;14reg[4:0]rd_cnt;15reg[31:0]mem [15:0];16reg[31:0]dout_r;1718wire[3:0]wr_p;19wire[3:0]rd_p;2021assignwr_p =wr_cnt[3:0];22assignrd_p =rd_cnt[3:0];23assigndout =dout_r;24assignfull=(wr_cnt[4]!=rd_cnt[4]&&wr_p ==rd_p)?1'b1:1'b0;25assignempty =(wr_cnt ==rd_cnt)?1'b1:1'b0;2627always@(posedgeclk_ck ornegedgerst_b)28if(!rst_b)29begin30wr_cnt <=5'd0;31rd_cnt <=5'd0;32end33else34begin35if(!full &&wr_en)36begin37 mem[wr_p]<=din;38 wr_cnt <=wr_cnt +1'b1;39end40if(!empty &&rd_en)41begin42dout_r <=mem[rd_p];43rd_cnt <=rd_cnt +1'b1;44end45end4647endmodule//------------------Testbench如下所示://------------------
01moduletb_filter_data_store();0203regclk_ck;04regrst_b;05regreq_in;06reg[31:0]data_in;0708wirereq_in_ack;09wire[31:0]data_out;10wiredata_out_vld;1112//初始化系统时钟、全局复位13initialbegin14clk_ck =1'b1;15rst_b <=1'b0;16req_in <=1'b0;17data_in <=32'h0000_0000;18#2019rst_b <=1'b1;20@(posedgeclk_ck)21req_in <=1'b1;22data_in <=32'h0000_0001;23@(posedgeclk_ck)24data_in <=32'h0000_0002;25@(posedgeclk_ck)26data_in <=32'h0000_0003;27@(posedgeclk_ck)28data_in <=32'h0000_0004;29@(posedgeclk_ck)30data_in <=32'h0000_0005;31@(posedgeclk_ck)32data_in <=32'hA1B9_0000;33@(posedgeclk_ck)34data_in <=32'h0000_0006;35@(posedgeclk_ck)36data_in <=32'h0000_0007;37@(posedgeclk_ck)38data_in <=32'h0000_0008;39@(posedgeclk_ck)40data_in <=32'h0000_0009;41@(posedgeclk_ck)42req_in <=1'b0;43data_in <=32'h0000_0000;44req_in <=1'b0;45#100046$finish;47end4849always#10clk_ck =~clk_ck;5051//------filter_data_store_inst-------52filter_data_store filter_data_store_isnt(53.clk_ck(clk_ck),//inputclk_ck54.rst_b(rst_b),//inputrst_b55.req_in(req_in),//inputreq_in56.data_in(data_in),//input [31:0] data_in5758.req_in_ack(req_in_ack ),//output req_in_ack 59.data_out (data_out ),//output [31:0] data_out 60.data_out_vld(data_out_vld)//output data_out_vld 61);6263endmodule//----------------用QuestaSim仿真出的波形如下所示:
审核编辑:汤梓红
-
fifo
+关注
关注
3文章
387浏览量
43532 -
Verilog
+关注
关注
28文章
1343浏览量
109970 -
HDL
+关注
关注
8文章
327浏览量
47336
原文标题:求职攻略| 一题解决同步FIFO设计难题
文章出处:【微信号:达尔闻说,微信公众号:达尔闻说】欢迎添加关注!文章转载请注明出处。
发布评论请先 登录
相关推荐
评论