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

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:               alumux_rtl.vhd
  51. --
  52. --         Date of Creation:       Mon Aug  9 12:14:48 1999
  53. --
  54. --         Version:                $Revision: 1.6 $
  55. --
  56. --         Date of Latest Version: $Date: 2002/01/07 12:17:44 $
  57. --
  58. --
  59. --         Description: Select data path according to the actual command.
  60. --
  61. --
  62. --
  63. --
  64. -------------------------------------------------------------------------------
  65. architecture rtl of alumux is
  66.   constant DA             : std_logic_vector(5 downto 0) := "100000";
  67.   constant ADD_ACC_RAM    : std_logic_vector(5 downto 0) := "100001";
  68.   constant ADD_ACC_ROM    : std_logic_vector(5 downto 0) := "100010";
  69.   constant ADDC_ACC_RAM   : std_logic_vector(5 downto 0) := "100011";
  70.   constant ADDC_ACC_ROM   : std_logic_vector(5 downto 0) := "100100";
  71.   constant AND_ACC_RAM    : std_logic_vector(5 downto 0) := "100101";
  72.   constant AND_ACC_ROM    : std_logic_vector(5 downto 0) := "100110";
  73.   constant AND_RAM_ROM    : std_logic_vector(5 downto 0) := "100111";
  74.   constant SUB_ACC_RAM    : std_logic_vector(5 downto 0) := "101000";
  75.   constant SUB_ACC_ROM    : std_logic_vector(5 downto 0) := "101001";
  76.   constant MUL_ACC_RAM    : std_logic_vector(5 downto 0) := "101010";
  77.   constant DIV_ACC_RAM    : std_logic_vector(5 downto 0) := "101011";
  78.   constant OR_RAM_ACC     : std_logic_vector(5 downto 0) := "101100";
  79.   constant OR_ROM_ACC     : std_logic_vector(5 downto 0) := "101101";
  80.   constant OR_ROM_RAM     : std_logic_vector(5 downto 0) := "101110";
  81.   constant XOR_RAM_ACC    : std_logic_vector(5 downto 0) := "101111";
  82.   constant XOR_ROM_ACC    : std_logic_vector(5 downto 0) := "110000";
  83.   constant XOR_ROM_RAM    : std_logic_vector(5 downto 0) := "110001";
  84.   constant RL_ACC         : std_logic_vector(5 downto 0) := "110010";
  85.   constant RLC_ACC        : std_logic_vector(5 downto 0) := "110011";
  86.   constant RR_ACC         : std_logic_vector(5 downto 0) := "110100";
  87.   constant RRC_ACC        : std_logic_vector(5 downto 0) := "110101";
  88.   constant INV_ACC        : std_logic_vector(5 downto 0) := "110110";
  89.   constant INV_RAM        : std_logic_vector(5 downto 0) := "110111";
  90.   constant DEC_ACC        : std_logic_vector(5 downto 0) := "111000";
  91.   constant DEC_RAM        : std_logic_vector(5 downto 0) := "111001";
  92.   constant COMP_RAM_ACC   : std_logic_vector(5 downto 0) := "111010";
  93.   constant COMP_ROM_ACC   : std_logic_vector(5 downto 0) := "111011";
  94.   constant COMP_ROM_RAM   : std_logic_vector(5 downto 0) := "111100";
  95.   constant INC_ACC        : std_logic_vector(5 downto 0) := "111110";
  96.   constant INC_RAM        : std_logic_vector(5 downto 0) := "111111";
  97.   constant NOP  : std_logic_vector(3 downto 0) := "0000";
  98.   constant LAND : std_logic_vector(3 downto 0) := "0011";
  99.   constant LOR  : std_logic_vector(3 downto 0) := "0101";
  100.   constant LXOR : std_logic_vector(3 downto 0) := "0110";
  101.   constant RL   : std_logic_vector(3 downto 0) := "0111";
  102.   constant RLC  : std_logic_vector(3 downto 0) := "1000";
  103.   constant RR   : std_logic_vector(3 downto 0) := "1001";
  104.   constant RRC  : std_logic_vector(3 downto 0) := "1010";
  105.   constant COMP : std_logic_vector(3 downto 0) := "1011";
  106.   constant INV  : std_logic_vector(3 downto 0) := "1100";
  107. begin
  108.   -- Multiplex the input data and generate the command for the alu core.
  109.   p_alucore_mux : process (rom_data_i,
  110.                            ram_data_i,
  111.                            acc_i,     
  112.                            cmd_i)
  113.   begin
  114.     case cmd_i is
  115.        when AND_ACC_RAM   =>
  116.          alu_cmd_o <= LAND;
  117.          op_a_o    <= acc_i;
  118.          op_b_o    <= ram_data_i;
  119.        when AND_ACC_ROM   =>
  120.          alu_cmd_o <= LAND;
  121.          op_a_o    <= acc_i;
  122.          op_b_o    <= rom_data_i;
  123.        when AND_RAM_ROM   =>
  124.          alu_cmd_o <= LAND;
  125.          op_a_o    <= ram_data_i;
  126.          op_b_o    <= rom_data_i;
  127.        when OR_RAM_ACC    =>
  128.          alu_cmd_o <= LOR;
  129.          op_a_o    <= acc_i;
  130.          op_b_o    <= ram_data_i;
  131.        when OR_ROM_ACC    =>
  132.          alu_cmd_o <= LOR;
  133.          op_a_o    <= acc_i;
  134.          op_b_o    <= rom_data_i;
  135.        when OR_ROM_RAM    =>
  136.          alu_cmd_o <= LOR;
  137.          op_a_o    <= rom_data_i;
  138.          op_b_o    <= ram_data_i;
  139.        when XOR_RAM_ACC   =>
  140.          alu_cmd_o <= LXOR;
  141.          op_a_o    <= acc_i;
  142.          op_b_o    <= ram_data_i;
  143.        when XOR_ROM_ACC   =>
  144.          alu_cmd_o <= LXOR;
  145.          op_a_o    <= acc_i;
  146.          op_b_o    <= rom_data_i;
  147.        when XOR_ROM_RAM   =>
  148.          alu_cmd_o <= LXOR;
  149.          op_a_o    <= rom_data_i;
  150.          op_b_o    <= ram_data_i;
  151.        when RL_ACC        =>
  152.          alu_cmd_o <= RL;
  153.          op_a_o    <= acc_i;
  154.          op_b_o    <= ( others => '0' );
  155.        when RLC_ACC       =>
  156.          alu_cmd_o <= RLC;
  157.          op_a_o    <= acc_i;
  158.          op_b_o    <= ( others => '0' );
  159.        when RR_ACC        =>
  160.          alu_cmd_o <= RR;
  161.          op_a_o    <= acc_i;
  162.          op_b_o    <= ( others => '0' );
  163.        when RRC_ACC       =>          
  164.          alu_cmd_o <= RRC;            
  165.          op_a_o    <= acc_i;          
  166.          op_b_o    <= ( others => '0' );
  167.        when INV_ACC       =>          
  168.          alu_cmd_o <= INV;            
  169.          op_a_o    <= acc_i;          
  170.          op_b_o    <= ( others => '0' );
  171.        when INV_RAM       =>          
  172.          alu_cmd_o <= INV;            
  173.          op_a_o    <= ram_data_i;     
  174.          op_b_o    <= ( others => '0' );
  175.        when COMP_RAM_ACC  =>          
  176.          alu_cmd_o <= COMP;           
  177.          op_a_o    <= acc_i;          
  178.          op_b_o    <= ram_data_i;     
  179.        when COMP_ROM_ACC  =>          
  180.          alu_cmd_o <= COMP;           
  181.          op_a_o    <= acc_i;          
  182.          op_b_o    <= rom_data_i;     
  183.        when COMP_ROM_RAM  =>          
  184.          alu_cmd_o <= COMP;           
  185.          op_a_o    <= ram_data_i;     
  186.          op_b_o    <= rom_data_i;     
  187.        when others        =>          
  188.          alu_cmd_o <= NOP;            
  189.          op_a_o    <= ( others => '0' );
  190.          op_b_o    <= ( others => '0' );
  191.     end case;
  192.   end process p_alucore_mux;
  193.   -- Multiplex the input data for all the functions not included in the
  194.   -- alu core.
  195.   p_ext_mux : process (ram_data_i,
  196.                        rom_data_i,
  197.                        acc_i,
  198.        cy_i,
  199.                        cmd_i)
  200.   begin
  201.     case cmd_i is
  202.        when DA =>
  203.          dcml_data_o <= acc_i;
  204.          mltplcnd_o  <= ( others => '0' );
  205.          mltplctr_o  <= ( others => '0' );
  206.          dvdnd_o     <= ( others => '0' );
  207.          dvsor_o     <= ( others => '0' );
  208.          addsub_o    <= '0';
  209.          addsub_cy_o <= '0';
  210.          opa_o       <= ( others => '0' );
  211.          opb_o       <= ( others => '0' );
  212.        when DIV_ACC_RAM =>
  213.          dcml_data_o <= ( others => '0' );
  214.          mltplcnd_o  <= ( others => '0' );
  215.          mltplctr_o  <= ( others => '0' );
  216.          dvdnd_o     <= acc_i;
  217.          dvsor_o     <= ram_data_i;
  218.          addsub_o    <= '0';
  219.          addsub_cy_o <= '0';
  220.          opa_o       <= ( others => '0' );
  221.          opb_o       <= ( others => '0' );
  222.        when MUL_ACC_RAM =>
  223.          dcml_data_o <= ( others => '0' );
  224.          mltplcnd_o  <= acc_i;
  225.          mltplctr_o  <= ram_data_i;
  226.          dvdnd_o     <= ( others => '0' );
  227.          dvsor_o     <= ( others => '0' );
  228.          addsub_o    <= '0';
  229.          addsub_cy_o <= '0';
  230.          opa_o       <= ( others => '0' );
  231.          opb_o       <= ( others => '0' );
  232.        when INC_ACC =>
  233.          dcml_data_o <= ( others => '0' );
  234.          mltplcnd_o  <= ( others => '0' );
  235.          mltplctr_o  <= ( others => '0' );
  236.          dvdnd_o     <= ( others => '0' );
  237.          dvsor_o     <= ( others => '0' );
  238.          addsub_o    <= '1';
  239.          addsub_cy_o <= '0';
  240.          opa_o       <= acc_i;
  241.          opb_o       <= std_logic_vector(conv_unsigned(1, DWIDTH));
  242.        when INC_RAM =>
  243.          dcml_data_o <= ( others => '0' );
  244.          mltplcnd_o  <= ( others => '0' );
  245.          mltplctr_o  <= ( others => '0' );
  246.          dvdnd_o     <= ( others => '0' );
  247.          dvsor_o     <= ( others => '0' );
  248.          addsub_o    <= '1';
  249.          addsub_cy_o <= '0';
  250.          opa_o       <= ram_data_i;
  251.          opb_o       <= std_logic_vector(conv_unsigned(1, DWIDTH));
  252.        when DEC_ACC =>
  253.          dcml_data_o <= ( others => '0' );
  254.          mltplcnd_o  <= ( others => '0' );
  255.          mltplctr_o  <= ( others => '0' );
  256.          dvdnd_o     <= ( others => '0' );
  257.          dvsor_o     <= ( others => '0' );
  258.          addsub_o    <= '0';
  259.          addsub_cy_o <= '0';
  260.          opa_o       <= acc_i;
  261.          opb_o       <= std_logic_vector(conv_unsigned(1, DWIDTH));
  262.        when DEC_RAM =>
  263.          dcml_data_o <= ( others => '0' );
  264.          mltplcnd_o  <= ( others => '0' );
  265.          mltplctr_o  <= ( others => '0' );
  266.          dvdnd_o     <= ( others => '0' );
  267.          dvsor_o     <= ( others => '0' );
  268.          addsub_o    <= '0';
  269.          addsub_cy_o <= '0';
  270.          opa_o       <= ram_data_i;
  271.          opb_o       <= std_logic_vector(conv_unsigned(1, DWIDTH));
  272.        when SUB_ACC_RAM =>
  273.          dcml_data_o <= ( others => '0' );
  274.          mltplcnd_o  <= ( others => '0' );
  275.          mltplctr_o  <= ( others => '0' );
  276.          dvdnd_o     <= ( others => '0' );
  277.          dvsor_o     <= ( others => '0' );
  278.          addsub_o    <= '0';
  279.          addsub_cy_o <= cy_i((DWIDTH-1)/4);
  280.          opa_o       <= acc_i;
  281.          opb_o       <= ram_data_i;
  282.        when SUB_ACC_ROM =>
  283.          dcml_data_o <= ( others => '0' );
  284.          mltplcnd_o  <= ( others => '0' );
  285.          mltplctr_o  <= ( others => '0' );
  286.          dvdnd_o     <= ( others => '0' );
  287.          dvsor_o     <= ( others => '0' );
  288.          addsub_o    <= '0';
  289.          addsub_cy_o <= cy_i((DWIDTH-1)/4);
  290.          opa_o       <= acc_i;
  291.          opb_o       <= rom_data_i;
  292.        when ADD_ACC_RAM =>
  293.          dcml_data_o <= ( others => '0' );
  294.          mltplcnd_o  <= ( others => '0' );
  295.          mltplctr_o  <= ( others => '0' );
  296.          dvdnd_o     <= ( others => '0' );
  297.          dvsor_o     <= ( others => '0' );
  298.          addsub_o    <= '1';
  299.          addsub_cy_o <= '0';
  300.          opa_o       <= acc_i;
  301.          opb_o       <= ram_data_i;
  302.        when ADD_ACC_ROM =>
  303.          dcml_data_o <= ( others => '0' );
  304.          mltplcnd_o  <= ( others => '0' );
  305.          mltplctr_o  <= ( others => '0' );
  306.          dvdnd_o     <= ( others => '0' );
  307.          dvsor_o     <= ( others => '0' );
  308.          addsub_o    <= '1';
  309.          addsub_cy_o <= '0';
  310.          opa_o       <= acc_i;
  311.          opb_o       <= rom_data_i;
  312.        when ADDC_ACC_RAM =>
  313.          dcml_data_o <= ( others => '0' );
  314.          mltplcnd_o  <= ( others => '0' );
  315.          mltplctr_o  <= ( others => '0' );
  316.          dvdnd_o     <= ( others => '0' );
  317.          dvsor_o     <= ( others => '0' );
  318.          addsub_o    <= '1';
  319.          addsub_cy_o <= cy_i((DWIDTH-1)/4);
  320.          opa_o       <= acc_i;
  321.          opb_o       <= ram_data_i;
  322.        when ADDC_ACC_ROM =>
  323.          dcml_data_o <= ( others => '0' );
  324.          mltplcnd_o  <= ( others => '0' );
  325.          mltplctr_o  <= ( others => '0' );
  326.          dvdnd_o     <= ( others => '0' );
  327.          dvsor_o     <= ( others => '0' );
  328.          addsub_o    <= '1';
  329.          addsub_cy_o <= cy_i((DWIDTH-1)/4);
  330.          opa_o       <= acc_i;
  331.          opb_o       <= rom_data_i;
  332.        when others =>
  333.          dcml_data_o <= ( others => '0' );
  334.          mltplcnd_o  <= ( others => '0' );
  335.          mltplctr_o  <= ( others => '0' );
  336.          dvdnd_o     <= ( others => '0' );
  337.          dvsor_o     <= ( others => '0' );
  338.          addsub_o    <= '0';
  339.          addsub_cy_o <= '0';
  340.          opa_o       <= ( others => '0' );
  341.          opb_o       <= ( others => '0' );
  342.     end case;
  343.   end process p_ext_mux;
  344.   -- Multiplex the results for all the units contributing to the ALU.
  345.   p_rslt_mux : process (ram_data_i,
  346.                         cy_i,
  347.                         ov_i,
  348.                         product_i,
  349.                         qutnt_i,
  350.                         rmndr_i,
  351.                         result_i,
  352.                         new_cy_i,
  353. addsub_rslt_i,
  354. addsub_cy_i,
  355. addsub_ov_i,
  356.                         dcml_data_i,
  357.                         dcml_cy_i,
  358.                         cmd_i)
  359.   begin
  360.     case cmd_i is
  361.        when DA          =>
  362.  if (C_IMPL_DA /= 0) then
  363.            result_a_o         <= dcml_data_i;
  364.            result_b_o         <= ( others => '0' );
  365.            cy_o               <= cy_i;
  366.            cy_o((DWIDTH-1)/4) <= dcml_cy_i;
  367.            ov_o               <= ov_i;
  368.  else  
  369.            result_a_o         <= ( others => '0' );
  370.            result_b_o         <= ( others => '0' );
  371.            cy_o               <= conv_std_logic_vector(0,(DWIDTH-1)/4+1);
  372.            ov_o               <= '0';
  373.  end if;
  374.        when DIV_ACC_RAM =>
  375.  if (C_IMPL_DIV /= 0) then
  376.            result_a_o         <= qutnt_i;
  377.            result_b_o         <= rmndr_i;
  378.            cy_o               <= conv_std_logic_vector(0,(DWIDTH-1)/4+1);
  379.            if ram_data_i = conv_std_logic_vector(0,DWIDTH) then
  380.              ov_o             <= '1';
  381.            else
  382.              ov_o             <= '0';
  383.            end if;
  384.  else
  385.            result_a_o         <= ( others => '0' );
  386.            result_b_o         <= ( others => '0' );
  387.            cy_o               <= conv_std_logic_vector(0,(DWIDTH-1)/4+1);
  388.    ov_o               <= '0';
  389.  end if;
  390.        when MUL_ACC_RAM =>
  391.  if (C_IMPL_MUL /= 0) then
  392.            result_a_o         <= product_i(DWIDTH-1 downto 0);
  393.            result_b_o         <= product_i(DWIDTH*2-1 downto DWIDTH);
  394.            cy_o               <= conv_std_logic_vector(0,(DWIDTH-1)/4+1);
  395.            if product_i(DWIDTH*2-1 downto DWIDTH)
  396.                = conv_std_logic_vector(0, DWIDTH) then
  397.              ov_o             <= '0';
  398.            else
  399.              ov_o             <= '1';
  400.            end if;
  401.  else
  402.            result_a_o         <= ( others => '0' );
  403.            result_b_o         <= ( others => '0' );
  404.            cy_o               <= conv_std_logic_vector(0,(DWIDTH-1)/4+1);
  405.            ov_o               <= '0';
  406.  end if;
  407.        when SUB_ACC_RAM | SUB_ACC_ROM | ADD_ACC_RAM | ADD_ACC_ROM |
  408.     ADDC_ACC_RAM | ADDC_ACC_ROM  =>
  409.          result_a_o         <= addsub_rslt_i;
  410.          result_b_o         <= ( others => '0' );
  411.          cy_o               <= addsub_cy_i;
  412.          ov_o               <= addsub_ov_i;
  413.        when INC_ACC | INC_RAM | DEC_ACC | DEC_RAM =>
  414.          result_a_o         <= addsub_rslt_i;
  415.          result_b_o         <= ( others => '0' );
  416.          cy_o               <= cy_i;
  417.          ov_o               <= addsub_ov_i;  
  418.        when others      =>
  419.          result_a_o         <= result_i;
  420.          result_b_o         <= ( others => '0' );
  421.          cy_o               <= new_cy_i;
  422.          ov_o               <= ov_i;
  423.     end case;
  424.   end process p_rslt_mux;
  425. end rtl;