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瀏覽量
43649 -
Verilog
+關注
關注
28文章
1351瀏覽量
110075 -
HDL
+關注
關注
8文章
327瀏覽量
47377
原文標題:求職攻略| 一題解決同步FIFO設計難題
文章出處:【微信號:達爾聞說,微信公眾號:達爾聞說】歡迎添加關注!文章轉載請注明出處。
發布評論請先 登錄
相關推薦
評論