当前位置:网站首页>[Verilog] I2S Master Test Bench
[Verilog] I2S Master Test Bench
2022-08-11 05:14:00 【LateLinux】
因工作需要,写了一个模拟I2S Master总线协议激励的test bench。左右声道的数据分别为16-bit,采样率为8kHz,因为需要重复发送,所以发送部分写了一个task,仿真中重复调用。
event bclk_negedge; // 定义一个event,叫“bclk_negedge”
always @(negedge i2s_bclk) begin
-> bclk_negedge; // 就是i2s_bclk的下降沿
end
task send_i2s_data(
input i2s_bclk, // bit clock
input [15:0] left_data, // left channel voice data
input [15:0] right_data, // right channel voice data
output ws, // word select, namely sampling rate
output sdo // serial data output
);
integer i; // counter
for (i=0;i<64;i=i+1) begin
if (i==0) ws = 1'b0; // cycle #0,
else if (i<=15) sdo = left_data[16-i]; // cycle #1 to #15
else if (i<=31) sdo = 1'b0; // cycle #16 to #31
else if (i==32) ws = 1'b1; // cycle #32
else if (i<=47) sdo = right_data[48-i]; // cycle #33 to #47
else sdo = 1'b0; // cycle #48 to #63
@(bclk_negedge); // 等待bclk_negedge事件
end
endtask //of send_i2s_data
// 以上for 循环中 if分支判断值可以做成几个宏,如果数据不是16-bit而是20-bit或24-bit的情况,方便修改。或者复杂一点用条件编译,没来得及研究。下面的TB中激励部分的代码,略去例化逻辑模块部分的代码。
module tb_XXXX();
real PERIOD_12M288 = 40.690; // 1/(12288000*2);
real PERIOD_2M048 = 244.141; // 1/(2048000*2);
real PERIOD_BCLK = 1953.125; // 1/(256000*2);
integer PERIOD_8K = 62500; // 1/(8000*2);
reg reset_n;
reg osc_clk;
reg i2s_bclk;
reg i2s_ws;
reg i2s_sdo;
initial begin // 生成晶振时钟
osc_clk = 1'b0;
forever begin
#PERIOD_12M288 osc_clk = 1'b0;
#PERIOD_12M288 osc_clk = 1'b1;
end
end // 生成晶振时钟
initial begin // 生成i2s的bit clock时钟
i2s_bclk = 1'b0;
forever begin
#PERIOD_BCLK i2s_bclk = 1'b0;
#PERIOD_BCLK i2s_bclk = 1'b1;
end
end // 生成i2s的bit clock时钟
initial begin // 主激励部分
#0 reset_n = 1'b0;
i2s_ws = 1'b1;
i2s_sdo = 1'b0;
#100 reset_n = 1'b1;
@(posedge dcm_lock)
reset_n = 1'b1;
#(1*PERIOD_BCLK)
send_i2s_data(i2s_bclk,16'hfc25,16'hda78,i2s_ws,i2s_sdo);
end // 主激励部分
// 例化DUT模块的代码,略
// ......
endmodule
边栏推荐
- (二)Docker安装Redis实战(持久化AOF和RDB快照)
- Redis - Data Types (Basic Instructions, String, List, Set, Hash, ZSet, BitMaps, HyperLogLog, GeoSpatial) / Publish and Subscribe
- MyEclipse数据库工具使用教程:使用驱动程序
- ARM结构体系4:嵌入式硬件平台接口开发
- 2022 building welder (building a special type of work) examination questions and simulation test
- You must understand - the nine built-in objects and four domain objects of JSP
- Tips to improve your productivity, you have to know - Navitcat shortcuts
- 课堂练习--0708
- 华为od德科面试数据算法解析 2022-8-10 迷宫问题
- 宝塔Linux环境下redis开启多端口
猜你喜欢
随机推荐
(三)Redis 如何进行压测
BitLocker的解密
切分字符串进行输出显示
pytorch基础之 pytorch 模型开发模板
代理模式(简要介绍)
ARM Architecture 4: Embedded Hardware Platform Interface Development
第二篇 DS5 Armv8 样例工程报错之GCC编译
你务必得明白——JSP的九大内置对象与四大域对象
Configure checkstyle in IDEA
2022 coal mine gas inspection test, simulation test question and answer
MFC 进程间通信(共享内存)
MySQL必知必会(初级篇)
【Cron】学习:cron 表达式
BGP综合实验
flask框架学习:debug与配置项
PCIe 接口 引脚定义 一览表
一个月闭关直接面进大厂,这份Android面试笔记是真的牛逼
guava RateLimiter uniform current limit
Win10远程连接(实现多用户同时连接)
Golden Warehouse Database KingbaseGIS User Manual (6.10. Geometric Object Operation Operator)





![[Embedded open source library] The use of cJSON, an efficient and streamlined json parsing library](/img/11/26ec988a23b239d7b01e2e29e3e32d.png)



