Advertisement
alex1232222

Untitled

Dec 12th, 2020
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 8.10 KB | None | 0 0
  1. LIBRARY ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. use ieee.std_logic_unsigned.all;
  5. entity FSM_DMA_C is
  6. port (                         -- r_ - register
  7.     clk         :IN     std_logic;
  8.     r_ready         :IN std_logic; -- 0 ничё не меняется
  9.     r_towork_request    :IN     std_logic;
  10.     r_reset         :IN     std_logic;
  11.     r_command_address   :IN std_logic_vector (0 to 15);
  12.     r_data_in       :IN std_logic_vector (0 to 63);
  13.     r_cs            :OUT    std_logic; --+
  14.     r_address_out       :OUT    std_logic_vector (0 to 15);
  15.     r_data_out      :OUT    std_logic_vector (0 to 63);
  16.     r_command       :OUT    std_logic_vector (0 to 1); -- 01 read , 10 - write
  17.     r_output        :OUT    std_logic_vector (0 to 2));
  18.     end FSM_DMA_C;
  19.  
  20. architecture FSM of FSM_DMA_C IS
  21.     TYPE state_type IS (Idle,Req_Read_INFO_CPU,Req_Read_Com,Read_Com,Req_Read_Info,Read_Info, Write_Info); -- Req - request
  22.    
  23.     signal state            : state_type; --+
  24.     signal r_buff_data      : std_logic_vector (0 to 63);
  25.     signal r_memo_addr_data     : std_logic_vector (0 to 15);
  26.     signal r_memo_com       : std_logic_vector (0 to 63);
  27.     signal count            : std_logic_vector (0 to 11);
  28.     signal r_buff_address_rd    : std_logic_vector (0 to 15);
  29.     signal r_buff_address_wr    : std_logic_vector (0 to 15);
  30.    
  31.     begin
  32.     state_proc:
  33.     process (clk)
  34.     begin
  35.     IF r_reset = '1' then
  36.         state <= Idle;
  37.     ELSIF (rising_edge(clk)) then
  38.         IF (r_ready = '1') then
  39.         state <= state;
  40.         else
  41.             CASE state is
  42.                 when Idle =>
  43.                     IF (r_towork_request = '1') then
  44.                         state <= Req_Read_INFO_CPU;
  45.                     else
  46.                         state <= Idle;
  47.                     end if;
  48.            
  49.                 when Req_Read_INFO_CPU =>
  50.                     state <= Req_Read_Com;
  51.                
  52.                 when Req_Read_Com =>
  53.                     state <= Read_Com;
  54.                
  55.                 when Read_Com =>
  56.                     state <= Req_Read_Info;
  57.                
  58.                 when Req_Read_Info =>
  59.                     state <= Read_Info;
  60.                
  61.                 when Read_Info =>
  62.                     state <= Write_Info;
  63.                
  64.                 when Write_Info =>
  65.                     if (count = x"000") then
  66.                         if r_memo_com(44) = '1' then -- следующая команда
  67.                                 state <= Req_Read_Com;
  68.                         else
  69.                             state <= Idle;
  70.                         end if;
  71.                     else
  72.                         state <= Req_Read_Info;
  73.                     end if;
  74.             end case;   end if;        
  75.     end if;
  76.     end process;
  77.    
  78.  
  79. proces_sig:
  80. Process (state)
  81. begin
  82.     -------------------------------------in_sig----------------------------------------------
  83.     ----------------------------------r_memo_addr_data-----------------------------------------
  84.     IF (r_ready = '1') then
  85.         r_memo_addr_data<= r_memo_addr_data;
  86.     else
  87.     IF (state = Req_Read_INFO_CPU) then
  88.             r_memo_addr_data <= r_command_address ;
  89.     elsif (state = Write_Info) then
  90.                  if (count = x"000") then
  91.             if r_memo_com(44) = '1' then -- следующая команда
  92.                 r_memo_addr_data <= r_memo_com(48 to 63);
  93.             end if;
  94.         else
  95.             r_memo_addr_data<= r_memo_addr_data;
  96.         end if;
  97.     elsif( state = Req_Read_Com or state = Read_Com or state =  Req_Read_Info or state = Read_Info ) then
  98.         r_memo_addr_data <= r_memo_addr_data;
  99.          
  100.     elsif (state =  Idle ) then
  101.         r_memo_addr_data <= x"0000";
  102.     end if;
  103.     end if;
  104.    
  105.    
  106.     -------------------------------------r_buff_data---------------------------------------
  107.    
  108.     IF (r_ready = '1') then
  109.         r_buff_data <= r_buff_data;
  110.     else
  111.     IF ( state =  Req_Read_Com or state = Req_Read_INFO_CPU or state = Read_Com
  112.     or state = Req_Read_Info or state = Write_Info) then
  113.         r_buff_data <= r_buff_data;
  114.     elsif (state = Read_Info) then
  115.         r_buff_data <= r_data_in;
  116.     elsif (state = Idle) then
  117.         r_buff_data <= x"0000000000000000";
  118.     end if;
  119.     end if;
  120.    
  121.    
  122.     ----------------------------------r_memo_com-----------------------------------------
  123.     IF (r_ready = '1') then
  124.         r_memo_com <= r_memo_com;
  125.     else
  126.     IF (state = Req_Read_Com or state = Req_Read_INFO_CPU or state = Req_Read_Info or state = Read_Info or state = Write_Info) then
  127.         r_memo_com <= r_memo_com;
  128.     elsif (state = Read_Com) then
  129.         r_memo_com <= r_data_in;
  130.     elsif (state = Idle) then
  131.         r_memo_com <= x"0000000000000000";
  132.     end if;
  133.     end if;
  134.    
  135.    
  136.     ----------------------------------r_count-------------------------------------------
  137.     IF (r_ready = '1') then
  138.         count <= count;
  139.     else
  140.         if (state = Idle or state = Req_Read_Com) then
  141.             count <= x"000";
  142.         elsif (state = Req_Read_INFO_CPU  or state = Read_Info or state = Write_Info or state = Read_Com) then
  143.             count <= count;
  144.         elsif (state = Req_Read_Info) then
  145.             if (count = x"000") then
  146.             count <= r_memo_com(32 to 43);
  147.         else
  148.             count <= count - 1;
  149.         end if;
  150.     end if;
  151.     end if;
  152.    
  153.    
  154.     -------------------------------r_buff_address_rd----------------------------------------
  155.     IF (r_ready = '1') then
  156.         r_buff_address_rd <= r_buff_address_rd;
  157.     else
  158.         if (state = Idle) then
  159.             r_buff_address_rd <= x"0000";
  160.         elsif (state = Req_Read_Com or state = Req_Read_INFO_CPU or state = Write_Info or state = Read_Com) then
  161.             r_buff_address_rd <= r_buff_address_rd;
  162.         elsif (state = Req_Read_Info) then
  163.             if count = x"000" then
  164.                 r_buff_address_rd <= r_memo_com(0 to 15);
  165.             else
  166.                 r_buff_address_rd <= r_buff_address_rd;
  167.             end if;
  168.         elsif (state = Read_Info) then
  169.             r_buff_address_rd <= r_buff_address_rd + '1';
  170.     end if;
  171.     end if;
  172.    
  173.    
  174.     -------------------------------r_buff_adress_wr----------------------------------------
  175.     IF (r_ready = '1') then
  176.         r_buff_address_wr <= r_buff_address_wr;
  177.     else
  178.         if (state = Idle) then
  179.             r_buff_address_wr <= x"0000";
  180.     elsif (state = Req_Read_Com or state = Req_Read_INFO_CPU  or state = Read_Info or state = Write_Info or state = Read_Com) then
  181.             r_buff_address_wr <= r_buff_address_wr;
  182.         elsif (state = Req_Read_Info) then
  183.             if count = x"000" then
  184.             r_buff_address_wr <= r_memo_com(16 to 31);
  185.         else
  186.             r_buff_address_wr <= r_buff_address_wr + '1';
  187.         end if;
  188.     end if;
  189.     end if;
  190.     -------------------------------------out_sig-----------------------------------------
  191.     ---------------------------------------r_csl-------------------------------------------
  192.     IF (state = Idle or state = Req_Read_INFO_CPU) then --or state = Read_Com or state = Read_Info) then
  193.         r_cs <= '1';
  194.     elsif (state = Req_Read_Com or state = Req_Read_Com or state = Write_Info or state = Read_Com or state = Read_Info) then
  195.         r_cs <= '0';
  196.     end if;
  197.    
  198.     ------------------------------------r_comand------------------------------------------
  199.     if r_ready = '1' then
  200.         r_command <= "00";
  201.     else
  202.     IF (state = Req_Read_Com or state = Req_Read_Info) then
  203.         r_command <= "01";
  204.     elsif (state = Write_Info) then
  205.         r_command <= "10";
  206.     elsif (state = Idle or state = Read_Com or state = Req_Read_INFO_CPU or state = Read_Info) then
  207.         r_command <= "00";
  208.     end if;
  209.     end if;
  210.    
  211.    
  212.     ------------------------------------r_data_out------------------------------------------
  213.     IF (r_ready = '1') then
  214.         r_data_out <= x"0000000000000000";
  215.     else
  216.     IF (state = Write_Info) then
  217.         r_data_out <= r_buff_data;
  218.     elsif(state = Idle or  state = Req_Read_INFO_CPU or state =  Req_Read_Com or state = Read_Com or state =  Req_Read_Info or state = Read_Info) then
  219.         r_data_out <= x"0000000000000000";
  220.     end if;
  221.     end if;
  222.    
  223.    
  224.     ------------------------------------r_adress_out--------------------------------------------
  225.     IF (r_ready = '1') then
  226.         r_address_out <= x"0000";
  227.     else
  228.     IF (state = Idle or state = Req_Read_INFO_CPU or state = Read_Com or state = Read_Info) then
  229.         r_address_out <= x"0000";
  230.     elsif (state = Req_Read_Com) then
  231.         r_address_out <= r_memo_addr_data;
  232.     elsif (state =  Req_Read_Info ) then
  233.         if (count = x"000") then
  234.             r_address_out <= r_memo_com(0 to 15);
  235.         else
  236.             r_address_out <= r_buff_address_rd;
  237.         end if;
  238.     elsif (state = Write_Info) then
  239.         r_address_out <= r_buff_address_wr;
  240.     end if;
  241.     end if;
  242.    
  243.     -------------------------------------------------------------------------------------------------------
  244.    
  245. end process;
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253. out_proces_state:
  254. PROCESS (state)
  255. begin
  256.     case state is
  257.         when Idle =>
  258.             r_output <= "000";
  259.         when Req_Read_INFO_CPU =>
  260.             r_output <= "001";
  261.         when Req_Read_Com =>
  262.             r_output <= "010";
  263.         when Read_Com =>
  264.             r_output <= "011";
  265.         when Req_Read_Info =>
  266.             r_output <= "100";
  267.         when Read_Info =>
  268.             r_output <= "101";
  269.         when Write_Info =>
  270.             r_output <= "110";
  271.         end case;
  272. end process;
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280. end FSM;
  281.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement