⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tb_i2s.vhd

📁 这是一个I2S接口的VHDL实现源代码
💻 VHD
📖 第 1 页 / 共 2 页
字号:
      wb_clk_i => wb_clk_o,      wb_rst_i => wb_rst_o,      wb_sel_i => wb_sel_o,      wb_stb_i => wb_stb_32bit_tx2,      wb_we_i => wb_we_o,      wb_cyc_i => wb_cyc_o,      wb_bte_i => wb_bte_o,      wb_cti_i => wb_cti_o,      wb_adr_i => wb_adr_o(5 downto 0),      wb_dat_i => wb_dat_o(31 downto 0),      wb_ack_o => tx2_ack,      wb_dat_o => tx2_dat_i,      tx_int_o => tx2_int_o,      i2s_sd_o => i2s_sd2,      i2s_sck_o => i2s_sck2,      i2s_ws_o => i2s_ws2);-- I2S receiver 1, master mode  IRX32M: rx_i2s_topm     generic map (DATA_WIDTH => 32,                 ADDR_WIDTH => 6)    port map (      -- Wishbone interface      wb_clk_i => wb_clk_o,      wb_rst_i => wb_rst_o,      wb_sel_i => wb_sel_o,      wb_stb_i => wb_stb_32bit_rx1,      wb_we_i => wb_we_o,      wb_cyc_i => wb_cyc_o,      wb_bte_i => wb_bte_o,      wb_cti_i => wb_cti_o,      wb_adr_i => wb_adr_o(5 downto 0),      wb_dat_i => wb_dat_o(31 downto 0),      i2s_sd_i => i2s_sd1,      wb_ack_o => rx1_ack,      wb_dat_o => rx1_dat_i,      rx_int_o => rx1_int_o,      i2s_sck_o => i2s_sck1,      i2s_ws_o => i2s_ws1);-- I2S receiver 2, slave mode  IRX32S: rx_i2s_tops     generic map (DATA_WIDTH => 32,                 ADDR_WIDTH => 6)    port map (      -- Wishbone interface      wb_clk_i => wb_clk_o,      wb_rst_i => wb_rst_o,      wb_sel_i => wb_sel_o,      wb_stb_i => wb_stb_32bit_rx2,      wb_we_i => wb_we_o,      wb_cyc_i => wb_cyc_o,      wb_bte_i => wb_bte_o,      wb_cti_i => wb_cti_o,      wb_adr_i => wb_adr_o(5 downto 0),      wb_dat_i => wb_dat_o(31 downto 0),      i2s_sd_i => i2s_sd2,      i2s_sck_i => i2s_sck2,      i2s_ws_i => i2s_ws2,      wb_ack_o => rx2_ack,      wb_dat_o => rx2_dat_i,      rx_int_o => rx2_int_o);  -- Main test process  MAIN: process    variable read_32bit : std_logic_vector(31 downto 0);    variable idx : integer;    -- Make simplified versions of procedures in wb_tb_pack    procedure wb_write_32 (      constant ADDRESS: in natural;       constant DATA: in natural) is     begin      wb_write(ADDRESS, DATA, wb_adr_o, wb_dat_o(31 downto 0), wb_cyc_o,               wb_sel_o, wb_we_o, wb_clk_o, wb_ack_i);    end;        procedure wb_check_32 (      constant ADDRESS: in natural;      constant EXP_DATA : in natural) is    begin      wb_check(ADDRESS, EXP_DATA, wb_adr_o, wb_dat_i(31 downto 0), wb_cyc_o,               wb_sel_o, wb_we_o, wb_clk_o, wb_ack_i);    end;        procedure wb_read_32 (      constant ADDRESS: in natural) is    begin       wb_read(ADDRESS, read_32bit, wb_adr_o, wb_dat_i(31 downto 0), wb_cyc_o,              wb_sel_o, wb_we_o, wb_clk_o, wb_ack_i);    end;      begin    message("Simulation start with system reset.");    wb_rst_o <= '1'; -- system reset    wb_sel_o <= '0';    wb_stb_o <= '0';    wb_sel_o <= '0';    wb_we_o <= '0';    wb_cyc_o <= '0';    wb_bte_o <= "00";    wb_cti_o <= "000";    wb_adr_o <= (others => '0');    wb_dat_o <= (others => '0');    wait for 200 ns;    wb_rst_o <= '0';        message("Check receiver version registers:");    wb_check_32(RX1_VERSION, 16#000001b1#);    wb_check_32(RX2_VERSION, 16#00000191#);    message("Check transmitter version registers:");    wb_check_32(TX1_VERSION, 16#00000191#);    wb_check_32(TX2_VERSION, 16#000001b1#);    message("Fill up sample buffers with test signal, ");    message("ramp up in left, ramp down in right:");    SGEN: for i in 0 to 15 loop      wb_write_32(TX1_BUF_BASE + 2*i, (32768 + i*497)*256);  -- left      wb_write_32(TX1_BUF_BASE + 2*i + 1, (32767 - i*497)*256);  -- right      wb_write_32(TX2_BUF_BASE + 2*i, (32767 - i*497)*16);  -- left      wb_write_32(TX2_BUF_BASE + 2*i + 1, (32768 + i*497)*16);  --right    end loop;     message("*** Test of master TX and slave RX ***");    message("Enable transmitter 2:");    wb_write_32(TX2_INTMASK, 16#00000003#);  -- enable interrupts    wb_write_32(TX2_CONFIG, 16#00140703#);  -- 20bit resolution    message("Enable recevier 2:");    wb_write_32(RX2_INTMASK, 16#00000003#);  -- enable interrupts    wb_write_32(RX2_CONFIG, 16#00180003#);  -- 24bit resolution    wait_for_event("Wait for transmitter 2 LSBF interrupt", 150 us, tx2_int_o);    wait_for_event("Wait for recevier 2 LSBF interrupt", 150 us, rx2_int_o);    message("Clear transmitter LSBF interrupt:");    wb_write_32(TX2_INTSTAT, 16#00000001#);    wb_check_32(TX2_INTSTAT, 16#00000000#);    signal_check("tx2_int_o", '0', tx2_int_o);    message("Clear receiver LSBF interrupt:");    wb_write_32(RX2_INTSTAT, 16#00000001#);    wb_check_32(RX2_INTSTAT, 16#00000000#);    signal_check("rx2_int_o", '0', rx2_int_o);    message("Check received data, lower sample buffer:");    wb_read_32(RX2_BUF_BASE);    -- calculate which index this word was generated with    idx := (32767 - to_integer(unsigned(read_32bit(31 downto 8)))) / 497;    -- then check for correct values    CHKL: for i in 0 to 7 - idx loop      wb_check_32(RX2_BUF_BASE + 2*i, (32767 - (i+idx)*497)*256);      wb_check_32(RX2_BUF_BASE + 2*i + 1, (32768 + (i+idx)*497)*256);    end loop;    wait_for_event("Wait for transmitter 2 HSBF interrupt", 150 us, tx2_int_o);    wait_for_event("Wait for recevier 2 HSBF interrupt", 150 us, rx2_int_o);    message("Clear transmitter HSBF interrupt:");    wb_write_32(TX2_INTSTAT, 16#00000002#);    wb_check_32(TX2_INTSTAT, 16#00000000#);    signal_check("tx2_int_o", '0', tx2_int_o);    message("Clear receiver HSBF interrupt:");    wb_write_32(RX2_INTSTAT, 16#00000002#);    wb_check_32(RX2_INTSTAT, 16#00000000#);    signal_check("rx2_int_o", '0', rx2_int_o);    message("Check received data, upper sample buffer:");    CHKH: for i in 8 - idx to 15 - idx loop      wb_check_32(RX2_BUF_BASE + 2*i, (32767 - (i+idx)*497)*256);      wb_check_32(RX2_BUF_BASE + 2*i + 1, (32768 + (i+idx)*497)*256);    end loop;    message("*** Test of slave TX and master RX ***");    message("Enable transmitter 1:");    wb_write_32(TX1_INTMASK, 16#00000003#);  -- enable interrupts    wb_write_32(TX1_CONFIG, 16#00180007#);  -- 24bit resolution    message("Enable recevier 1:");    wb_write_32(RX1_INTMASK, 16#00000003#);  -- enable interrupts    wb_write_32(RX1_CONFIG, 16#00100707#);  -- 16bit resolution              wait_for_event("Wait for transmitter 1 LSBF interrupt", 150 us, tx1_int_o);    message("Clear LSBF interrupt:");    wb_write_32(TX1_INTSTAT, 16#00000001#);    wb_check_32(TX1_INTSTAT, 16#00000000#);    signal_check("tx1_int_o", '0', tx1_int_o);    wait_for_event("Wait for recevier 1 LSBF interrupt", 150 us, rx1_int_o);    message("Clear LSBF interrupt:");    wb_write_32(RX1_INTSTAT, 16#00000001#);    wb_check_32(RX1_INTSTAT, 16#00000000#);    signal_check("rx1_int_o", '0', rx1_int_o);    message("Check received data (#1), lower sample buffer:");    wb_read_32(RX1_BUF_BASE);    -- calculate which index this word was generated with    idx := (32767 - to_integer(unsigned(read_32bit(15 downto 0)))) / 497;    -- then check for correct values    CHKL1: for i in 0 to 7 - idx loop      wb_check_32(RX1_BUF_BASE + 2*i, 32768 + (i+idx)*497);      wb_check_32(RX1_BUF_BASE + 2*i + 1, 32767 - (i+idx)*497);    end loop;    wait_for_event("Wait for transmitter 1 HSBF interrupt", 150 us, tx1_int_o);    message("Clear HSBF interrupt:");    wb_write_32(TX1_INTSTAT, 16#00000002#);    wb_check_32(TX1_INTSTAT, 16#00000000#);    signal_check("tx1_int_o", '0', tx1_int_o);    wait_for_event("Wait for recevier 1 HSBF interrupt", 150 us, rx1_int_o);    message("Clear HSBF interrupt:");    wb_write_32(RX1_INTSTAT, 16#00000002#);    wb_check_32(RX1_INTSTAT, 16#00000000#);    signal_check("rx1_int_o", '0', rx1_int_o);    message("Check received data (#1), higher sample buffer:");    CHKH1: for i in 8 - idx to 15 - idx loop      wb_check_32(RX1_BUF_BASE + 2*i, 32768 + (i+idx)*497);      wb_check_32(RX1_BUF_BASE + 2*i + 1, 32767 - (i+idx)*497);    end loop;        sim_report("");    report "End of simulation! (ignore this failure)"      severity failure;    wait;  end process MAIN;  -- Bus strobe generator based on address. 32bit recevier mapped to addr. 0x1000-- 32bit transmitter mapped to address 0x2000  wb_stb_32bit_rx1 <= '1' when wb_adr_o(15 downto 12) = "0001" else '0';  wb_stb_32bit_tx1 <= '1' when wb_adr_o(15 downto 12) = "0010" else '0';  wb_stb_32bit_rx2 <= '1' when wb_adr_o(15 downto 12) = "0011" else '0';  wb_stb_32bit_tx2 <= '1' when wb_adr_o(15 downto 12) = "0100" else '0';  -- Clock process, 50Mhz Wishbone master freq.  CLKGEN: process  begin    wb_clk_o <= '0';    wait for 10 ns;    wb_clk_o <= '1';    wait for 10 ns;  end process CLKGEN;  end behav;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -