📄 rx_phase_det.vhd
字号:
else p_long <= '0'; end if; if last_cnt = 0 then preamble(0) <= ZERO; end if; if (last_cnt < max_thres) and (last_cnt >= min_thres) then preamble(0) <= MED; end if; preamble(3) <= preamble(2); preamble(2) <= preamble(1); preamble(1) <= preamble(0); end if; -- preamble detection if preamble(3) = LONG and preamble(2) = LONG and preamble(1) = SHORT and preamble(0) = SHORT then new_preamble <= PRE_X; elsif preamble(3) = LONG and preamble(2) = MED and preamble(1) = SHORT and preamble(0) = MED then new_preamble <= PRE_Y; elsif preamble(3) = LONG and preamble(2) = SHORT and preamble(1) = SHORT and preamble(0) = LONG then new_preamble <= PRE_Z; else new_preamble <= NONE; end if; -- delayed transition pulse for the state machine ztrans <= trans; new_pulse <= ztrans; end if; end if; end process; lock <= ilock; rx_channel_a <= irx_channel_a; -- State machine that hunt for and lock onto sub-frames FRX : process (wb_clk_i, rxen) begin if rxen = '0' then framerx <= IDLE; ilock <= '0'; zilock <= '0'; rx_data <= '0'; rx_data_en <= '0'; rx_block_start <= '0'; rx_frame_start <= '0'; irx_channel_a <= '0'; ud_a_en <= '0'; ud_b_en <= '0'; cs_a_en <= '0'; cs_b_en <= '0'; rx_error <= '0'; lock_evt <= '0'; bit_cnt <= 0; pre_cnt <= 0; short_idx <= '0'; frame_cnt <= 0; last_preamble <= NONE; elsif rising_edge(wb_clk_i) then zilock <= ilock; if zilock /= ilock then -- generate event for event reg. lock_evt <= '1'; else lock_evt <= '0'; end if; case framerx is when IDLE => -- wait for recevier to be enabled if valid = '1' then framerx <= HUNT; end if; when HUNT => -- wait for preamble detection frame_cnt <= 0; ilock <= '0'; rx_error <= '0'; if new_pulse = '1' then if new_preamble /= NONE then framerx <= FRAMESTART; end if; end if; when FRAMESTART => -- reset sub-frame bit counter bit_cnt <= 0; pre_cnt <= 0; if frame_cnt < FRAMES_FOR_LOCK then frame_cnt <= frame_cnt + 1; else ilock <= '1'; end if; last_preamble <= new_preamble; short_idx <= '0'; rx_frame_start <= '1'; rx_block_start <= '0'; framerx <= FRAME_RX; when FRAME_RX => -- receive complete sub-frame if new_pulse = '1' then if bit_cnt < 28 then case preamble(0) is when ZERO => short_idx <= '0'; when SHORT => if short_idx = '0' then short_idx <= '1'; else -- two short pulses is a logical '1' bit_cnt <= bit_cnt + 1; short_idx <= '0'; rx_data <= '1'; rx_data_en <= ilock; -- user data enable for the capture register if bit_cnt = 25 and ilock = '1' then ud_a_en <= irx_channel_a; ud_b_en <= not irx_channel_a; end if; -- channel status enable for the capture register if bit_cnt = 26 and ilock = '1' then cs_a_en <= irx_channel_a; cs_b_en <= not irx_channel_a; end if; end if; when MED => -- medium pulse is logical '0' bit_cnt <= bit_cnt + 1; rx_data <= '0'; rx_data_en <= ilock; short_idx <= '0'; -- user data enable for the capture register if bit_cnt = 25 and ilock = '1' then ud_a_en <= irx_channel_a; ud_b_en <= not irx_channel_a; end if; -- channel status enable for the capture register if bit_cnt = 26 and ilock = '1' then cs_a_en <= irx_channel_a; cs_b_en <= not irx_channel_a; end if; when LONG => short_idx <= '0'; when others => framerx <= HUNT; end case; else -- there should be 4 pulses in preamble if pre_cnt < 7 then pre_cnt <= pre_cnt + 1; else rx_error <= '1'; framerx <= HUNT; end if; -- check for correct preamble here if pre_cnt = 3 then case last_preamble is when PRE_X => if new_preamble = PRE_Y then framerx <= FRAMESTART; irx_channel_a <= '0'; else rx_error <= '1'; framerx <= HUNT; end if; when PRE_Y => if new_preamble = PRE_X or new_preamble = PRE_Z then irx_channel_a <= '1'; -- start of new block? if new_preamble = PRE_Z then rx_block_start <= '1'; end if; framerx <= FRAMESTART; else rx_error <= '1'; framerx <= HUNT; end if; when PRE_Z => if new_preamble = PRE_Y then irx_channel_a <= '0'; framerx <= FRAMESTART; else rx_error <= '1'; framerx <= HUNT; end if; when others => rx_error <= '1'; framerx <= HUNT; end case; end if; end if; else rx_data_en <= '0'; rx_block_start <= '0'; rx_frame_start <= '0'; ud_a_en <= '0'; ud_b_en <= '0'; cs_a_en <= '0'; cs_b_en <= '0'; end if; when others => framerx <= IDLE; end case; end if; end process FRX;end rtl;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -