mc8051_siu_rtl.vhd
上传用户:sztwq510
上传日期:2007-04-20
资源大小:209k
文件大小:48k
源码类别:

VHDL/FPGA/Verilog

开发平台:

Matlab

  1. -------------------------------------------------------------------------------
  2. --                                                                           --
  3. --          X       X   XXXXXX    XXXXXX    XXXXXX    XXXXXX      X          --
  4. --          XX     XX  X      X  X      X  X      X  X           XX          --
  5. --          X X   X X  X         X      X  X      X  X          X X          --
  6. --          X  X X  X  X         X      X  X      X  X         X  X          --
  7. --          X   X   X  X          XXXXXX   X      X   XXXXXX      X          --
  8. --          X       X  X         X      X  X      X         X     X          --
  9. --          X       X  X         X      X  X      X         X     X          --
  10. --          X       X  X      X  X      X  X      X         X     X          --
  11. --          X       X   XXXXXX    XXXXXX    XXXXXX    XXXXXX      X          --
  12. --                                                                           --
  13. --                                                                           --
  14. --                       O R E G A N O   S Y S T E M S                       --
  15. --                                                                           --
  16. --                            Design & Consulting                            --
  17. --                                                                           --
  18. -------------------------------------------------------------------------------
  19. --                                                                           --
  20. --         Web:           http://www.oregano.at/                             --
  21. --                                                                           --
  22. --         Contact:       mc8051@oregano.at                                  --
  23. --                                                                           --
  24. -------------------------------------------------------------------------------
  25. --                                                                           --
  26. --  MC8051 - VHDL 8051 Microcontroller IP Core                               --
  27. --  Copyright (C) 2001 OREGANO SYSTEMS                                       --
  28. --                                                                           --
  29. --  This library is free software; you can redistribute it and/or            --
  30. --  modify it under the terms of the GNU Lesser General Public               --
  31. --  License as published by the Free Software Foundation; either             --
  32. --  version 2.1 of the License, or (at your option) any later version.       --
  33. --                                                                           --
  34. --  This library is distributed in the hope that it will be useful,          --
  35. --  but WITHOUT ANY WARRANTY; without even the implied warranty of           --
  36. --  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        --
  37. --  Lesser General Public License for more details.                          --
  38. --                                                                           --
  39. --  Full details of the license can be found in the file LGPL.TXT.           --
  40. --                                                                           --
  41. --  You should have received a copy of the GNU Lesser General Public         --
  42. --  License along with this library; if not, write to the Free Software      --
  43. --  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  --
  44. --                                                                           --
  45. -------------------------------------------------------------------------------
  46. --
  47. --
  48. --         Author:                 Roland H鰈ler
  49. --
  50. --         Filename:               mc8051_siu_rtl.vhd
  51. --
  52. --         Date of Creation:       Mon Aug  9 12:14:48 1999
  53. --
  54. --         Version:                $Revision: 1.7 $
  55. --
  56. --         Date of Latest Version: $Date: 2002/01/30 16:42:16 $
  57. --
  58. --
  59. --         Description: Serial interface unit for the mc8051 microcontroller.
  60. --
  61. --
  62. --
  63. --
  64. -------------------------------------------------------------------------------
  65. architecture rtl of mc8051_siu is
  66.   signal s_pre_count    : unsigned(5 downto 0);  -- these three signals provide
  67.   signal s_m0_shift_en  : std_logic;             -- masks out every sixteenth
  68.                                                  -- rising edge of clk
  69.   signal s_m2_shift_en  : std_logic;             -- mode 2 shift enable
  70.   signal s_m13_shift_en : std_logic;             -- mode 1 and 3 shift enable
  71.   signal s_ff0          : std_logic;             -- flipflop for edge dedection
  72.   signal s_ff1          : std_logic;             -- flipflop for edge dedection
  73.   signal s_tf           : std_logic;             -- synchronised timer flag
  74.   signal s_mode         : unsigned(1 downto 0);  -- mode
  75.   signal s_sm2          : std_logic;             -- multi processor comm. bit
  76.   signal s_detect       : std_logic;             -- indicates start of recept. 
  77.   signal s_ren          : std_logic;             -- receive enable
  78.   signal s_rxd_val      : std_logic;             -- received data bit
  79.   signal s_txdm0        : std_logic;             -- shift clock for m0
  80.   signal s_ri           : std_logic;             -- external receive interrupt 
  81.   signal s_trans        : std_logic;             -- enable transmission 
  82.   signal s_recv_done    : std_logic;             -- receive interrupt
  83.   signal s_tran_done    : std_logic;             -- transmit interrupt
  84.   signal s_rb8          : std_logic;             -- 8th data bit
  85.   signal s_tb8          : std_logic;             -- 8th data bit
  86.   signal s_recv_state   : unsigned(3 downto 0);  -- state reg. of receive unit
  87.   signal s_tran_state   : unsigned(3 downto 0);  -- state reg. of transmit unit
  88.   signal s_rxd_ff0      : std_logic;             -- sample flip-flop
  89.   signal s_rxd_ff1      : std_logic;             -- sample flip-flop
  90.   signal s_rxd_ff2      : std_logic;             -- sample flip-flop
  91.   signal s_det_ff0      : std_logic;             -- rec. detect flip-flop
  92.   signal s_det_ff1      : std_logic;             -- rec. detect flip-flop
  93.   signal s_tran_sh      : unsigned(10 downto 0); -- transmission shift register
  94.   signal s_recv_sh      : unsigned(7 downto 0);  -- reception shift register
  95.   signal s_recv_buf     : unsigned(7 downto 0);  -- reception buffer register
  96.   signal s_m13_ff0      : std_logic;             -- generates an enable singal
  97.   signal s_m13_ff1      : std_logic;             -- generates an enable singal
  98.   
  99. begin                 -- architecture rtl
  100.     
  101.   s_mode(1) <= scon_i(4);               -- defines the 4 operating modes
  102.   s_mode(0) <= scon_i(3); 
  103.   s_ren  <= scon_i(1);                  -- receive enable
  104.   s_sm2  <= scon_i(2);                  -- 1 time or half time baud rate
  105.   s_tb8  <= scon_i(0);                  -- 8th data bit for transmission
  106.   s_ri   <= scon_i(5);                  -- the receive interrupt bit of the
  107.                                         -- control unit
  108.   sbuf_o <= std_logic_vector(s_recv_buf);  -- the receive buffer output
  109.   scon_o(0) <= s_recv_done;             -- set when reception is completed
  110.   scon_o(1) <= s_tran_done;             -- set when transmission is completed
  111.   scon_o(2) <= s_rb8;                   -- 8th data bit of reception  
  112. -------------------------------------------------------------------------------
  113.   -- The two flip flops are updated every rising clock edge of clk.
  114.   -- If a rising edge
  115.   -- on the port tf_i is dedected the signal s_tf is set to 1 for one period.
  116.   --
  117.   -- The transmission start signal s_trans is generated and held high till
  118.   -- the statemachine has been launched with its first shift.
  119.   --
  120.   -- The shift clock for mode0 is generated. It toggles with the half
  121.   -- s_m0_shift_en rate.
  122.   
  123.   s_tf <= '1' when (s_ff0 = '1' and s_ff1 = '0') else '0';      
  124.   p_sample_tf: process (clk,
  125.                         reset)
  126.       
  127.     begin
  128.       if reset = '1' then
  129.         s_ff0 <= '0';
  130.         s_ff1 <= '0';
  131.         s_trans <= '0';
  132.       else
  133.         if clk'event and clk = '1' then
  134.           s_ff0 <= tf_i;
  135.           s_ff1 <= s_ff0;
  136.           
  137.           if trans_i = '1' then
  138.             s_trans <= '1';
  139.           else
  140.             case s_mode is
  141.               when ("00") =>
  142.                 if s_m0_shift_en = '1' then
  143.                   s_trans <= '0';
  144.                 end if;
  145.               when ("01") => 
  146.                 if s_m13_shift_en = '1' then
  147.                   s_trans <= '0';
  148.                 end if;
  149.               when ("10") => 
  150.                 if s_m2_shift_en = '1' then
  151.                   s_trans <= '0';
  152.                 end if;
  153.               when others => 
  154.                 if s_m13_shift_en = '1' then
  155.                   s_trans <= '0';
  156.                 end if;
  157.             end case;
  158.           end if;
  159.         end if;    
  160.       end if;    
  161.   end process p_sample_tf;
  162.       
  163. -------------------------------------------------------------------------------
  164.   -- The register s_pre_count is driven with the system clock clk. So a
  165.   -- good enable signal (which is stable when clk has its rising edge) can be
  166.   -- derived to mask out every pulse of clk needed.
  167.   -- s_m0_shift_en activates every sixteenth clock cycle
  168.   -- s_m2_shift_en activates baud rates of 1/32 or 1/64 the clock frequenzy
  169.   -- depending on signal smod_i
  170.   -- s_m13_shift_en activates baud rates depending on timer/counter1 flag
  171.       
  172.   s_m0_shift_en <= '1' when s_pre_count(3 downto 0) = conv_unsigned(15,5)
  173.                    else '0';
  174.   s_m2_shift_en <= '1' when (s_pre_count(4 downto 0) = conv_unsigned(31,5) and
  175.                              smod_i = '1') or
  176.                             (s_pre_count = conv_unsigned(63,6) and
  177.                              smod_i = '0')
  178.                    else '0';
  179.   s_m13_shift_en <= '1' when s_m13_ff0 = '1' and s_m13_ff1 = '0' else '0';
  180.       
  181.   p_divide_clk: process (clk, reset)
  182.     
  183.     begin
  184.       if reset = '1' then
  185.         s_pre_count <= conv_unsigned(0,6);
  186.         s_m13_ff0 <= '0';
  187.         s_m13_ff1 <= '0';
  188.       else
  189.         if clk'event and clk='1' then
  190.             
  191.          s_m13_ff1 <= s_m13_ff0;
  192.          
  193.          if smod_i = '1' then
  194.             if s_pre_count(3 downto 0) = conv_unsigned(15,4) then
  195.               s_m13_ff0 <= '1';
  196.             else
  197.               s_m13_ff0 <= '0';
  198.             end if;
  199.           else
  200.             if s_pre_count(4 downto 0) = conv_unsigned(31,5) then
  201.               s_m13_ff0 <= '1';
  202.             else
  203.               s_m13_ff0 <= '0';
  204.             end if;              
  205.           end if;
  206.             
  207.           if s_detect = '1' then
  208.             s_pre_count <= conv_unsigned(0,6);
  209.           else
  210.             if s_mode=conv_unsigned(0,2) or s_mode=conv_unsigned(2,2) then 
  211.               s_pre_count <= s_pre_count + conv_unsigned(1,1);
  212.             else
  213.               if s_tf = '1' then
  214.                 s_pre_count <= s_pre_count + conv_unsigned(1,1);  
  215.               end if;
  216.             end if;              
  217.           end if;
  218.         end if;
  219.       end if;    
  220.   end process p_divide_clk;
  221. -------------------------------------------------------------------------------
  222.   -- This section samples the serial input for data detection, that is a
  223.   -- 1-to-0 transition at rxd in state "0000".
  224.   -- In all other states this unit reads the data bits depending on the baud
  225.   -- rate. In mode0 this section is not active.
  226.   s_detect <= '1' when s_det_ff0 = '0' and s_det_ff1 = '1' else '0'; 
  227.   s_rxd_val <= '1' when (s_rxd_ff0 = '1' and s_rxd_ff1 = '1') or
  228.                         (s_rxd_ff0 = '1' and s_rxd_ff2 = '1') or
  229.                         (s_rxd_ff1 = '1' and s_rxd_ff2 = '1') else '0';
  230.                
  231.   p_sample_rx: process (clk,
  232.                         reset)
  233.     
  234.   begin
  235.     if reset = '1' then
  236.       s_rxd_ff0 <= '0';
  237.       s_rxd_ff1 <= '0';
  238.       s_rxd_ff2 <= '0';
  239.       s_det_ff0 <= '0';
  240.       s_det_ff1 <= '0';
  241.     else
  242.       if clk'event and clk='1' then          
  243.         if s_recv_state = conv_unsigned(0,4) then   -- state "0000" means
  244.           if s_ren = '1' then                       -- to listen for a 1 to 0
  245.             case s_mode is                          -- transition
  246.               when ("01") | ("11") => 
  247.                 if smod_i = '1' then
  248.                   if s_tf = '1' then
  249.                     s_det_ff0 <= rxd_i;  
  250.                     s_det_ff1 <= s_det_ff0;
  251.                   end if;
  252.                 else
  253.                   if s_pre_count(0) = '1' then
  254.                     s_det_ff0 <= rxd_i;  
  255.                     s_det_ff1 <= s_det_ff0;                    
  256.                   end if;
  257.                 end if;
  258.               when ("10") =>
  259.                 if smod_i = '1' then
  260.                   if s_pre_count(0) = '1' then
  261.                     s_det_ff0 <= rxd_i;  
  262.                     s_det_ff1 <= s_det_ff0;
  263.                   end if;
  264.                 else
  265.                   if s_pre_count(1) = '1' then
  266.                     s_det_ff0 <= rxd_i;  
  267.                     s_det_ff1 <= s_det_ff0;                    
  268.                   end if;
  269.                 end if;
  270.               when others =>
  271.                 null;
  272.             end case;
  273.           else
  274.             s_det_ff0 <= '0';
  275.             s_det_ff1 <= '0';              
  276.           end if;
  277.         else                                        -- in all other states
  278.           s_det_ff0 <= '0';
  279.           s_det_ff1 <= '0';
  280.           if s_ren = '1' then                       -- sample for data bits
  281.             case s_mode is
  282.               when ("01") | ("11") => 
  283.                 if smod_i = '1' then
  284.                   if s_pre_count(3 downto 0) = conv_unsigned(7,4) or
  285.                      s_pre_count(3 downto 0) = conv_unsigned(8,4) or
  286.                      s_pre_count(3 downto 0) = conv_unsigned(9,4) then
  287.                     s_rxd_ff0 <= rxd_i;  
  288.                     s_rxd_ff1 <= s_rxd_ff0;
  289.                     s_rxd_ff2 <= s_rxd_ff1;
  290.                   end if;                
  291.                 else
  292.                   if s_pre_count(4 downto 0) = conv_unsigned(14,5) or
  293.                      s_pre_count(4 downto 0) = conv_unsigned(16,5) or
  294.                      s_pre_count(4 downto 0) = conv_unsigned(18,5) then 
  295.                     s_rxd_ff0 <= rxd_i;  
  296.                     s_rxd_ff1 <= s_rxd_ff0;                    
  297.                     s_rxd_ff2 <= s_rxd_ff1;
  298.                   end if;
  299.                 end if;
  300.               when ("10") =>
  301.                 if smod_i = '1' then
  302.                   if s_pre_count(4 downto 0) = conv_unsigned(14,5) or
  303.                      s_pre_count(4 downto 0) = conv_unsigned(16,5) or
  304.                      s_pre_count(4 downto 0) = conv_unsigned(18,5) then 
  305.                     s_rxd_ff0 <= rxd_i;  
  306.                     s_rxd_ff1 <= s_rxd_ff0;
  307.                     s_rxd_ff2 <= s_rxd_ff1;
  308.                   end if;
  309.                 else
  310.                   if s_pre_count(5 downto 0) = conv_unsigned(28,6) or
  311.                      s_pre_count(5 downto 0) = conv_unsigned(32,6) or
  312.                      s_pre_count(5 downto 0) = conv_unsigned(36,6) then
  313.                     s_rxd_ff0 <= rxd_i;  
  314.                     s_rxd_ff1 <= s_rxd_ff0;                    
  315.                     s_rxd_ff2 <= s_rxd_ff1;
  316.                   end if;
  317.                 end if;
  318.               when others =>
  319.                 null;
  320.             end case;
  321.           end if;
  322.         end if;
  323.       end if;
  324.     end if;
  325.   end process p_sample_rx;
  326. -------------------------------------------------------------------------------
  327. --*************************** TRANSMIT ****************************************
  328. -- This is the finit state machine for the transmit shift register
  329. -------------------------------------------------------------------------------
  330.     txd_o <= s_txdm0;
  331.   
  332.   p_transmit : process (clk, reset)
  333.     variable v_txstep : std_logic_vector(1 downto 0);
  334.     
  335.   begin
  336.     
  337.     if reset = '1' then
  338.       s_tran_state <= conv_unsigned(0, 4);
  339.       s_tran_sh    <= conv_unsigned(0, 11);
  340.       s_tran_done  <= '0';
  341.       s_txdm0 <= '1';
  342.       rxd_o   <= '0';
  343.       rxdwr_o <= '0';
  344.     else
  345.       if clk'event and clk = '1' then
  346.         -- Set default behavior
  347.         v_txstep := "00";
  348.         case s_mode is
  349. -------------------------------------------------------------------------------
  350. -- MODE 0
  351. -------------------------------------------------------------------------------
  352.           when ("00") =>
  353.     
  354.             if s_tran_state = conv_unsigned(1, 4) or
  355.               s_tran_state = conv_unsigned(2, 4) or
  356.               s_tran_state = conv_unsigned(3, 4) or
  357.               s_tran_state = conv_unsigned(4, 4) or
  358.               s_tran_state = conv_unsigned(5, 4) or
  359.               s_tran_state = conv_unsigned(6, 4) or
  360.               s_tran_state = conv_unsigned(7, 4) or
  361.               s_tran_state = conv_unsigned(8, 4) or
  362.               s_recv_state = conv_unsigned(1, 4) or
  363.               s_recv_state = conv_unsigned(2, 4) or
  364.               s_recv_state = conv_unsigned(3, 4) or
  365.               s_recv_state = conv_unsigned(4, 4) or
  366.               s_recv_state = conv_unsigned(5, 4) or
  367.               s_recv_state = conv_unsigned(6, 4) or
  368.               s_recv_state = conv_unsigned(7, 4) or
  369.               s_recv_state = conv_unsigned(8, 4) then
  370.               if s_pre_count(3 downto 0) = conv_unsigned(14, 4) or
  371.                 s_pre_count(3 downto 0) = conv_unsigned(6, 4) then
  372.                 s_txdm0 <= not(s_txdm0);
  373.               end if;
  374.             else
  375.               s_txdm0 <= '1';
  376.             end if;
  377.             if s_m0_shift_en = '1' then
  378.               case s_tran_state is
  379.                 when ("0001") =>   -- D1
  380.                   s_tran_sh(10)         <= '1';
  381.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  382.                   v_txstep              := "01";
  383.                   rxd_o                 <= s_tran_sh(1);
  384.                   rxdwr_o <= '1';
  385.                 when ("0010") =>   -- D2
  386.                   s_tran_sh(10)         <= '1';
  387.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  388.                   v_txstep              := "01";
  389.                   rxd_o                 <= s_tran_sh(1);
  390.                   rxdwr_o <= '1';
  391.                 when ("0011") =>   -- D3
  392.                   s_tran_sh(10)         <= '1';
  393.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  394.                   v_txstep              := "01";
  395.                   rxd_o                 <= s_tran_sh(1);
  396.                   rxdwr_o <= '1';
  397.                 when ("0100") =>   -- D4
  398.                   s_tran_sh(10)         <= '1';
  399.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  400.                   v_txstep              := "01";
  401.                   rxd_o                 <= s_tran_sh(1);
  402.                   rxdwr_o <= '1';
  403.                 when ("0101") =>   -- D5
  404.                   s_tran_sh(10)         <= '1';
  405.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  406.                   v_txstep              := "01";
  407.                   rxd_o                 <= s_tran_sh(1);
  408.                   rxdwr_o <= '1';
  409.                 when ("0110") =>   -- D6
  410.                   s_tran_sh(10)         <= '1';
  411.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  412.                   v_txstep              := "01";
  413.                   rxd_o                 <= s_tran_sh(1);
  414.                   rxdwr_o <= '1';
  415.                 when ("0111") =>   -- D7
  416.                   s_tran_sh(10)         <= '1';
  417.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  418.                   v_txstep              := "01";
  419.                   rxd_o                 <= s_tran_sh(1);
  420.                   rxdwr_o <= '1';
  421.                 when ("1000") =>   -- D8, STOP BIT
  422.                   s_tran_sh(10)         <= '1';
  423.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  424.                   s_tran_done           <= '1';
  425.                   v_txstep              := "10";
  426.                   rxd_o                 <= s_tran_sh(1);
  427.                   rxdwr_o <= '1';
  428.                 when others =>   -- D0
  429.                   -- commence transmission if conditions are met
  430.                   if s_trans = '1' then
  431.                     s_tran_sh(10 downto 8) <= conv_unsigned(7, 3);
  432.                     s_tran_sh(7 downto 0)  <= unsigned(sbuf_i);
  433.                     v_txstep               := "01";
  434.                     s_tran_done            <= '0';
  435.                     rxd_o                  <= sbuf_i(0);
  436.                     rxdwr_o <= '1';
  437.                   end if;
  438.               end case;
  439.             end if;
  440. -------------------------------------------------------------------------------
  441. -- MODE 1
  442. -------------------------------------------------------------------------------
  443.           when ("01") =>
  444.             rxdwr_o <= '0';
  445.             rxd_o <= '0';
  446.             case s_tran_state is
  447.               when ("0001") =>   -- D1
  448.                 if s_m13_shift_en = '1' then
  449.                   s_tran_sh(10)         <= '1';
  450.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  451.                   v_txstep              := "01";
  452.                   s_txdm0               <= s_tran_sh(1);
  453.                 end if;
  454.               when ("0010") =>   -- D2
  455.                 if s_m13_shift_en = '1' then
  456.                   s_tran_sh(10)         <= '1';
  457.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  458.                   v_txstep              := "01";
  459.                   s_txdm0               <= s_tran_sh(1);
  460.                 end if;
  461.               when ("0011") =>   -- D3
  462.                 if s_m13_shift_en = '1' then
  463.                   s_tran_sh(10)         <= '1';
  464.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  465.                   v_txstep              := "01";
  466.                   s_txdm0               <= s_tran_sh(1);
  467.                 end if;
  468.               when ("0100") =>   -- D4
  469.                 if s_m13_shift_en = '1' then
  470.                   s_tran_sh(10)         <= '1';
  471.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  472.                   v_txstep              := "01";
  473.                   s_txdm0               <= s_tran_sh(1);
  474.                 end if;
  475.               when ("0101") =>   -- D5
  476.                 if s_m13_shift_en = '1' then
  477.                   s_tran_sh(10)         <= '1';
  478.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  479.                   v_txstep              := "01";
  480.                   s_txdm0               <= s_tran_sh(1);
  481.                 end if;
  482.               when ("0110") =>   -- D6
  483.                 if s_m13_shift_en = '1' then
  484.                   s_tran_sh(10)         <= '1';
  485.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  486.                   v_txstep              := "01";
  487.                   s_txdm0               <= s_tran_sh(1);
  488.                 end if;
  489.               when ("0111") =>   -- D7
  490.                 if s_m13_shift_en = '1' then
  491.                   s_tran_sh(10)         <= '1';
  492.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  493.                   v_txstep              := "01";
  494.                   s_txdm0               <= s_tran_sh(1);
  495.                 end if;
  496.               when ("1000") =>   -- D8
  497.                 if s_m13_shift_en = '1' then
  498.                   s_tran_sh(10)         <= '1';
  499.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  500.                   v_txstep              := "01";
  501.                   s_txdm0               <= s_tran_sh(1);
  502.                 end if;
  503.               when ("1001") =>   -- D9, set done bit
  504.                 if s_m13_shift_en = '1' then
  505.                   s_tran_sh(10)         <= '1';
  506.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  507.                   s_tran_done           <= '1';
  508.                   v_txstep              := "10";
  509.                   s_txdm0               <= s_tran_sh(1);
  510.                 end if;
  511.               when others =>   -- D0
  512.                 -- commence transmission if conditions are met
  513.                 s_txdm0 <= '1';
  514.                 if s_m13_shift_en = '1' then
  515.                   if s_trans = '1' then
  516.                     s_tran_sh(10 downto 9) <= conv_unsigned(3, 2);
  517.                     s_tran_sh(8 downto 1)  <= unsigned(sbuf_i);
  518.                     s_tran_sh(0)           <= '0';
  519.                     v_txstep               := "01";
  520.                     s_tran_done            <= '0';
  521.                     s_txdm0                <= '0';
  522.                   end if;
  523.                 end if;
  524.             end case;
  525. -------------------------------------------------------------------------------
  526. -- MODE 2
  527. -------------------------------------------------------------------------------
  528.           when ("10") =>
  529.             rxdwr_o <= '0';
  530.             rxd_o <= '0';
  531.             case s_tran_state is
  532.               when ("0001") =>   -- D1
  533.                 if s_m2_shift_en = '1' then
  534.                   s_tran_sh(10)         <= '1';
  535.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  536.                   v_txstep              := "01";
  537.                   s_txdm0               <= s_tran_sh(1);
  538.                 end if;
  539.               when ("0010") =>   -- D2
  540.                 if s_m2_shift_en = '1' then
  541.                   s_tran_sh(10)         <= '1';
  542.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  543.                   v_txstep              := "01";
  544.                   s_txdm0               <= s_tran_sh(1);
  545.                 end if;
  546.               when ("0011") =>   -- D3
  547.                 if s_m2_shift_en = '1' then
  548.                   s_tran_sh(10)         <= '1';
  549.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  550.                   v_txstep              := "01";
  551.                   s_txdm0               <= s_tran_sh(1);
  552.                 end if;
  553.               when ("0100") =>   -- D4
  554.                 if s_m2_shift_en = '1' then
  555.                   s_tran_sh(10)         <= '1';
  556.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  557.                   v_txstep              := "01";
  558.                   s_txdm0               <= s_tran_sh(1);
  559.                 end if;
  560.               when ("0101") =>   -- D5
  561.                 if s_m2_shift_en = '1' then
  562.                   s_tran_sh(10)         <= '1';
  563.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  564.                   v_txstep              := "01";
  565.                   s_txdm0               <= s_tran_sh(1);
  566.                 end if;
  567.               when ("0110") =>   -- D6
  568.                 if s_m2_shift_en = '1' then
  569.                   s_tran_sh(10)         <= '1';
  570.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  571.                   v_txstep              := "01";
  572.                   s_txdm0               <= s_tran_sh(1);
  573.                 end if;
  574.               when ("0111") =>   -- D7
  575.                 if s_m2_shift_en = '1' then
  576.                   s_tran_sh(10)         <= '1';
  577.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  578.                   v_txstep              := "01";
  579.                   s_txdm0               <= s_tran_sh(1);
  580.                 end if;
  581.               when ("1000") =>   -- D8
  582.                 if s_m2_shift_en = '1' then
  583.                   s_tran_sh(10)         <= '1';
  584.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  585.                   v_txstep              := "01";
  586.                   s_txdm0               <= s_tran_sh(1);
  587.                 end if;
  588.               when ("1001") =>   -- D9
  589.                 if s_m2_shift_en = '1' then
  590.                   s_tran_sh(10)         <= '1';
  591.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  592.                   v_txstep              := "01";
  593.                   s_txdm0               <= s_tran_sh(1);
  594.                 end if;
  595.               when ("1010") =>   -- D10, set done bit
  596.                 if s_m2_shift_en = '1' then
  597.                   s_tran_sh(10)         <= '1';
  598.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  599.                   s_tran_done           <= '1';
  600.                   v_txstep              := "10";
  601.                   s_txdm0               <= s_tran_sh(1);
  602.                 end if;
  603.               when others =>   -- D0
  604.                 -- commence transmission if conditions are met
  605.                 s_txdm0 <= '1';
  606.                 if s_m2_shift_en = '1' then
  607.                   if s_trans = '1' then
  608.                     s_tran_sh(10)         <= '1';
  609.                     s_tran_sh(9)          <= s_tb8;
  610.                     s_tran_sh(8 downto 1) <= unsigned(sbuf_i);
  611.                     s_tran_sh(0)          <= '0';
  612.                     v_txstep              := "01";
  613.                     s_tran_done           <= '0';
  614.                     s_txdm0               <= '0';
  615.                   end if;
  616.                 end if;
  617.             end case;
  618. -------------------------------------------------------------------------------
  619. -- MODE 3
  620. -------------------------------------------------------------------------------
  621.           when ("11") =>
  622.             rxd_o <= '0';
  623.             rxdwr_o <= '0';
  624.             case s_tran_state is
  625.               when ("0001") =>   -- D1
  626.                 if s_m13_shift_en = '1' then
  627.                   s_tran_sh(10)         <= '1';
  628.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  629.                   v_txstep              := "01";
  630.                   s_txdm0               <= s_tran_sh(1);
  631.                 end if;
  632.               when ("0010") =>   -- D2
  633.                 if s_m13_shift_en = '1' then
  634.                   s_tran_sh(10)         <= '1';
  635.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  636.                   v_txstep              := "01";
  637.                   s_txdm0               <= s_tran_sh(1);
  638.                 end if;
  639.               when ("0011") =>   -- D3
  640.                 if s_m13_shift_en = '1' then
  641.                   s_tran_sh(10)         <= '1';
  642.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  643.                   v_txstep              := "01";
  644.                   s_txdm0               <= s_tran_sh(1);
  645.                 end if;
  646.               when ("0100") =>   -- D4
  647.                 if s_m13_shift_en = '1' then
  648.                   s_tran_sh(10)         <= '1';
  649.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  650.                   v_txstep              := "01";
  651.                   s_txdm0               <= s_tran_sh(1);
  652.                 end if;
  653.               when ("0101") =>   -- D5
  654.                 if s_m13_shift_en = '1' then
  655.                   s_tran_sh(10)         <= '1';
  656.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  657.                   v_txstep              := "01";
  658.                   s_txdm0               <= s_tran_sh(1);
  659.                 end if;
  660.               when ("0110") =>   -- D6
  661.                 if s_m13_shift_en = '1' then
  662.                   s_tran_sh(10)         <= '1';
  663.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  664.                   v_txstep              := "01";
  665.                   s_txdm0               <= s_tran_sh(1);
  666.                 end if;
  667.               when ("0111") =>   -- D7
  668.                 if s_m13_shift_en = '1' then
  669.                   s_tran_sh(10)         <= '1';
  670.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  671.                   v_txstep              := "01";
  672.                   s_txdm0               <= s_tran_sh(1);
  673.                 end if;
  674.               when ("1000") =>   -- D8
  675.                 if s_m13_shift_en = '1' then
  676.                   s_tran_sh(10)         <= '1';
  677.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  678.                   v_txstep              := "01";
  679.                   s_txdm0               <= s_tran_sh(1);
  680.                 end if;
  681.               when ("1001") =>   -- D9
  682.                 if s_m13_shift_en = '1' then
  683.                   s_tran_sh(10)         <= '1';
  684.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  685.                   v_txstep              := "01";
  686.                   s_txdm0               <= s_tran_sh(1);
  687.                 end if;
  688.               when ("1010") =>   -- D10, set done bit
  689.                 if s_m13_shift_en = '1' then
  690.                   s_tran_sh(10)         <= '1';
  691.                   s_tran_sh(9 downto 0) <= s_tran_sh(10 downto 1);
  692.                   s_tran_done           <= '1';
  693.                   v_txstep              := "10";
  694.                   s_txdm0               <= s_tran_sh(1);
  695.                 end if;
  696.               when others =>   -- D0
  697.                 -- commence transmission if conditions are met
  698.                 s_txdm0 <= '1';
  699.                 if s_m13_shift_en = '1' then
  700.                   if s_trans = '1' then
  701.                     s_tran_sh(10)         <= '1';
  702.                     s_tran_sh(9)          <= s_tb8;
  703.                     s_tran_sh(8 downto 1) <= unsigned(sbuf_i);
  704.                     s_tran_sh(0)          <= '0';
  705.                     s_tran_done           <= '0';
  706.                     v_txstep              := "01";
  707.                     s_txdm0               <= '0';
  708.                   end if;
  709.                 end if;
  710.             end case;
  711. -------------------------------------------------------------------------------
  712.           when others =>
  713.             null;
  714.         end case;
  715.         case v_txstep is
  716.           when "01" =>
  717.             s_tran_state <= s_tran_state + conv_unsigned(1, 1);
  718.           when "10" =>
  719.             s_tran_state <= conv_unsigned(0, 4);
  720.           when others =>
  721.             null;
  722.         end case;
  723.         
  724.       end if;
  725.     end if;
  726.   end process p_transmit;
  727. -------------------------------------------------------------------------------
  728. --**************************** RECEIVE ****************************************
  729. -- This is the finit state machine for the receive shift register
  730. -------------------------------------------------------------------------------
  731.       
  732.   p_receive: process (clk,
  733.                       reset)
  734.     
  735.     variable v_rxstep : std_logic_vector(1 downto 0);
  736.     
  737.     begin
  738.       if reset = '1' then
  739.         s_recv_state <= conv_unsigned(0,4);
  740.         s_recv_sh <= conv_unsigned(0,8);
  741.         s_recv_buf <= conv_unsigned(0,8);
  742.         s_recv_done <= '0';
  743.         s_rb8 <= '0';
  744.       else
  745.         if clk'event and clk = '1' then
  746. -------------------------------------------------------------------------------
  747. -- MODE 0
  748. -------------------------------------------------------------------------------
  749.   v_rxstep := "00";
  750.           case s_mode is
  751.           when ("00") =>
  752.             case s_recv_state is
  753.             when ("0000") =>            -- D0
  754.               -- commence reception if conditions are met
  755.               if s_ren = '1' and s_ri = '0' then
  756.                 if s_m0_shift_en = '1' then
  757.                   v_rxstep := "01";
  758.                   s_recv_done <= '0';
  759.                 end if;
  760.               end if;
  761.             when ("0001") =>            -- D1
  762.               if s_m0_shift_en = '1' then
  763.                 s_recv_sh(7) <= rxd_i;
  764. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  765.                 v_rxstep := "01";
  766.               end if;
  767.             when ("0010") =>            -- D2
  768.               if s_m0_shift_en = '1' then
  769.                 s_recv_sh(7) <= rxd_i;
  770. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  771.                 v_rxstep := "01";
  772.               end if;
  773.             when ("0011") =>            -- D3
  774.               if s_m0_shift_en = '1' then
  775.                 s_recv_sh(7) <= rxd_i;
  776. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  777.                 v_rxstep := "01";
  778.               end if;
  779.             when ("0100") =>            -- D4
  780.               if s_m0_shift_en = '1' then
  781.                 s_recv_sh(7) <= rxd_i;
  782. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  783.                 v_rxstep := "01";
  784.               end if;
  785.             when ("0101") =>            -- D5
  786.               if s_m0_shift_en = '1' then
  787.                 s_recv_sh(7) <= rxd_i;
  788. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  789.                 v_rxstep := "01";
  790.               end if;
  791.             when ("0110") =>            -- D6
  792.               if s_m0_shift_en = '1' then
  793.                 s_recv_sh(7) <= rxd_i;
  794. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  795.                 v_rxstep := "01";
  796.               end if;
  797.             when ("0111") =>            -- D6
  798.               if s_m0_shift_en = '1' then
  799.                 s_recv_sh(7) <= rxd_i;
  800. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  801.                 v_rxstep := "01";
  802.               end if;
  803.             when ("1000") =>            -- D7, set bits and store data
  804.               if s_m0_shift_en = '1' then
  805.                 s_recv_sh(7) <= rxd_i;
  806. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  807.                 s_recv_done <= '1';
  808.                 s_recv_buf(7) <= rxd_i;
  809. s_recv_buf(6 downto 0) <= s_recv_sh(7 downto 1);
  810.                 v_rxstep := "10";
  811.               end if;
  812.             when others =>            
  813.                 v_rxstep := "10";
  814.             end case;
  815. -------------------------------------------------------------------------------
  816. -- MODE 1
  817. -------------------------------------------------------------------------------
  818.           when ("01") =>
  819.             case s_recv_state is
  820.             when ("0000") =>            -- synchronise reception
  821.               if s_ren = '1' and s_detect = '1' then
  822.                 v_rxstep := "01";
  823.                 s_recv_sh <= conv_unsigned(0,8);
  824.                 s_recv_done <= '0';
  825.               end if;
  826.             when ("0001") =>            -- D0 = START BIT
  827.               if s_detect = '0' then
  828.                 if s_rxd_val = '0' then
  829.                   if s_m13_shift_en = '1' then
  830.                     s_recv_sh(7) <= s_rxd_val;
  831.     s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  832.                 v_rxstep := "01";
  833.                   end if;
  834.                 else                    -- reject false start bits
  835.                   if s_m13_shift_en = '1' then
  836.                 v_rxstep := "10";                    
  837.                   end if;
  838.                 end if;                  
  839.               end if;
  840.             when ("0010") =>            -- D1
  841.               if s_m13_shift_en = '1' then
  842.                 s_recv_sh(7) <= s_rxd_val;
  843. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  844.                 v_rxstep := "01";
  845.               end if;
  846.             when ("0011") =>            -- D2
  847.               if s_m13_shift_en = '1' then
  848.                 s_recv_sh(7) <= s_rxd_val;
  849. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  850.                 v_rxstep := "01";
  851.               end if;
  852.             when ("0100") =>            -- D3
  853.               if s_m13_shift_en = '1' then
  854.                 s_recv_sh(7) <= s_rxd_val;
  855. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  856.                 v_rxstep := "01";
  857.               end if;
  858.             when ("0101") =>            -- D4
  859.               if s_m13_shift_en = '1' then
  860.                 s_recv_sh(7) <= s_rxd_val;
  861. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  862.                 v_rxstep := "01";
  863.               end if;
  864.             when ("0110") =>            -- D5
  865.               if s_m13_shift_en = '1' then
  866.                 s_recv_sh(7) <= s_rxd_val;
  867. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  868.                 v_rxstep := "01";
  869.               end if;
  870.             when ("0111") =>            -- D6
  871.               if s_m13_shift_en = '1' then
  872.                 s_recv_sh(7) <= s_rxd_val;
  873. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  874.                 v_rxstep := "01";
  875.               end if;
  876.             when ("1000") =>            -- D7
  877.               if s_m13_shift_en = '1' then
  878.                 s_recv_sh(7) <= s_rxd_val;
  879. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  880.                 v_rxstep := "01";
  881.               end if;
  882.             when ("1001") =>            -- D8
  883.               if s_m13_shift_en = '1' then
  884.                 s_recv_sh(7) <= s_rxd_val;
  885. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  886.                 v_rxstep := "01";
  887.               end if;
  888.             when ("1010") =>            -- D9 = STOP BIT
  889.               -- store data and set interrupt bit if conditions are met.
  890.               if (s_ri = '0' and s_sm2 = '0') or
  891.                  (s_ri = '0' and s_rxd_val = '1') then
  892.                 if s_m13_shift_en = '1' then
  893.                   s_recv_sh(7) <= s_rxd_val;
  894.   s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  895.                   v_rxstep := "10";
  896.                   s_recv_done <= '1';
  897.                   s_rb8 <= s_rxd_val;
  898.                   s_recv_buf <= s_recv_sh(7 downto 0);
  899.                 end if;
  900.               -- forget data and recommence listening for a start bit
  901.               else
  902.                 if s_m13_shift_en = '1' then
  903.                 v_rxstep := "10";                  
  904.                 end if;                
  905.               end if;
  906.             when others =>
  907.                 v_rxstep := "10";
  908.             end case;
  909. -------------------------------------------------------------------------------
  910. -- MODE 2
  911. -------------------------------------------------------------------------------
  912.           when ("10") =>
  913.             case s_recv_state is
  914.             when ("0000") =>            -- synchronise reception
  915.               if s_ren = '1' and s_detect = '1' then
  916.                 v_rxstep := "01";
  917.                 s_recv_sh <= conv_unsigned(0,8);
  918.                 s_recv_done <= '0';
  919.               end if;
  920.             when ("0001") =>            -- D0 = START BIT
  921.               if s_rxd_val = '0' then
  922.                 if s_m2_shift_en = '1' then
  923.                   s_recv_sh(7) <= s_rxd_val;
  924.   s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  925.                 v_rxstep := "01";
  926.                 end if;
  927.               else                    -- reject false start bits
  928.                 if s_m2_shift_en = '1' then
  929.                 v_rxstep := "10";                    
  930.                 end if;
  931.               end if;
  932.             when ("0010") =>            -- D1
  933.               if s_m2_shift_en = '1' then
  934.                 s_recv_sh(7) <= s_rxd_val;
  935. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  936.                 v_rxstep := "01";
  937.               end if;
  938.             when ("0011") =>            -- D2
  939.               if s_m2_shift_en = '1' then
  940.                 s_recv_sh(7) <= s_rxd_val;
  941. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  942.                 v_rxstep := "01";
  943.               end if;
  944.             when ("0100") =>            -- D3
  945.               if s_m2_shift_en = '1' then
  946.                 s_recv_sh(7) <= s_rxd_val;
  947. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  948.                 v_rxstep := "01";
  949.               end if;
  950.             when ("0101") =>            -- D4
  951.               if s_m2_shift_en = '1' then
  952.                 s_recv_sh(7) <= s_rxd_val;
  953. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  954.                 v_rxstep := "01";
  955.               end if;
  956.             when ("0110") =>            -- D5
  957.               if s_m2_shift_en = '1' then
  958.                 s_recv_sh(7) <= s_rxd_val;
  959. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  960.                 v_rxstep := "01";
  961.               end if;
  962.             when ("0111") =>            -- D6
  963.               if s_m2_shift_en = '1' then
  964.                 s_recv_sh(7) <= s_rxd_val;
  965. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  966.                 v_rxstep := "01";
  967.               end if;
  968.             when ("1000") =>            -- D7
  969.               if s_m2_shift_en = '1' then
  970.                 s_recv_sh(7) <= s_rxd_val;
  971. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  972.                 v_rxstep := "01";
  973.               end if;
  974.             when ("1001") =>            -- D8
  975.               if s_m2_shift_en = '1' then
  976.                 s_recv_sh(7) <= s_rxd_val;
  977. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  978.                 v_rxstep := "01";
  979.               end if;
  980.             when ("1010") =>            -- D9
  981.               -- store data and set interrupt bit if conditions are met.
  982.               if (s_ri = '0' and s_sm2 = '0') or
  983.                  (s_ri = '0' and s_rxd_val = '1') then
  984.                 if s_m2_shift_en = '1' then
  985.                   s_recv_sh(7) <= s_rxd_val;
  986.   s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  987.                   s_recv_done <= '1';
  988.                   s_rb8 <= s_rxd_val;
  989.                   s_recv_buf <= s_recv_sh(7 downto 0);
  990.                 end if;
  991.               end if;
  992.               -- forget data 
  993.               if s_m2_shift_en = '1' then
  994.                 v_rxstep := "01";
  995.               end if;                
  996.             when ("1011") =>            -- D10 STOP BIT
  997.               -- recommence listening for a start bit
  998.               if s_m2_shift_en = '1' then
  999.                 -- s_recv_state <= conv_unsigned(0,4);
  1000.                 v_rxstep := "10";
  1001.               end if;
  1002.             when others =>
  1003.               -- s_recv_state <= conv_unsigned(0,4);
  1004.                 v_rxstep := "10";
  1005.             end case;
  1006. -------------------------------------------------------------------------------
  1007. -- MODE 3
  1008. -------------------------------------------------------------------------------
  1009.           when ("11") =>
  1010.             case s_recv_state is
  1011.             when ("0000") =>            -- synchronise reception
  1012.               if s_ren = '1' and s_detect = '1' then
  1013.                 v_rxstep := "01";
  1014.                 s_recv_sh <= conv_unsigned(0,8);
  1015.                 s_recv_done <= '0';
  1016.               end if;
  1017.             when ("0001") =>            -- D0 = START BIT
  1018.               if s_rxd_val = '0' then
  1019.                 if s_m13_shift_en = '1' then
  1020.                   s_recv_sh(7) <= s_rxd_val;
  1021.   s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  1022.                 v_rxstep := "01";
  1023.                 end if;
  1024.               else                    -- reject false start bits
  1025.                 if s_m13_shift_en = '1' then
  1026.                 v_rxstep := "10";                    
  1027.                 end if;
  1028.               end if;
  1029.             when ("0010") =>            -- D1
  1030.               if s_m13_shift_en = '1' then
  1031.                 s_recv_sh(7) <= s_rxd_val;
  1032. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  1033.                 v_rxstep := "01";
  1034.               end if;
  1035.             when ("0011") =>            -- D2
  1036.               if s_m13_shift_en = '1' then
  1037.                 s_recv_sh(7) <= s_rxd_val;
  1038. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  1039.                 v_rxstep := "01";
  1040.               end if;
  1041.             when ("0100") =>            -- D3
  1042.               if s_m13_shift_en = '1' then
  1043.                 s_recv_sh(7) <= s_rxd_val;
  1044. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  1045.                 v_rxstep := "01";
  1046.               end if;
  1047.             when ("0101") =>            -- D4
  1048.               if s_m13_shift_en = '1' then
  1049.                 s_recv_sh(7) <= s_rxd_val;
  1050. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  1051.                 v_rxstep := "01";
  1052.               end if;
  1053.             when ("0110") =>            -- D5
  1054.               if s_m13_shift_en = '1' then
  1055.                 s_recv_sh(7) <= s_rxd_val;
  1056. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  1057.                 v_rxstep := "01";
  1058.               end if;
  1059.             when ("0111") =>            -- D6
  1060.               if s_m13_shift_en = '1' then
  1061.                 s_recv_sh(7) <= s_rxd_val;
  1062. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  1063.                 v_rxstep := "01";
  1064.               end if;
  1065.             when ("1000") =>            -- D7
  1066.               if s_m13_shift_en = '1' then
  1067.                 s_recv_sh(7) <= s_rxd_val;
  1068. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  1069.                 v_rxstep := "01";
  1070.               end if;
  1071.             when ("1001") =>            -- D8
  1072.               if s_m13_shift_en = '1' then
  1073.                 s_recv_sh(7) <= s_rxd_val;
  1074. s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  1075.                 v_rxstep := "01";
  1076.               end if;
  1077.             when ("1010") =>            -- D9
  1078.               -- store data and set interrupt bit if conditions are met.
  1079.               if (s_ri = '0' and s_sm2 = '0') or
  1080.                  (s_ri = '0' and s_rxd_val = '1') then
  1081.                 if s_m13_shift_en = '1' then
  1082.                   s_recv_sh(7) <= s_rxd_val;
  1083.   s_recv_sh(6 downto 0) <= s_recv_sh(7 downto 1);
  1084.                   s_recv_done <= '1';
  1085.                   s_rb8 <= s_rxd_val;
  1086.                   s_recv_buf <= s_recv_sh(7 downto 0);
  1087.                 end if;
  1088.               end if;
  1089.               -- forget data 
  1090.               if s_m13_shift_en = '1' then
  1091.                 v_rxstep := "01";
  1092.               end if;                
  1093.             when ("1011") =>            -- D10 STOP BIT
  1094.               -- recommence listening for a start bit
  1095.               if s_m13_shift_en = '1' then
  1096.                 v_rxstep := "10";
  1097.               end if;
  1098.             when others =>
  1099.                 v_rxstep := "10";
  1100.             end case;
  1101.           when others =>
  1102.             null;
  1103.           end case;
  1104.   case v_rxstep is
  1105.     when "01" =>
  1106.       s_recv_state <= s_recv_state + conv_unsigned(1,1);
  1107.     when "10" =>
  1108.       s_recv_state <= conv_unsigned(0,4);
  1109.     when others =>
  1110.       null;
  1111.   end case;
  1112.   
  1113.         end if;
  1114.       end if;
  1115.   end process p_receive;
  1116.   
  1117. end rtl;