1 -------------------------------------------------------------------------------     3 -- Company    : SLAC National Accelerator Laboratory     4 -- Created    : 2016-05-13     5 -- Last update: 2016-06-09     6 -------------------------------------------------------------------------------     7 -- Description: UART Receiver     8 -------------------------------------------------------------------------------     9 -- This file is part of 'SLAC Firmware Standard Library'.    10 -- It is subject to the license terms in the LICENSE.txt file found in the     11 -- top-level directory of this distribution and at:     12 --    https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.     13 -- No part of 'SLAC Firmware Standard Library', including this file,     14 -- may be copied, modified, propagated, or distributed except according to     15 -- the terms contained in the LICENSE.txt file.    16 -------------------------------------------------------------------------------    19 use ieee.std_logic_1164.
all;
    20 use ieee.std_logic_unsigned.
all;
    25  --! @ingroup protocols_uart    39 architecture rtl 
of UartRx is
    41    type StateType is (WAIT_START_BIT_S, WAIT_8_S, WAIT_16_S, SAMPLE_RX_S, WAIT_STOP_S, WRITE_OUT_S);
    48       rxShiftReg   : slv(7 downto 0);
    49       rxShiftCount : slv(2 downto 0);
    50       baud16xCount : slv(3 downto 0);
    53    constant REG_INIT_C : RegType := (    56       rxState      => WAIT_START_BIT_S,    57       rxShiftReg   => (others => '0'),    58       rxShiftCount => (others => '0'),    59       baud16xCount => (others => '0'));
    61    signal r   : RegType := REG_INIT_C;
    93          -- Wait for RX to drop to indicate start bit    94          when WAIT_START_BIT_S =>    95             if (rxFall = '1') then    96                v.rxState      := WAIT_8_S;
    97                v.baud16xCount := "0000";
   100          -- Wait 8 baud16x counts to find center of start bit   101          -- Every rx bit is 16 baud16x pulses apart   104                v.baud16xCount := r.baud16xCount + 1;
   105                if (r.baud16xCount = "0111") then   106                   v.baud16xCount := "0000";
   107                   v.rxState      := WAIT_16_S;
   111          -- Wait 16 baud16x counts (center of next bit)   114                v.baud16xCount := r.baud16xCount + 1;
   115                if (r.baud16xCount = "1111") then   116                   v.rxState := SAMPLE_RX_S;
   120          -- Sample the rx line and shift it in.   121          -- Go back and wait 16 for the next bit unless last bit   123             v.rxShiftReg   := rxSync & r.rxShiftReg(7 downto 1);
   124             v.rxShiftCount := r.rxShiftCount + 1;
   125             v.rxState      := WAIT_16_S;
   126             if (r.rxShiftCount = "111") then   127                v.rxState := WAIT_STOP_S;
   130          -- Wait for the stop bit   132             if (rxSync = '1') then   133                v.rxState := WRITE_OUT_S;
   136          -- Put the parallel rx data on the output port.   140             v.rxState := WAIT_START_BIT_S;
   154    sync : 
process (
clk) 
is   156       if (rising_edge(clk)) then   157          r <= rin after TPD_G;
   161 end architecture RTL;
 
out rdDataslv( 7 downto  0)  
 
in rstsl  :=not    RST_POLARITY_G