📄 tx_encoder.vhd
字号:
else if spdif_clk_en = '1' then -- SPDIF clock is twice the bit rate case framest is when IDLE => bit_cnt <= 0; frame_cnt <= 0; inv_preamble <= '0'; toggle <= '0'; framest <= BLOCK_START; when BLOCK_START => -- Start of channels status block/Ch. A evt_lcsbf <= '0'; evt_hcsbf <= '0'; chb_samp_ack <= '0'; toggle <= not toggle; -- Each bit uses two clock enables, if toggle = '1' then -- counted by the toggle bit. if bit_cnt < 31 then bit_cnt <= bit_cnt + 1; else bit_cnt <= 0; if send_audio = '1' then cha_samp_ack <= '1'; end if; framest <= CHANNEL_B; end if; end if; -- Block start uses preamble Z. if bit_cnt < 4 then if toggle = '0' then spdif_out <= Z_PREAMBLE(2 * bit_cnt) xor inv_preamble; else spdif_out <= Z_PREAMBLE(2 * bit_cnt + 1) xor inv_preamble; end if; par_cnt <= 0; elsif bit_cnt > 3 and bit_cnt <= 31 then spdif_out <= encode_bit(bit_cnt, valid, frame_cnt, par_cnt, active_user_data, active_ch_status, audio, toggle, spdif_out); if bit_cnt = 31 then inv_preamble <= encode_bit(bit_cnt, valid, frame_cnt, par_cnt, active_user_data, active_ch_status, audio, toggle, spdif_out); end if; if toggle = '0' then if bit_cnt > 3 and bit_cnt < 31 and par_vector(bit_cnt - 4) = '1' then par_cnt <= par_cnt + 1; end if; end if; end if; when CHANNEL_A => -- Sub-frame: channel A. evt_lcsbf <= '0'; evt_hcsbf <= '0'; chb_samp_ack <= '0'; toggle <= not toggle; if toggle = '1' then if bit_cnt < 31 then bit_cnt <= bit_cnt + 1; else bit_cnt <= 0; if spdif_out = '1' then inv_preamble <= '1'; else inv_preamble <= '0'; end if; if send_audio = '1' then cha_samp_ack <= '1'; end if; framest <= CHANNEL_B; end if; end if; -- Channel A uses preable X. if bit_cnt < 4 then if toggle = '0' then spdif_out <= X_PREAMBLE(2 * bit_cnt) xor inv_preamble; else spdif_out <= X_PREAMBLE(2 * bit_cnt + 1) xor inv_preamble; end if; par_cnt <= 0; elsif bit_cnt > 3 and bit_cnt <= 31 then spdif_out <= encode_bit(bit_cnt, valid, frame_cnt, par_cnt, active_user_data, active_ch_status, audio, toggle, spdif_out); if bit_cnt = 31 then inv_preamble <= encode_bit(bit_cnt, valid, frame_cnt, par_cnt, active_user_data, active_ch_status, audio, toggle, spdif_out); end if; if toggle = '0' then if bit_cnt > 3 and bit_cnt < 31 and par_vector(bit_cnt - 4) = '1' then par_cnt <= par_cnt + 1; end if; end if; end if; when CHANNEL_B => -- Sub-frame: channel B. cha_samp_ack <= '0'; toggle <= not toggle; if toggle = '1' then if bit_cnt < 31 then bit_cnt <= bit_cnt + 1; else bit_cnt <= 0; valid <= not conf_txdata; if spdif_out = '1' then inv_preamble <= '1'; else inv_preamble <= '0'; end if; send_audio <= conf_txdata; -- 1 if audio samples sohuld be sent if send_audio = '1' then chb_samp_ack <= '1'; end if; if frame_cnt < 191 then -- One block is 192 frames frame_cnt <= frame_cnt + 1; if frame_cnt = 96 then evt_lcsbf <= '1'; end if; framest <= CHANNEL_A; else frame_cnt <= 0; evt_hcsbf <= '1'; framest <= BLOCK_START; end if; end if; end if; -- Channel B uses preable Y. if bit_cnt < 4 then if toggle = '0' then spdif_out <= Y_PREAMBLE(2 * bit_cnt) xor inv_preamble; else spdif_out <= Y_PREAMBLE(2 * bit_cnt + 1) xor inv_preamble; end if; par_cnt <= 0; elsif bit_cnt > 3 and bit_cnt <= 31 then spdif_out <= encode_bit(bit_cnt, valid, frame_cnt, par_cnt, active_user_data, active_ch_status, audio, toggle, spdif_out); if bit_cnt = 31 then inv_preamble <= encode_bit(bit_cnt, valid, frame_cnt, par_cnt, active_user_data, active_ch_status, audio, toggle, spdif_out); end if; if toggle = '0' then if bit_cnt > 3 and bit_cnt < 31 and par_vector(bit_cnt - 4) = '1' then par_cnt <= par_cnt + 1; end if; end if; end if; when others => framest <= IDLE; end case; end if; end if; end if; end process FRST;-- Audio data latching DA32 : if DATA_WIDTH = 32 generate ALAT : process (wb_clk_i) begin if rising_edge(wb_clk_i) then if send_audio = '0' then audio(23 downto 0) <= (others => '0'); else case to_integer(unsigned(conf_mode)) is when 0 => -- 16 bit audio audio(23 downto 8) <= sample_data(15 downto 0); audio(7 downto 0) <= (others => '0'); when 1 => -- 17 bit audio audio(23 downto 7) <= sample_data(16 downto 0); audio(6 downto 0) <= (others => '0'); when 2 => -- 18 bit audio audio(23 downto 6) <= sample_data(17 downto 0); audio(5 downto 0) <= (others => '0'); when 3 => -- 19 bit audio audio(23 downto 5) <= sample_data(18 downto 0); audio(4 downto 0) <= (others => '0'); when 4 => -- 20 bit audio audio(23 downto 4) <= sample_data(19 downto 0); audio(3 downto 0) <= (others => '0'); when 5 => -- 21 bit audio audio(23 downto 3) <= sample_data(20 downto 0); audio(2 downto 0) <= (others => '0'); when 6 => -- 22 bit audio audio(23 downto 2) <= sample_data(21 downto 0); audio(1 downto 0) <= (others => '0'); when 7 => -- 23 bit audio audio(23 downto 1) <= sample_data(22 downto 0); audio(0) <= '0'; when 8 => -- 24 bit audio audio(23 downto 0) <= sample_data(23 downto 0); when others => -- unsupported modes audio(23 downto 0) <= (others => '0'); end case; end if; end if; end process ALAT; end generate DA32; DA16 : if DATA_WIDTH = 16 generate ALAT : process (wb_clk_i) begin if rising_edge(wb_clk_i) then if send_audio = '0' then audio(23 downto 0) <= (others => '0'); else audio(23 downto 8) <= sample_data(15 downto 0); audio(7 downto 0) <= (others => '0'); end if; end if; end process ALAT; end generate DA16;-- Parity vector. These bits are counted to generate even parity par_vector(23 downto 0) <= audio(23 downto 0); par_vector(24) <= valid; par_vector(25) <= active_user_data(frame_cnt); par_vector(26) <= active_ch_status(frame_cnt);-- Channel status and user datat to be used if buffers are disabled.-- User data is then all zero, while channel status bits are taken from-- register TxChStat. def_user_data(191 downto 0) <= (others => '0'); def_ch_status(0) <= '0'; -- consumer mode def_ch_status(1) <= chstat_audio; -- audio bit def_ch_status(2) <= chstat_copy; -- copy right def_ch_status(5 downto 3) <= "000" when chstat_preem = '0' else "001"; -- pre-emphasis def_ch_status(7 downto 6) <= "00"; def_ch_status(14 downto 8) <= (others => '0'); def_ch_status(15) <= chstat_gstat; -- generation status def_ch_status(23 downto 16) <= (others => '0'); def_ch_status(27 downto 24) <= "0000" when chstat_freq = "00" else "0010" when chstat_freq = "01" else "0011" when chstat_freq = "10" else "0001"; def_ch_status(191 downto 28) <= (others => '0');-- Generate channel status vector based on configuration register setting. active_ch_status <= ch_stat_a when conf_chsten = "01" else ch_stat_a when conf_chsten = "10" and framest = CHANNEL_A else ch_stat_b when conf_chsten = "10" and framest = CHANNEL_B else def_ch_status;-- Generate user data vector based on configuration register setting. active_user_data <= user_data_a when conf_udaten = "01" else user_data_a when conf_udaten = "10" and framest = CHANNEL_A else user_data_b when conf_udaten = "10" and framest = CHANNEL_B else def_user_data; end rtl;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -